run 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash
  2. # Script to run all U-Boot tests that use sandbox.
  3. # $1: tests to run (empty for all, 'quick' for quick ones only)
  4. # Runs a test and checks the exit code to decide if it passed
  5. # $1: Test name
  6. # $2 onwards: command line to run
  7. run_test() {
  8. echo -n "$1: "
  9. shift
  10. "$@"
  11. [ $? -ne 0 ] && failures=$((failures+1))
  12. }
  13. # Select test attributes
  14. ut_mark_expr=test_ut
  15. if [ "$1" = "quick" ]; then
  16. mark_expr="not slow"
  17. ut_mark_expr="test_ut and not slow"
  18. skip=--skip-net-tests
  19. fi
  20. [ "$1" == "tools" ] && tools_only=y
  21. if [ "$1" = "parallel" ]; then
  22. if ! echo 'import xdist' | python3 2>/dev/null; then
  23. echo "Please install python3-pytest-xdist - see doc/develop/py_testing.rst"
  24. exit 1
  25. fi
  26. jobs="$(($(nproc) > 16 ? 16 : $(nproc)))"
  27. para="-n${jobs} -q"
  28. prompt="Building and..."
  29. skip=--skip-net-tests
  30. mark_expr="not slow and not bootstd and not spi_flash"
  31. ut_mark_expr="test_ut and not slow and not bootstd and not spi_flash"
  32. echo "Note: test log is garbled with parallel tests"
  33. fi
  34. failures=0
  35. if [ -z "$tools_only" ]; then
  36. # Run all tests that the standard sandbox build can support
  37. echo "${prompt}"
  38. run_test "sandbox" ./test/py/test.py --bd sandbox --build ${para} \
  39. -k "${mark_expr}"
  40. fi
  41. # Run tests which require sandbox_spl
  42. echo "${prompt}"
  43. run_test "sandbox_spl" ./test/py/test.py --bd sandbox_spl --build ${para} \
  44. -k 'test_ofplatdata or test_handoff or test_spl'
  45. # Run the same tests with sandbox_noinst (i.e. without OF_PLATDATA_INST)
  46. echo "${prompt}"
  47. run_test "sandbox_noinst" ./test/py/test.py --bd sandbox_noinst --build ${para} \
  48. -k 'test_ofplatdata or test_handoff or test_spl'
  49. # Run tests which require sandbox_vpl
  50. echo "${prompt}"
  51. run_test "sandbox_vpl" ./test/py/test.py --bd sandbox_vpl --build ${para} \
  52. -k 'vpl or test_spl'
  53. if [ -z "$tools_only" ]; then
  54. # Run tests for the flat-device-tree version of sandbox. This is a special
  55. # build which does not enable CONFIG_OF_LIVE for the live device tree, so we can
  56. # check that functionality is the same. The standard sandbox build (above) uses
  57. # CONFIG_OF_LIVE.
  58. echo "${prompt}"
  59. run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree \
  60. ${para} --build -k "${ut_mark_expr}"
  61. fi
  62. # Set up a path to dtc (device-tree compiler) and libfdt.py, a library it
  63. # provides and which is built by the sandbox_spl config. Also set up the path
  64. # to tools build by the build.
  65. DTC_DIR=build-sandbox_spl/scripts/dtc
  66. export PYTHONPATH=${DTC_DIR}/pylibfdt
  67. export DTC=${DTC_DIR}/dtc
  68. TOOLS_DIR=build-sandbox_spl/tools
  69. run_test "binman" ./tools/binman/binman --toolpath ${TOOLS_DIR} test
  70. run_test "patman" ./tools/patman/patman test
  71. run_test "u_boot_pylib" ./tools/u_boot_pylib/u_boot_pylib
  72. run_test "buildman" ./tools/buildman/buildman -t ${skip}
  73. run_test "fdt" ./tools/dtoc/test_fdt -t
  74. run_test "dtoc" ./tools/dtoc/dtoc -t
  75. # This needs you to set up Python test coverage tools.
  76. # To enable Python test coverage on Debian-type distributions (e.g. Ubuntu):
  77. # $ sudo apt-get install python-pytest python-coverage
  78. # Code-coverage tests cannot run in parallel, so skip them in that case
  79. if [ -z "${para}" ]; then
  80. export PATH=$PATH:${TOOLS_DIR}
  81. run_test "binman code coverage" ./tools/binman/binman test -T
  82. run_test "dtoc code coverage" ./tools/dtoc/dtoc -T
  83. run_test "fdt code coverage" ./tools/dtoc/test_fdt -T
  84. fi
  85. if [ $failures == 0 ]; then
  86. echo "Tests passed!"
  87. else
  88. echo "Tests FAILED"
  89. exit 1
  90. fi