Simon Glass | 9e78ad6 | 2021-03-07 17:34:42 -0700 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | Tests Under the Hood |
| 4 | ==================== |
| 5 | |
| 6 | Running sandbox tests directly |
| 7 | ------------------------------ |
| 8 | |
| 9 | Typically tests are run using the pytest suite. Running pytests on sandbox is |
| 10 | easy and always gets things right. For example some tests require files to be |
| 11 | set up before they can work. |
| 12 | |
| 13 | But it is also possible to run some sandbox tests directly. For example, this |
| 14 | runs the dm_test_gpio() test which you can find in test/dm/gpio.c:: |
| 15 | |
| 16 | $ ./u-boot -T -c "ut dm gpio" |
| 17 | |
| 18 | |
| 19 | U-Boot 2021.01 |
| 20 | |
| 21 | Model: sandbox |
| 22 | DRAM: 128 MiB |
| 23 | WDT: Started with servicing (60s timeout) |
| 24 | MMC: mmc2: 2 (SD), mmc1: 1 (SD), mmc0: 0 (SD) |
| 25 | In: serial |
| 26 | Out: vidconsole |
| 27 | Err: vidconsole |
| 28 | Model: sandbox |
| 29 | SCSI: |
| 30 | Net: eth0: eth@10002000, eth5: eth@10003000, eth3: sbe5, eth6: eth@10004000 |
| 31 | Test: dm_test_gpio: gpio.c |
| 32 | Test: dm_test_gpio: gpio.c (flat tree) |
| 33 | Failures: 0 |
| 34 | |
| 35 | The -T option tells the U-Boot sandbox to run with the 'test' devicetree |
| 36 | (test.dts) instead of -D which selects the normal sandbox.dts - this is |
| 37 | necessary because many tests rely on nodes or properties in the test devicetree. |
| 38 | If you try running tests without -T then you may see failures, like:: |
| 39 | |
| 40 | $ ./u-boot -c "ut dm gpio" |
| 41 | |
| 42 | |
| 43 | U-Boot 2021.01 |
| 44 | |
| 45 | DRAM: 128 MiB |
| 46 | WDT: Not found! |
| 47 | MMC: |
| 48 | In: serial |
| 49 | Out: serial |
| 50 | Err: serial |
| 51 | SCSI: |
| 52 | Net: No ethernet found. |
| 53 | Please run with test device tree: |
| 54 | ./u-boot -d arch/sandbox/dts/test.dtb |
| 55 | Test: dm_test_gpio: gpio.c |
| 56 | test/dm/gpio.c:37, dm_test_gpio(): 0 == gpio_lookup_name("b4", &dev, &offset, &gpio): Expected 0x0 (0), got 0xffffffea (-22) |
| 57 | Test: dm_test_gpio: gpio.c (flat tree) |
| 58 | test/dm/gpio.c:37, dm_test_gpio(): 0 == gpio_lookup_name("b4", &dev, &offset, &gpio): Expected 0x0 (0), got 0xffffffea (-22) |
| 59 | Failures: 2 |
| 60 | |
| 61 | The message above should provide a hint if you forget to use the -T flag. Even |
| 62 | running with -D will produce different results. |
| 63 | |
| 64 | You can easily use gdb on these tests, without needing --gdbserver:: |
| 65 | |
| 66 | $ gdb u-boot --args -T -c "ut dm gpio" |
| 67 | ... |
| 68 | (gdb) break dm_test_gpio |
| 69 | Breakpoint 1 at 0x1415bd: file test/dm/gpio.c, line 37. |
| 70 | (gdb) run -T -c "ut dm gpio" |
| 71 | Starting program: u-boot -T -c "ut dm gpio" |
| 72 | Test: dm_test_gpio: gpio.c |
| 73 | |
| 74 | Breakpoint 1, dm_test_gpio (uts=0x5555558029a0 <global_dm_test_state>) |
| 75 | at files/test/dm/gpio.c:37 |
| 76 | 37 ut_assertok(gpio_lookup_name("b4", &dev, &offset, &gpio)); |
| 77 | (gdb) |
| 78 | |
| 79 | You can then single-step and look at variables as needed. |
| 80 | |
Simon Glass | eaf2196 | 2021-03-07 17:34:43 -0700 | [diff] [blame] | 81 | |
| 82 | Running sandbox_spl tests directly |
| 83 | ---------------------------------- |
| 84 | |
| 85 | SPL is the phase before U-Boot proper. It is present in the sandbox_spl build, |
| 86 | so you can run SPL like this:: |
| 87 | |
| 88 | ./spl/u-boot-spl |
| 89 | |
| 90 | SPL tests are special in that they run (only in the SPL phase, of course) if the |
| 91 | -u flag is given:: |
| 92 | |
| 93 | ./spl/u-boot-spl -u |
| 94 | |
| 95 | U-Boot SPL 2021.01-00723-g43c77b51be5-dirty (Jan 24 2021 - 16:38:24 -0700) |
| 96 | Running 5 driver model tests |
| 97 | Test: dm_test_of_plat_base: of_platdata.c (flat tree) |
| 98 | Test: dm_test_of_plat_dev: of_platdata.c (flat tree) |
| 99 | Test: dm_test_of_plat_parent: of_platdata.c (flat tree) |
| 100 | Test: dm_test_of_plat_phandle: of_platdata.c (flat tree) |
| 101 | Test: dm_test_of_plat_props: of_platdata.c (flat tree) |
| 102 | Failures: 0 |
| 103 | |
| 104 | |
| 105 | U-Boot 2021.01-00723-g43c77b51be5-dirty (Jan 24 2021 - 16:38:24 -0700) |
| 106 | |
| 107 | DRAM: 128 MiB |
| 108 | ... |
| 109 | |
| 110 | It is not possible to run SPL tests in U-Boot proper, firstly because they are |
| 111 | not built into U-Boot proper and secondly because the environment is very |
| 112 | different, e.g. some SPL tests rely on of-platdata which is only available in |
| 113 | SPL. |
| 114 | |
| 115 | Note that after running, SPL continues to boot into U-Boot proper. You can add |
| 116 | '-c exit' to make U-Boot quit without doing anything further. It is not |
| 117 | currently possible to run SPL tests and then stop, since the pytests require |
| 118 | that U-Boot produces the expected banner. |
| 119 | |
| 120 | You can use the -k flag to select which tests run:: |
| 121 | |
| 122 | ./spl/u-boot-spl -u -k dm_test_of_plat_parent |
| 123 | |
| 124 | Of course you can use gdb with sandbox_spl, just as with sandbox. |
| 125 | |
| 126 | |
| 127 | Running all tests directly |
| 128 | -------------------------- |
| 129 | |
| 130 | A fast way to run all sandbox tests is:: |
| 131 | |
| 132 | ./u-boot -T -c "ut all" |
| 133 | |
| 134 | It typically runs single-thread in 6 seconds on 2021 hardware, with 2s of that |
| 135 | to the delays in the time test. |
| 136 | |
| 137 | This should not be considered a substitute for 'make check', but can be helpful |
| 138 | for git bisect, etc. |
| 139 | |
| 140 | |
| 141 | What tests are built in? |
| 142 | ------------------------ |
| 143 | |
| 144 | Whatever sandbox build is used, which tests are present is determined by which |
| 145 | source files are built. For sandbox_spl, the of_platdata tests are built |
| 146 | because of the build rule in test/dm/Makefile:: |
| 147 | |
| 148 | ifeq ($(CONFIG_SPL_BUILD),y) |
| 149 | obj-$(CONFIG_SPL_OF_PLATDATA) += of_platdata.o |
| 150 | else |
| 151 | ...other tests for non-spl |
| 152 | endif |
| 153 | |
| 154 | You can get a list of tests in a U-Boot ELF file by looking for the |
| 155 | linker_list:: |
| 156 | |
| 157 | $ nm /tmp/b/sandbox_spl/spl/u-boot-spl |grep 2_dm_test |
| 158 | 000000000001f200 D _u_boot_list_2_dm_test_2_dm_test_of_plat_base |
| 159 | 000000000001f220 D _u_boot_list_2_dm_test_2_dm_test_of_plat_dev |
| 160 | 000000000001f240 D _u_boot_list_2_dm_test_2_dm_test_of_plat_parent |
| 161 | 000000000001f260 D _u_boot_list_2_dm_test_2_dm_test_of_plat_phandle |
| 162 | 000000000001f280 D _u_boot_list_2_dm_test_2_dm_test_of_plat_props |