@ -36,6 +36,20 @@ base_run_test() {
fi
fi
}
}
shorten_echo () {
limit=32
echo -n "$1"
shift
for x; do
if [ ${#x} -le $limit ]; then
echo -n " $x"
else
short=$(echo "$x" | head -c$limit)
echo -n " \"$short\"...<${#x} bytes>"
fi
done
}
run_test () {
run_test () {
echo -n "$@: "
echo -n "$@: "
if [ -n "$VALGRIND" -a -f $1.supp ]; then
if [ -n "$VALGRIND" -a -f $1.supp ]; then
@ -70,6 +84,28 @@ run_wrap_test () {
base_run_test wrap_test "$@"
base_run_test wrap_test "$@"
}
}
wrap_error () {
(
if verbose_run "$@"; then
FAIL "Expected non-zero return code"
else
ret="$?"
if [ "$ret" -gt 127 ]; then
signame=$(kill -l $((ret - 128)))
FAIL "Killed by SIG$signame"
else
PASS
fi
fi
)
}
run_wrap_error_test () {
shorten_echo "$@"
echo -n " {!= 0}: "
base_run_test wrap_error "$@"
}
run_dtc_test () {
run_dtc_test () {
echo -n "dtc $@: "
echo -n "dtc $@: "
base_run_test wrap_test $VALGRIND $DTC "$@"
base_run_test wrap_test $VALGRIND $DTC "$@"
@ -84,25 +120,18 @@ asm_to_so_test () {
}
}
run_fdtget_test () {
run_fdtget_test () {
# run_fdtget_test name expected_output dtb_file args...
expect="$1"
echo -n "$1: "
shift
shift
base_run_test sh fdtget-runtest.sh "$@"
echo -n "fdtget-runtest.sh "$expect" $@: "
base_run_test sh fdtget-runtest.sh "$expect" "$@"
}
}
run_fdtput_test () {
run_fdtput_test () {
# run_fdtput_test name expected_output dtb_file node property flags value...
expect="$1"
echo -n "$1: "
shift
shift
output="$1"
shorten_echo fdtput-runtest.sh "$expect" "$@"
dtb="$2"
echo -n ": "
node="$3"
base_run_test sh fdtput-runtest.sh "$expect" "$@"
property="$4"
flags="$5"
shift 5
base_run_test sh fdtput-runtest.sh "$output" "$dtb" "$node" "$property" \
"$flags" $@
# base_run_test sh fdtput-runtest.sh "$@"
}
}
tree1_tests () {
tree1_tests () {
@ -425,39 +454,32 @@ dtbs_equal_tests () {
}
}
fdtget_tests () {
fdtget_tests () {
file=label01.dtb
dts=label01.dts
$DTC -O dtb -o $file ${file%.dtb}.dts 2>/dev/null
dtb=$dts.fdtget.test.dtb
run_dtc_test -O dtb -o $dtb $dts
# run_fdtget_test <test-name> <expected-result> <args>...
# run_fdtget_test <expected-result> [<flags>] <file> <node> <property>
run_fdtget_test "Simple string" "MyBoardName" $file / model
run_fdtget_test "MyBoardName" $dtb / model
run_fdtget_test "Multiple string i" "77 121 66 111 \
run_fdtget_test "77 121 66 111 \
97 114 100 78 97 109 101 0 77 121 66 111 97 114 100 70 97 109 105 \
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
108 121 78 97 109 101 0" $dtb / compatible
run_fdtget_test "Multiple string s" "MyBoardName MyBoardFamilyName" \
run_fdtget_test "MyBoardName MyBoardFamilyName" -t s $dtb / compatible
-t s $file / compatible
run_fdtget_test 32768 $dtb /cpus/PowerPC,970@1 d-cache-size
run_fdtget_test "Integer" "32768" $file /cpus/PowerPC,970@1 d-cache-size
run_fdtget_test 8000 -tx $dtb /cpus/PowerPC,970@1 d-cache-size
run_fdtget_test "Integer hex" "8000" -tx $file \
run_fdtget_test "61 62 63 0" -tbx $dtb /randomnode tricky1
/cpus/PowerPC,970@1 d-cache-size
run_fdtget_test "a b c d de ea ad be ef" -tbx $dtb /randomnode blob
run_fdtget_test "Integer list" "61 62 63 0" -tbx $file \
/randomnode tricky1
run_fdtget_test "Byte list short" "a b c d de ea ad be ef" -tbx \
$file /randomnode blob
# Here the property size is not a multiple of 4 bytes, so it should fail
# Here the property size is not a multiple of 4 bytes, so it should fail
run_fdtget_test "Integer list invalid" ERR -tlx \
run_wrap_error_test $DTGET -tlx $dtb /randomnode mixed
$file /randomnode mixed
run_fdtget_test "6162 6300 1234 0 a 0 b 0 c" -thx $dtb /randomnode mixed
run_fdtget_test "Integer list halfword" "6162 6300 1234 0 a 0 b 0 c" -thx \
run_fdtget_test "61 62 63 0 12 34 0 0 0 a 0 0 0 b 0 0 0 c" \
$file /randomnode mixed
-thhx $dtb /randomnode mixed
run_fdtget_test "Integer list byte" \
run_wrap_error_test $DTGET -ts $dtb /randomnode doctor-who
"61 62 63 0 12 34 0 0 0 a 0 0 0 b 0 0 0 c" -thhx \
$file /randomnode mixed
run_fdtget_test "Missing property" ERR -ts \
$file /randomnode doctor-who
}
}
fdtput_tests () {
fdtput_tests () {
file=label01.dtb
dts=label01.dts
src=label01.dts
dtb=$dts.fdtput.test.dtb
# Create some test files containing useful strings
# Create some test files containing useful strings
base=tmp.test0
base=tmp.test0
@ -467,7 +489,7 @@ fdtput_tests () {
bigfile2=tmp.test4
bigfile2=tmp.test4
# Filter out anything the shell might not like
# Filter out anything the shell might not like
cat $src | tr -d "'\"\n\;/\.\*{}\-" | tr -s "[:blank:]" " " >$base
cat $dts | tr -d "'\"\n\;/\.\*{}\-" | tr -s "[:blank:]" " " >$base
# Make two small files
# Make two small files
head -5 $base >$file1
head -5 $base >$file1
@ -479,31 +501,25 @@ fdtput_tests () {
# Allow just enough space for both file1 and file2
# Allow just enough space for both file1 and file2
space=$(( $(stat -c %s $file1) + $(stat -c %s $file2) ))
space=$(( $(stat -c %s $file1) + $(stat -c %s $file2) ))
$DTC -O dtb -p $space -o $file ${file%.dtb}.dts 2>/dev/null
run_dtc_test -O dtb -p $space -o $dtb $dts
# run_fdtput_test <test-name> <expected-result> <file> <key> <flags>
# run_fdtput_test <expected-result> <file> <node> <property> <flags> <value>
# <args>...
run_fdtput_test "a_model" $dtb / model -ts "a_model"
run_fdtput_test "Simple string" "a_model" $file / model -ts "a_model"
run_fdtput_test "board1 board2" $dtb / compatible -ts board1 board2
run_fdtput_test "Multiple string s" "board1 board2" \
run_fdtput_test "board1 board2" $dtb / compatible -ts "board1 board2"
$file / compatible -ts board1 board2
run_fdtput_test "32768" $dtb /cpus/PowerPC,970@1 d-cache-size "" "32768"
run_fdtput_test "Single string with spaces" "board1 board2" \
run_fdtput_test "8001" $dtb /cpus/PowerPC,970@1 d-cache-size -tx 0x8001
$file / compatible -ts "board1 board2"
run_fdtput_test "2 3 12" $dtb /randomnode tricky1 -tbi "02 003 12"
run_fdtput_test "Integer" "32768" \
run_fdtput_test "a b c ea ad be ef" $dtb /randomnode blob \
$file /cpus/PowerPC,970@1 d-cache-size "" "32768"
-tbx "a b c ea ad be ef"
run_fdtput_test "Integer hex" "8001" \
run_fdtput_test "a0b0c0d deeaae ef000000" $dtb /randomnode blob \
$file /cpus/PowerPC,970@1 d-cache-size -tx 0x8001
-tx "a0b0c0d deeaae ef000000"
run_fdtput_test "Integer list" "2 3 12" \
run_fdtput_test "`cat $file1 $file2`" $dtb /randomnode blob \
$file /randomnode tricky1 -tbi "02 003 12"
-ts "`cat $file1`" "`cat $file2`"
run_fdtput_test "Byte list short" "a b c ea ad be ef" \
$file /randomnode blob -tbx "a b c ea ad be ef"
run_fdtput_test "Integer list short" "a0b0c0d deeaae ef000000" \
$file /randomnode blob -tx "a0b0c0d deeaae ef000000"
run_fdtput_test "Large string list" "`cat $file1 $file2`" \
$file /randomnode blob -ts "`cat $file1`" "`cat $file2`"
# This should be larger than available space in the fdt ($space)
# This should be larger than available space in the fdt ($space)
run_fdtput_test "Enormous string list" ERR \
run_wrap_error_test $DTPUT $dtb /randomnode blob \
$file /randomnode blob -ts "`cat $bigfile1`" "`cat $bigfile2`"
-ts "`cat $bigfile1`" "`cat $bigfile2`"
# TODO: Add tests for verbose mode?
# TODO: Add tests for verbose mode?
}
}