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