Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 1 | U-Boot pytest suite |
| 2 | =================== |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 3 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 4 | Introduction |
| 5 | ------------ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 6 | |
| 7 | This tool aims to test U-Boot by executing U-Boot shell commands using the |
| 8 | console interface. A single top-level script exists to execute or attach to the |
| 9 | U-Boot console, run the entire script of tests against it, and summarize the |
| 10 | results. 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 Glass | 2540410 | 2021-03-07 17:35:17 -0700 | [diff] [blame] | 16 | flexible than writing it all in C. But see :doc:`tests_writing` for caveats |
| 17 | and more discussion / analysis. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 18 | - It is reasonably simple to interact with U-Boot in this way. |
| 19 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 20 | Requirements |
| 21 | ------------ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 22 | |
| 23 | The test suite is implemented using pytest. Interaction with the U-Boot console |
| 24 | involves executing some binary and interacting with its stdin/stdout. You will |
| 25 | need to implement various "hook" scripts that are called by the test suite at |
| 26 | the appropriate time. |
| 27 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 28 | In order to run the test suite at a minimum we require that both Python 3 and |
| 29 | pip for Python 3 are installed. All of the required python modules are |
| 30 | described in the requirements.txt file in the /test/py/ directory and can be |
| 31 | installed via the command |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 32 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 33 | .. code-block:: bash |
Tom Rini | a39e81b | 2019-10-24 11:59:26 -0400 | [diff] [blame] | 34 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 35 | pip install -r requirements.txt |
| 36 | |
| 37 | In order to execute certain tests on their supported platforms other tools |
| 38 | will be required. The following is an incomplete list: |
AKASHI Takahiro | 58c95c2 | 2020-04-14 11:51:49 +0900 | [diff] [blame] | 39 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 40 | * gdisk |
| 41 | * dfu-util |
| 42 | * dtc |
| 43 | * openssl |
| 44 | * sudo OR guestmount |
| 45 | * e2fsprogs |
| 46 | * util-linux |
| 47 | * coreutils |
| 48 | * dosfstools |
| 49 | * efitools |
| 50 | * mount |
| 51 | * mtools |
| 52 | * sbsigntool |
| 53 | * udisks2 |
Tom Rini | a39e81b | 2019-10-24 11:59:26 -0400 | [diff] [blame] | 54 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 55 | Please use the appropriate commands for your distribution to match these tools |
Tom Rini | a39e81b | 2019-10-24 11:59:26 -0400 | [diff] [blame] | 56 | up with the package that provides them. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 57 | |
| 58 | The test script supports either: |
| 59 | |
| 60 | - Executing a sandbox port of U-Boot on the local machine as a sub-process, |
| 61 | and interacting with it over stdin/stdout. |
| 62 | - Executing an external "hook" scripts to flash a U-Boot binary onto a |
| 63 | physical board, attach to the board's console stream, and reset the board. |
| 64 | Further details are described later. |
| 65 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 66 | Using `virtualenv` to provide requirements |
| 67 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 68 | |
Tom Rini | a39e81b | 2019-10-24 11:59:26 -0400 | [diff] [blame] | 69 | The recommended way to run the test suite, in order to ensure reproducibility |
| 70 | is to use `virtualenv` to set up the necessary environment. This can be done |
| 71 | via the following commands: |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 72 | |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 73 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 74 | .. code-block:: console |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 75 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 76 | $ cd /path/to/u-boot |
| 77 | $ sudo apt-get install python3 python3-virtualenv |
| 78 | $ virtualenv -p /usr/bin/python3 venv |
| 79 | $ . ./venv/bin/activate |
| 80 | $ pip install -r test/py/requirements.txt |
| 81 | |
| 82 | Testing sandbox |
| 83 | --------------- |
| 84 | |
| 85 | To run the test suite on the sandbox port (U-Boot built as a native user-space |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 86 | application), simply execute: |
| 87 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 88 | .. code-block:: bash |
| 89 | |
| 90 | ./test/py/test.py --bd sandbox --build |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 91 | |
| 92 | The `--bd` option tells the test suite which board type is being tested. This |
| 93 | lets the test suite know which features the board has, and hence exactly what |
| 94 | can be tested. |
| 95 | |
| 96 | The `--build` option tells U-Boot to compile U-Boot. Alternatively, you may |
| 97 | omit this option and build U-Boot yourself, in whatever way you choose, before |
| 98 | running the test script. |
| 99 | |
| 100 | The test script will attach to U-Boot, execute all valid tests for the board, |
| 101 | then print a summary of the test process. A complete log of the test session |
| 102 | will be written to `${build_dir}/test-log.html`. This is best viewed in a web |
| 103 | browser, but may be read directly as plain text, perhaps with the aid of the |
| 104 | `html2text` utility. |
| 105 | |
Simon Glass | 1919348 | 2021-10-05 20:18:00 -0600 | [diff] [blame] | 106 | Controlling output |
| 107 | ~~~~~~~~~~~~~~~~~~ |
| 108 | |
| 109 | By default a short backtrace is reported. If you would like a longer one, |
| 110 | pass ``--tb=long`` when running the test. See the pytest documentation for |
| 111 | more options. |
| 112 | |
Simon Glass | 5c8b884 | 2021-09-19 15:14:51 -0600 | [diff] [blame] | 113 | Running tests in parallel |
| 114 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 115 | |
| 116 | Note: This does not fully work yet and is documented only so you can try to |
| 117 | fix the problems. |
| 118 | |
| 119 | First install support for parallel tests:: |
| 120 | |
| 121 | pip3 install pytest-xdist |
| 122 | |
| 123 | Then build sandbox in a suitable build directory. It is not possible to use |
| 124 | the --build flag with xdist. |
| 125 | |
| 126 | Finally, run the tests in parallel using the -n flag:: |
| 127 | |
| 128 | # build sandbox first, in a suitable build directory. It is not possible |
| 129 | # to use the --build flag with -n |
| 130 | test/py/test.py -B sandbox --build-dir /tmp/b/sandbox -q -k 'not slow' -n32 |
| 131 | |
| 132 | At least the following non-slow tests are known to fail: |
| 133 | |
| 134 | - test_fit_ecdsa |
| 135 | - test_bind_unbind_with_uclass |
| 136 | - ut_dm_spi_flash |
| 137 | - test_gpt_rename_partition |
| 138 | - test_gpt_swap_partitions |
| 139 | - test_pinmux_status |
| 140 | - test_sqfs_load |
| 141 | |
| 142 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 143 | Testing under a debugger |
| 144 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
Stephen Warren | c9afc50 | 2016-02-08 14:49:02 -0700 | [diff] [blame] | 145 | |
| 146 | If you need to run sandbox under a debugger, you may pass the command-line |
| 147 | option `--gdbserver COMM`. This causes two things to happens: |
| 148 | |
| 149 | - Instead of running U-Boot directly, it will be run under gdbserver, with |
| 150 | debug communication via the channel `COMM`. You can attach a debugger to the |
| 151 | sandbox process in order to debug it. See `man gdbserver` and the example |
| 152 | below for details of valid values for `COMM`. |
| 153 | - All timeouts in tests are disabled, allowing U-Boot an arbitrary amount of |
| 154 | time to execute commands. This is useful if U-Boot is stopped at a breakpoint |
| 155 | during debugging. |
| 156 | |
| 157 | A usage example is: |
| 158 | |
| 159 | Window 1: |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 160 | |
| 161 | .. code-block:: bash |
| 162 | |
| 163 | ./test/py/test.py --bd sandbox --gdbserver localhost:1234 |
Stephen Warren | c9afc50 | 2016-02-08 14:49:02 -0700 | [diff] [blame] | 164 | |
| 165 | Window 2: |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 166 | |
| 167 | .. code-block:: bash |
| 168 | |
| 169 | gdb ./build-sandbox/u-boot -ex 'target remote localhost:1234' |
Stephen Warren | c9afc50 | 2016-02-08 14:49:02 -0700 | [diff] [blame] | 170 | |
| 171 | Alternatively, you could leave off the `-ex` option and type the command |
| 172 | manually into gdb once it starts. |
| 173 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 174 | You can use any debugger you wish, as long as it speaks the gdb remote |
Stephen Warren | c9afc50 | 2016-02-08 14:49:02 -0700 | [diff] [blame] | 175 | protocol, or any graphical wrapper around gdb. |
| 176 | |
| 177 | Some tests deliberately cause the sandbox process to exit, e.g. to test the |
| 178 | reset command, or sandbox's CTRL-C handling. When this happens, you will need |
| 179 | to attach the debugger to the new sandbox instance. If these tests are not |
| 180 | relevant to your debugging session, you can skip them using pytest's -k |
| 181 | command-line option; see the next section. |
| 182 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 183 | Command-line options |
| 184 | -------------------- |
| 185 | |
| 186 | --board-type, --bd, -B |
| 187 | set the type of the board to be tested. For example, `sandbox` or `seaboard`. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 188 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 189 | --board-identity`, --id |
| 190 | sets the identity of the board to be tested. This allows differentiation |
| 191 | between multiple instances of the same type of physical board that are |
| 192 | attached to the same host machine. This parameter is not interpreted by th |
| 193 | test script in any way, but rather is simply passed to the hook scripts |
| 194 | described below, and may be used in any site-specific way deemed necessary. |
| 195 | |
| 196 | --build |
| 197 | indicates that the test script should compile U-Boot itself before running |
| 198 | the tests. If using this option, make sure that any environment variables |
| 199 | required by the build process are already set, such as `$CROSS_COMPILE`. |
| 200 | |
| 201 | --buildman |
| 202 | indicates that `--build` should use buildman to build U-Boot. There is no need |
| 203 | to set $CROSS_COMPILE` in this case since buildman handles it. |
| 204 | |
| 205 | --build-dir |
| 206 | sets the directory containing the compiled U-Boot binaries. If omitted, this |
| 207 | is `${source_dir}/build-${board_type}`. |
| 208 | |
| 209 | --result-dir |
| 210 | sets the directory to write results, such as log files, into. |
| 211 | If omitted, the build directory is used. |
| 212 | |
| 213 | --persistent-data-dir |
| 214 | sets the directory used to store persistent test data. This is test data that |
| 215 | may be re-used across test runs, such as file-system images. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 216 | |
Stephen Warren | c9afc50 | 2016-02-08 14:49:02 -0700 | [diff] [blame] | 217 | `pytest` also implements a number of its own command-line options. Commonly used |
| 218 | options are mentioned below. Please see `pytest` documentation for complete |
| 219 | details. Execute `py.test --version` for a brief summary. Note that U-Boot's |
| 220 | test.py script passes all command-line arguments directly to `pytest` for |
| 221 | processing. |
| 222 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 223 | -k |
| 224 | selects which tests to run. The default is to run all known tests. This |
Stephen Warren | c9afc50 | 2016-02-08 14:49:02 -0700 | [diff] [blame] | 225 | option takes a single argument which is used to filter test names. Simple |
| 226 | logical operators are supported. For example: |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 227 | |
| 228 | - `'-k ums'` runs only tests with "ums" in their name. |
| 229 | - `'-k ut_dm'` runs only tests with "ut_dm" in their name. Note that in this |
Stephen Warren | c9afc50 | 2016-02-08 14:49:02 -0700 | [diff] [blame] | 230 | case, "ut_dm" is a parameter to a test rather than the test name. The full |
| 231 | test name is e.g. "test_ut[ut_dm_leak]". |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 232 | - `'-k not reset'` runs everything except tests with "reset" in their name. |
| 233 | - `'-k ut or hush'` runs only tests with "ut" or "hush" in their name. |
| 234 | - `'-k not (ut or hush)'` runs everything except tests with "ut" or "hush" in |
Stephen Warren | c9afc50 | 2016-02-08 14:49:02 -0700 | [diff] [blame] | 235 | their name. |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 236 | |
| 237 | -s |
| 238 | prevents pytest from hiding a test's stdout. This allows you to see |
Stephen Warren | c9afc50 | 2016-02-08 14:49:02 -0700 | [diff] [blame] | 239 | U-Boot's console log in real time on pytest's stdout. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 240 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 241 | Testing real hardware |
| 242 | --------------------- |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 243 | |
| 244 | The tools and techniques used to interact with real hardware will vary |
| 245 | radically between different host and target systems, and the whims of the user. |
| 246 | For this reason, the test suite does not attempt to directly interact with real |
| 247 | hardware in any way. Rather, it executes a standardized set of "hook" scripts |
| 248 | via `$PATH`. These scripts implement certain actions on behalf of the test |
| 249 | suite. This keeps the test suite simple and isolated from system variances |
| 250 | unrelated to U-Boot features. |
| 251 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 252 | Hook scripts |
| 253 | ~~~~~~~~~~~~ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 254 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 255 | Environment variables |
| 256 | ''''''''''''''''''''' |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 257 | |
| 258 | The following environment variables are set when running hook scripts: |
| 259 | |
| 260 | - `UBOOT_BOARD_TYPE` the board type being tested. |
| 261 | - `UBOOT_BOARD_IDENTITY` the board identity being tested, or `na` if none was |
| 262 | specified. |
| 263 | - `UBOOT_SOURCE_DIR` the U-Boot source directory. |
| 264 | - `UBOOT_TEST_PY_DIR` the full path to `test/py/` in the source directory. |
| 265 | - `UBOOT_BUILD_DIR` the U-Boot build directory. |
| 266 | - `UBOOT_RESULT_DIR` the test result directory. |
Masahiro Yamada | c901891 | 2017-10-19 19:08:52 +0900 | [diff] [blame] | 267 | - `UBOOT_PERSISTENT_DATA_DIR` the test persistent data directory. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 268 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 269 | u-boot-test-console |
| 270 | ''''''''''''''''''' |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 271 | |
| 272 | This script provides access to the U-Boot console. The script's stdin/stdout |
| 273 | should be connected to the board's console. This process should continue to run |
| 274 | indefinitely, until killed. The test suite will run this script in parallel |
| 275 | with all other hooks. |
| 276 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 277 | This script may be implemented e.g. by executing `cu`, `kermit`, `conmux`, etc. |
| 278 | via exec(). |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 279 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 280 | If you are able to run U-Boot under a hardware simulator such as QEMU, then |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 281 | you would likely spawn that simulator from this script. However, note that |
| 282 | `u-boot-test-reset` may be called multiple times per test script run, and must |
| 283 | cause U-Boot to start execution from scratch each time. Hopefully your |
| 284 | simulator includes a virtual reset button! If not, you can launch the |
| 285 | simulator from `u-boot-test-reset` instead, while arranging for this console |
| 286 | process to always communicate with the current simulator instance. |
| 287 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 288 | u-boot-test-flash |
| 289 | ''''''''''''''''' |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 290 | |
| 291 | Prior to running the test suite against a board, some arrangement must be made |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 292 | so that the board executes the particular U-Boot binary to be tested. Often |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 293 | this involves writing the U-Boot binary to the board's flash ROM. The test |
| 294 | suite calls this hook script for that purpose. |
| 295 | |
| 296 | This script should perform the entire flashing process synchronously; the |
| 297 | script should only exit once flashing is complete, and a board reset will |
| 298 | cause the newly flashed U-Boot binary to be executed. |
| 299 | |
| 300 | It is conceivable that this script will do nothing. This might be useful in |
| 301 | the following cases: |
| 302 | |
| 303 | - Some other process has already written the desired U-Boot binary into the |
| 304 | board's flash prior to running the test suite. |
| 305 | - The board allows U-Boot to be downloaded directly into RAM, and executed |
| 306 | from there. Use of this feature will reduce wear on the board's flash, so |
| 307 | may be preferable if available, and if cold boot testing of U-Boot is not |
| 308 | required. If this feature is used, the `u-boot-test-reset` script should |
Masahiro Yamada | c901891 | 2017-10-19 19:08:52 +0900 | [diff] [blame] | 309 | perform this download, since the board could conceivably be reset multiple |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 310 | times in a single test run. |
| 311 | |
| 312 | It is up to the user to determine if those situations exist, and to code this |
| 313 | hook script appropriately. |
| 314 | |
| 315 | This script will typically be implemented by calling out to some SoC- or |
| 316 | board-specific vendor flashing utility. |
| 317 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 318 | u-boot-test-reset |
| 319 | ''''''''''''''''' |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 320 | |
| 321 | Whenever the test suite needs to reset the target board, this script is |
| 322 | executed. This is guaranteed to happen at least once, prior to executing the |
| 323 | first test function. If any test fails, the test infra-structure will execute |
| 324 | this script again to restore U-Boot to an operational state before running the |
| 325 | next test function. |
| 326 | |
| 327 | This script will likely be implemented by communicating with some form of |
| 328 | relay or electronic switch attached to the board's reset signal. |
| 329 | |
| 330 | The semantics of this script require that when it is executed, U-Boot will |
| 331 | start running from scratch. If the U-Boot binary to be tested has been written |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 332 | to flash, pulsing the board's reset signal is likely all this script needs to |
| 333 | do. However, in some scenarios, this script may perform other actions. For |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 334 | example, it may call out to some SoC- or board-specific vendor utility in order |
| 335 | to download the U-Boot binary directly into RAM and execute it. This would |
| 336 | avoid the need for `u-boot-test-flash` to actually write U-Boot to flash, thus |
| 337 | saving wear on the flash chip(s). |
| 338 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 339 | Examples |
| 340 | '''''''' |
Stephen Warren | 140d04d | 2016-04-06 11:46:59 -0600 | [diff] [blame] | 341 | |
Tom Rini | 2a1df58 | 2021-02-24 17:05:04 -0500 | [diff] [blame] | 342 | https://source.denx.de/u-boot/u-boot-test-hooks contains some working example hook |
Stephen Warren | 140d04d | 2016-04-06 11:46:59 -0600 | [diff] [blame] | 343 | scripts, and may be useful as a reference when implementing hook scripts for |
| 344 | your platform. These scripts are not considered part of U-Boot itself. |
| 345 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 346 | Board-type-specific configuration |
| 347 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 348 | |
| 349 | Each board has a different configuration and behaviour. Many of these |
| 350 | differences can be automatically detected by parsing the `.config` file in the |
| 351 | build directory. However, some differences can't yet be handled automatically. |
| 352 | |
| 353 | For each board, an optional Python module `u_boot_board_${board_type}` may exist |
| 354 | to provide board-specific information to the test script. Any global value |
| 355 | defined in these modules is available for use by any test function. The data |
| 356 | contained in these scripts must be purely derived from U-Boot source code. |
| 357 | Hence, these configuration files are part of the U-Boot source tree too. |
| 358 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 359 | Execution environment configuration |
| 360 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 361 | |
| 362 | Each user's hardware setup may enable testing different subsets of the features |
| 363 | implemented by a particular board's configuration of U-Boot. For example, a |
| 364 | U-Boot configuration may support USB device mode and USB Mass Storage, but this |
| 365 | can only be tested if a USB cable is connected between the board and the host |
| 366 | machine running the test script. |
| 367 | |
| 368 | For each board, optional Python modules `u_boot_boardenv_${board_type}` and |
| 369 | `u_boot_boardenv_${board_type}_${board_identity}` may exist to provide |
| 370 | board-specific and board-identity-specific information to the test script. Any |
| 371 | global value defined in these modules is available for use by any test |
| 372 | function. The data contained in these is specific to a particular user's |
| 373 | hardware configuration. Hence, these configuration files are not part of the |
| 374 | U-Boot source tree, and should be installed outside of the source tree. Users |
| 375 | should set `$PYTHONPATH` prior to running the test script to allow these |
| 376 | modules to be loaded. |
| 377 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 378 | Board module parameter usage |
| 379 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 380 | |
| 381 | The test scripts rely on the following variables being defined by the board |
| 382 | module: |
| 383 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 384 | - none at present |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 385 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 386 | U-Boot `.config` feature usage |
| 387 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 388 | |
| 389 | The test scripts rely on various U-Boot `.config` features, either directly in |
| 390 | order to test those features, or indirectly in order to query information from |
| 391 | the running U-Boot instance in order to test other features. |
| 392 | |
| 393 | One example is that testing of the `md` command requires knowledge of a RAM |
| 394 | address to use for the test. This data is parsed from the output of the |
| 395 | `bdinfo` command, and hence relies on CONFIG_CMD_BDI being enabled. |
| 396 | |
| 397 | For a complete list of dependencies, please search the test scripts for |
| 398 | instances of: |
| 399 | |
| 400 | - `buildconfig.get(...` |
| 401 | - `@pytest.mark.buildconfigspec(...` |
Heinrich Schuchardt | 59264ae | 2019-04-22 09:18:55 +0200 | [diff] [blame] | 402 | - `@pytest.mark.notbuildconfigspec(...` |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 403 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 404 | Complete invocation example |
| 405 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 406 | |
| 407 | Assuming that you have installed the hook scripts into $HOME/ubtest/bin, and |
| 408 | any required environment configuration Python modules into $HOME/ubtest/py, |
| 409 | then you would likely invoke the test script as follows: |
| 410 | |
| 411 | If U-Boot has already been built: |
| 412 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 413 | .. code-block:: bash |
| 414 | |
| 415 | PATH=$HOME/ubtest/bin:$PATH \ |
Liam Beguin | ce3f90e | 2018-03-14 19:15:13 -0400 | [diff] [blame] | 416 | PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 417 | ./test/py/test.py --bd seaboard |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 418 | |
| 419 | If you want the test script to compile U-Boot for you too, then you likely |
| 420 | need to set `$CROSS_COMPILE` to allow this, and invoke the test script as |
Simon Glass | 6e09484 | 2020-03-18 09:43:01 -0600 | [diff] [blame] | 421 | follows: |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 422 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 423 | .. code-block:: bash |
| 424 | |
| 425 | CROSS_COMPILE=arm-none-eabi- \ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 426 | PATH=$HOME/ubtest/bin:$PATH \ |
Liam Beguin | ce3f90e | 2018-03-14 19:15:13 -0400 | [diff] [blame] | 427 | PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 428 | ./test/py/test.py --bd seaboard --build |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 429 | |
Simon Glass | 6e09484 | 2020-03-18 09:43:01 -0600 | [diff] [blame] | 430 | or, using buildman to handle it: |
| 431 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 432 | .. code-block:: bash |
| 433 | |
Simon Glass | 6e09484 | 2020-03-18 09:43:01 -0600 | [diff] [blame] | 434 | PATH=$HOME/ubtest/bin:$PATH \ |
| 435 | PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \ |
| 436 | ./test/py/test.py --bd seaboard --build --buildman |
Simon Glass | 6e09484 | 2020-03-18 09:43:01 -0600 | [diff] [blame] | 437 | |
Heinrich Schuchardt | 79c9f0e | 2021-01-18 20:24:03 +0100 | [diff] [blame] | 438 | Writing tests |
| 439 | ------------- |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 440 | |
| 441 | Please refer to the pytest documentation for details of writing pytest tests. |
| 442 | Details specific to the U-Boot test suite are described below. |
| 443 | |
| 444 | A test fixture named `u_boot_console` should be used by each test function. This |
| 445 | provides the means to interact with the U-Boot console, and retrieve board and |
| 446 | environment configuration information. |
| 447 | |
| 448 | The function `u_boot_console.run_command()` executes a shell command on the |
| 449 | U-Boot console, and returns all output from that command. This allows |
| 450 | validation or interpretation of the command output. This function validates |
| 451 | that certain strings are not seen on the U-Boot console. These include shell |
| 452 | error messages and the U-Boot sign-on message (in order to detect unexpected |
| 453 | board resets). See the source of `u_boot_console_base.py` for a complete list of |
| 454 | "bad" strings. Some test scenarios are expected to trigger these strings. Use |
| 455 | `u_boot_console.disable_check()` to temporarily disable checking for specific |
| 456 | strings. See `test_unknown_cmd.py` for an example. |
| 457 | |
| 458 | Board- and board-environment configuration values may be accessed as sub-fields |
| 459 | of the `u_boot_console.config` object, for example |
| 460 | `u_boot_console.config.ram_base`. |
| 461 | |
| 462 | Build configuration values (from `.config`) may be accessed via the dictionary |
| 463 | `u_boot_console.config.buildconfig`, with keys equal to the Kconfig variable |
| 464 | names. |