[Crosstoolchain-logs] [device-tree-compiler] 196/357: dtc: Add testcases for tree checks

Hector Oron zumbi at moszumanska.debian.org
Thu Dec 8 17:06:13 UTC 2016


This is an automated email from the git hooks/post-receive script.

zumbi pushed a commit to branch upstream/1.3.x
in repository device-tree-compiler.

commit 0d6ade254773aa4798fed1b2f1639ea2b8bdeb89
Author: David Gibson <david at gibson.dropbear.id.au>
Date:   Tue Nov 20 16:24:23 2007 +1100

    dtc: Add testcases for tree checks
    
    This patch adds a group of testcases to check that dtc correctly
    rejects trees with various structural errors.
    
    To make things easier to test, we change dtc so that failing checks
    (as opposed to other errors) result in exit code 2.
    
    This patch also fixes an embarrasing bug uncovered by these new tests:
    check_phandles() worked out if the tree's phandles were valid, then
    throws that information away and returns success always.
    
    Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 checks.c                   |  2 +-
 dtc.c                      |  2 +-
 tests/dtc-checkfails.sh    | 22 ++++++++++++++++++++++
 tests/dtc.sh               | 20 +-------------------
 tests/dup-nodename.dts     |  8 ++++++++
 tests/dup-phandle.dts      | 10 ++++++++++
 tests/dup-propname.dts     |  6 ++++++
 tests/minusone-phandle.dts |  7 +++++++
 tests/run_tests.sh         |  6 ++++++
 tests/{dtc.sh => tests.sh} |  9 +--------
 tests/zero-phandle.dts     |  7 +++++++
 11 files changed, 70 insertions(+), 29 deletions(-)

diff --git a/checks.c b/checks.c
index f0e7505..0a34109 100644
--- a/checks.c
+++ b/checks.c
@@ -101,7 +101,7 @@ static int check_phandles(struct node *root, struct node *node)
 	for_each_child(node, child)
 		ok = ok && check_phandles(root, child);
 
-	return 1;
+	return ok;
 }
 
 int check_structure(struct node *dt)
diff --git a/dtc.c b/dtc.c
index bbef829..602b296 100644
--- a/dtc.c
+++ b/dtc.c
@@ -197,7 +197,7 @@ int main(int argc, char *argv[])
 	if (!structure_ok) {
 		if (!force) {
 			fprintf(stderr, "ERROR: Input tree has structural errors, aborting (use -f to force output)\n");
-			exit(1);
+			exit(2);
 		} else if (quiet < 3) {
 			fprintf(stderr, "Warning: Input tree has structural errors, output forced\n");
 		}
diff --git a/tests/dtc-checkfails.sh b/tests/dtc-checkfails.sh
new file mode 100755
index 0000000..0a45a0b
--- /dev/null
+++ b/tests/dtc-checkfails.sh
@@ -0,0 +1,22 @@
+#! /bin/sh
+
+. tests.sh
+
+TMPFILE="tmp.out.$$"
+
+rm -f $TMPFILE
+
+verbose_run "$DTC" -o $TMPFILE "$@"
+ret="$?"
+
+if [ -f $TMPFILE ]; then
+    FAIL "output file was created despite bad input"
+fi
+
+if [ "$ret" = "2" ]; then
+    PASS
+else
+    FAIL "dtc returned error code $ret instead of 2 (check failed)"
+fi
+
+rm -f $TMPFILE
diff --git a/tests/dtc.sh b/tests/dtc.sh
index f704f55..c5a7324 100755
--- a/tests/dtc.sh
+++ b/tests/dtc.sh
@@ -1,24 +1,6 @@
 #! /bin/sh
 
-PASS () {
-    echo "PASS"
-    exit 0
-}
-
-FAIL () {
-    echo "FAIL" "$@"
-    exit 2
-}
-
-DTC=../dtc
-
-verbose_run () {
-    if [ -z "$QUIET_TEST" ]; then
-	"$@"
-    else
-	"$@" > /dev/null 2> /dev/null
-    fi
-}
+. tests.sh
 
 if verbose_run "$DTC" "$@"; then
     PASS
diff --git a/tests/dup-nodename.dts b/tests/dup-nodename.dts
new file mode 100644
index 0000000..2a3aa75
--- /dev/null
+++ b/tests/dup-nodename.dts
@@ -0,0 +1,8 @@
+/dts-v1/;
+
+/ {
+	node {
+	};
+	node {
+	};
+};
diff --git a/tests/dup-phandle.dts b/tests/dup-phandle.dts
new file mode 100644
index 0000000..c266c61
--- /dev/null
+++ b/tests/dup-phandle.dts
@@ -0,0 +1,10 @@
+/dts-v1/;
+
+/ {
+	node1 {
+		linux,phandle = <1>;
+	};
+	node2 {
+		linux,phandle = <1>;
+	};
+};
diff --git a/tests/dup-propname.dts b/tests/dup-propname.dts
new file mode 100644
index 0000000..8145f6e
--- /dev/null
+++ b/tests/dup-propname.dts
@@ -0,0 +1,6 @@
+/dts-v1/;
+
+/ {
+	prop;
+	prop;
+};
diff --git a/tests/minusone-phandle.dts b/tests/minusone-phandle.dts
new file mode 100644
index 0000000..21d9986
--- /dev/null
+++ b/tests/minusone-phandle.dts
@@ -0,0 +1,7 @@
+/dts-v1/;
+
+/ {
+	node {
+		linux,phandle = <0xffffffff>;
+	};
+};
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 9ae2a12..2a41d43 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -142,6 +142,12 @@ dtc_tests () {
 	run_test dtbs_equal_ordered $tree odts_$tree.test.dtb
     done
 
+    # Check some checks
+    run_test dtc-checkfails.sh -I dts -O dtb dup-nodename.dts
+    run_test dtc-checkfails.sh -I dts -O dtb dup-propname.dts
+    run_test dtc-checkfails.sh -I dts -O dtb dup-phandle.dts
+    run_test dtc-checkfails.sh -I dts -O dtb zero-phandle.dts
+    run_test dtc-checkfails.sh -I dts -O dtb minusone-phandle.dts
 }
 
 while getopts "vdt:" ARG ; do
diff --git a/tests/dtc.sh b/tests/tests.sh
old mode 100755
new mode 100644
similarity index 63%
copy from tests/dtc.sh
copy to tests/tests.sh
index f704f55..396b4cf
--- a/tests/dtc.sh
+++ b/tests/tests.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+# Common functions for shell testcases
 
 PASS () {
     echo "PASS"
@@ -19,10 +19,3 @@ verbose_run () {
 	"$@" > /dev/null 2> /dev/null
     fi
 }
-
-if verbose_run "$DTC" "$@"; then
-    PASS
-else
-    ret="$?"
-    FAIL "dtc returned error code $ret"
-fi
diff --git a/tests/zero-phandle.dts b/tests/zero-phandle.dts
new file mode 100644
index 0000000..7997d98
--- /dev/null
+++ b/tests/zero-phandle.dts
@@ -0,0 +1,7 @@
+/dts-v1/;
+
+/ {
+	node {
+		linux,phandle = <0>;
+	};
+};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list