blob: f01ca4dc4084e1aa04de63a59ec6c8b1b95f14d1 [file] [log] [blame]
Simon Glassf6349c32016-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 Glass07f4ead2016-07-03 09:40:34 -06008Running tests
9-------------
10
Simon Glassccf69382021-03-07 17:34:38 -070011To run most tests on sandbox, type this::
Simon Glass07f4ead2016-07-03 09:40:34 -060012
Simon Glass499fde52018-11-18 08:14:29 -070013 make check
Simon Glass07f4ead2016-07-03 09:40:34 -060014
15in the U-Boot directory. Note that only the pytest suite is run using this
Simon Glassbcbd0c82016-07-31 17:35:02 -060016command.
Simon Glass07f4ead2016-07-03 09:40:34 -060017
Simon Glass8d16ebd2021-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 Glass499fde52018-11-18 08:14:29 -070020
21 make qcheck
22
Simon Glass8d16ebd2021-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 Glass07f4ead2016-07-03 09:40:34 -060032
Simon Glassf6349c32016-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
39
40Pytest Suite
41------------
42
43Many tests are available using the pytest suite, in test/py. This can run
44either on sandbox or on real hardware. It relies on the U-Boot console to
45inject test commands and check the result. It is slower to run than C code,
Simon Glassbcbd0c82016-07-31 17:35:02 -060046but provides the ability to unify lots of tests and summarise their results.
Simon Glassf6349c32016-07-03 09:40:33 -060047
Simon Glassccf69382021-03-07 17:34:38 -070048You can run the tests on sandbox with::
Simon Glassf6349c32016-07-03 09:40:33 -060049
Simon Glassccf69382021-03-07 17:34:38 -070050 ./test/py/test.py --bd sandbox --build
Simon Glassf6349c32016-07-03 09:40:33 -060051
52This will produce HTML output in build-sandbox/test-log.html
53
54See test/py/README.md for more information about the pytest suite.
55
56
57tbot
58----
59
60Tbot provides a way to execute tests on target hardware. It is intended for
61trying out both U-Boot and Linux (and potentially other software) on a
62number of boards automatically. It can be used to create a continuous test
Heiko Schocher630dfed2017-06-09 06:13:34 +020063environment. See http://www.tbot.tools for more information.
Simon Glassf6349c32016-07-03 09:40:33 -060064
65
66Ad-hoc tests
67------------
68
69There are several ad-hoc tests which run outside the pytest environment:
70
Simon Glassccf69382021-03-07 17:34:38 -070071test/fs
72 File system test (shell script)
73test/image
74 FIT and legacy image tests (shell script and Python)
75test/stdint
76 A test that stdint.h can be used in U-Boot (shell script)
77trace
78 Test for the tracing feature (shell script)
Simon Glassf6349c32016-07-03 09:40:33 -060079
Simon Glassbcbd0c82016-07-31 17:35:02 -060080TODO: Move these into pytest.
Simon Glassf6349c32016-07-03 09:40:33 -060081
82
83When to write tests
84-------------------
85
86If you add code to U-Boot without a test you are taking a risk. Even if you
87perform thorough manual testing at the time of submission, it may break when
88future changes are made to U-Boot. It may even break when applied to mainline,
89if other changes interact with it. A good mindset is that untested code
90probably doesn't work and should be deleted.
91
92You can assume that the Pytest suite will be run before patches are accepted
93to mainline, so this provides protection against future breakage.
94
95On the other hand there is quite a bit of code that is not covered with tests,
96or is covered sparingly. So here are some suggestions:
97
98- If you are adding a new uclass, add a sandbox driver and a test that uses it
99- If you are modifying code covered by an existing test, add a new test case
100 to cover your changes
101- If the code you are modifying has not tests, consider writing one. Even a
102 very basic test is useful, and may be picked up and enhanced by others. It
103 is much easier to add onto a test - writing a new large test can seem
104 daunting to most contributors.
105
106
107Future work
108-----------
109
110Converting existing shell scripts into pytest tests.