blob: 42b64882cd9f3709110a03d85f0c4e899aab05f0 [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