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