blob: 6ff7810340980ae2c8c05b4d769b9e4398d9ebe6 [file] [log] [blame]
Heinrich Schuchardt01576192021-01-18 20:24:03 +01001U-Boot pytest suite
2===================
Stephen Warrend2015062016-01-15 11:15:24 -07003
Heinrich Schuchardt01576192021-01-18 20:24:03 +01004Introduction
5------------
Stephen Warrend2015062016-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 Glassfc328332021-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 Warrend2015062016-01-15 11:15:24 -070018- It is reasonably simple to interact with U-Boot in this way.
19
Heinrich Schuchardt01576192021-01-18 20:24:03 +010020Requirements
21------------
Stephen Warrend2015062016-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 Schuchardt01576192021-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
32
33.. code-block:: bash
34
35 pip install -r requirements.txt
Stephen Warrend2015062016-01-15 11:15:24 -070036
Tom Riniddaa8be2019-10-24 11:59:26 -040037In order to execute certain tests on their supported platforms other tools
Heinrich Schuchardt01576192021-01-18 20:24:03 +010038will be required. The following is an incomplete list:
Tom Riniddaa8be2019-10-24 11:59:26 -040039
Heinrich Schuchardt01576192021-01-18 20:24:03 +010040* gdisk
41* dfu-util
42* dtc
43* openssl
44* sudo OR guestmount
45* e2fsprogs
46* util-linux
47* coreutils
48* dosfstools
49* efitools
Heinrich Schuchardt88991b92022-10-08 01:19:22 +020050* guestfs-tools
Heinrich Schuchardt01576192021-01-18 20:24:03 +010051* mount
52* mtools
53* sbsigntool
54* udisks2
AKASHI Takahirofe6ca4d2020-04-14 11:51:49 +090055
Heinrich Schuchardt01576192021-01-18 20:24:03 +010056Please use the appropriate commands for your distribution to match these tools
Tom Riniddaa8be2019-10-24 11:59:26 -040057up with the package that provides them.
Stephen Warrend2015062016-01-15 11:15:24 -070058
59The test script supports either:
60
61- Executing a sandbox port of U-Boot on the local machine as a sub-process,
62 and interacting with it over stdin/stdout.
63- Executing an external "hook" scripts to flash a U-Boot binary onto a
64 physical board, attach to the board's console stream, and reset the board.
65 Further details are described later.
66
Heinrich Schuchardt88991b92022-10-08 01:19:22 +020067The usage of command 'sudo' should be avoided in tests. To create disk images
68use command virt-make-fs which is provided by package guestfs-tools. This
69command creates a virtual machine with QEMU in which the disk image is
70generated.
71
72Command virt-make-fs needs read access to the current kernel. On Ubuntu only
73root has this privilege. You can add a script /etc/initramfs-tools/hooks/vmlinuz
74with the following content to overcome the problem:
75
76.. code-block:: bash
77
78 #!/bin/sh
79 echo "chmod a+r vmlinuz-*"
80 chmod a+r /boot/vmlinuz-*
81
82The script should be chmod 755. It will be invoked whenever the initial RAM file
83system is updated.
84
Heinrich Schuchardt01576192021-01-18 20:24:03 +010085Using `virtualenv` to provide requirements
86~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warrend2015062016-01-15 11:15:24 -070087
Tom Riniddaa8be2019-10-24 11:59:26 -040088The recommended way to run the test suite, in order to ensure reproducibility
89is to use `virtualenv` to set up the necessary environment. This can be done
90via the following commands:
Stephen Warrend2015062016-01-15 11:15:24 -070091
Stephen Warrend2015062016-01-15 11:15:24 -070092
Heinrich Schuchardt01576192021-01-18 20:24:03 +010093.. code-block:: console
Stephen Warrend2015062016-01-15 11:15:24 -070094
Heinrich Schuchardt01576192021-01-18 20:24:03 +010095 $ cd /path/to/u-boot
96 $ sudo apt-get install python3 python3-virtualenv
97 $ virtualenv -p /usr/bin/python3 venv
98 $ . ./venv/bin/activate
99 $ pip install -r test/py/requirements.txt
100
101Testing sandbox
102---------------
103
104To run the test suite on the sandbox port (U-Boot built as a native user-space
Stephen Warrend2015062016-01-15 11:15:24 -0700105application), simply execute:
106
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100107.. code-block:: bash
108
109 ./test/py/test.py --bd sandbox --build
Stephen Warrend2015062016-01-15 11:15:24 -0700110
111The `--bd` option tells the test suite which board type is being tested. This
112lets the test suite know which features the board has, and hence exactly what
113can be tested.
114
115The `--build` option tells U-Boot to compile U-Boot. Alternatively, you may
116omit this option and build U-Boot yourself, in whatever way you choose, before
117running the test script.
118
119The test script will attach to U-Boot, execute all valid tests for the board,
120then print a summary of the test process. A complete log of the test session
121will be written to `${build_dir}/test-log.html`. This is best viewed in a web
122browser, but may be read directly as plain text, perhaps with the aid of the
123`html2text` utility.
124
Simon Glass35839ed2021-10-08 09:15:23 -0600125If sandbox crashes (e.g. with a segfault) you will see message like this::
126
127
128 test/py/u_boot_spawn.py:171: in expect
129 c = os.read(self.fd, 1024).decode(errors='replace')
130 E ValueError: U-Boot exited with signal 11 (Signals.SIGSEGV)
131
132
Simon Glassb04f64a2021-10-05 20:18:00 -0600133Controlling output
134~~~~~~~~~~~~~~~~~~
135
136By default a short backtrace is reported. If you would like a longer one,
137pass ``--tb=long`` when running the test. See the pytest documentation for
138more options.
139
Simon Glass5f8cefb2021-09-19 15:14:51 -0600140Running tests in parallel
141~~~~~~~~~~~~~~~~~~~~~~~~~
142
Simon Glassd1962ac2022-08-06 17:51:59 -0600143Note: Not all tests can run in parallel at present, so the usual approach is
144to just run those that can.
Simon Glass5f8cefb2021-09-19 15:14:51 -0600145
146First install support for parallel tests::
147
Simon Glassd1962ac2022-08-06 17:51:59 -0600148 sudo apt install python3-pytest-xdist
149
150or:::
151
Simon Glass5f8cefb2021-09-19 15:14:51 -0600152 pip3 install pytest-xdist
153
Simon Glassd1962ac2022-08-06 17:51:59 -0600154Then run the tests in parallel using the -n flag::
Simon Glass5f8cefb2021-09-19 15:14:51 -0600155
Simon Glassd1962ac2022-08-06 17:51:59 -0600156 test/py/test.py -B sandbox --build --build-dir /tmp/b/sandbox -q -k \
157 'not slow and not bootstd and not spi_flash' -n16
Simon Glass5f8cefb2021-09-19 15:14:51 -0600158
Simon Glassd1962ac2022-08-06 17:51:59 -0600159You can also use `make pcheck` to run all tests in parallel. This uses a maximum
160of 16 threads, since the setup time is significant and there are under 1000
161tests.
Simon Glass5f8cefb2021-09-19 15:14:51 -0600162
Simon Glassd1962ac2022-08-06 17:51:59 -0600163Note that the `test-log.html` output does not work correctly at present with
164parallel testing. All the threads write to it at once, so it is garbled.
Simon Glass5f8cefb2021-09-19 15:14:51 -0600165
Simon Glassd1962ac2022-08-06 17:51:59 -0600166Note that the `tools/` tests still run each tool's tests once after the other,
167although within that, they do run in parallel. So for example, the buildman
168tests run in parallel, then the binman tests run in parallel. There would be a
169significant advantage to running them all in parallel together, but that would
170require a large amount of refactoring, e.g. with more use of pytest fixtures.
171The code-coverage tests are omitted since they cannot run in parallel due to a
172Python limitation.
Simon Glass5f8cefb2021-09-19 15:14:51 -0600173
174
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100175Testing under a debugger
176~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warrend70facf2016-02-08 14:49:02 -0700177
178If you need to run sandbox under a debugger, you may pass the command-line
179option `--gdbserver COMM`. This causes two things to happens:
180
181- Instead of running U-Boot directly, it will be run under gdbserver, with
182 debug communication via the channel `COMM`. You can attach a debugger to the
183 sandbox process in order to debug it. See `man gdbserver` and the example
184 below for details of valid values for `COMM`.
185- All timeouts in tests are disabled, allowing U-Boot an arbitrary amount of
186 time to execute commands. This is useful if U-Boot is stopped at a breakpoint
187 during debugging.
188
189A usage example is:
190
191Window 1:
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100192
193.. code-block:: bash
194
195 ./test/py/test.py --bd sandbox --gdbserver localhost:1234
Stephen Warrend70facf2016-02-08 14:49:02 -0700196
197Window 2:
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100198
199.. code-block:: bash
200
201 gdb ./build-sandbox/u-boot -ex 'target remote localhost:1234'
Stephen Warrend70facf2016-02-08 14:49:02 -0700202
203Alternatively, you could leave off the `-ex` option and type the command
204manually into gdb once it starts.
205
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100206You can use any debugger you wish, as long as it speaks the gdb remote
Stephen Warrend70facf2016-02-08 14:49:02 -0700207protocol, or any graphical wrapper around gdb.
208
209Some tests deliberately cause the sandbox process to exit, e.g. to test the
210reset command, or sandbox's CTRL-C handling. When this happens, you will need
211to attach the debugger to the new sandbox instance. If these tests are not
212relevant to your debugging session, you can skip them using pytest's -k
213command-line option; see the next section.
214
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100215Command-line options
216--------------------
Stephen Warrend2015062016-01-15 11:15:24 -0700217
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100218--board-type, --bd, -B
219 set the type of the board to be tested. For example, `sandbox` or `seaboard`.
220
221--board-identity`, --id
222 sets the identity of the board to be tested. This allows differentiation
223 between multiple instances of the same type of physical board that are
224 attached to the same host machine. This parameter is not interpreted by th
225 test script in any way, but rather is simply passed to the hook scripts
226 described below, and may be used in any site-specific way deemed necessary.
227
228--build
229 indicates that the test script should compile U-Boot itself before running
230 the tests. If using this option, make sure that any environment variables
231 required by the build process are already set, such as `$CROSS_COMPILE`.
232
233--buildman
234 indicates that `--build` should use buildman to build U-Boot. There is no need
235 to set $CROSS_COMPILE` in this case since buildman handles it.
236
237--build-dir
238 sets the directory containing the compiled U-Boot binaries. If omitted, this
239 is `${source_dir}/build-${board_type}`.
240
241--result-dir
242 sets the directory to write results, such as log files, into.
243 If omitted, the build directory is used.
244
245--persistent-data-dir
246 sets the directory used to store persistent test data. This is test data that
247 may be re-used across test runs, such as file-system images.
Stephen Warrend2015062016-01-15 11:15:24 -0700248
Stephen Warrend70facf2016-02-08 14:49:02 -0700249`pytest` also implements a number of its own command-line options. Commonly used
250options are mentioned below. Please see `pytest` documentation for complete
251details. Execute `py.test --version` for a brief summary. Note that U-Boot's
252test.py script passes all command-line arguments directly to `pytest` for
253processing.
254
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100255-k
256 selects which tests to run. The default is to run all known tests. This
Stephen Warrend70facf2016-02-08 14:49:02 -0700257 option takes a single argument which is used to filter test names. Simple
258 logical operators are supported. For example:
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100259
260 - `'-k ums'` runs only tests with "ums" in their name.
261 - `'-k ut_dm'` runs only tests with "ut_dm" in their name. Note that in this
Stephen Warrend70facf2016-02-08 14:49:02 -0700262 case, "ut_dm" is a parameter to a test rather than the test name. The full
263 test name is e.g. "test_ut[ut_dm_leak]".
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100264 - `'-k not reset'` runs everything except tests with "reset" in their name.
265 - `'-k ut or hush'` runs only tests with "ut" or "hush" in their name.
266 - `'-k not (ut or hush)'` runs everything except tests with "ut" or "hush" in
Stephen Warrend70facf2016-02-08 14:49:02 -0700267 their name.
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100268
269-s
270 prevents pytest from hiding a test's stdout. This allows you to see
Stephen Warrend70facf2016-02-08 14:49:02 -0700271 U-Boot's console log in real time on pytest's stdout.
Stephen Warrend2015062016-01-15 11:15:24 -0700272
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100273Testing real hardware
274---------------------
Stephen Warrend2015062016-01-15 11:15:24 -0700275
276The tools and techniques used to interact with real hardware will vary
277radically between different host and target systems, and the whims of the user.
278For this reason, the test suite does not attempt to directly interact with real
279hardware in any way. Rather, it executes a standardized set of "hook" scripts
280via `$PATH`. These scripts implement certain actions on behalf of the test
281suite. This keeps the test suite simple and isolated from system variances
282unrelated to U-Boot features.
283
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100284Hook scripts
285~~~~~~~~~~~~
Stephen Warrend2015062016-01-15 11:15:24 -0700286
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100287Environment variables
288'''''''''''''''''''''
Stephen Warrend2015062016-01-15 11:15:24 -0700289
290The following environment variables are set when running hook scripts:
291
292- `UBOOT_BOARD_TYPE` the board type being tested.
293- `UBOOT_BOARD_IDENTITY` the board identity being tested, or `na` if none was
294 specified.
295- `UBOOT_SOURCE_DIR` the U-Boot source directory.
296- `UBOOT_TEST_PY_DIR` the full path to `test/py/` in the source directory.
297- `UBOOT_BUILD_DIR` the U-Boot build directory.
298- `UBOOT_RESULT_DIR` the test result directory.
Masahiro Yamada3aca4a42017-10-19 19:08:52 +0900299- `UBOOT_PERSISTENT_DATA_DIR` the test persistent data directory.
Stephen Warrend2015062016-01-15 11:15:24 -0700300
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100301u-boot-test-console
302'''''''''''''''''''
Stephen Warrend2015062016-01-15 11:15:24 -0700303
304This script provides access to the U-Boot console. The script's stdin/stdout
305should be connected to the board's console. This process should continue to run
306indefinitely, until killed. The test suite will run this script in parallel
307with all other hooks.
308
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100309This script may be implemented e.g. by executing `cu`, `kermit`, `conmux`, etc.
310via exec().
Stephen Warrend2015062016-01-15 11:15:24 -0700311
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100312If you are able to run U-Boot under a hardware simulator such as QEMU, then
Stephen Warrend2015062016-01-15 11:15:24 -0700313you would likely spawn that simulator from this script. However, note that
314`u-boot-test-reset` may be called multiple times per test script run, and must
315cause U-Boot to start execution from scratch each time. Hopefully your
316simulator includes a virtual reset button! If not, you can launch the
317simulator from `u-boot-test-reset` instead, while arranging for this console
318process to always communicate with the current simulator instance.
319
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100320u-boot-test-flash
321'''''''''''''''''
Stephen Warrend2015062016-01-15 11:15:24 -0700322
323Prior to running the test suite against a board, some arrangement must be made
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100324so that the board executes the particular U-Boot binary to be tested. Often
Stephen Warrend2015062016-01-15 11:15:24 -0700325this involves writing the U-Boot binary to the board's flash ROM. The test
326suite calls this hook script for that purpose.
327
328This script should perform the entire flashing process synchronously; the
329script should only exit once flashing is complete, and a board reset will
330cause the newly flashed U-Boot binary to be executed.
331
332It is conceivable that this script will do nothing. This might be useful in
333the following cases:
334
335- Some other process has already written the desired U-Boot binary into the
336 board's flash prior to running the test suite.
337- The board allows U-Boot to be downloaded directly into RAM, and executed
338 from there. Use of this feature will reduce wear on the board's flash, so
339 may be preferable if available, and if cold boot testing of U-Boot is not
340 required. If this feature is used, the `u-boot-test-reset` script should
Masahiro Yamada3aca4a42017-10-19 19:08:52 +0900341 perform this download, since the board could conceivably be reset multiple
Stephen Warrend2015062016-01-15 11:15:24 -0700342 times in a single test run.
343
344It is up to the user to determine if those situations exist, and to code this
345hook script appropriately.
346
347This script will typically be implemented by calling out to some SoC- or
348board-specific vendor flashing utility.
349
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100350u-boot-test-reset
351'''''''''''''''''
Stephen Warrend2015062016-01-15 11:15:24 -0700352
353Whenever the test suite needs to reset the target board, this script is
354executed. This is guaranteed to happen at least once, prior to executing the
355first test function. If any test fails, the test infra-structure will execute
356this script again to restore U-Boot to an operational state before running the
357next test function.
358
359This script will likely be implemented by communicating with some form of
360relay or electronic switch attached to the board's reset signal.
361
362The semantics of this script require that when it is executed, U-Boot will
363start running from scratch. If the U-Boot binary to be tested has been written
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100364to flash, pulsing the board's reset signal is likely all this script needs to
365do. However, in some scenarios, this script may perform other actions. For
Stephen Warrend2015062016-01-15 11:15:24 -0700366example, it may call out to some SoC- or board-specific vendor utility in order
367to download the U-Boot binary directly into RAM and execute it. This would
368avoid the need for `u-boot-test-flash` to actually write U-Boot to flash, thus
369saving wear on the flash chip(s).
370
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100371Examples
372''''''''
Stephen Warren5b2beab2016-04-06 11:46:59 -0600373
Tom Rini85ae52b2021-02-24 17:05:04 -0500374https://source.denx.de/u-boot/u-boot-test-hooks contains some working example hook
Stephen Warren5b2beab2016-04-06 11:46:59 -0600375scripts, and may be useful as a reference when implementing hook scripts for
376your platform. These scripts are not considered part of U-Boot itself.
377
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100378Board-type-specific configuration
379~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warrend2015062016-01-15 11:15:24 -0700380
381Each board has a different configuration and behaviour. Many of these
382differences can be automatically detected by parsing the `.config` file in the
383build directory. However, some differences can't yet be handled automatically.
384
385For each board, an optional Python module `u_boot_board_${board_type}` may exist
386to provide board-specific information to the test script. Any global value
387defined in these modules is available for use by any test function. The data
388contained in these scripts must be purely derived from U-Boot source code.
389Hence, these configuration files are part of the U-Boot source tree too.
390
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100391Execution environment configuration
392~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warrend2015062016-01-15 11:15:24 -0700393
394Each user's hardware setup may enable testing different subsets of the features
395implemented by a particular board's configuration of U-Boot. For example, a
396U-Boot configuration may support USB device mode and USB Mass Storage, but this
397can only be tested if a USB cable is connected between the board and the host
398machine running the test script.
399
400For each board, optional Python modules `u_boot_boardenv_${board_type}` and
401`u_boot_boardenv_${board_type}_${board_identity}` may exist to provide
402board-specific and board-identity-specific information to the test script. Any
403global value defined in these modules is available for use by any test
404function. The data contained in these is specific to a particular user's
405hardware configuration. Hence, these configuration files are not part of the
406U-Boot source tree, and should be installed outside of the source tree. Users
407should set `$PYTHONPATH` prior to running the test script to allow these
408modules to be loaded.
409
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100410Board module parameter usage
411~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warrend2015062016-01-15 11:15:24 -0700412
413The test scripts rely on the following variables being defined by the board
414module:
415
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100416- none at present
Stephen Warrend2015062016-01-15 11:15:24 -0700417
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100418U-Boot `.config` feature usage
419~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warrend2015062016-01-15 11:15:24 -0700420
421The test scripts rely on various U-Boot `.config` features, either directly in
422order to test those features, or indirectly in order to query information from
423the running U-Boot instance in order to test other features.
424
425One example is that testing of the `md` command requires knowledge of a RAM
426address to use for the test. This data is parsed from the output of the
427`bdinfo` command, and hence relies on CONFIG_CMD_BDI being enabled.
428
429For a complete list of dependencies, please search the test scripts for
430instances of:
431
432- `buildconfig.get(...`
433- `@pytest.mark.buildconfigspec(...`
Heinrich Schuchardt10feb302019-04-22 09:18:55 +0200434- `@pytest.mark.notbuildconfigspec(...`
Stephen Warrend2015062016-01-15 11:15:24 -0700435
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100436Complete invocation example
437~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Warrend2015062016-01-15 11:15:24 -0700438
439Assuming that you have installed the hook scripts into $HOME/ubtest/bin, and
440any required environment configuration Python modules into $HOME/ubtest/py,
441then you would likely invoke the test script as follows:
442
443If U-Boot has already been built:
444
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100445.. code-block:: bash
446
447 PATH=$HOME/ubtest/bin:$PATH \
Liam Beguinbe916912018-03-14 19:15:13 -0400448 PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \
Stephen Warrend2015062016-01-15 11:15:24 -0700449 ./test/py/test.py --bd seaboard
Stephen Warrend2015062016-01-15 11:15:24 -0700450
451If you want the test script to compile U-Boot for you too, then you likely
452need to set `$CROSS_COMPILE` to allow this, and invoke the test script as
Simon Glassf5ec7ee2020-03-18 09:43:01 -0600453follows:
Stephen Warrend2015062016-01-15 11:15:24 -0700454
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100455.. code-block:: bash
456
457 CROSS_COMPILE=arm-none-eabi- \
Stephen Warrend2015062016-01-15 11:15:24 -0700458 PATH=$HOME/ubtest/bin:$PATH \
Liam Beguinbe916912018-03-14 19:15:13 -0400459 PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \
Stephen Warrend2015062016-01-15 11:15:24 -0700460 ./test/py/test.py --bd seaboard --build
Stephen Warrend2015062016-01-15 11:15:24 -0700461
Simon Glassf5ec7ee2020-03-18 09:43:01 -0600462or, using buildman to handle it:
463
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100464.. code-block:: bash
465
Simon Glassf5ec7ee2020-03-18 09:43:01 -0600466 PATH=$HOME/ubtest/bin:$PATH \
467 PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \
468 ./test/py/test.py --bd seaboard --build --buildman
Simon Glassf5ec7ee2020-03-18 09:43:01 -0600469
Heinrich Schuchardt01576192021-01-18 20:24:03 +0100470Writing tests
471-------------
Stephen Warrend2015062016-01-15 11:15:24 -0700472
473Please refer to the pytest documentation for details of writing pytest tests.
474Details specific to the U-Boot test suite are described below.
475
476A test fixture named `u_boot_console` should be used by each test function. This
477provides the means to interact with the U-Boot console, and retrieve board and
478environment configuration information.
479
480The function `u_boot_console.run_command()` executes a shell command on the
481U-Boot console, and returns all output from that command. This allows
482validation or interpretation of the command output. This function validates
483that certain strings are not seen on the U-Boot console. These include shell
484error messages and the U-Boot sign-on message (in order to detect unexpected
485board resets). See the source of `u_boot_console_base.py` for a complete list of
486"bad" strings. Some test scenarios are expected to trigger these strings. Use
487`u_boot_console.disable_check()` to temporarily disable checking for specific
488strings. See `test_unknown_cmd.py` for an example.
489
490Board- and board-environment configuration values may be accessed as sub-fields
491of the `u_boot_console.config` object, for example
492`u_boot_console.config.ram_base`.
493
494Build configuration values (from `.config`) may be accessed via the dictionary
495`u_boot_console.config.buildconfig`, with keys equal to the Kconfig variable
496names.