[PATCH 7/9] Add some tests for dtput

Simon Glass sjg at chromium.org
Wed Jul 6 05:02:55 EST 2011


Signed-off-by: Simon Glass <sjg at chromium.org>
---
 tests/dtput-runtest.sh |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
 tests/run_tests.sh     |   40 +++++++++++++++++++++++++++++++++++++-
 tests/tests.sh         |    1 +
 3 files changed, 90 insertions(+), 1 deletions(-)
 create mode 100644 tests/dtput-runtest.sh

diff --git a/tests/dtput-runtest.sh b/tests/dtput-runtest.sh
new file mode 100644
index 0000000..a8c9655
--- /dev/null
+++ b/tests/dtput-runtest.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+
+# Run script for dtput tests
+# We run dtput to update the device tree, thn dtget to check it
+
+# Usage
+#	dtput-runtest.sh name expected_output dtb_file key value flags
+
+. ./tests.sh
+
+LOG="tmp.log.$$"
+EXPECT="tmp.expect.$$"
+
+rm -f $TMPFILE $LOG
+
+echo "$1" >$EXPECT
+dtb="$2"
+key="$3"
+value="$4"
+flags="$5"
+
+# First run dtput
+verbose_run $VALGRIND "$DTPUT" "$dtb" "$key" $value $flags
+ret="$?"
+
+if [ "$ret" -gt 127 ]; then
+    signame=$(kill -l $[ret - 128])
+    FAIL "Killed by SIG$signame"
+fi
+
+
+# Now dtget to read the value
+verbose_run_log "$LOG" $VALGRIND "$DTGET" "$dtb" "$key" $flags
+ret="$?"
+
+if [ "$ret" -gt 127 ]; then
+    signame=$(kill -l $[ret - 128])
+    FAIL "Killed by SIG$signame"
+fi
+
+diff $EXPECT $LOG
+ret="$?"
+
+rm -f $LOG $EXPECT
+
+if [ "$ret" -eq 0 ]; then
+	PASS
+else
+	FAIL
+fi
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 01a2b60..d95d1fe 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -84,11 +84,25 @@ asm_to_so_test () {
 }
 
 run_dtget_test () {
+    # run_dtget_test name expected_output dtb_file args...
     echo -n "$1:	"
     shift
     base_run_test sh dtget-runtest.sh "$@"
 }
 
+run_dtput_test () {
+    # run_dtput_test name expected_output dtb_file key value flags
+    echo -n "$1:	"
+    shift
+    output="$1"
+    dtb="$2"
+    key="$3"
+    value="$4"
+    flags="$5"
+    echo output: $output
+    base_run_test sh dtput-runtest.sh "$output" "$dtb" "$key" "$value" "$flags"
+}
+
 tree1_tests () {
     TREE=$1
 
@@ -416,6 +430,27 @@ dtget_tests () {
 	-t i $file "/randomnode/blob"
 }
 
+dtput_tests () {
+    file=dtget-test.dtb
+    $DTC -O dtb -o $file ${file%.dtb}.dts 2>/dev/null
+
+    # run_dtput_test <test-name> <expected-result> <file> <key> <value>
+    run_dtput_test "Simple string" "a_model" $file "/model" "a_model" -ts
+
+    run_dtput_test "Multiple string s" "board1 board2" \
+	$file "/compatible" "board1 board2" -ts
+    run_dtput_test "Integer" "32768" $file "/cpus/PowerPC,970 at 1/d-cache-size" \
+	"32768"
+    run_dtput_test "Integer hex" "8001" $file \
+	"/cpus/PowerPC,970 at 1/d-cache-size" 0x8001 "-f %x"
+    run_dtput_test "Integer list" "02 03 04" $file \
+	"/randomnode/tricky1" "02 03 04" "-f %02x -t b"
+    run_dtput_test "Byte list short" "a b c ea ad be ef" \
+	$file "/randomnode/blob" "a b c ea ad be ef" "-f %x -t b"
+    run_dtput_test "Integer list short" "a0b0c0d deeaae ef000000" \
+	$file "/randomnode/blob" "a0b0c0d deeaae ef000000" "-t i -f %x"
+}
+
 while getopts "vt:m" ARG ; do
     case $ARG in
 	"v")
@@ -431,7 +466,7 @@ while getopts "vt:m" ARG ; do
 done
 
 if [ -z "$TESTSETS" ]; then
-    TESTSETS="libfdt dtc dtbs_equal dtget"
+    TESTSETS="libfdt dtc dtbs_equal dtget dtput"
 fi
 
 # Make sure we don't have stale blobs lying around
@@ -451,6 +486,9 @@ for set in $TESTSETS; do
 	"dtget")
 	    dtget_tests
 	    ;;
+	"dtput")
+	    dtput_tests
+	    ;;
     esac
 done
 
diff --git a/tests/tests.sh b/tests/tests.sh
index cf7f19e..bdd3c79 100644
--- a/tests/tests.sh
+++ b/tests/tests.sh
@@ -12,6 +12,7 @@ FAIL () {
 
 DTC=../dtc
 DTGET=../dtget
+DTPUT=../dtput
 
 verbose_run () {
     if [ -z "$QUIET_TEST" ]; then
-- 
1.7.3.1



More information about the devicetree-discuss mailing list