Skip to content

Commit

Permalink
All the unit tests working again
Browse files Browse the repository at this point in the history
Signed-off-by: Sourav Moitra <[email protected]>
  • Loading branch information
xw19 committed Jan 19, 2025
1 parent cc3b7ef commit 7cf8461
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/ocispec/json_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ gen_json_map_string_string (json_object *root, const json_map_string_string *map
if (JSON_GEN_SUCCESS != stat)
GEN_SET_ERROR_AND_RETURN (stat, err);
}
// printf(">X> \n%s\n", json_object_to_json_string_ext(root, JSON_C_TO_STRING_NOSLASHESCAPE | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_PRETTY_TAB));
return JSON_GEN_SUCCESS;
}

Expand Down
22 changes: 12 additions & 10 deletions src/ocispec/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ def parse_obj_type_array(obj, c_file, prefix, obj_typename):
c_file.append(f' ret->{obj.fixname}_item_lens = calloc ( len + 1, sizeof (size_t));\n')
c_file.append(f' if (ret->{obj.fixname}_item_lens == NULL)\n')
c_file.append(' return NULL;\n')
c_file.append(' for(int i = 0; i < len; i++)\n')
c_file.append(' for(size_t i = 0; i < len; i++)\n')
c_file.append(' {\n')
c_file.append(' json_object *value = json_object_array_get_idx(tmp, i);\n')
if obj.doublearray:
c_file.append(' int rec_len = json_object_array_length(value);\n')
c_file.append(f' ret->{obj.fixname}[i] = calloc ( json_object_array_length(value) + 1, sizeof (**ret->{obj.fixname}));\n')
c_file.append(f' if (ret->{obj.fixname}[i] == NULL)\n')
c_file.append(' return NULL;\n')
c_file.append(' for(int j = 0; j < rec_len; i++)\n')
c_file.append(' for(size_t j = 0; j < rec_len; j++)\n')
c_file.append(' {\n')
c_file.append(' json_object *rec_value = json_object_array_get_idx(value, j);\n\n')
read_val_generator(c_file, 5, 'rec_value', \
Expand Down Expand Up @@ -632,10 +632,10 @@ def read_val_generator(c_file, level, src, dest, typ, keyname, obj_typename):
c_file.append(f"{' ' * (level + 1)} return NULL;\n")
c_file.append(f'{" " * (level + 1)} }}\n')
c_file.append(f'{" " * (level + 1)}{dest} = json_object_get_uint64(val);\n')
c_file.append(f'{" " * (level + 1)}}}\n')
# c_file.append(f'{" " * (level + 1)}}}\n')
if '[' not in dest:
c_file.append(f"{' ' * (level + 1)}{dest}_present = 1;\n")
# c_file.append(f'{" " * (level)}}}\n')
c_file.append(f'{" " * (level)}}}\n')
elif helpers.judge_data_pointer_type(typ):
num_type = helpers.obtain_data_pointer_type(typ)
if num_type == "":
Expand Down Expand Up @@ -1467,8 +1467,9 @@ def get_c_epilog(c_file, prefix, typ, obj):
f"\n {typename} * " +
f"{typename}_parse_data (const char *jsondata, const struct parser_context *ctx, parser_error *err)\n {{ \n" +
f" {typename} *ptr = NULL;\n" +
"""\t__auto_cleanup(json_object_put) json_object *tree = NULL;
"""\t//__auto_cleanup(json_object_put)\n\tjson_object *tree = NULL;
enum json_tokener_error *error;
struct json_tokener *tok = json_tokener_new();
struct parser_context tmp_ctx = { 0 };
if (jsondata == NULL || err == NULL)
Expand All @@ -1478,10 +1479,11 @@ def get_c_epilog(c_file, prefix, typ, obj):
if (ctx == NULL)
ctx = (const struct parser_context *)(&tmp_ctx);
tree = json_tokener_parse (jsondata);
tree = json_tokener_parse_ex (tok, jsondata, strlen(jsondata));
if (tree == NULL)
{
if (asprintf (err, "cannot parse the data: %s", "TODO") < 0)
enum json_tokener_error e = json_tokener_get_error(tok);
if (asprintf (err, "cannot parse the data: %s", json_tokener_error_desc(e)) < 0)
*err = strdup ("error allocating memory");
return NULL;
}\n""" +
Expand All @@ -1493,22 +1495,22 @@ def get_c_epilog(c_file, prefix, typ, obj):
f"{typename}_generate_json (const {typename} *ptr, parser_error *err)" +
"""{
""" +
f" __auto_cleanup(json_object_put) json_object *root = json_object_new_{typ}();" +
f" //__auto_cleanup(json_object_put)\n\tjson_object *root = json_object_new_{typ}();" +
"""
if (ptr == NULL || err == NULL)
return NULL;
*err = NULL;
""" +
f"if (JSON_GEN_FAILED == gen_{typename} (root, ptr, err))" +
f"\tif (JSON_GEN_FAILED == gen_{typename} (root, ptr, err))" +
""" {
if (*err == NULL)
*err = strdup ("Failed to generate json");
return NULL;
}
char *json_str = (char *)json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY);
char *json_str = (char *)json_object_to_json_string_ext(root, JSON_C_TO_STRING_NOSLASHESCAPE | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);
return json_str;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ main ()
exit (1);
}
container_gen = runtime_spec_schema_config_schema_parse_data(json_buf, 0, &err);
if (container == NULL) {
if (container_gen == NULL) {
printf ("parse error %s\n", err);
exit (1);
}
Expand All @@ -56,7 +56,7 @@ main ()
if (!container->process->terminal_present)
exit (53);
if (!container->process->user->uid_present || container_gen->process->user->gid_present)
exit (6);
exit (65);
if (strcmp (container->process->args[0], "ARGS1") && strcmp (container->process->args[0], container_gen->process->args[0]))
exit (61);
if (container->process->rlimits[0]->hard != hard_limit)
Expand Down

0 comments on commit 7cf8461

Please sign in to comment.