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