From f116f4800edce6cd58f680a36fbaed656018d528 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Sat, 13 Jun 2026 20:07:37 +1000 Subject: [PATCH] tests: Dont have test cases link directly against example dtb data Several tests (truncated_property, truncated_string, truncated_memrsv and unterminated_memrsv), rather than loading their example dtb from a file, instead link directly to trees.o and get the data from directly in their own data segment. This was a clever trick once, but it's kind of awkward, and makes it harder to generalise how we generate those trees. Change them to load their example data from file, like most of the tests already do. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: David Gibson --- tests/Makefile.tests | 14 ++++---------- tests/meson.build | 7 ++----- tests/run_tests.sh | 8 ++++---- tests/truncated_memrsv.c | 3 ++- tests/truncated_property.c | 6 ++---- tests/truncated_string.c | 6 ++---- tests/unterminated_memrsv.c | 3 ++- 7 files changed, 18 insertions(+), 29 deletions(-) diff --git a/tests/Makefile.tests b/tests/Makefile.tests index c8f22be..bed2f36 100644 --- a/tests/Makefile.tests +++ b/tests/Makefile.tests @@ -29,20 +29,17 @@ LIB_TESTS_L = get_mem_rsv \ subnode_iterate \ overlay overlay_bad_fixup \ check_path check_header check_full \ - fs_tree1 -LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%) - -LIBTREE_TESTS_L = truncated_property truncated_string \ + fs_tree1 \ + truncated_property truncated_string \ truncated_memrsv unterminated_memrsv - -LIBTREE_TESTS = $(LIBTREE_TESTS_L:%=$(TESTS_PREFIX)%) +LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%) ifneq ($(STATIC_BUILD),1) DL_LIB_TESTS_L = asm_tree_dump value-labels DL_LIB_TESTS = $(DL_LIB_TESTS_L:%=$(TESTS_PREFIX)%) endif -TESTS = $(LIB_TESTS) $(LIBTREE_TESTS) $(DL_LIB_TESTS) +TESTS = $(LIB_TESTS) $(DL_LIB_TESTS) TESTS_TREES_L = test_tree1.dtb bad_node_char.dtb bad_node_format.dtb \ bad_prop_char.dtb ovf_size_strings.dtb truncated_property.dtb \ @@ -74,9 +71,6 @@ $(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_dep) @$(VECHO) LD [libdl] $@ $(LINK.c) -o $@ $^ $(LIBDL) -$(LIBTREE_TESTS): %: $(TESTS_PREFIX)testutils.o $(TESTS_PREFIX)trees.o \ - util.o $(LIBFDT_dep) - $(TESTS_PREFIX)dumptrees: $(TESTS_PREFIX)trees.o $(TESTS_TREES): $(TESTS_PREFIX)dumptrees diff --git a/tests/meson.build b/tests/meson.build index 4c68eee..571c42f 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -22,7 +22,7 @@ dumptrees_dtb = custom_target( ] ) -testutil_dep = declare_dependency(sources: ['testutils.c'], link_with: trees) +testutil_dep = declare_dependency(sources: ['testutils.c']) tests = [ 'add_subnode_with_nops', @@ -90,14 +90,11 @@ tests = [ 'supernode_atdepth_offset', 'sw_states', 'sw_tree1', - 'utilfdt_test', -] - -tests += [ 'truncated_memrsv', 'truncated_property', 'truncated_string', 'unterminated_memrsv', + 'utilfdt_test', ] test_deps = [testutil_dep, util_dep, libfdt_dep] diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 34110c1..842b543 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -492,10 +492,10 @@ libfdt_tests () { run_test appendprop_addrrange unit-addr-without-reg.dtb 2 1 3 # Tests for behaviour on various sorts of corrupted trees - run_test truncated_property - run_test truncated_string - run_test truncated_memrsv - run_test unterminated_memrsv + run_test truncated_property truncated_property.dtb + run_test truncated_string truncated_string.dtb + run_test truncated_memrsv truncated_memrsv.dtb + run_test unterminated_memrsv unterminated_memrsv.dtb # Check aliases support in fdt_path_offset run_dtc_test -I dts -O dtb -o aliases.dtb "$SRCDIR/aliases.dts" diff --git a/tests/truncated_memrsv.c b/tests/truncated_memrsv.c index b7ab4e7..e9b18cc 100644 --- a/tests/truncated_memrsv.c +++ b/tests/truncated_memrsv.c @@ -19,12 +19,13 @@ int main(int argc, char *argv[]) { - void *fdt = &truncated_memrsv; + void *fdt; void *buf; int err; uint64_t addr, size; test_init(argc, argv); + fdt = load_blob_arg(argc, argv); err = fdt_check_header(fdt); if (err != 0) diff --git a/tests/truncated_property.c b/tests/truncated_property.c index d9d52b2..eb09aa4 100644 --- a/tests/truncated_property.c +++ b/tests/truncated_property.c @@ -13,17 +13,15 @@ #include #include "tests.h" -#include "testdata.h" int main(int argc, char *argv[]) { - void *fdt = &truncated_property; + void *fdt; const void *prop; int len; test_init(argc, argv); - - vg_prepare_blob(fdt, fdt_totalsize(fdt)); + fdt = load_blob_arg(argc, argv); prop = fdt_getprop(fdt, 0, "truncated", &len); if (prop) diff --git a/tests/truncated_string.c b/tests/truncated_string.c index d745414..45e6cd3 100644 --- a/tests/truncated_string.c +++ b/tests/truncated_string.c @@ -13,18 +13,16 @@ #include #include "tests.h" -#include "testdata.h" int main(int argc, char *argv[]) { - void *fdt = &truncated_string; + void *fdt; const struct fdt_property *good, *bad; int off, len; const char *name; test_init(argc, argv); - - vg_prepare_blob(fdt, fdt_totalsize(fdt)); + fdt = load_blob_arg(argc, argv); off = fdt_first_property_offset(fdt, 0); good = fdt_get_property_by_offset(fdt, off, NULL); diff --git a/tests/unterminated_memrsv.c b/tests/unterminated_memrsv.c index 441b8d7..a19dc2d 100644 --- a/tests/unterminated_memrsv.c +++ b/tests/unterminated_memrsv.c @@ -22,12 +22,13 @@ int main(int argc, char *argv[]) { - void *fdt = &unterminated_memrsv; + void *fdt; void *buf; int err; uint64_t addr, size; test_init(argc, argv); + fdt = load_blob_arg(argc, argv); err = fdt_check_header(fdt); if (err != 0)