- /* Block Definition */
- if (!json_object_object_get_ex(root_obj, "block", &block_obj)) {
- fprintf(stderr, "block isn't defined\n");
- goto pro_end;
- }
-
- /* Type Definition */
- if (!json_object_object_get_ex(root_obj, "type", &type_obj)) {
- fprintf(stderr, "type isn't defined\n");
- goto pro_end;
- }
-
- /* Enumulate test items */
- if (!json_object_object_get_ex(root_obj, "tests", &tests_obj)) {
- fprintf(stderr, "tests are empty\n");
- goto pro_end;
- }
-
- length = json_object_array_length(tests_obj);
-
- items = malloc(sizeof(struct ras_test_item) * length);
- if (!items) {
- fprintf(stderr, "malloc failed\n");
- goto pro_end;
- }
-
- for (i = 0; i < length; i++) {
- test_obj = json_object_array_get_idx(tests_obj, i);
-
- /* Name */
- if (!json_object_object_get_ex(test_obj, "name", &tmp_obj)) {
- fprintf(stderr, "Test %d has no name\n", i);
- goto pro_end;
- }
- strncpy(items[i].name, json_object_get_string(tmp_obj), 64);
-
- /* block */
- if (!json_object_object_get_ex(test_obj, "block", &tmp_obj)) {
- fprintf(stderr, "Test:%s: block isn't defined\n",
- items[i].name);
- goto pro_end;
- }
- items[i].block = _json_get_block_id(
- block_obj, json_object_get_string(tmp_obj));
-
- /* check block id */
- if (items[i].block < AMDGPU_RAS_BLOCK__UMC ||
- items[i].block >= AMDGPU_RAS_BLOCK__LAST) {
- fprintf(stderr, "Test:%s: block id %d is invalid\n",
- items[i].name, items[i].block);
- goto pro_end;
- }
-
- /* subblock */
- if (json_object_object_get_ex(test_obj, "subblock", &tmp_obj)) {
- json_object_object_get_ex(test_obj, "block",
- &subblock_obj);
-
- items[i].sub_block = _json_get_subblock_id(
- block_obj,
- json_object_get_string(subblock_obj),
- json_object_get_string(tmp_obj));
- if (items[i].sub_block < 0) {
- fprintf(stderr, "Test:%s: subblock in block id %d is invalid\n",
- items[i].name, items[i].block);
- goto pro_end;
- }
- } else
- items[i].sub_block = 0;
-
- /* type */
- if (json_object_object_get_ex(test_obj, "type", &tmp_obj)) {
- strncpy(items[i].error_type_str,
- json_object_get_string(tmp_obj), 64);
-
- if (json_object_object_get_ex(type_obj,
- json_object_get_string(tmp_obj), &tmp_type_obj))
- items[i].type = json_object_get_int(tmp_type_obj);
- else
- items[i].type = (enum amdgpu_ras_error_type)0;
- }
-
- /* address */
- if (json_object_object_get_ex(test_obj, "address", &tmp_obj))
- items[i].address = json_object_get_int(tmp_obj);
- else
- items[i].address = 0; /* default address 0 */
-
- /* value */
- if (json_object_object_get_ex(test_obj, "value", &tmp_obj))
- items[i].value = json_object_get_int(tmp_obj);
- else
- items[i].value = 0; /* default value 0 */
- }
-
- *pitems = items;
- *size = length;
- ret = 0;
-pro_end:
- if (root_obj)
- json_object_put(root_obj);
-
- return ret;