Skip to contentSkip to conversation

Tests and corrections for asm output and value labels (v2)

PATCH New David Gibson 1 participant 3 messages Oct 7, 2008 1 message not in the archive Kbuild

lore
Share & tools
lore
#0 lore raw

cover Tests and corrections for asm output and value labels (v2)

Revised version of my patch to check -Oasm mode, plus a patch using that infrastructure to test labels within property values.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#2 lore raw

PATCH 1/2 dtc: Make asm output more portable and add testcases

In reply to a message not in the archive

This patch adds some testcases for dtc's -Oasm mode. Specifically it checks that building the asm will result in the same device tree blob in memory as -Odtb mode would produce, for a variety of trees. This test uncovered two difficulties with our current -Oasm output, both of which are addressed in this patch as well.

First, -Oasm output would only be correct if assembled for a big-endian target. Usually that would be the case, when building device trees into a firmware or similar. However this makes life inconvenient for testing on a little-endian target, and one can think up use cases where a program running on a little endian host might want to embed a device tree for a big-endian target. This patch therefore changes -Oasm output to use .byte directives instead of .long throughout in order to generate byte-for-byte identical trees regardless of the endianness of the assembler target.

Second, -Oasm output emitted several #define statements which were then used in the innards of the output - i.e. it assumed the output would be processed by cpp before being assembled. That may not be convenient in all build environments, and in any case doesn't work well with the above fix. So, -Oasm output no longer needs to be preprocessed before assembling.

---
 Makefile              |    2 -
 flattree.c            |   90 ++++++++++++++++++++++++++++++--------------------
 tests/Makefile.tests  |    7 +++
 tests/asm_tree_dump.c |   62 ++++++++++++++++++++++++++++++++++
 tests/data.S          |    3 +
 tests/run_tests.sh    |   19 ++++++++++
 6 files changed, 145 insertions(+), 38 deletions(-)
tests/run_tests.sh +19 -0
Index: dtc/tests/run_tests.sh
===================================================================
@@ -71,6 +71,15 @@ run_dtc_test () {
     base_run_test wrap_test $VALGRIND $DTC "$@"
 }
 
+asm_to_so () {
+    as -o $1.test.o data.S $1.test.s && \
+	ld -shared -o $1.test.so $1.test.o
+}
+
+asm_to_so_test () {
+    run_wrap_test asm_to_so "$@"
+}
+
 tree1_tests () {
     TREE=$1
 
@@ -228,6 +237,16 @@ dtc_tests () {
     run_dtc_test -I dtb -O dtb -o boot_cpuid_preserved_test_tree1.test.dtb boot_cpuid_test_tree1.test.dtb
     run_test dtbs_equal_ordered boot_cpuid_preserved_test_tree1.test.dtb boot_cpuid_test_tree1.test.dtb
 
+    # Check -Oasm mode
+    for tree in test_tree1.dts escapes.dts references.dts path-references.dts \
+	comments.dts aliases.dts include0.dts incbin.dts ; do
+	run_dtc_test -I dts -O asm -o oasm_$tree.test.s $tree
+	asm_to_so_test oasm_$tree
+	run_dtc_test -I dts -O dtb -o $tree.test.dtb $tree
+	run_test asm_tree_dump ./oasm_$tree.test.so oasm_$tree.test.dtb
+	run_wrap_test cmp oasm_$tree.test.dtb $tree.test.dtb
+    done
+
     # Check -Odts mode preserve all dtb information
     for tree in test_tree1.dtb dtc_tree1.test.dtb dtc_escapes.test.dtb ; do
 	run_dtc_test -I dtb -O dts -o odts_$tree.test.dts $tree
Makefile +1 -1
Index: dtc/Makefile
===================================================================
@@ -171,7 +171,7 @@ include tests/Makefile.tests
 #
 # Clean rules
 #
-STD_CLEANFILES = *~ *.o *.d *.a *.i *.s core a.out vgcore.* \
+STD_CLEANFILES = *~ *.o *.so *.d *.a *.i *.s core a.out vgcore.* \
 	*.tab.[ch] *.lex.c *.output
 
 clean: libfdt_clean tests_clean
tests/Makefile.tests +6 -1
Index: dtc/tests/Makefile.tests
===================================================================
@@ -18,7 +18,10 @@ LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREF
 LIBTREE_TESTS_L = truncated_property
 LIBTREE_TESTS = $(LIBTREE_TESTS_L:%=$(TESTS_PREFIX)%)
 
-TESTS = $(LIB_TESTS) $(LIBTREE_TESTS)
+DL_LIB_TESTS_L = asm_tree_dump
+DL_LIB_TESTS = $(DL_LIB_TESTS_L:%=$(TESTS_PREFIX)%)
+
+TESTS = $(LIB_TESTS) $(LIBTREE_TESTS) $(DL_LIB_TESTS)
 
 TESTS_TREES_L = test_tree1.dtb
 TESTS_TREES = $(TESTS_TREES_L:%=$(TESTS_PREFIX)%)
@@ -37,6 +40,8 @@ tests:	$(TESTS) $(TESTS_TREES)
 
 $(LIB_TESTS): %: $(TESTS_PREFIX)testutils.o $(LIBFDT_lib)
 
+$(DL_LIB_TESTS): %: $(TESTS_PREFIX)testutils.o $(LIBFDT_lib) -ldl
+
 $(LIBTREE_TESTS): %: $(TESTS_PREFIX)testutils.o $(TESTS_PREFIX)trees.o $(LIBFDT_lib)
 
 $(TESTS_PREFIX)dumptrees: $(TESTS_PREFIX)trees.o
flattree.c +54 -36

152 lines not on this page · raw message

tests/asm_tree_dump.c new file +62 -0

62 lines not on this page · raw message

tests/data.S new file +3 -0
Index: dtc/tests/data.S
===================================================================
@@ -0,0 +1,3 @@
+/* Used in combination with dtc -Oasm output to embed
+ * a device tree in the data section of a .o */
+	.data
#3 lore raw

PATCH 2/2 dtc: Add testcases for labels within values

In reply to a message not in the archive

This patch adds a testcase using asm output mode to check that labels within property values are correctly processed.

---
 tests/Makefile.tests   |    2 
 tests/run_tests.sh     |    5 +
 tests/tests.h          |    1 
 tests/value-labels.c   |  128 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/value-labels.dts |    8 +++
 5 files changed, 142 insertions(+), 2 deletions(-)
tests/run_tests.sh +4 -1
Index: dtc/tests/run_tests.sh
===================================================================
@@ -239,7 +239,8 @@ dtc_tests () {
 
     # Check -Oasm mode
     for tree in test_tree1.dts escapes.dts references.dts path-references.dts \
-	comments.dts aliases.dts include0.dts incbin.dts ; do
+	comments.dts aliases.dts include0.dts incbin.dts \
+	value-labels.dts ; do
 	run_dtc_test -I dts -O asm -o oasm_$tree.test.s $tree
 	asm_to_so_test oasm_$tree
 	run_dtc_test -I dts -O dtb -o $tree.test.dtb $tree
@@ -247,6 +248,8 @@ dtc_tests () {
 	run_wrap_test cmp oasm_$tree.test.dtb $tree.test.dtb
     done
 
+    run_test value-labels ./oasm_value-labels.dts.test.so
+
     # Check -Odts mode preserve all dtb information
     for tree in test_tree1.dtb dtc_tree1.test.dtb dtc_escapes.test.dtb ; do
 	run_dtc_test -I dtb -O dts -o odts_$tree.test.dts $tree
tests/value-labels.dts new file +8 -0
Index: dtc/tests/value-labels.dts
===================================================================
@@ -0,0 +1,8 @@
+/dts-v1/;
+
+/ {
+	prop1: prop1 = start1: "a", mid1: "b" end1:;
+	prop2: prop2 = start2: < innerstart2: 0xdeadbeef innermid2: 0xabcd1234 innerend2: > end2:;
+	prop3: prop3 = start3: [ innerstart3: ab innermid3: cd innerend3: ] end3:;
+};
+
tests/Makefile.tests +1 -1
Index: dtc/tests/Makefile.tests
===================================================================
@@ -18,7 +18,7 @@ LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREF
 LIBTREE_TESTS_L = truncated_property
 LIBTREE_TESTS = $(LIBTREE_TESTS_L:%=$(TESTS_PREFIX)%)
 
-DL_LIB_TESTS_L = asm_tree_dump
+DL_LIB_TESTS_L = asm_tree_dump value-labels
 DL_LIB_TESTS = $(DL_LIB_TESTS_L:%=$(TESTS_PREFIX)%)
 
 TESTS = $(LIB_TESTS) $(LIBTREE_TESTS) $(DL_LIB_TESTS)
tests/value-labels.c new file +128 -0

128 lines not on this page · raw message

tests/tests.h +1 -0
Index: dtc/tests/tests.h
===================================================================
@@ -34,6 +34,7 @@ void test_init(int argc, char *argv[]);
 
 #define ALIGN(x, a)	(((x) + (a) - 1) & ~((a) - 1))
 #define PALIGN(p, a)	((void *)ALIGN((unsigned long)(p), (a)))
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 #define streq(s1, s2)	(strcmp((s1),(s2)) == 0)