blob: 2b2c4be2dd11b3392d416a47a789fe2f98a0109d [file] [log] [blame]
Simon Glass4c8850a2021-03-07 17:34:42 -07001.. SPDX-License-Identifier: GPL-2.0+
2
3Tests Under the Hood
4====================
5
6Running sandbox tests directly
7------------------------------
8
9Typically tests are run using the pytest suite. Running pytests on sandbox is
10easy and always gets things right. For example some tests require files to be
11set up before they can work.
12
13But it is also possible to run some sandbox tests directly. For example, this
14runs 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
35The -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
37necessary because many tests rely on nodes or properties in the test devicetree.
38If 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
61The message above should provide a hint if you forget to use the -T flag. Even
62running with -D will produce different results.
63
64You 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
79You can then single-step and look at variables as needed.
80
Simon Glasse56c0942021-03-07 17:34:43 -070081
82Running sandbox_spl tests directly
83----------------------------------
84
85SPL is the phase before U-Boot proper. It is present in the sandbox_spl build,
86so you can run SPL like this::
87
88 ./spl/u-boot-spl
89
90SPL 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
110It is not possible to run SPL tests in U-Boot proper, firstly because they are
111not built into U-Boot proper and secondly because the environment is very
112different, e.g. some SPL tests rely on of-platdata which is only available in
113SPL.
114
115Note 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
117currently possible to run SPL tests and then stop, since the pytests require
118that U-Boot produces the expected banner.
119
120You can use the -k flag to select which tests run::
121
122 ./spl/u-boot-spl -u -k dm_test_of_plat_parent
123
124Of course you can use gdb with sandbox_spl, just as with sandbox.
125
126
127Running all tests directly
128--------------------------
129
130A fast way to run all sandbox tests is::
131
132 ./u-boot -T -c "ut all"
133
134It typically runs single-thread in 6 seconds on 2021 hardware, with 2s of that
135to the delays in the time test.
136
137This should not be considered a substitute for 'make check', but can be helpful
138for git bisect, etc.
139
140
141What tests are built in?
142------------------------
143
144Whatever sandbox build is used, which tests are present is determined by which
145source files are built. For sandbox_spl, the of_platdata tests are built
146because 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
154You can get a list of tests in a U-Boot ELF file by looking for the
155linker_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