[PATCH 3/9] Add basic tests for dtget

Grant Likely grant.likely at secretlab.ca
Thu Jul 7 04:42:33 EST 2011


On Tue, Jul 05, 2011 at 12:02:51PM -0700, Simon Glass wrote:
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>

Yay, testcases.  :-)

g.

> ---
>  tests/dtget-runtest.sh |   30 ++++++++++++++++++++++
>  tests/dtget-test.dts   |   63 ++++++++++++++++++++++++++++++++++++++++++++++++

Rather than creating a new dts file, these test should probably
leverage the existing ones in the tests directory.

>  tests/run_tests.sh     |   33 ++++++++++++++++++++++++-
>  tests/tests.sh         |    1 +
>  4 files changed, 126 insertions(+), 1 deletions(-)
>  create mode 100755 tests/dtget-runtest.sh
>  create mode 100644 tests/dtget-test.dts
> 
> diff --git a/tests/dtget-runtest.sh b/tests/dtget-runtest.sh
> new file mode 100755
> index 0000000..aa2b744
> --- /dev/null
> +++ b/tests/dtget-runtest.sh
> @@ -0,0 +1,30 @@
> +#! /bin/sh
> +
> +. ./tests.sh
> +
> +LOG="tmp.log.$$"
> +EXPECT="tmp.expect.$$"
> +
> +rm -f $TMPFILE $LOG
> +
> +echo "$1" >$EXPECT
> +shift
> +
> +verbose_run_log "$LOG" $VALGRIND "$DTGET" "$@"
> +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/dtget-test.dts b/tests/dtget-test.dts
> new file mode 100644
> index 0000000..79f9633
> --- /dev/null
> +++ b/tests/dtget-test.dts
> @@ -0,0 +1,63 @@
> +/dts-v1/;
> +
> +/memreserve/ 0x1000000000000000 0x0000000002000000;
> +memrsv2: /memreserve/ 0x2000000000000000 0x0100000000000000;
> +/memreserve/ 0x0000000000000000 0x0000000000000014;
> +
> +/ {
> +	model = "MyBoardName";
> +	compatible = "MyBoardName", "MyBoardFamilyName";
> +	#address-cells = <2>;
> +	#size-cells = <2>;
> +
> +	cpus {
> +		linux,phandle = <0x1>;
> +		#address-cells = <1>;
> +		#size-cells = <0>;
> +		PowerPC,970 at 0 {
> +			name = "PowerPC,970";
> +			device_type = "cpu";
> +			reg = <0x00000000>;
> +			clock-frequency = <1600000000>;
> +			timebase-frequency = <33333333>;
> +			linux,boot-cpu;
> +			i-cache-size = <65536>;
> +			d-cache-size = <32768>;
> +		};
> +
> +		PowerPC,970 at 1 {
> +			name = "PowerPC,970";
> +			device_type = "cpu";
> +			reg = <0x00000001>;
> +			clock-frequency = <1600000000>;
> +			timebase-frequency = <33333333>;
> +			i-cache-size = <65536>;
> +			d-cache-size = <32768>;
> +		};
> +
> +	};
> +
> +	node: randomnode {
> +		prop: string = str: "foo", "stuffstuff\t\t\t\n\n\n" str_end: ;
> +		blob = [byte: 0a 0b 0c 0d byte_mid: de ea ad be ef byte_end: ];
> +		ref = < cell: &{/memory at 0} 0x0 cell_mid: 0xffffffff cell_end: >;
> +		mixed = "abc", pre: [1234] post: , gap: < aligned: 0xa 0xb 0xc>;
> +		tricky1 = [61 lt1: 62 63 00];
> +		subnode: child {
> +		};
> +		/* subnode_end: is auto-generated by node emit */
> +	};
> +	/* node_end: is auto-generated by node emit */
> +
> +	memory at 0 {
> +		device_type = "memory";
> +		memreg: reg = <0x00000000 0x00000000 0x00000000 0x20000000>;
> +	};
> +
> +	chosen {
> +		bootargs = "root=/dev/sda2";
> +		linux,platform = <0x600>;
> +	};
> +
> +};
> +
> diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> index 72dda32..01a2b60 100755
> --- a/tests/run_tests.sh
> +++ b/tests/run_tests.sh
> @@ -83,6 +83,12 @@ asm_to_so_test () {
>      run_wrap_test asm_to_so "$@"
>  }
>  
> +run_dtget_test () {
> +    echo -n "$1:	"
> +    shift
> +    base_run_test sh dtget-runtest.sh "$@"
> +}
> +
>  tree1_tests () {
>      TREE=$1
>  
> @@ -388,6 +394,28 @@ dtbs_equal_tests () {
>      cmp_tests test_tree1.dtb $WRONG_TREE1
>  }
>  
> +dtget_tests () {
> +    file=dtget-test.dtb
> +    $DTC -O dtb -o $file ${file%.dtb}.dts 2>/dev/null
> +
> +    # run_dtget_test <test-name> <expected-result> <args>...
> +    run_dtget_test "Simple string" "MyBoardName" $file "/model"
> +    run_dtget_test "Multiple string i" "77 121 66 111 \
> +97 114 100 78 97 109 101 0 77 121 66 111 97 114 100 70 97 109 105 \
> +108 121 78 97 109 101 0" $file "/compatible"
> +    run_dtget_test "Multiple string s" "MyBoardName MyBoardFamilyName" \
> +	-t s $file "/compatible"
> +    run_dtget_test "Integer" "32768" $file "/cpus/PowerPC,970 at 1/d-cache-size"
> +    run_dtget_test "Integer hex" "8000" -f %x $file \
> +	"/cpus/PowerPC,970 at 1/d-cache-size"
> +    run_dtget_test "Integer list" "61 62 63 00" -f %02x -t b $file \
> +	"/randomnode/tricky1"
> +    run_dtget_test "Byte list short" "a b c d de ea ad be ef" -f %x -t b \
> +	$file "/randomnode/blob"
> +    run_dtget_test "Integer list short" "a0b0c0d deeaadbe ef000000" -f %x \
> +	-t i $file "/randomnode/blob"
> +}
> +
>  while getopts "vt:m" ARG ; do
>      case $ARG in
>  	"v")
> @@ -403,7 +431,7 @@ while getopts "vt:m" ARG ; do
>  done
>  
>  if [ -z "$TESTSETS" ]; then
> -    TESTSETS="libfdt dtc dtbs_equal"
> +    TESTSETS="libfdt dtc dtbs_equal dtget"
>  fi
>  
>  # Make sure we don't have stale blobs lying around
> @@ -420,6 +448,9 @@ for set in $TESTSETS; do
>  	"dtbs_equal")
>  	    dtbs_equal_tests
>  	    ;;
> +	"dtget")
> +	    dtget_tests
> +	    ;;
>      esac
>  done
>  
> diff --git a/tests/tests.sh b/tests/tests.sh
> index 30ffead..cf7f19e 100644
> --- a/tests/tests.sh
> +++ b/tests/tests.sh
> @@ -11,6 +11,7 @@ FAIL () {
>  }
>  
>  DTC=../dtc
> +DTGET=../dtget
>  
>  verbose_run () {
>      if [ -z "$QUIET_TEST" ]; then
> -- 
> 1.7.3.1
> 


More information about the devicetree-discuss mailing list