blob: 502053f09fc4f42e3f01c13c4ce1489088137f08 [file] [log] [blame]
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +01001U-Boot pytest suite
2===================
Stephen Warren10e50632016-01-15 11:15:24 -07003
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +01004Introduction
5------------
Stephen Warren10e50632016-01-15 11:15:24 -07006
7This tool aims to test U-Boot by executing U-Boot shell commands using the
8console interface. A single top-level script exists to execute or attach to the
9U-Boot console, run the entire script of tests against it, and summarize the
10results. Advantages of this approach are:
11
12- Testing is performed in the same way a user or script would interact with
13 U-Boot; there can be no disconnect.
14- There is no need to write or embed test-related code into U-Boot itself.
15 It is asserted that writing test-related code in Python is simpler and more
Simon Glass25404102021-03-07 17:35:17 -070016 flexible than writing it all in C. But see :doc:`tests_writing` for caveats
17 and more discussion / analysis.
Stephen Warren10e50632016-01-15 11:15:24 -070018- It is reasonably simple to interact with U-Boot in this way.
19
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010020Requirements
21------------
Stephen Warren10e50632016-01-15 11:15:24 -070022
23The test suite is implemented using pytest. Interaction with the U-Boot console
24involves executing some binary and interacting with its stdin/stdout. You will
25need to implement various "hook" scripts that are called by the test suite at
26the appropriate time.
27
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010028In order to run the test suite at a minimum we require that both Python 3 and
29pip for Python 3 are installed. All of the required python modules are
30described in the requirements.txt file in the /test/py/ directory and can be
31installed via the command
Stephen Warren10e50632016-01-15 11:15:24 -070032
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010033.. code-block:: bash
Tom Rinia39e81b2019-10-24 11:59:26 -040034
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010035 pip install -r requirements.txt
36
37In order to execute certain tests on their supported platforms other tools
38will be required. The following is an incomplete list:
AKASHI Takahiro58c95c22020-04-14 11:51:49 +090039
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010040* gdisk
41* dfu-util
42* dtc
43* openssl
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010044* e2fsprogs
45* util-linux
46* coreutils
47* dosfstools
48* efitools
49* mount
50* mtools
51* sbsigntool
52* udisks2
Tom Rinia39e81b2019-10-24 11:59:26 -040053
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010054Please use the appropriate commands for your distribution to match these tools
Tom Rinia39e81b2019-10-24 11:59:26 -040055up with the package that provides them.
Stephen Warren10e50632016-01-15 11:15:24 -070056
57The test script supports either:
58
59- Executing a sandbox port of U-Boot on the local machine as a sub-process,
60 and interacting with it over stdin/stdout.
61- Executing an external "hook" scripts to flash a U-Boot binary onto a
62 physical board, attach to the board's console stream, and reset the board.
63 Further details are described later.
64
Tom Rinib9e20602025-03-20 07:59:30 -060065The usage of the command 'sudo' is not allowed in tests. Using elevated
66priviledges can lead to security concerns. Furthermore not all users may have
67administrator rights. Therefore the command 'sudo' must not be used in tests.
68To create disk images we have helper functions located in
69`test/py/tests/fs_helper.py` which shall be used in any tests that require
70creating disk images.
Heinrich Schuchardt2c6206d2022-10-08 01:19:22 +020071
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010072Using `virtualenv` to provide requirements
73~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warren10e50632016-01-15 11:15:24 -070074
Tom Rinia39e81b2019-10-24 11:59:26 -040075The recommended way to run the test suite, in order to ensure reproducibility
76is to use `virtualenv` to set up the necessary environment. This can be done
77via the following commands:
Stephen Warren10e50632016-01-15 11:15:24 -070078
Stephen Warren10e50632016-01-15 11:15:24 -070079
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010080.. code-block:: console
Stephen Warren10e50632016-01-15 11:15:24 -070081
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010082 $ cd /path/to/u-boot
83 $ sudo apt-get install python3 python3-virtualenv
84 $ virtualenv -p /usr/bin/python3 venv
85 $ . ./venv/bin/activate
86 $ pip install -r test/py/requirements.txt
87
88Testing sandbox
89---------------
90
91To run the test suite on the sandbox port (U-Boot built as a native user-space
Stephen Warren10e50632016-01-15 11:15:24 -070092application), simply execute:
93
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +010094.. code-block:: bash
95
96 ./test/py/test.py --bd sandbox --build
Stephen Warren10e50632016-01-15 11:15:24 -070097
98The `--bd` option tells the test suite which board type is being tested. This
99lets the test suite know which features the board has, and hence exactly what
100can be tested.
101
102The `--build` option tells U-Boot to compile U-Boot. Alternatively, you may
103omit this option and build U-Boot yourself, in whatever way you choose, before
104running the test script.
105
106The test script will attach to U-Boot, execute all valid tests for the board,
107then print a summary of the test process. A complete log of the test session
108will be written to `${build_dir}/test-log.html`. This is best viewed in a web
109browser, but may be read directly as plain text, perhaps with the aid of the
110`html2text` utility.
111
Simon Glassafd00042021-10-08 09:15:23 -0600112If sandbox crashes (e.g. with a segfault) you will see message like this::
113
114
Simon Glassfb916372025-02-09 09:07:15 -0700115 test/py/spawn.py:171: in expect
Simon Glassafd00042021-10-08 09:15:23 -0600116 c = os.read(self.fd, 1024).decode(errors='replace')
117 E ValueError: U-Boot exited with signal 11 (Signals.SIGSEGV)
118
119
Simon Glass19193482021-10-05 20:18:00 -0600120Controlling output
121~~~~~~~~~~~~~~~~~~
122
123By default a short backtrace is reported. If you would like a longer one,
124pass ``--tb=long`` when running the test. See the pytest documentation for
125more options.
126
Simon Glass5c8b8842021-09-19 15:14:51 -0600127Running tests in parallel
128~~~~~~~~~~~~~~~~~~~~~~~~~
129
Simon Glassb23b98f2022-08-06 17:51:59 -0600130Note: Not all tests can run in parallel at present, so the usual approach is
131to just run those that can.
Simon Glass5c8b8842021-09-19 15:14:51 -0600132
133First install support for parallel tests::
134
Simon Glassb23b98f2022-08-06 17:51:59 -0600135 sudo apt install python3-pytest-xdist
136
137or:::
138
Simon Glass5c8b8842021-09-19 15:14:51 -0600139 pip3 install pytest-xdist
140
Simon Glassb23b98f2022-08-06 17:51:59 -0600141Then run the tests in parallel using the -n flag::
Simon Glass5c8b8842021-09-19 15:14:51 -0600142
Simon Glassb23b98f2022-08-06 17:51:59 -0600143 test/py/test.py -B sandbox --build --build-dir /tmp/b/sandbox -q -k \
144 'not slow and not bootstd and not spi_flash' -n16
Simon Glass5c8b8842021-09-19 15:14:51 -0600145
Simon Glassb23b98f2022-08-06 17:51:59 -0600146You can also use `make pcheck` to run all tests in parallel. This uses a maximum
147of 16 threads, since the setup time is significant and there are under 1000
148tests.
Simon Glass5c8b8842021-09-19 15:14:51 -0600149
Simon Glassb23b98f2022-08-06 17:51:59 -0600150Note that the `test-log.html` output does not work correctly at present with
151parallel testing. All the threads write to it at once, so it is garbled.
Simon Glass5c8b8842021-09-19 15:14:51 -0600152
Simon Glassb23b98f2022-08-06 17:51:59 -0600153Note that the `tools/` tests still run each tool's tests once after the other,
154although within that, they do run in parallel. So for example, the buildman
155tests run in parallel, then the binman tests run in parallel. There would be a
156significant advantage to running them all in parallel together, but that would
157require a large amount of refactoring, e.g. with more use of pytest fixtures.
158The code-coverage tests are omitted since they cannot run in parallel due to a
159Python limitation.
Simon Glass5c8b8842021-09-19 15:14:51 -0600160
161
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100162Testing under a debugger
163~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warrenc9afc502016-02-08 14:49:02 -0700164
165If you need to run sandbox under a debugger, you may pass the command-line
166option `--gdbserver COMM`. This causes two things to happens:
167
168- Instead of running U-Boot directly, it will be run under gdbserver, with
169 debug communication via the channel `COMM`. You can attach a debugger to the
170 sandbox process in order to debug it. See `man gdbserver` and the example
171 below for details of valid values for `COMM`.
172- All timeouts in tests are disabled, allowing U-Boot an arbitrary amount of
173 time to execute commands. This is useful if U-Boot is stopped at a breakpoint
174 during debugging.
175
176A usage example is:
177
178Window 1:
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100179
180.. code-block:: bash
181
182 ./test/py/test.py --bd sandbox --gdbserver localhost:1234
Stephen Warrenc9afc502016-02-08 14:49:02 -0700183
184Window 2:
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100185
186.. code-block:: bash
187
188 gdb ./build-sandbox/u-boot -ex 'target remote localhost:1234'
Stephen Warrenc9afc502016-02-08 14:49:02 -0700189
190Alternatively, you could leave off the `-ex` option and type the command
191manually into gdb once it starts.
192
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100193You can use any debugger you wish, as long as it speaks the gdb remote
Stephen Warrenc9afc502016-02-08 14:49:02 -0700194protocol, or any graphical wrapper around gdb.
195
196Some tests deliberately cause the sandbox process to exit, e.g. to test the
197reset command, or sandbox's CTRL-C handling. When this happens, you will need
198to attach the debugger to the new sandbox instance. If these tests are not
199relevant to your debugging session, you can skip them using pytest's -k
200command-line option; see the next section.
201
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100202Command-line options
203--------------------
204
205--board-type, --bd, -B
206 set the type of the board to be tested. For example, `sandbox` or `seaboard`.
Stephen Warren10e50632016-01-15 11:15:24 -0700207
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100208--board-identity`, --id
209 sets the identity of the board to be tested. This allows differentiation
210 between multiple instances of the same type of physical board that are
211 attached to the same host machine. This parameter is not interpreted by th
212 test script in any way, but rather is simply passed to the hook scripts
213 described below, and may be used in any site-specific way deemed necessary.
214
215--build
216 indicates that the test script should compile U-Boot itself before running
217 the tests. If using this option, make sure that any environment variables
218 required by the build process are already set, such as `$CROSS_COMPILE`.
219
220--buildman
221 indicates that `--build` should use buildman to build U-Boot. There is no need
222 to set $CROSS_COMPILE` in this case since buildman handles it.
223
224--build-dir
225 sets the directory containing the compiled U-Boot binaries. If omitted, this
226 is `${source_dir}/build-${board_type}`.
227
228--result-dir
229 sets the directory to write results, such as log files, into.
230 If omitted, the build directory is used.
231
232--persistent-data-dir
233 sets the directory used to store persistent test data. This is test data that
234 may be re-used across test runs, such as file-system images.
Stephen Warren10e50632016-01-15 11:15:24 -0700235
Simon Glass1dffd532025-01-27 07:52:54 -0700236--timing
237 shows a histogram of test duration, at the end of the run. The columns are:
238
239 Duration
240 the duration-bucket that this test was in
241
242 Total
243 total time of all tests in this bucket
244
245 Number of tests
246 graph showing the number of tests in this bucket, with the actual number
247 shown at the end
248
249 Example::
250
251 Duration : Total | Number of tests
252 ======== : ======= |========================================
253 <20ms : 418ms |## 23
254 <30ms : 9.1s |######################################## 347
255 <40ms : 10.0s |################################# 294
256 <50ms : 3.1s |####### 69
257 <75ms : 2.6s |#### 43
258 <100ms : 1.7s |## 19
259 <200ms : 3.0s |## 22
260 <300ms : 1.7s | 7
261 <400ms : 675ms | 2
262 <500ms : 2.2s | 5
263 <750ms : 8.3s |# 13
264 <1.0s : 1.6s | 2
265 <2.0s : 9.4s | 7
266 <3.0s : 2.4s | 1
267 <7.5s : 6.1s | 1
268
Stephen Warrenc9afc502016-02-08 14:49:02 -0700269`pytest` also implements a number of its own command-line options. Commonly used
270options are mentioned below. Please see `pytest` documentation for complete
271details. Execute `py.test --version` for a brief summary. Note that U-Boot's
272test.py script passes all command-line arguments directly to `pytest` for
273processing.
274
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100275-k
276 selects which tests to run. The default is to run all known tests. This
Stephen Warrenc9afc502016-02-08 14:49:02 -0700277 option takes a single argument which is used to filter test names. Simple
278 logical operators are supported. For example:
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100279
280 - `'-k ums'` runs only tests with "ums" in their name.
281 - `'-k ut_dm'` runs only tests with "ut_dm" in their name. Note that in this
Stephen Warrenc9afc502016-02-08 14:49:02 -0700282 case, "ut_dm" is a parameter to a test rather than the test name. The full
283 test name is e.g. "test_ut[ut_dm_leak]".
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100284 - `'-k not reset'` runs everything except tests with "reset" in their name.
285 - `'-k ut or hush'` runs only tests with "ut" or "hush" in their name.
286 - `'-k not (ut or hush)'` runs everything except tests with "ut" or "hush" in
Stephen Warrenc9afc502016-02-08 14:49:02 -0700287 their name.
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100288
289-s
290 prevents pytest from hiding a test's stdout. This allows you to see
Stephen Warrenc9afc502016-02-08 14:49:02 -0700291 U-Boot's console log in real time on pytest's stdout.
Stephen Warren10e50632016-01-15 11:15:24 -0700292
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100293Testing real hardware
294---------------------
Stephen Warren10e50632016-01-15 11:15:24 -0700295
296The tools and techniques used to interact with real hardware will vary
297radically between different host and target systems, and the whims of the user.
298For this reason, the test suite does not attempt to directly interact with real
299hardware in any way. Rather, it executes a standardized set of "hook" scripts
300via `$PATH`. These scripts implement certain actions on behalf of the test
301suite. This keeps the test suite simple and isolated from system variances
302unrelated to U-Boot features.
303
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100304Hook scripts
305~~~~~~~~~~~~
Stephen Warren10e50632016-01-15 11:15:24 -0700306
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100307Environment variables
308'''''''''''''''''''''
Stephen Warren10e50632016-01-15 11:15:24 -0700309
310The following environment variables are set when running hook scripts:
311
312- `UBOOT_BOARD_TYPE` the board type being tested.
313- `UBOOT_BOARD_IDENTITY` the board identity being tested, or `na` if none was
314 specified.
315- `UBOOT_SOURCE_DIR` the U-Boot source directory.
316- `UBOOT_TEST_PY_DIR` the full path to `test/py/` in the source directory.
317- `UBOOT_BUILD_DIR` the U-Boot build directory.
318- `UBOOT_RESULT_DIR` the test result directory.
Masahiro Yamadac9018912017-10-19 19:08:52 +0900319- `UBOOT_PERSISTENT_DATA_DIR` the test persistent data directory.
Stephen Warren10e50632016-01-15 11:15:24 -0700320
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100321u-boot-test-console
322'''''''''''''''''''
Stephen Warren10e50632016-01-15 11:15:24 -0700323
324This script provides access to the U-Boot console. The script's stdin/stdout
325should be connected to the board's console. This process should continue to run
326indefinitely, until killed. The test suite will run this script in parallel
327with all other hooks.
328
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100329This script may be implemented e.g. by executing `cu`, `kermit`, `conmux`, etc.
330via exec().
Stephen Warren10e50632016-01-15 11:15:24 -0700331
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100332If you are able to run U-Boot under a hardware simulator such as QEMU, then
Stephen Warren10e50632016-01-15 11:15:24 -0700333you would likely spawn that simulator from this script. However, note that
334`u-boot-test-reset` may be called multiple times per test script run, and must
335cause U-Boot to start execution from scratch each time. Hopefully your
336simulator includes a virtual reset button! If not, you can launch the
337simulator from `u-boot-test-reset` instead, while arranging for this console
338process to always communicate with the current simulator instance.
339
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100340u-boot-test-flash
341'''''''''''''''''
Stephen Warren10e50632016-01-15 11:15:24 -0700342
343Prior to running the test suite against a board, some arrangement must be made
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100344so that the board executes the particular U-Boot binary to be tested. Often
Stephen Warren10e50632016-01-15 11:15:24 -0700345this involves writing the U-Boot binary to the board's flash ROM. The test
346suite calls this hook script for that purpose.
347
348This script should perform the entire flashing process synchronously; the
349script should only exit once flashing is complete, and a board reset will
350cause the newly flashed U-Boot binary to be executed.
351
352It is conceivable that this script will do nothing. This might be useful in
353the following cases:
354
355- Some other process has already written the desired U-Boot binary into the
356 board's flash prior to running the test suite.
357- The board allows U-Boot to be downloaded directly into RAM, and executed
358 from there. Use of this feature will reduce wear on the board's flash, so
359 may be preferable if available, and if cold boot testing of U-Boot is not
360 required. If this feature is used, the `u-boot-test-reset` script should
Masahiro Yamadac9018912017-10-19 19:08:52 +0900361 perform this download, since the board could conceivably be reset multiple
Stephen Warren10e50632016-01-15 11:15:24 -0700362 times in a single test run.
363
364It is up to the user to determine if those situations exist, and to code this
365hook script appropriately.
366
367This script will typically be implemented by calling out to some SoC- or
368board-specific vendor flashing utility.
369
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100370u-boot-test-reset
371'''''''''''''''''
Stephen Warren10e50632016-01-15 11:15:24 -0700372
373Whenever the test suite needs to reset the target board, this script is
374executed. This is guaranteed to happen at least once, prior to executing the
375first test function. If any test fails, the test infra-structure will execute
376this script again to restore U-Boot to an operational state before running the
377next test function.
378
379This script will likely be implemented by communicating with some form of
380relay or electronic switch attached to the board's reset signal.
381
382The semantics of this script require that when it is executed, U-Boot will
383start running from scratch. If the U-Boot binary to be tested has been written
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100384to flash, pulsing the board's reset signal is likely all this script needs to
385do. However, in some scenarios, this script may perform other actions. For
Stephen Warren10e50632016-01-15 11:15:24 -0700386example, it may call out to some SoC- or board-specific vendor utility in order
387to download the U-Boot binary directly into RAM and execute it. This would
388avoid the need for `u-boot-test-flash` to actually write U-Boot to flash, thus
389saving wear on the flash chip(s).
390
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100391Examples
392''''''''
Stephen Warren140d04d2016-04-06 11:46:59 -0600393
Tom Rini2a1df582021-02-24 17:05:04 -0500394https://source.denx.de/u-boot/u-boot-test-hooks contains some working example hook
Stephen Warren140d04d2016-04-06 11:46:59 -0600395scripts, and may be useful as a reference when implementing hook scripts for
396your platform. These scripts are not considered part of U-Boot itself.
397
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100398Board-type-specific configuration
399~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warren10e50632016-01-15 11:15:24 -0700400
401Each board has a different configuration and behaviour. Many of these
402differences can be automatically detected by parsing the `.config` file in the
403build directory. However, some differences can't yet be handled automatically.
404
405For each board, an optional Python module `u_boot_board_${board_type}` may exist
406to provide board-specific information to the test script. Any global value
407defined in these modules is available for use by any test function. The data
408contained in these scripts must be purely derived from U-Boot source code.
409Hence, these configuration files are part of the U-Boot source tree too.
410
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100411Execution environment configuration
412~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warren10e50632016-01-15 11:15:24 -0700413
414Each user's hardware setup may enable testing different subsets of the features
415implemented by a particular board's configuration of U-Boot. For example, a
416U-Boot configuration may support USB device mode and USB Mass Storage, but this
417can only be tested if a USB cable is connected between the board and the host
418machine running the test script.
419
420For each board, optional Python modules `u_boot_boardenv_${board_type}` and
421`u_boot_boardenv_${board_type}_${board_identity}` may exist to provide
422board-specific and board-identity-specific information to the test script. Any
423global value defined in these modules is available for use by any test
424function. The data contained in these is specific to a particular user's
425hardware configuration. Hence, these configuration files are not part of the
426U-Boot source tree, and should be installed outside of the source tree. Users
427should set `$PYTHONPATH` prior to running the test script to allow these
428modules to be loaded.
429
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100430Board module parameter usage
431~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warren10e50632016-01-15 11:15:24 -0700432
433The test scripts rely on the following variables being defined by the board
434module:
435
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100436- none at present
Stephen Warren10e50632016-01-15 11:15:24 -0700437
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100438U-Boot `.config` feature usage
439~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warren10e50632016-01-15 11:15:24 -0700440
441The test scripts rely on various U-Boot `.config` features, either directly in
442order to test those features, or indirectly in order to query information from
443the running U-Boot instance in order to test other features.
444
445One example is that testing of the `md` command requires knowledge of a RAM
446address to use for the test. This data is parsed from the output of the
447`bdinfo` command, and hence relies on CONFIG_CMD_BDI being enabled.
448
449For a complete list of dependencies, please search the test scripts for
450instances of:
451
452- `buildconfig.get(...`
453- `@pytest.mark.buildconfigspec(...`
Heinrich Schuchardt59264ae2019-04-22 09:18:55 +0200454- `@pytest.mark.notbuildconfigspec(...`
Stephen Warren10e50632016-01-15 11:15:24 -0700455
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100456Complete invocation example
457~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warren10e50632016-01-15 11:15:24 -0700458
459Assuming that you have installed the hook scripts into $HOME/ubtest/bin, and
460any required environment configuration Python modules into $HOME/ubtest/py,
461then you would likely invoke the test script as follows:
462
463If U-Boot has already been built:
464
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100465.. code-block:: bash
466
467 PATH=$HOME/ubtest/bin:$PATH \
Liam Beguince3f90e2018-03-14 19:15:13 -0400468 PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \
Stephen Warren10e50632016-01-15 11:15:24 -0700469 ./test/py/test.py --bd seaboard
Stephen Warren10e50632016-01-15 11:15:24 -0700470
471If you want the test script to compile U-Boot for you too, then you likely
472need to set `$CROSS_COMPILE` to allow this, and invoke the test script as
Simon Glass6e094842020-03-18 09:43:01 -0600473follows:
Stephen Warren10e50632016-01-15 11:15:24 -0700474
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100475.. code-block:: bash
476
477 CROSS_COMPILE=arm-none-eabi- \
Stephen Warren10e50632016-01-15 11:15:24 -0700478 PATH=$HOME/ubtest/bin:$PATH \
Liam Beguince3f90e2018-03-14 19:15:13 -0400479 PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \
Stephen Warren10e50632016-01-15 11:15:24 -0700480 ./test/py/test.py --bd seaboard --build
Stephen Warren10e50632016-01-15 11:15:24 -0700481
Simon Glass6e094842020-03-18 09:43:01 -0600482or, using buildman to handle it:
483
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100484.. code-block:: bash
485
Simon Glass6e094842020-03-18 09:43:01 -0600486 PATH=$HOME/ubtest/bin:$PATH \
487 PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \
488 ./test/py/test.py --bd seaboard --build --buildman
Simon Glass6e094842020-03-18 09:43:01 -0600489
Heinrich Schuchardt79c9f0e2021-01-18 20:24:03 +0100490Writing tests
491-------------
Stephen Warren10e50632016-01-15 11:15:24 -0700492
493Please refer to the pytest documentation for details of writing pytest tests.
494Details specific to the U-Boot test suite are described below.
495
Simon Glassddba5202025-02-09 09:07:14 -0700496A test fixture named `ubman` should be used by each test function. This
Stephen Warren10e50632016-01-15 11:15:24 -0700497provides the means to interact with the U-Boot console, and retrieve board and
498environment configuration information.
499
Simon Glassddba5202025-02-09 09:07:14 -0700500The function `ubman.run_command()` executes a shell command on the
Stephen Warren10e50632016-01-15 11:15:24 -0700501U-Boot console, and returns all output from that command. This allows
502validation or interpretation of the command output. This function validates
503that certain strings are not seen on the U-Boot console. These include shell
504error messages and the U-Boot sign-on message (in order to detect unexpected
Simon Glassfb916372025-02-09 09:07:15 -0700505board resets). See the source of `console_base.py` for a complete list of
Stephen Warren10e50632016-01-15 11:15:24 -0700506"bad" strings. Some test scenarios are expected to trigger these strings. Use
Simon Glassddba5202025-02-09 09:07:14 -0700507`ubman.disable_check()` to temporarily disable checking for specific
Stephen Warren10e50632016-01-15 11:15:24 -0700508strings. See `test_unknown_cmd.py` for an example.
509
510Board- and board-environment configuration values may be accessed as sub-fields
Simon Glassddba5202025-02-09 09:07:14 -0700511of the `ubman.config` object, for example
512`ubman.config.ram_base`.
Stephen Warren10e50632016-01-15 11:15:24 -0700513
514Build configuration values (from `.config`) may be accessed via the dictionary
Simon Glassddba5202025-02-09 09:07:14 -0700515`ubman.config.buildconfig`, with keys equal to the Kconfig variable
Stephen Warren10e50632016-01-15 11:15:24 -0700516names.