From cb637bc17becf609349d6a09afd26aaeebc144ed Mon Sep 17 00:00:00 2001 From: Guchun Chen Date: Tue, 27 Aug 2019 10:27:18 +0800 Subject: [PATCH] amdgpu: remove json package dependence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Except CUnit library, no additional external library should be needed when compiling amdgpu_test. This will keep this binary self containing. Suggested-by: Christian König Acked-by: Christian König Reviewed-by: Tao Zhou Signed-off-by: Guchun Chen Signed-off-by: Alex Deucher --- configure.ac | 18 ----- meson.build | 1 - tests/amdgpu/Makefile.am | 5 +- tests/amdgpu/meson.build | 16 +--- tests/amdgpu/ras_tests.c | 165 +-------------------------------------- 5 files changed, 9 insertions(+), 196 deletions(-) diff --git a/configure.ac b/configure.ac index 983b4371..1cf91347 100644 --- a/configure.ac +++ b/configure.ac @@ -430,24 +430,10 @@ if test "x$AMDGPU" != xno; then AC_SUBST([CUNIT_CFLAGS]) fi fi - - # Detect json-c library - PKG_CHECK_MODULES([JSONC], [json-c >= 0.10.1], [have_jsonc=yes], [have_jsonc=no]) - if test "x${have_jsonc}" = "xno"; then - AC_CHECK_LIB([json-c], [json_object_object_get], [have_jsonc=yes], [have_jsonc=no]) - if test "x${have_jsonc}" = "xyes"; then - JSONC_LIBS="-ljson-c" - JSONC_CFLAGS="" - AC_SUBST([JSONC_LIBS]) - AC_SUBST([JSONC_CFLAGS]) - fi - fi else have_cunit=no - have_jsonc=no fi AM_CONDITIONAL(HAVE_CUNIT, [test "x$have_cunit" != "xno"]) -AM_CONDITIONAL(HAVE_JSONC, [test "x$have_jsonc" != "xno"]) AM_CONDITIONAL(HAVE_AMDGPU, [test "x$AMDGPU" = xyes]) if test "x$AMDGPU" = xyes; then @@ -456,10 +442,6 @@ if test "x$AMDGPU" = xyes; then if test "x$have_cunit" = "xno"; then AC_MSG_WARN([Could not find cunit library. Disabling amdgpu tests]) fi - - if test "x$have_jsonc" = "xno"; then - AC_MSG_WARN([Could not find json-c library. Disabling amdgpu tests]) - fi else AC_DEFINE(HAVE_AMDGPU, 0) fi diff --git a/meson.build b/meson.build index 263f691a..99fd0cb8 100644 --- a/meson.build +++ b/meson.build @@ -222,7 +222,6 @@ libdrm_c_args = warn_c_args + ['-fvisibility=hidden'] dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel) dep_cunit = dependency('cunit', version : '>= 2.1', required : false) -dep_json = dependency('json-c', version : '>= 0.10.1', required : false) _cairo_tests = get_option('cairo-tests') if _cairo_tests != 'false' dep_cairo = dependency('cairo', required : _cairo_tests == 'true') diff --git a/tests/amdgpu/Makefile.am b/tests/amdgpu/Makefile.am index 339bb0a9..920882d0 100644 --- a/tests/amdgpu/Makefile.am +++ b/tests/amdgpu/Makefile.am @@ -7,8 +7,7 @@ AM_CFLAGS = \ LDADD = $(top_builddir)/libdrm.la \ $(top_builddir)/amdgpu/libdrm_amdgpu.la \ - $(CUNIT_LIBS) \ - $(JSONC_LIBS) + $(CUNIT_LIBS) if HAVE_INSTALL_TESTS bin_PROGRAMS = \ @@ -18,7 +17,7 @@ noinst_PROGRAMS = \ amdgpu_test endif -amdgpu_test_CPPFLAGS = $(CUNIT_CFLAGS) $(JSONC_CFLAGS) +amdgpu_test_CPPFLAGS = $(CUNIT_CFLAGS) amdgpu_test_SOURCES = \ amdgpu_test.c \ diff --git a/tests/amdgpu/meson.build b/tests/amdgpu/meson.build index 4307295e..1726cb43 100644 --- a/tests/amdgpu/meson.build +++ b/tests/amdgpu/meson.build @@ -18,7 +18,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -if dep_cunit.found() and dep_json.found() +if dep_cunit.found() amdgpu_test = executable( 'amdgpu_test', files( @@ -26,19 +26,9 @@ if dep_cunit.found() and dep_json.found() 'vce_tests.c', 'uvd_enc_tests.c', 'vcn_tests.c', 'deadlock_tests.c', 'vm_tests.c', 'ras_tests.c', 'syncobj_tests.c', ), - dependencies : [dep_cunit, dep_json, dep_threads], + dependencies : [dep_cunit, dep_threads], include_directories : [inc_root, inc_drm, include_directories('../../amdgpu')], link_with : [libdrm, libdrm_amdgpu], install : with_install_tests, ) - - configure_file(input : '../../data/amdgpu_ras.json', - output : 'amdgpu_ras.json', - configuration : configuration_data()) - - install_data( - '../../data/amdgpu_ras.json', - install_mode : 'rw-r--r--', - install_dir : datadir_amdgpu, - ) -endif \ No newline at end of file +endif diff --git a/tests/amdgpu/ras_tests.c b/tests/amdgpu/ras_tests.c index 5309bf64..86b4137b 100644 --- a/tests/amdgpu/ras_tests.c +++ b/tests/amdgpu/ras_tests.c @@ -30,7 +30,7 @@ #include #include #include "xf86drm.h" -#include "json.h" +#include "stdlib.h" const char *ras_block_string[] = { "umc", @@ -775,169 +775,12 @@ static void amdgpu_ras_enable_test(void) } } -static int _json_get_block_id(json_object *block_obj, const char *name) -{ - json_object *item_obj, *index_obj; - - if (!json_object_object_get_ex(block_obj, name, &item_obj)) - return -1; - - if (!json_object_object_get_ex(item_obj, "index", &index_obj)) - return -1; - - return json_object_get_int(index_obj); -} - -static int _json_get_subblock_id(json_object *block_obj, const char *block_name, - const char *subblock_name) -{ - json_object *item_obj, *subblock_obj, *name_obj; - - if (!json_object_object_get_ex(block_obj, block_name, &item_obj)) - return -1; - - if (!json_object_object_get_ex(item_obj, "subblock", &subblock_obj)) - return -1; - - if (!json_object_object_get_ex(subblock_obj, subblock_name, &name_obj)) - return -1; - - return json_object_get_int(name_obj); -} - static int amdgpu_ras_get_test_items(struct ras_test_item **pitems, int *size) { - json_object *root_obj = NULL; - json_object *block_obj = NULL; - json_object *type_obj = NULL; - json_object *tests_obj = NULL; - json_object *test_obj = NULL; - json_object *tmp_obj = NULL; - json_object *tmp_type_obj = NULL; - json_object *subblock_obj = NULL; - int i, length; - struct ras_test_item *items = NULL; - int ret = -1; + *pitems = NULL; + *size = 0; - root_obj = json_object_from_file("./amdgpu_ras.json"); - if (!root_obj) - root_obj = json_object_from_file( - "/usr/share/libdrm/amdgpu_ras.json"); - - if (!root_obj) { - CU_FAIL_FATAL("Couldn't find amdgpu_ras.json"); - goto pro_end; - } - - /* Check Version */ - if (!json_object_object_get_ex(root_obj, "version", &tmp_obj)) { - CU_FAIL_FATAL("Wrong format of amdgpu_ras.json"); - goto pro_end; - } - - /* 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; + return 0; } static void __amdgpu_ras_inject_test(void)