Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+: |
| 2 | |
Heinrich Schuchardt | 1b0c316 | 2024-01-14 14:53:13 +0100 | [diff] [blame] | 3 | .. index:: |
| 4 | single: ut (command) |
| 5 | |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 6 | ut command |
| 7 | ========== |
| 8 | |
Heinrich Schuchardt | 44b09b3 | 2024-03-16 11:09:36 +0100 | [diff] [blame] | 9 | Synopsis |
| 10 | -------- |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 11 | |
| 12 | :: |
| 13 | |
Simon Glass | c240264 | 2025-02-07 11:31:00 -0700 | [diff] [blame] | 14 | ut [-r<runs>] [-f] [-I<n>:<one_test>] [-r<n>] [<suite> | 'all' [<test>]] |
| 15 | ut [-s] info |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 16 | |
| 17 | Description |
| 18 | ----------- |
| 19 | |
| 20 | The ut command runs unit tests written in C. |
| 21 | |
Simon Glass | c240264 | 2025-02-07 11:31:00 -0700 | [diff] [blame] | 22 | suite |
| 23 | Specifies the suite to run, This can be a single suite, or a comma-separated |
| 24 | list |
| 25 | |
| 26 | test |
| 27 | Speciifes a particular test to run, within a suite, or all suites |
| 28 | |
| 29 | -f |
| 30 | Forces running of a manual test. |
| 31 | |
| 32 | -r <n> |
| 33 | Specifies the number of types to run each test |
| 34 | |
| 35 | -I <n>:<one_test> |
| 36 | Test to run after <n> other tests have run. This is used to find which test |
| 37 | causes another test to fail. If the one test fails, testing stops |
| 38 | immediately. |
| 39 | |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 40 | Typically the command is run on :ref:`arch/sandbox/sandbox:sandbox` since it |
| 41 | includes a near-complete set of emulators, no code-size limits, many CONFIG |
| 42 | options enabled and runs easily in CI without needing QEMU. It is also possible |
| 43 | to run some tests on real boards. |
| 44 | |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 45 | Each test is normally run once, although those marked with `UTF_DM` are |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 46 | run with livetree and flattree where possible. To run a test more than once, |
| 47 | use the `-r` flag. |
| 48 | |
| 49 | Manual tests are normally skipped by this command. Use `-f` to run them. See |
Simon Glass | c240264 | 2025-02-07 11:31:00 -0700 | [diff] [blame] | 50 | :ref:`develop/tests_writing:mixing python and c` for more information on manual |
| 51 | tests. |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 52 | |
Simon Glass | 85ba7c3 | 2022-10-29 19:47:13 -0600 | [diff] [blame] | 53 | When running unit tests, some may have side effects which cause a subsequent |
| 54 | test to break. This can sometimes be seen when using 'ut dm' or similar. To |
| 55 | fix this, select the 'one' test which breaks. Then tell the 'ut' command to |
| 56 | run this one test after a certain number of other tests have run. Using a |
| 57 | binary search method with `-I` you can quickly figure one which test is causing |
| 58 | the problem. |
| 59 | |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 60 | Generally all tests in the suite are run. To run just a single test from the |
| 61 | suite, provide the <test> argument. |
| 62 | |
Simon Glass | c240264 | 2025-02-07 11:31:00 -0700 | [diff] [blame] | 63 | To specify a list of suites to run, <suites> can also be a comma-separated list. |
| 64 | |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 65 | See :ref:`develop/tests_writing:writing c tests` for more information on how to |
| 66 | write unit tests. |
| 67 | |
Simon Glass | c240264 | 2025-02-07 11:31:00 -0700 | [diff] [blame] | 68 | ut all |
| 69 | ~~~~~~ |
| 70 | |
| 71 | Instead of a suite name 'all' may be used to run all tests. |
| 72 | |
| 73 | ut info |
| 74 | ~~~~~~~ |
| 75 | |
| 76 | This provides information about the total number of suites and tests. Use the |
| 77 | `-s` flag to show a detailed list of suites. |
| 78 | |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 79 | Example |
| 80 | ------- |
| 81 | |
Simon Glass | e411746 | 2025-01-20 14:26:06 -0700 | [diff] [blame] | 82 | Show information about tests:: |
| 83 | |
| 84 | => ut info |
| 85 | Test suites: 23 |
| 86 | Total tests: 833 |
| 87 | |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 88 | List available unit-test suites:: |
| 89 | |
Simon Glass | e411746 | 2025-01-20 14:26:06 -0700 | [diff] [blame] | 90 | => ut info -s |
| 91 | Test suites: 23 |
| 92 | Total tests: 833 |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 93 | |
Simon Glass | e411746 | 2025-01-20 14:26:06 -0700 | [diff] [blame] | 94 | Tests Suite Purpose |
| 95 | ----- ------------ ------------------------- |
| 96 | 1 addrmap very basic test of addrmap command |
| 97 | 4 bdinfo bdinfo (board info) command |
| 98 | 14 bloblist bloblist implementation |
| 99 | 7 bootm bootm command |
| 100 | 66 bootstd standard boot implementation |
| 101 | 2 cmd various commands |
| 102 | 14 common tests for common/ directory |
| 103 | 502 dm driver model |
| 104 | 6 env environment |
| 105 | 1 exit shell exit and variables |
| 106 | 19 fdt fdt command |
| 107 | 10 fdt_overlay device tree overlays |
| 108 | 1 font font command |
| 109 | 20 hush hush behaviour |
| 110 | 115 lib library functions |
| 111 | 2 loadm loadm command parameters and loading memory blob |
| 112 | 18 log logging functions |
| 113 | 1 mbr mbr command |
| 114 | 1 measurement TPM-based measured boot |
| 115 | 13 mem memory-related commands |
| 116 | 1 pci_mps PCI Express Maximum Payload Size |
| 117 | 11 setexpr setexpr command |
| 118 | 4 upl Universal payload support |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 119 | |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 120 | |
| 121 | Run one of the suites:: |
| 122 | |
Simon Glass | c240264 | 2025-02-07 11:31:00 -0700 | [diff] [blame] | 123 | => ut common |
| 124 | Running 14 common tests |
| 125 | Test: cli_ch_test: cread.c |
| 126 | Test: cread_test: cread.c |
| 127 | Test: dm_test_cyclic_running: cyclic.c |
| 128 | Test: print_display_buffer: print.c |
| 129 | Test: print_do_hex_dump: print.c |
| 130 | Test: print_efi_ut: print.c |
| 131 | Test: print_guid: print.c |
| 132 | Test: print_hexdump_line: print.c |
| 133 | Test: print_printf: print.c |
| 134 | Test: snprint: print.c |
| 135 | Test: test_autoboot: test_autoboot.c |
| 136 | Enter password "a" in 1 seconds to stop autoboot |
| 137 | Enter password "a" in 1 seconds to stop autoboot |
| 138 | Enter password "a" in 1 seconds to stop autoboot |
| 139 | Enter password "a" in 1 seconds to stop autoboot |
| 140 | Enter password "a" in 1 seconds to stop autoboot |
| 141 | Enter password "a" in 1 seconds to stop autoboot |
| 142 | Autoboot password unlock not successful |
| 143 | Test: test_event_base: event.c |
| 144 | Test: test_event_probe: event.c |
| 145 | Test: test_event_probe: event.c (flat tree) |
| 146 | Test: test_event_simple: event.c |
| 147 | Tests run: 14, 2611 ms, average 186 ms, skipped: 2, failures: 0 |
Simon Glass | 3814e89 | 2022-10-29 19:47:11 -0600 | [diff] [blame] | 148 | |
| 149 | Run just a single test in a suite:: |
| 150 | |
Simon Glass | c240264 | 2025-02-07 11:31:00 -0700 | [diff] [blame] | 151 | => ut fdt_overlay change_int_property |
| 152 | Test: fdt_overlay_init: cmd_ut_fdt_overlay.c |
| 153 | Test: change_int_property: cmd_ut_fdt_overlay.c |
| 154 | Tests run: 2, 0 ms, average 0 ms, failures: 0 |
| 155 | |
| 156 | Run a selection of three suites:: |
| 157 | |
| 158 | => ut bloblist,mem,fdt_overlay |
| 159 | Running 14 bloblist tests |
| 160 | Test: align: bloblist.c |
| 161 | Test: bad_blob: bloblist.c |
| 162 | Test: blob: bloblist.c |
| 163 | Test: blob_ensure: bloblist.c |
| 164 | Test: blob_maxsize: bloblist.c |
| 165 | Test: checksum: bloblist.c |
| 166 | Test: cmd_info: bloblist.c |
| 167 | Test: cmd_list: bloblist.c |
| 168 | Test: grow: bloblist.c |
| 169 | Test: init: bloblist.c |
| 170 | Test: reloc: bloblist.c |
| 171 | Test: resize_fail: bloblist.c |
| 172 | Test: resize_last: bloblist.c |
| 173 | Test: shrink: bloblist.c |
| 174 | Tests run: 14, 1 ms, average: 0 ms, failures: 0 |
| 175 | Running 13 mem tests |
| 176 | Test: cp_b: mem_copy.c |
| 177 | Test: cp_l: mem_copy.c |
| 178 | Test: cp_q: mem_copy.c |
| 179 | Test: cp_w: mem_copy.c |
| 180 | Test: ms_b: mem_search.c |
| 181 | Test: ms_cont: mem_search.c |
| 182 | Test: ms_cont_end: mem_search.c |
| 183 | Test: ms_l: mem_search.c |
| 184 | Test: ms_limit: mem_search.c |
| 185 | Test: ms_mult: mem_search.c |
| 186 | Test: ms_quiet: mem_search.c |
| 187 | Test: ms_s: mem_search.c |
| 188 | Test: ms_w: mem_search.c |
| 189 | Tests run: 13, 13 ms, average: 1 ms, failures: 0 |
| 190 | Running 10 fdt_overlay tests |
| 191 | Test: fdt_overlay_init: cmd_ut_fdt_overlay.c |
| 192 | Test: add_node_by_path: cmd_ut_fdt_overlay.c |
| 193 | Test: add_node_by_phandle: cmd_ut_fdt_overlay.c |
| 194 | Test: add_str_property: cmd_ut_fdt_overlay.c |
| 195 | Test: add_subnode_property: cmd_ut_fdt_overlay.c |
| 196 | Test: change_int_property: cmd_ut_fdt_overlay.c |
| 197 | Test: change_str_property: cmd_ut_fdt_overlay.c |
| 198 | Test: local_phandle: cmd_ut_fdt_overlay.c |
| 199 | Test: local_phandles: cmd_ut_fdt_overlay.c |
| 200 | Test: stacked: cmd_ut_fdt_overlay.c |
| 201 | Tests run: 10, 12 ms, average: 1 ms, failures: 0 |
| 202 | Suites run: 3, total tests run: 37, 26 ms, average: 0 ms, failures: 0 |
| 203 | Average test time: 0 ms, worst case 'mem' took 1 ms |