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