testing.rst 3.9 KB

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