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