blob: ced13ac8bb468858f4ca7047eca45e094bf3ba10 [file] [log] [blame]
Simon Glassd8e36352016-07-03 09:40:33 -06001Testing in U-Boot
2=================
3
4U-Boot has a large amount of code. This file describes how this code is
5tested and what tests you should write when adding a new feature.
6
7
Simon Glass8ab6cc32016-07-03 09:40:34 -06008Running tests
9-------------
10
Simon Glasscb605d22021-03-07 17:34:38 -070011To run most tests on sandbox, type this::
Simon Glass8ab6cc32016-07-03 09:40:34 -060012
Simon Glass3fcb8282018-11-18 08:14:29 -070013 make check
Simon Glass8ab6cc32016-07-03 09:40:34 -060014
15in the U-Boot directory. Note that only the pytest suite is run using this
Simon Glassdc3ab7e2016-07-31 17:35:02 -060016command.
Simon Glass8ab6cc32016-07-03 09:40:34 -060017
Simon Glass3602c552021-03-07 17:34:39 -070018Some tests take ages to run and are marked with @pytest.mark.slow. To run just
19the quick ones, type this::
Simon Glass3fcb8282018-11-18 08:14:29 -070020
21 make qcheck
22
Simon Glass3602c552021-03-07 17:34:39 -070023It is also possible to run just the tests for tools (patman, binman, etc.).
24Such tests are included with those tools, i.e. no actual U-Boot unit tests are
25run. Type this::
26
27 make tcheck
28
29All of the above use the test/run script with a paremeter to select which tests
30are run.
31
Simon Glass8ab6cc32016-07-03 09:40:34 -060032
Simon Glassd8e36352016-07-03 09:40:33 -060033Sandbox
34-------
35U-Boot can be built as a user-space application (e.g. for Linux). This
36allows test to be executed without needing target hardware. The 'sandbox'
37target provides this feature and it is widely used in tests.
38
Simon Glass9e78ad62021-03-07 17:34:42 -070039See :doc:`tests_sandbox` for more information.
Simon Glassd8e36352016-07-03 09:40:33 -060040
41Pytest Suite
42------------
43
44Many tests are available using the pytest suite, in test/py. This can run
45either on sandbox or on real hardware. It relies on the U-Boot console to
46inject test commands and check the result. It is slower to run than C code,
Simon Glassdc3ab7e2016-07-31 17:35:02 -060047but provides the ability to unify lots of tests and summarise their results.
Simon Glassd8e36352016-07-03 09:40:33 -060048
Simon Glasscb605d22021-03-07 17:34:38 -070049You can run the tests on sandbox with::
Simon Glassd8e36352016-07-03 09:40:33 -060050
Simon Glasscb605d22021-03-07 17:34:38 -070051 ./test/py/test.py --bd sandbox --build
Simon Glassd8e36352016-07-03 09:40:33 -060052
53This will produce HTML output in build-sandbox/test-log.html
54
Simon Glass9e78ad62021-03-07 17:34:42 -070055Some tests run with other versions of sandbox. For example sandbox_flattree
56runs the tests with livetree (the hierachical devicetree) disabled. You can
57also select particular tests with -k::
58
59 ./test/py/test.py --bd sandbox_flattree --build -k hello
60
Simon Glasseaf21962021-03-07 17:34:43 -070061There are some special tests that run in SPL. For this you need the sandbox_spl
62build::
63
64 ./test/py/test.py --bd sandbox_spl --build -k test_spl
65
Simon Glassd8e36352016-07-03 09:40:33 -060066See test/py/README.md for more information about the pytest suite.
67
Simon Glass9e78ad62021-03-07 17:34:42 -070068See :doc:`tests_sandbox` for how to run tests directly (not through pytest).
69
Simon Glassd8e36352016-07-03 09:40:33 -060070
71tbot
72----
73
74Tbot provides a way to execute tests on target hardware. It is intended for
75trying out both U-Boot and Linux (and potentially other software) on a
76number of boards automatically. It can be used to create a continuous test
Heiko Schocherd551b842017-06-09 06:13:34 +020077environment. See http://www.tbot.tools for more information.
Simon Glassd8e36352016-07-03 09:40:33 -060078
79
80Ad-hoc tests
81------------
82
83There are several ad-hoc tests which run outside the pytest environment:
84
Simon Glasscb605d22021-03-07 17:34:38 -070085test/fs
86 File system test (shell script)
87test/image
88 FIT and legacy image tests (shell script and Python)
89test/stdint
90 A test that stdint.h can be used in U-Boot (shell script)
91trace
92 Test for the tracing feature (shell script)
Simon Glassd8e36352016-07-03 09:40:33 -060093
Simon Glassdc3ab7e2016-07-31 17:35:02 -060094TODO: Move these into pytest.
Simon Glassd8e36352016-07-03 09:40:33 -060095
96
97When to write tests
98-------------------
99
100If you add code to U-Boot without a test you are taking a risk. Even if you
101perform thorough manual testing at the time of submission, it may break when
102future changes are made to U-Boot. It may even break when applied to mainline,
103if other changes interact with it. A good mindset is that untested code
104probably doesn't work and should be deleted.
105
106You can assume that the Pytest suite will be run before patches are accepted
107to mainline, so this provides protection against future breakage.
108
109On the other hand there is quite a bit of code that is not covered with tests,
110or is covered sparingly. So here are some suggestions:
111
112- If you are adding a new uclass, add a sandbox driver and a test that uses it
113- If you are modifying code covered by an existing test, add a new test case
114 to cover your changes
115- If the code you are modifying has not tests, consider writing one. Even a
116 very basic test is useful, and may be picked up and enhanced by others. It
117 is much easier to add onto a test - writing a new large test can seem
118 daunting to most contributors.
119
Simon Glass25404102021-03-07 17:35:17 -0700120See doc:`tests_writing` for how to write tests.
121
Simon Glassd8e36352016-07-03 09:40:33 -0600122
123Future work
124-----------
125
126Converting existing shell scripts into pytest tests.