Skip to contentSkip to conversation

dtc: Make asm output more portable and add testcases

PATCH David Gibson 1 participant 1 message Oct 6, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

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    |   18 ++++++++++
 6 files changed, 144 insertions(+), 38 deletions(-)

It occurred to me while thinking about the new language stuff that the grammar re-arrangements we'll need for expression support run the risk of breaking the somewhat curly grammatical constructs we use to handle labels anywhere in (including beginning and end) of property values. Therefore, we ought to have testcases for it.

But property value labels only influence -Oasm output, which we currently don't test at all. Implementing the infrastructure for doing the label tests led me to discover the other problems with -Oasm output described above, hence this patch. Patch to actually do the label testing coming tomorrow.

tests/run_tests.sh +18 -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,15 @@ 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
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