testing.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. Introduction to testing
  3. =======================
  4. U-Boot has a large amount of code. This file describes how this code is
  5. tested and what tests you should write when adding a new feature.
  6. Running tests
  7. -------------
  8. To run most tests on sandbox, type this::
  9. make check
  10. in the U-Boot directory. Note that only the pytest suite is run using this
  11. command.
  12. Some tests take ages to run and are marked with @pytest.mark.slow. To run just
  13. the quick ones, type this::
  14. make qcheck
  15. It is also possible to run just the tests for tools (patman, binman, etc.).
  16. Such tests are included with those tools, i.e. no actual U-Boot unit tests are
  17. run. Type this::
  18. make tcheck
  19. You can also run a selection tests in parallel with::
  20. make pcheck
  21. All of the above use the test/run script with a paremeter to select which tests
  22. are run. See :doc:`py_testing` for more information.
  23. Sandbox
  24. -------
  25. U-Boot can be built as a user-space application (e.g. for Linux). This
  26. allows test to be executed without needing target hardware. The 'sandbox'
  27. target provides this feature and it is widely used in tests.
  28. See :doc:`tests_sandbox` for more information.
  29. Pytest Suite
  30. ------------
  31. Many tests are available using the pytest suite, in test/py. This can run
  32. either on sandbox or on real hardware. It relies on the U-Boot console to
  33. inject test commands and check the result. It is slower to run than C code,
  34. but provides the ability to unify lots of tests and summarise their results.
  35. You can run the tests on sandbox with::
  36. ./test/py/test.py --bd sandbox --build
  37. This will produce HTML output in build-sandbox/test-log.html
  38. Some tests run with other versions of sandbox. For example sandbox_flattree
  39. runs the tests with livetree (the hierachical devicetree) disabled. You can
  40. also select particular tests with -k::
  41. ./test/py/test.py --bd sandbox_flattree --build -k hello
  42. There are some special tests that run in SPL. For this you need the sandbox_spl
  43. build::
  44. ./test/py/test.py --bd sandbox_spl --build -k test_spl
  45. See test/py/README.md for more information about the pytest suite.
  46. See :doc:`tests_sandbox` for how to run tests directly (not through pytest).
  47. tbot
  48. ----
  49. Tbot provides a way to execute tests on target hardware. It is intended for
  50. trying out both U-Boot and Linux (and potentially other software) on a
  51. number of boards automatically. It can be used to create a continuous test
  52. environment. See http://www.tbot.tools for more information.
  53. Ad-hoc tests
  54. ------------
  55. There are several ad-hoc tests which run outside the pytest environment:
  56. test/fs
  57. File system test (shell script)
  58. test/image
  59. FIT and legacy image tests (shell script and Python)
  60. test/stdint
  61. A test that stdint.h can be used in U-Boot (shell script)
  62. trace
  63. Test for the tracing feature (shell script)
  64. TODO: Move these into pytest.
  65. When to write tests
  66. -------------------
  67. If you add code to U-Boot without a test you are taking a risk. Even if you
  68. perform thorough manual testing at the time of submission, it may break when
  69. future changes are made to U-Boot. It may even break when applied to mainline,
  70. if other changes interact with it. A good mindset is that untested code
  71. probably doesn't work and should be deleted.
  72. You can assume that the Pytest suite will be run before patches are accepted
  73. to mainline, so this provides protection against future breakage.
  74. On the other hand there is quite a bit of code that is not covered with tests,
  75. or is covered sparingly. So here are some suggestions:
  76. - If you are adding a new uclass, add a sandbox driver and a test that uses it
  77. - If you are modifying code covered by an existing test, add a new test case
  78. to cover your changes
  79. - If the code you are modifying has not tests, consider writing one. Even a
  80. very basic test is useful, and may be picked up and enhanced by others. It
  81. is much easier to add onto a test - writing a new large test can seem
  82. daunting to most contributors.
  83. See doc:`tests_writing` for how to write tests.
  84. Future work
  85. -----------
  86. Converting existing shell scripts into pytest tests.