1#! /bin/sh 2 3. ./tests.sh 4 5if [ -z "$CC" ]; then 6 CC=gcc 7fi 8 9export QUIET_TEST=1 10STOP_ON_FAIL=0 11 12export VALGRIND= 13VGCODE=126 14 15tot_tests=0 16tot_pass=0 17tot_fail=0 18tot_config=0 19tot_vg=0 20tot_strange=0 21 22base_run_test() { 23 tot_tests=$((tot_tests + 1)) 24 if VALGRIND="$VALGRIND" "$@"; then 25 tot_pass=$((tot_pass + 1)) 26 else 27 ret="$?" 28 if [ "$STOP_ON_FAIL" -eq 1 ]; then 29 exit 1 30 fi 31 if [ "$ret" -eq 1 ]; then 32 tot_config=$((tot_config + 1)) 33 elif [ "$ret" -eq 2 ]; then 34 tot_fail=$((tot_fail + 1)) 35 elif [ "$ret" -eq $VGCODE ]; then 36 tot_vg=$((tot_vg + 1)) 37 else 38 tot_strange=$((tot_strange + 1)) 39 fi 40 fi 41} 42 43shorten_echo () { 44 limit=32 45 printf "$1" 46 shift 47 for x; do 48 if [ ${#x} -le $limit ]; then 49 printf " $x" 50 else 51 short=$(echo "$x" | head -c$limit) 52 printf " \"$short\"...<${#x} bytes>" 53 fi 54 done 55} 56 57run_test () { 58 printf "$*: " 59 if [ -n "$VALGRIND" -a -f $1.supp ]; then 60 VGSUPP="--suppressions=$1.supp" 61 fi 62 base_run_test $VALGRIND $VGSUPP "./$@" 63} 64 65run_sh_test () { 66 printf "$*: " 67 base_run_test sh "$@" 68} 69 70wrap_test () { 71 ( 72 if verbose_run "$@"; then 73 PASS 74 else 75 ret="$?" 76 if [ "$ret" -gt 127 ]; then 77 signame=$(kill -l $((ret - 128))) 78 FAIL "Killed by SIG$signame" 79 else 80 FAIL "Returned error code $ret" 81 fi 82 fi 83 ) 84} 85 86run_wrap_test () { 87 shorten_echo "$@: " 88 base_run_test wrap_test "$@" 89} 90 91wrap_error () { 92 ( 93 if verbose_run "$@"; then 94 FAIL "Expected non-zero return code" 95 else 96 ret="$?" 97 if [ "$ret" -gt 127 ]; then 98 signame=$(kill -l $((ret - 128))) 99 FAIL "Killed by SIG$signame" 100 else 101 PASS 102 fi 103 fi 104 ) 105} 106 107run_wrap_error_test () { 108 shorten_echo "$@" 109 printf " {!= 0}: " 110 base_run_test wrap_error "$@" 111} 112 113# $1: dtb file 114# $2: align base 115check_align () { 116 shorten_echo "check_align $@: " 117 local size=$(stat -c %s "$1") 118 local align="$2" 119 ( 120 if [ $(($size % $align)) -eq 0 ] ;then 121 PASS 122 else 123 FAIL "Output size $size is not $align-byte aligned" 124 fi 125 ) 126} 127 128run_dtc_test () { 129 printf "dtc $*: " 130 base_run_test wrap_test $VALGRIND $DTC "$@" 131} 132 133asm_to_so () { 134 $CC -shared -o $1.test.so data.S $1.test.s 135} 136 137asm_to_so_test () { 138 run_wrap_test asm_to_so "$@" 139} 140 141run_fdtget_test () { 142 expect="$1" 143 shift 144 printf "fdtget-runtest.sh %s $*: " "$(echo $expect)" 145 base_run_test sh fdtget-runtest.sh "$expect" "$@" 146} 147 148run_fdtput_test () { 149 expect="$1" 150 shift 151 shorten_echo fdtput-runtest.sh "$expect" "$@" 152 printf ": " 153 base_run_test sh fdtput-runtest.sh "$expect" "$@" 154} 155 156run_fdtdump_test() { 157 file="$1" 158 shorten_echo fdtdump-runtest.sh "$file" 159 printf ": " 160 base_run_test sh fdtdump-runtest.sh "$file" 2>/dev/null 161} 162 163run_fdtoverlay_test() { 164 expect="$1" 165 shift 166 shorten_echo fdtoverlay-runtest.sh "$expect" "$@" 167 printf ": " 168 base_run_test sh fdtoverlay-runtest.sh "$expect" "$@" 169} 170 171BAD_FIXUP_TREES="bad_index \ 172 empty \ 173 empty_index \ 174 index_trailing \ 175 path_empty_prop \ 176 path_only \ 177 path_only_sep \ 178 path_prop" 179 180# Test to exercise libfdt overlay application without dtc's overlay support 181libfdt_overlay_tests () { 182 # First test a doctored overlay which requires only local fixups 183 run_dtc_test -I dts -O dtb -o overlay_base_no_symbols.test.dtb overlay_base.dts 184 run_test check_path overlay_base_no_symbols.test.dtb not-exists "/__symbols__" 185 run_test check_path overlay_base_no_symbols.test.dtb not-exists "/__fixups__" 186 run_test check_path overlay_base_no_symbols.test.dtb not-exists "/__local_fixups__" 187 188 run_dtc_test -I dts -O dtb -o overlay_overlay_no_fixups.test.dtb overlay_overlay_no_fixups.dts 189 run_test check_path overlay_overlay_no_fixups.test.dtb not-exists "/__symbols__" 190 run_test check_path overlay_overlay_no_fixups.test.dtb not-exists "/__fixups__" 191 run_test check_path overlay_overlay_no_fixups.test.dtb exists "/__local_fixups__" 192 193 run_test overlay overlay_base_no_symbols.test.dtb overlay_overlay_no_fixups.test.dtb 194 195 # Then test with manually constructed fixups 196 run_dtc_test -I dts -O dtb -o overlay_base_manual_symbols.test.dtb overlay_base_manual_symbols.dts 197 run_test check_path overlay_base_manual_symbols.test.dtb exists "/__symbols__" 198 run_test check_path overlay_base_manual_symbols.test.dtb not-exists "/__fixups__" 199 run_test check_path overlay_base_manual_symbols.test.dtb not-exists "/__local_fixups__" 200 201 run_dtc_test -I dts -O dtb -o overlay_overlay_manual_fixups.test.dtb overlay_overlay_manual_fixups.dts 202 run_test check_path overlay_overlay_manual_fixups.test.dtb not-exists "/__symbols__" 203 run_test check_path overlay_overlay_manual_fixups.test.dtb exists "/__fixups__" 204 run_test check_path overlay_overlay_manual_fixups.test.dtb exists "/__local_fixups__" 205 206 run_test overlay overlay_base_manual_symbols.test.dtb overlay_overlay_manual_fixups.test.dtb 207 208 # Bad fixup tests 209 for test in $BAD_FIXUP_TREES; do 210 tree="overlay_bad_fixup_$test" 211 run_dtc_test -I dts -O dtb -o $tree.test.dtb $tree.dts 212 run_test overlay_bad_fixup overlay_base_no_symbols.test.dtb $tree.test.dtb 213 done 214} 215 216# Tests to exercise dtc's overlay generation support 217dtc_overlay_tests () { 218 # Overlay tests for dtc 219 run_dtc_test -@ -I dts -O dtb -o overlay_base.test.dtb overlay_base.dts 220 run_test check_path overlay_base.test.dtb exists "/__symbols__" 221 run_test check_path overlay_base.test.dtb not-exists "/__fixups__" 222 run_test check_path overlay_base.test.dtb not-exists "/__local_fixups__" 223 224 run_dtc_test -I dts -O dtb -o overlay_overlay.test.dtb overlay_overlay.dts 225 run_test check_path overlay_overlay.test.dtb not-exists "/__symbols__" 226 run_test check_path overlay_overlay.test.dtb exists "/__fixups__" 227 run_test check_path overlay_overlay.test.dtb exists "/__local_fixups__" 228 229 run_test overlay overlay_base.test.dtb overlay_overlay.test.dtb 230 231 # test plugin source to dtb and back 232 run_dtc_test -I dtb -O dts -o overlay_overlay_decompile.test.dts overlay_overlay.test.dtb 233 run_dtc_test -I dts -O dtb -o overlay_overlay_decompile.test.dtb overlay_overlay_decompile.test.dts 234 run_test dtbs_equal_ordered overlay_overlay.test.dtb overlay_overlay_decompile.test.dtb 235 236 # Test generation of aliases insted of symbols 237 run_dtc_test -A -I dts -O dtb -o overlay_base_with_aliases.dtb overlay_base.dts 238 run_test check_path overlay_base_with_aliases.dtb exists "/aliases" 239 run_test check_path overlay_base_with_aliases.dtb not-exists "/__symbols__" 240 run_test check_path overlay_base_with_aliases.dtb not-exists "/__fixups__" 241 run_test check_path overlay_base_with_aliases.dtb not-exists "/__local_fixups__" 242} 243 244tree1_tests () { 245 TREE=$1 246 247 # Read-only tests 248 run_test get_mem_rsv $TREE 249 run_test root_node $TREE 250 run_test find_property $TREE 251 run_test subnode_offset $TREE 252 run_test path_offset $TREE 253 run_test get_name $TREE 254 run_test getprop $TREE 255 run_test get_phandle $TREE 256 run_test get_path $TREE 257 run_test supernode_atdepth_offset $TREE 258 run_test parent_offset $TREE 259 run_test node_offset_by_prop_value $TREE 260 run_test node_offset_by_phandle $TREE 261 run_test node_check_compatible $TREE 262 run_test node_offset_by_compatible $TREE 263 run_test notfound $TREE 264 265 # Write-in-place tests 266 run_test setprop_inplace $TREE 267 run_test nop_property $TREE 268 run_test nop_node $TREE 269} 270 271tree1_tests_rw () { 272 TREE=$1 273 274 # Read-write tests 275 run_test set_name $TREE 276 run_test setprop $TREE 277 run_test del_property $TREE 278 run_test del_node $TREE 279} 280 281check_tests () { 282 tree="$1" 283 shift 284 run_sh_test dtc-checkfails.sh "$@" -- -I dts -O dtb $tree 285 run_dtc_test -I dts -O dtb -o $tree.test.dtb -f $tree 286 run_sh_test dtc-checkfails.sh "$@" -- -I dtb -O dtb $tree.test.dtb 287} 288 289ALL_LAYOUTS="mts mst tms tsm smt stm" 290 291libfdt_tests () { 292 tree1_tests test_tree1.dtb 293 294 run_dtc_test -I dts -O dtb -o addresses.test.dtb addresses.dts 295 run_test addr_size_cells addresses.test.dtb 296 297 run_dtc_test -I dts -O dtb -o stringlist.test.dtb stringlist.dts 298 run_test stringlist stringlist.test.dtb 299 300 # Sequential write tests 301 run_test sw_tree1 302 tree1_tests sw_tree1.test.dtb 303 tree1_tests unfinished_tree1.test.dtb 304 run_test dtbs_equal_ordered test_tree1.dtb sw_tree1.test.dtb 305 306 # Resizing tests 307 for mode in resize realloc; do 308 run_test sw_tree1 $mode 309 tree1_tests sw_tree1.test.dtb 310 tree1_tests unfinished_tree1.test.dtb 311 run_test dtbs_equal_ordered test_tree1.dtb sw_tree1.test.dtb 312 done 313 314 # fdt_move tests 315 for tree in test_tree1.dtb sw_tree1.test.dtb unfinished_tree1.test.dtb; do 316 rm -f moved.$tree shunted.$tree deshunted.$tree 317 run_test move_and_save $tree 318 run_test dtbs_equal_ordered $tree moved.$tree 319 run_test dtbs_equal_ordered $tree shunted.$tree 320 run_test dtbs_equal_ordered $tree deshunted.$tree 321 done 322 323 # v16 and alternate layout tests 324 for tree in test_tree1.dtb; do 325 for version in 17 16; do 326 for layout in $ALL_LAYOUTS; do 327 run_test mangle-layout $tree $version $layout 328 tree1_tests v$version.$layout.$tree 329 run_test dtbs_equal_ordered $tree v$version.$layout.$tree 330 done 331 done 332 done 333 334 # Read-write tests 335 for basetree in test_tree1.dtb; do 336 for version in 17 16; do 337 for layout in $ALL_LAYOUTS; do 338 tree=v$version.$layout.$basetree 339 rm -f opened.$tree repacked.$tree 340 run_test open_pack $tree 341 tree1_tests opened.$tree 342 tree1_tests repacked.$tree 343 344 tree1_tests_rw $tree 345 tree1_tests_rw opened.$tree 346 tree1_tests_rw repacked.$tree 347 done 348 done 349 done 350 run_test rw_tree1 351 tree1_tests rw_tree1.test.dtb 352 tree1_tests_rw rw_tree1.test.dtb 353 run_test appendprop1 354 run_test appendprop2 appendprop1.test.dtb 355 run_dtc_test -I dts -O dtb -o appendprop.test.dtb appendprop.dts 356 run_test dtbs_equal_ordered appendprop2.test.dtb appendprop.test.dtb 357 libfdt_overlay_tests 358 359 for basetree in test_tree1.dtb sw_tree1.test.dtb rw_tree1.test.dtb; do 360 run_test nopulate $basetree 361 run_test dtbs_equal_ordered $basetree noppy.$basetree 362 tree1_tests noppy.$basetree 363 tree1_tests_rw noppy.$basetree 364 done 365 366 run_dtc_test -I dts -O dtb -o subnode_iterate.dtb subnode_iterate.dts 367 run_test subnode_iterate subnode_iterate.dtb 368 369 run_dtc_test -I dts -O dtb -o property_iterate.dtb property_iterate.dts 370 run_test property_iterate property_iterate.dtb 371 372 # Tests for behaviour on various sorts of corrupted trees 373 run_test truncated_property 374 375 # Check aliases support in fdt_path_offset 376 run_dtc_test -I dts -O dtb -o aliases.dtb aliases.dts 377 run_test get_alias aliases.dtb 378 run_test path_offset_aliases aliases.dtb 379 380 # Specific bug tests 381 run_test add_subnode_with_nops 382 run_dtc_test -I dts -O dts -o sourceoutput.test.dts sourceoutput.dts 383 run_dtc_test -I dts -O dtb -o sourceoutput.test.dtb sourceoutput.dts 384 run_dtc_test -I dts -O dtb -o sourceoutput.test.dts.test.dtb sourceoutput.test.dts 385 run_test dtbs_equal_ordered sourceoutput.test.dtb sourceoutput.test.dts.test.dtb 386 387 run_dtc_test -I dts -O dtb -o embedded_nul.test.dtb embedded_nul.dts 388 run_dtc_test -I dts -O dtb -o embedded_nul_equiv.test.dtb embedded_nul_equiv.dts 389 run_test dtbs_equal_ordered embedded_nul.test.dtb embedded_nul_equiv.test.dtb 390 391 run_dtc_test -I dts -O dtb bad-size-cells.dts 392 393 run_wrap_error_test $DTC division-by-zero.dts 394 run_wrap_error_test $DTC bad-octal-literal.dts 395 run_dtc_test -I dts -O dtb nul-in-escape.dts 396 run_wrap_error_test $DTC nul-in-line-info1.dts 397 run_wrap_error_test $DTC nul-in-line-info2.dts 398 399 run_wrap_error_test $DTC -I dtb -O dts -o /dev/null ovf_size_strings.dtb 400} 401 402dtc_tests () { 403 run_dtc_test -I dts -O dtb -o dtc_tree1.test.dtb test_tree1.dts 404 tree1_tests dtc_tree1.test.dtb 405 tree1_tests_rw dtc_tree1.test.dtb 406 run_test dtbs_equal_ordered dtc_tree1.test.dtb test_tree1.dtb 407 408 run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb propname_escapes.dts 409 run_test propname_escapes dtc_escapes.test.dtb 410 411 run_dtc_test -I dts -O dtb -o line_directives.test.dtb line_directives.dts 412 413 run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts 414 run_test string_escapes dtc_escapes.test.dtb 415 416 run_dtc_test -I dts -O dtb -o dtc_char_literal.test.dtb char_literal.dts 417 run_test char_literal dtc_char_literal.test.dtb 418 419 run_dtc_test -I dts -O dtb -o dtc_sized_cells.test.dtb sized_cells.dts 420 run_test sized_cells dtc_sized_cells.test.dtb 421 422 run_dtc_test -I dts -O dtb -o dtc_extra-terminating-null.test.dtb extra-terminating-null.dts 423 run_test extra-terminating-null dtc_extra-terminating-null.test.dtb 424 425 run_dtc_test -I dts -O dtb -o dtc_references.test.dtb references.dts 426 run_test references dtc_references.test.dtb 427 428 run_dtc_test -I dts -O dtb -o dtc_path-references.test.dtb path-references.dts 429 run_test path-references dtc_path-references.test.dtb 430 431 run_test phandle_format dtc_references.test.dtb epapr 432 for f in legacy epapr both; do 433 run_dtc_test -I dts -O dtb -H $f -o dtc_references.test.$f.dtb references.dts 434 run_test phandle_format dtc_references.test.$f.dtb $f 435 done 436 437 run_dtc_test -I dts -O dtb -o multilabel.test.dtb multilabel.dts 438 run_test references multilabel.test.dtb 439 440 run_dtc_test -I dts -O dtb -o label_repeated.test.dtb label_repeated.dts 441 442 run_dtc_test -I dts -O dtb -o dtc_comments.test.dtb comments.dts 443 run_dtc_test -I dts -O dtb -o dtc_comments-cmp.test.dtb comments-cmp.dts 444 run_test dtbs_equal_ordered dtc_comments.test.dtb dtc_comments-cmp.test.dtb 445 446 # Check /include/ directive 447 run_dtc_test -I dts -O dtb -o includes.test.dtb include0.dts 448 run_test dtbs_equal_ordered includes.test.dtb test_tree1.dtb 449 450 # Check /incbin/ directive 451 run_dtc_test -I dts -O dtb -o incbin.test.dtb incbin.dts 452 run_test incbin incbin.test.dtb 453 454 # Check boot_cpuid_phys handling 455 run_dtc_test -I dts -O dtb -o boot_cpuid.test.dtb boot-cpuid.dts 456 run_test boot-cpuid boot_cpuid.test.dtb 16 457 458 run_dtc_test -I dts -O dtb -b 17 -o boot_cpuid_17.test.dtb boot-cpuid.dts 459 run_test boot-cpuid boot_cpuid_17.test.dtb 17 460 461 run_dtc_test -I dtb -O dtb -o preserve_boot_cpuid.test.dtb boot_cpuid.test.dtb 462 run_test boot-cpuid preserve_boot_cpuid.test.dtb 16 463 run_test dtbs_equal_ordered preserve_boot_cpuid.test.dtb boot_cpuid.test.dtb 464 465 run_dtc_test -I dtb -O dtb -o preserve_boot_cpuid_17.test.dtb boot_cpuid_17.test.dtb 466 run_test boot-cpuid preserve_boot_cpuid_17.test.dtb 17 467 run_test dtbs_equal_ordered preserve_boot_cpuid_17.test.dtb boot_cpuid_17.test.dtb 468 469 run_dtc_test -I dtb -O dtb -b17 -o override17_boot_cpuid.test.dtb boot_cpuid.test.dtb 470 run_test boot-cpuid override17_boot_cpuid.test.dtb 17 471 472 run_dtc_test -I dtb -O dtb -b0 -o override0_boot_cpuid_17.test.dtb boot_cpuid_17.test.dtb 473 run_test boot-cpuid override0_boot_cpuid_17.test.dtb 0 474 475 476 # Check -Oasm mode 477 for tree in test_tree1.dts escapes.dts references.dts path-references.dts \ 478 comments.dts aliases.dts include0.dts incbin.dts \ 479 value-labels.dts ; do 480 run_dtc_test -I dts -O asm -o oasm_$tree.test.s $tree 481 asm_to_so_test oasm_$tree 482 run_dtc_test -I dts -O dtb -o $tree.test.dtb $tree 483 run_test asm_tree_dump ./oasm_$tree.test.so oasm_$tree.test.dtb 484 run_wrap_test cmp oasm_$tree.test.dtb $tree.test.dtb 485 done 486 487 run_test value-labels ./oasm_value-labels.dts.test.so 488 489 # Check -Odts mode preserve all dtb information 490 for tree in test_tree1.dtb dtc_tree1.test.dtb dtc_escapes.test.dtb \ 491 dtc_extra-terminating-null.test.dtb dtc_references.test.dtb; do 492 run_dtc_test -I dtb -O dts -o odts_$tree.test.dts $tree 493 run_dtc_test -I dts -O dtb -o odts_$tree.test.dtb odts_$tree.test.dts 494 run_test dtbs_equal_ordered $tree odts_$tree.test.dtb 495 done 496 497 # Check version conversions 498 for tree in test_tree1.dtb ; do 499 for aver in 1 2 3 16 17; do 500 atree="ov${aver}_$tree.test.dtb" 501 run_dtc_test -I dtb -O dtb -V$aver -o $atree $tree 502 for bver in 16 17; do 503 btree="ov${bver}_$atree" 504 run_dtc_test -I dtb -O dtb -V$bver -o $btree $atree 505 run_test dtbs_equal_ordered $btree $tree 506 done 507 done 508 done 509 510 # Check merge/overlay functionality 511 run_dtc_test -I dts -O dtb -o dtc_tree1_merge.test.dtb test_tree1_merge.dts 512 tree1_tests dtc_tree1_merge.test.dtb test_tree1.dtb 513 run_dtc_test -I dts -O dtb -o dtc_tree1_merge_labelled.test.dtb test_tree1_merge_labelled.dts 514 tree1_tests dtc_tree1_merge_labelled.test.dtb test_tree1.dtb 515 run_dtc_test -I dts -O dtb -o dtc_tree1_label_noderef.test.dtb test_tree1_label_noderef.dts 516 run_test dtbs_equal_unordered dtc_tree1_label_noderef.test.dtb test_tree1.dtb 517 run_dtc_test -I dts -O dtb -o multilabel_merge.test.dtb multilabel_merge.dts 518 run_test references multilabel.test.dtb 519 run_test dtbs_equal_ordered multilabel.test.dtb multilabel_merge.test.dtb 520 run_dtc_test -I dts -O dtb -o dtc_tree1_merge_path.test.dtb test_tree1_merge_path.dts 521 tree1_tests dtc_tree1_merge_path.test.dtb test_tree1.dtb 522 run_wrap_error_test $DTC -I dts -O dtb -o /dev/null test_label_ref.dts 523 524 # Check prop/node delete functionality 525 run_dtc_test -I dts -O dtb -o dtc_tree1_delete.test.dtb test_tree1_delete.dts 526 tree1_tests dtc_tree1_delete.test.dtb 527 528 run_dtc_test -I dts -O dts -o delete_reinstate_multilabel.dts.test.dts delete_reinstate_multilabel.dts 529 run_wrap_test cmp delete_reinstate_multilabel.dts.test.dts delete_reinstate_multilabel_ref.dts 530 531 # Check some checks 532 check_tests dup-nodename.dts duplicate_node_names 533 check_tests dup-propname.dts duplicate_property_names 534 check_tests dup-phandle.dts explicit_phandles 535 check_tests zero-phandle.dts explicit_phandles 536 check_tests minusone-phandle.dts explicit_phandles 537 run_sh_test dtc-checkfails.sh phandle_references -- -I dts -O dtb nonexist-node-ref.dts 538 run_sh_test dtc-checkfails.sh phandle_references -- -I dts -O dtb nonexist-label-ref.dts 539 run_sh_test dtc-fatal.sh -I dts -O dtb nonexist-node-ref2.dts 540 check_tests bad-name-property.dts name_properties 541 542 check_tests bad-ncells.dts address_cells_is_cell size_cells_is_cell interrupt_cells_is_cell 543 check_tests bad-string-props.dts device_type_is_string model_is_string status_is_string 544 check_tests bad-reg-ranges.dts reg_format ranges_format 545 check_tests bad-empty-ranges.dts ranges_format 546 check_tests reg-ranges-root.dts reg_format ranges_format 547 check_tests default-addr-size.dts avoid_default_addr_size 548 check_tests obsolete-chosen-interrupt-controller.dts obsolete_chosen_interrupt_controller 549 check_tests reg-without-unit-addr.dts unit_address_vs_reg 550 check_tests unit-addr-without-reg.dts unit_address_vs_reg 551 check_tests unit-addr-leading-0x.dts unit_address_format 552 check_tests unit-addr-leading-0s.dts unit_address_format 553 run_sh_test dtc-checkfails.sh node_name_chars -- -I dtb -O dtb bad_node_char.dtb 554 run_sh_test dtc-checkfails.sh node_name_format -- -I dtb -O dtb bad_node_format.dtb 555 run_sh_test dtc-checkfails.sh prop_name_chars -- -I dtb -O dtb bad_prop_char.dtb 556 557 run_sh_test dtc-checkfails.sh duplicate_label -- -I dts -O dtb reuse-label1.dts 558 run_sh_test dtc-checkfails.sh duplicate_label -- -I dts -O dtb reuse-label2.dts 559 run_sh_test dtc-checkfails.sh duplicate_label -- -I dts -O dtb reuse-label3.dts 560 run_sh_test dtc-checkfails.sh duplicate_label -- -I dts -O dtb reuse-label4.dts 561 run_sh_test dtc-checkfails.sh duplicate_label -- -I dts -O dtb reuse-label5.dts 562 run_sh_test dtc-checkfails.sh duplicate_label -- -I dts -O dtb reuse-label6.dts 563 564 run_test check_path test_tree1.dtb exists "/subnode@1" 565 run_test check_path test_tree1.dtb not-exists "/subnode@10" 566 567 # Check warning options 568 run_sh_test dtc-checkfails.sh address_cells_is_cell interrupt_cells_is_cell -n size_cells_is_cell -- -Wno_size_cells_is_cell -I dts -O dtb bad-ncells.dts 569 run_sh_test dtc-fails.sh -n test-warn-output.test.dtb -I dts -O dtb bad-ncells.dts 570 run_sh_test dtc-fails.sh test-error-output.test.dtb -I dts -O dtb bad-ncells.dts -Esize_cells_is_cell 571 run_sh_test dtc-checkfails.sh always_fail -- -Walways_fail -I dts -O dtb test_tree1.dts 572 run_sh_test dtc-checkfails.sh -n always_fail -- -Walways_fail -Wno_always_fail -I dts -O dtb test_tree1.dts 573 run_sh_test dtc-fails.sh test-negation-1.test.dtb -Ealways_fail -I dts -O dtb test_tree1.dts 574 run_sh_test dtc-fails.sh -n test-negation-2.test.dtb -Ealways_fail -Eno_always_fail -I dts -O dtb test_tree1.dts 575 run_sh_test dtc-fails.sh test-negation-3.test.dtb -Ealways_fail -Wno_always_fail -I dts -O dtb test_tree1.dts 576 run_sh_test dtc-fails.sh -n test-negation-4.test.dtb -Esize_cells_is_cell -Eno_size_cells_is_cell -I dts -O dtb bad-ncells.dts 577 run_sh_test dtc-checkfails.sh size_cells_is_cell -- -Esize_cells_is_cell -Eno_size_cells_is_cell -I dts -O dtb bad-ncells.dts 578 579 # Check for proper behaviour reading from stdin 580 run_dtc_test -I dts -O dtb -o stdin_dtc_tree1.test.dtb - < test_tree1.dts 581 run_wrap_test cmp stdin_dtc_tree1.test.dtb dtc_tree1.test.dtb 582 run_dtc_test -I dtb -O dts -o stdin_odts_test_tree1.dtb.test.dts - < test_tree1.dtb 583 run_wrap_test cmp stdin_odts_test_tree1.dtb.test.dts odts_test_tree1.dtb.test.dts 584 585 # Check integer expresisons 586 run_test integer-expressions -g integer-expressions.test.dts 587 run_dtc_test -I dts -O dtb -o integer-expressions.test.dtb integer-expressions.test.dts 588 run_test integer-expressions integer-expressions.test.dtb 589 590 # Check for graceful failure in some error conditions 591 run_sh_test dtc-fatal.sh -I dts -O dtb nosuchfile.dts 592 run_sh_test dtc-fatal.sh -I dtb -O dtb nosuchfile.dtb 593 run_sh_test dtc-fatal.sh -I fs -O dtb nosuchfile 594 595 # Dependencies 596 run_dtc_test -I dts -O dtb -o dependencies.test.dtb -d dependencies.test.d dependencies.dts 597 run_wrap_test cmp dependencies.test.d dependencies.cmp 598 599 # Search paths 600 run_wrap_error_test $DTC -I dts -O dtb -o search_paths.dtb search_paths.dts 601 run_dtc_test -i search_dir -I dts -O dtb -o search_paths.dtb \ 602 search_paths.dts 603 run_wrap_error_test $DTC -i search_dir_b -I dts -O dtb \ 604 -o search_paths_b.dtb search_paths_b.dts 605 run_dtc_test -i search_dir_b -i search_dir -I dts -O dtb \ 606 -o search_paths_b.dtb search_paths_b.dts 607 run_dtc_test -I dts -O dtb -o search_paths_subdir.dtb \ 608 search_dir_b/search_paths_subdir.dts 609 610 # Check -a option 611 for align in 2 4 8 16 32 64; do 612 # -p -a 613 run_dtc_test -O dtb -p 1000 -a $align -o align0.dtb subnode_iterate.dts 614 check_align align0.dtb $align 615 # -S -a 616 run_dtc_test -O dtb -S 1999 -a $align -o align1.dtb subnode_iterate.dts 617 check_align align1.dtb $align 618 done 619 620 # Tests for overlay/plugin generation 621 dtc_overlay_tests 622} 623 624cmp_tests () { 625 basetree="$1" 626 shift 627 wrongtrees="$@" 628 629 run_test dtb_reverse $basetree 630 631 # First dtbs_equal_ordered 632 run_test dtbs_equal_ordered $basetree $basetree 633 run_test dtbs_equal_ordered -n $basetree $basetree.reversed.test.dtb 634 for tree in $wrongtrees; do 635 run_test dtbs_equal_ordered -n $basetree $tree 636 done 637 638 # now unordered 639 run_test dtbs_equal_unordered $basetree $basetree 640 run_test dtbs_equal_unordered $basetree $basetree.reversed.test.dtb 641 run_test dtbs_equal_unordered $basetree.reversed.test.dtb $basetree 642 for tree in $wrongtrees; do 643 run_test dtbs_equal_unordered -n $basetree $tree 644 done 645 646 # now dtc --sort 647 run_dtc_test -I dtb -O dtb -s -o $basetree.sorted.test.dtb $basetree 648 run_test dtbs_equal_unordered $basetree $basetree.sorted.test.dtb 649 run_dtc_test -I dtb -O dtb -s -o $basetree.reversed.sorted.test.dtb $basetree.reversed.test.dtb 650 run_test dtbs_equal_unordered $basetree.reversed.test.dtb $basetree.reversed.sorted.test.dtb 651 run_test dtbs_equal_ordered $basetree.sorted.test.dtb $basetree.reversed.sorted.test.dtb 652} 653 654dtbs_equal_tests () { 655 WRONG_TREE1="" 656 for x in 1 2 3 4 5 6 7 8 9; do 657 run_dtc_test -I dts -O dtb -o test_tree1_wrong$x.test.dtb test_tree1_wrong$x.dts 658 WRONG_TREE1="$WRONG_TREE1 test_tree1_wrong$x.test.dtb" 659 done 660 cmp_tests test_tree1.dtb $WRONG_TREE1 661} 662 663fdtget_tests () { 664 dts=label01.dts 665 dtb=$dts.fdtget.test.dtb 666 run_dtc_test -O dtb -o $dtb $dts 667 668 # run_fdtget_test <expected-result> [<flags>] <file> <node> <property> 669 run_fdtget_test "MyBoardName" $dtb / model 670 run_fdtget_test "MyBoardName MyBoardFamilyName" $dtb / compatible 671 run_fdtget_test "77 121 66 111 \ 67297 114 100 78 97 109 101 0 77 121 66 111 97 114 100 70 97 109 105 \ 673108 121 78 97 109 101 0" -t bu $dtb / compatible 674 run_fdtget_test "MyBoardName MyBoardFamilyName" -t s $dtb / compatible 675 run_fdtget_test 32768 $dtb /cpus/PowerPC,970@1 d-cache-size 676 run_fdtget_test 8000 -tx $dtb /cpus/PowerPC,970@1 d-cache-size 677 run_fdtget_test "61 62 63 0" -tbx $dtb /randomnode tricky1 678 run_fdtget_test "a b c d de ea ad be ef" -tbx $dtb /randomnode blob 679 680 # Here the property size is not a multiple of 4 bytes, so it should fail 681 run_wrap_error_test $DTGET -tlx $dtb /randomnode mixed 682 run_fdtget_test "6162 6300 1234 0 a 0 b 0 c" -thx $dtb /randomnode mixed 683 run_fdtget_test "61 62 63 0 12 34 0 0 0 a 0 0 0 b 0 0 0 c" \ 684 -thhx $dtb /randomnode mixed 685 run_wrap_error_test $DTGET -ts $dtb /randomnode doctor-who 686 687 # Test multiple arguments 688 run_fdtget_test "MyBoardName\nmemory" -ts $dtb / model /memory device_type 689 690 # Test defaults 691 run_wrap_error_test $DTGET -tx $dtb /randomnode doctor-who 692 run_fdtget_test "<the dead silence>" -tx \ 693 -d "<the dead silence>" $dtb /randomnode doctor-who 694 run_fdtget_test "<blink>" -tx -d "<blink>" $dtb /memory doctor-who 695} 696 697fdtput_tests () { 698 dts=label01.dts 699 dtb=$dts.fdtput.test.dtb 700 text=lorem.txt 701 702 # Allow just enough space for $text 703 run_dtc_test -O dtb -p $(stat -c %s $text) -o $dtb $dts 704 705 # run_fdtput_test <expected-result> <file> <node> <property> <flags> <value> 706 run_fdtput_test "a_model" $dtb / model -ts "a_model" 707 run_fdtput_test "board1 board2" $dtb / compatible -ts board1 board2 708 run_fdtput_test "board1 board2" $dtb / compatible -ts "board1 board2" 709 run_fdtput_test "32768" $dtb /cpus/PowerPC,970@1 d-cache-size "" "32768" 710 run_fdtput_test "8001" $dtb /cpus/PowerPC,970@1 d-cache-size -tx 0x8001 711 run_fdtput_test "2 3 12" $dtb /randomnode tricky1 -tbi "02 003 12" 712 run_fdtput_test "a b c ea ad be ef" $dtb /randomnode blob \ 713 -tbx "a b c ea ad be ef" 714 run_fdtput_test "a0b0c0d deeaae ef000000" $dtb /randomnode blob \ 715 -tx "a0b0c0d deeaae ef000000" 716 run_fdtput_test "$(cat $text)" $dtb /randomnode blob -ts "$(cat $text)" 717 718 # Test expansion of the blob when insufficient room for property 719 run_fdtput_test "$(cat $text $text)" $dtb /randomnode blob -ts "$(cat $text $text)" 720 721 # Start again with a fresh dtb 722 run_dtc_test -O dtb -p $(stat -c %s $text) -o $dtb $dts 723 724 # Node creation 725 run_wrap_error_test $DTPUT $dtb -c /baldrick sod 726 run_wrap_test $DTPUT $dtb -c /chosen/son /chosen/daughter 727 run_fdtput_test "eva" $dtb /chosen/daughter name "" -ts "eva" 728 run_fdtput_test "adam" $dtb /chosen/son name "" -ts "adam" 729 730 # Not allowed to create an existing node 731 run_wrap_error_test $DTPUT $dtb -c /chosen 732 run_wrap_error_test $DTPUT $dtb -c /chosen/son 733 734 # Automatic node creation 735 run_wrap_test $DTPUT $dtb -cp /blackadder/the-second/turnip \ 736 /blackadder/the-second/potato 737 run_fdtput_test 1000 $dtb /blackadder/the-second/turnip cost "" 1000 738 run_fdtput_test "fine wine" $dtb /blackadder/the-second/potato drink \ 739 "-ts" "fine wine" 740 run_wrap_test $DTPUT $dtb -p /you/are/drunk/sir/winston slurp -ts twice 741 742 # Test expansion of the blob when insufficent room for a new node 743 run_wrap_test $DTPUT $dtb -cp "$(cat $text $text)/longish" 744 745 # Allowed to create an existing node with -p 746 run_wrap_test $DTPUT $dtb -cp /chosen 747 run_wrap_test $DTPUT $dtb -cp /chosen/son 748 749 # Start again with a fresh dtb 750 run_dtc_test -O dtb -p $(stat -c %s $text) -o $dtb $dts 751 752 # Node delete 753 run_wrap_test $DTPUT $dtb -c /chosen/node1 /chosen/node2 /chosen/node3 754 run_fdtget_test "node3\nnode2\nnode1" $dtb -l /chosen 755 run_wrap_test $DTPUT $dtb -r /chosen/node1 /chosen/node2 756 run_fdtget_test "node3" $dtb -l /chosen 757 758 # Delete the non-existent node 759 run_wrap_error_test $DTPUT $dtb -r /non-existent/node 760 761 # Property delete 762 run_fdtput_test "eva" $dtb /chosen/ name "" -ts "eva" 763 run_fdtput_test "016" $dtb /chosen/ age "" -ts "016" 764 run_fdtget_test "age\nname\nbootargs\nlinux,platform" $dtb -p /chosen 765 run_wrap_test $DTPUT $dtb -d /chosen/ name age 766 run_fdtget_test "bootargs\nlinux,platform" $dtb -p /chosen 767 768 # Delete the non-existent property 769 run_wrap_error_test $DTPUT $dtb -d /chosen non-existent-prop 770 771 # TODO: Add tests for verbose mode? 772} 773 774utilfdt_tests () { 775 run_test utilfdt_test 776} 777 778fdtdump_tests () { 779 run_fdtdump_test fdtdump.dts 780} 781 782fdtoverlay_tests() { 783 base=overlay_base.dts 784 basedtb=overlay_base.fdoverlay.test.dtb 785 overlay=overlay_overlay_manual_fixups.dts 786 overlaydtb=overlay_overlay_manual_fixups.fdoverlay.test.dtb 787 targetdtb=target.fdoverlay.test.dtb 788 789 run_dtc_test -@ -I dts -O dtb -o $basedtb $base 790 run_dtc_test -@ -I dts -O dtb -o $overlaydtb $overlay 791 792 # test that the new property is installed 793 run_fdtoverlay_test foobar "/test-node" "test-str-property" "-ts" ${basedtb} ${targetdtb} ${overlaydtb} 794} 795 796pylibfdt_tests () { 797 TMP=/tmp/tests.stderr.$$ 798 python pylibfdt_tests.py -v 2> $TMP 799 800 # Use the 'ok' message meaning the test passed, 'ERROR' meaning it failed 801 # and the summary line for total tests (e.g. 'Ran 17 tests in 0.002s'). 802 # We could add pass + fail to get total tests, but this provides a useful 803 # sanity check. 804 pass_count=$(grep "\.\.\. ok$" $TMP | wc -l) 805 fail_count=$(grep "^ERROR: " $TMP | wc -l) 806 total_tests=$(sed -n 's/^Ran \([0-9]*\) tests.*$/\1/p' $TMP) 807 cat $TMP 808 rm $TMP 809 810 # Extract the test results and add them to our totals 811 tot_fail=$((tot_fail + $fail_count)) 812 tot_pass=$((tot_pass + $pass_count)) 813 tot_tests=$((tot_tests + $total_tests)) 814} 815 816while getopts "vt:me" ARG ; do 817 case $ARG in 818 "v") 819 unset QUIET_TEST 820 ;; 821 "t") 822 TESTSETS=$OPTARG 823 ;; 824 "m") 825 VALGRIND="valgrind --tool=memcheck -q --error-exitcode=$VGCODE" 826 ;; 827 "e") 828 STOP_ON_FAIL=1 829 ;; 830 esac 831done 832 833if [ -z "$TESTSETS" ]; then 834 TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump fdtoverlay" 835 836 # Test pylibfdt if the libfdt Python module is available. 837 if [ -f ../pylibfdt/_libfdt.so ]; then 838 TESTSETS="$TESTSETS pylibfdt" 839 fi 840fi 841 842# Make sure we don't have stale blobs lying around 843rm -f *.test.dtb *.test.dts 844 845for set in $TESTSETS; do 846 case $set in 847 "libfdt") 848 libfdt_tests 849 ;; 850 "utilfdt") 851 utilfdt_tests 852 ;; 853 "dtc") 854 dtc_tests 855 ;; 856 "dtbs_equal") 857 dtbs_equal_tests 858 ;; 859 "fdtget") 860 fdtget_tests 861 ;; 862 "fdtput") 863 fdtput_tests 864 ;; 865 "fdtdump") 866 fdtdump_tests 867 ;; 868 "pylibfdt") 869 pylibfdt_tests 870 ;; 871 "fdtoverlay") 872 fdtoverlay_tests 873 ;; 874 esac 875done 876 877echo "********** TEST SUMMARY" 878echo "* Total testcases: $tot_tests" 879echo "* PASS: $tot_pass" 880echo "* FAIL: $tot_fail" 881echo "* Bad configuration: $tot_config" 882if [ -n "$VALGRIND" ]; then 883 echo "* valgrind errors: $tot_vg" 884fi 885echo "* Strange test result: $tot_strange" 886echo "**********" 887 888