mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-27 16:01:27 +00:00
test: Update documentation
Update documentation for how to write tests and the 'ut' command. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
540bf7881a
commit
404cdf0cda
3 changed files with 149 additions and 60 deletions
|
@ -261,7 +261,7 @@ with the suite. For example, to add a new mem_search test::
|
||||||
/* Test 'ms' command with 32-bit values */
|
/* Test 'ms' command with 32-bit values */
|
||||||
static int mem_test_ms_new_thing(struct unit_test_state *uts)
|
static int mem_test_ms_new_thing(struct unit_test_state *uts)
|
||||||
{
|
{
|
||||||
/* test code here*/
|
/* test code here */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -291,32 +291,20 @@ suite. For example::
|
||||||
/* Declare a new wibble test */
|
/* Declare a new wibble test */
|
||||||
#define WIBBLE_TEST(_name, _flags) UNIT_TEST(_name, _flags, wibble_test)
|
#define WIBBLE_TEST(_name, _flags) UNIT_TEST(_name, _flags, wibble_test)
|
||||||
|
|
||||||
/* Tetss go here */
|
/* Tests go here */
|
||||||
|
|
||||||
/* At the bottom of the file: */
|
|
||||||
|
|
||||||
int do_ut_wibble(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
|
||||||
{
|
|
||||||
struct unit_test *tests = UNIT_TEST_SUITE_START(wibble_test);
|
|
||||||
const int n_ents = UNIT_TEST_SUITE_COUNT(wibble_test);
|
|
||||||
|
|
||||||
return cmd_ut_category("cmd_wibble", "wibble_test_", tests, n_ents, argc, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
Then add new tests to it as above.
|
Then add new tests to it as above.
|
||||||
|
|
||||||
Register this new suite in test/cmd_ut.c by adding to cmd_ut_sub[]::
|
Register this new suite in test/cmd_ut.c by adding to cmd_ut_sub[]::
|
||||||
|
|
||||||
/* Within cmd_ut_sub[]... */
|
/* with the other SUITE_DECL() declarations */
|
||||||
|
SUITE_DECL(wibble);
|
||||||
|
|
||||||
U_BOOT_CMD_MKENT(wibble, CONFIG_SYS_MAXARGS, 1, do_ut_wibble, "", ""),
|
/* Within suites[]... */
|
||||||
|
SUITE(wibble, "my test of wibbles");
|
||||||
|
|
||||||
and adding new help to ut_help_text[]::
|
If your feature is conditional on a particular Kconfig, you do not need to add
|
||||||
|
an #ifdef since the suite will automatically be compiled out in that case.
|
||||||
"ut wibble - Test the wibble feature\n"
|
|
||||||
|
|
||||||
If your feature is conditional on a particular Kconfig, then you can use #ifdef
|
|
||||||
to control that.
|
|
||||||
|
|
||||||
Finally, add the test to the build by adding to the Makefile in the same
|
Finally, add the test to the build by adding to the Makefile in the same
|
||||||
directory::
|
directory::
|
||||||
|
@ -326,17 +314,35 @@ directory::
|
||||||
Note that CMDLINE is never enabled in SPL, so this test will only be present in
|
Note that CMDLINE is never enabled in SPL, so this test will only be present in
|
||||||
U-Boot proper. See below for how to do SPL tests.
|
U-Boot proper. See below for how to do SPL tests.
|
||||||
|
|
||||||
As before, you can add an extra Kconfig check if needed::
|
You can add an extra Kconfig check if needed::
|
||||||
|
|
||||||
ifneq ($(CONFIG_$(XPL_)WIBBLE),)
|
ifneq ($(CONFIG_$(XPL_)WIBBLE),)
|
||||||
obj-$(CONFIG_$(XPL_)CMDLINE) += wibble.o
|
obj-$(CONFIG_$(XPL_)CMDLINE) += wibble.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Each suite can have an optional init and uninit function. These are run before
|
||||||
|
and after any suite tests, respectively::
|
||||||
|
|
||||||
Example commit: 919e7a8fb64 ("test: Add a simple test for bloblist") [1]
|
#define WIBBLE_TEST_INIT(_name, _flags) UNIT_TEST_INIT(_name, _flags, wibble_test)
|
||||||
|
#define WIBBLE_TEST_UNINIT(_name, _flags) UNIT_TEST_UNINIT(_name, _flags, wibble_test)
|
||||||
|
|
||||||
[1] https://gitlab.denx.de/u-boot/u-boot/-/commit/919e7a8fb64
|
static int wibble_test_init(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
/* init code here */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
WIBBLE_TEST_INIT(wibble_test_init, 0);
|
||||||
|
|
||||||
|
static int wibble_test_uninit(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
/* uninit code here */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
WIBBLE_TEST_INIT(wibble_test_uninit, 0);
|
||||||
|
|
||||||
|
Both functions are included in the totals for each suite.
|
||||||
|
|
||||||
Making the test run from pytest
|
Making the test run from pytest
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -11,34 +11,44 @@ Synopsis
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
ut [-r<runs>] [-fs] [-I<n>:<one_test>] [<suite> [<test>]]
|
ut [-r<runs>] [-f] [-I<n>:<one_test>] [-r<n>] [<suite> | 'all' [<test>]]
|
||||||
|
ut [-s] info
|
||||||
<runs> Number of times to run each test
|
|
||||||
-f Force 'manual' tests to run as well
|
|
||||||
<n> Run <one test> after <n> other tests have run
|
|
||||||
<one_test> Name of the 'one' test to run
|
|
||||||
<suite> Test suite to run, or `all`
|
|
||||||
<test> Name of single test to run
|
|
||||||
|
|
||||||
Description
|
Description
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
The ut command runs unit tests written in C.
|
The ut command runs unit tests written in C.
|
||||||
|
|
||||||
|
suite
|
||||||
|
Specifies the suite to run, This can be a single suite, or a comma-separated
|
||||||
|
list
|
||||||
|
|
||||||
|
test
|
||||||
|
Speciifes a particular test to run, within a suite, or all suites
|
||||||
|
|
||||||
|
-f
|
||||||
|
Forces running of a manual test.
|
||||||
|
|
||||||
|
-r <n>
|
||||||
|
Specifies the number of types to run each test
|
||||||
|
|
||||||
|
-I <n>:<one_test>
|
||||||
|
Test to run after <n> other tests have run. This is used to find which test
|
||||||
|
causes another test to fail. If the one test fails, testing stops
|
||||||
|
immediately.
|
||||||
|
|
||||||
Typically the command is run on :ref:`arch/sandbox/sandbox:sandbox` since it
|
Typically the command is run on :ref:`arch/sandbox/sandbox:sandbox` since it
|
||||||
includes a near-complete set of emulators, no code-size limits, many CONFIG
|
includes a near-complete set of emulators, no code-size limits, many CONFIG
|
||||||
options enabled and runs easily in CI without needing QEMU. It is also possible
|
options enabled and runs easily in CI without needing QEMU. It is also possible
|
||||||
to run some tests on real boards.
|
to run some tests on real boards.
|
||||||
|
|
||||||
For a list of available test suites, type `ut info -s`.
|
|
||||||
|
|
||||||
Each test is normally run once, although those marked with `UTF_DM` are
|
Each test is normally run once, although those marked with `UTF_DM` are
|
||||||
run with livetree and flattree where possible. To run a test more than once,
|
run with livetree and flattree where possible. To run a test more than once,
|
||||||
use the `-r` flag.
|
use the `-r` flag.
|
||||||
|
|
||||||
Manual tests are normally skipped by this command. Use `-f` to run them. See
|
Manual tests are normally skipped by this command. Use `-f` to run them. See
|
||||||
See :ref:`develop/tests_writing:mixing python and c` for more information on
|
:ref:`develop/tests_writing:mixing python and c` for more information on manual
|
||||||
manual test.
|
tests.
|
||||||
|
|
||||||
When running unit tests, some may have side effects which cause a subsequent
|
When running unit tests, some may have side effects which cause a subsequent
|
||||||
test to break. This can sometimes be seen when using 'ut dm' or similar. To
|
test to break. This can sometimes be seen when using 'ut dm' or similar. To
|
||||||
|
@ -50,9 +60,22 @@ the problem.
|
||||||
Generally all tests in the suite are run. To run just a single test from the
|
Generally all tests in the suite are run. To run just a single test from the
|
||||||
suite, provide the <test> argument.
|
suite, provide the <test> argument.
|
||||||
|
|
||||||
|
To specify a list of suites to run, <suites> can also be a comma-separated list.
|
||||||
|
|
||||||
See :ref:`develop/tests_writing:writing c tests` for more information on how to
|
See :ref:`develop/tests_writing:writing c tests` for more information on how to
|
||||||
write unit tests.
|
write unit tests.
|
||||||
|
|
||||||
|
ut all
|
||||||
|
~~~~~~
|
||||||
|
|
||||||
|
Instead of a suite name 'all' may be used to run all tests.
|
||||||
|
|
||||||
|
ut info
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
This provides information about the total number of suites and tests. Use the
|
||||||
|
`-s` flag to show a detailed list of suites.
|
||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
@ -97,26 +120,84 @@ List available unit-test suites::
|
||||||
|
|
||||||
Run one of the suites::
|
Run one of the suites::
|
||||||
|
|
||||||
=> ut bloblist
|
=> ut common
|
||||||
Running 14 bloblist tests
|
Running 14 common tests
|
||||||
Test: bloblist_test_align: bloblist.c
|
Test: cli_ch_test: cread.c
|
||||||
Test: bloblist_test_bad_blob: bloblist.c
|
Test: cread_test: cread.c
|
||||||
Test: bloblist_test_blob: bloblist.c
|
Test: dm_test_cyclic_running: cyclic.c
|
||||||
Test: bloblist_test_blob_ensure: bloblist.c
|
Test: print_display_buffer: print.c
|
||||||
Test: bloblist_test_blob_maxsize: bloblist.c
|
Test: print_do_hex_dump: print.c
|
||||||
Test: bloblist_test_checksum: bloblist.c
|
Test: print_efi_ut: print.c
|
||||||
Test: bloblist_test_cmd_info: bloblist.c
|
Test: print_guid: print.c
|
||||||
Test: bloblist_test_cmd_list: bloblist.c
|
Test: print_hexdump_line: print.c
|
||||||
Test: bloblist_test_grow: bloblist.c
|
Test: print_printf: print.c
|
||||||
Test: bloblist_test_init: bloblist.c
|
Test: snprint: print.c
|
||||||
Test: bloblist_test_reloc: bloblist.c
|
Test: test_autoboot: test_autoboot.c
|
||||||
Test: bloblist_test_resize_fail: bloblist.c
|
Enter password "a" in 1 seconds to stop autoboot
|
||||||
Test: bloblist_test_resize_last: bloblist.c
|
Enter password "a" in 1 seconds to stop autoboot
|
||||||
Test: bloblist_test_shrink: bloblist.c
|
Enter password "a" in 1 seconds to stop autoboot
|
||||||
Failures: 0
|
Enter password "a" in 1 seconds to stop autoboot
|
||||||
|
Enter password "a" in 1 seconds to stop autoboot
|
||||||
|
Enter password "a" in 1 seconds to stop autoboot
|
||||||
|
Autoboot password unlock not successful
|
||||||
|
Test: test_event_base: event.c
|
||||||
|
Test: test_event_probe: event.c
|
||||||
|
Test: test_event_probe: event.c (flat tree)
|
||||||
|
Test: test_event_simple: event.c
|
||||||
|
Tests run: 14, 2611 ms, average 186 ms, skipped: 2, failures: 0
|
||||||
|
|
||||||
Run just a single test in a suite::
|
Run just a single test in a suite::
|
||||||
|
|
||||||
=> ut bloblist bloblist_test_grow
|
=> ut fdt_overlay change_int_property
|
||||||
Test: bloblist_test_grow: bloblist.c
|
Test: fdt_overlay_init: cmd_ut_fdt_overlay.c
|
||||||
Failures: 0
|
Test: change_int_property: cmd_ut_fdt_overlay.c
|
||||||
|
Tests run: 2, 0 ms, average 0 ms, failures: 0
|
||||||
|
|
||||||
|
Run a selection of three suites::
|
||||||
|
|
||||||
|
=> ut bloblist,mem,fdt_overlay
|
||||||
|
Running 14 bloblist tests
|
||||||
|
Test: align: bloblist.c
|
||||||
|
Test: bad_blob: bloblist.c
|
||||||
|
Test: blob: bloblist.c
|
||||||
|
Test: blob_ensure: bloblist.c
|
||||||
|
Test: blob_maxsize: bloblist.c
|
||||||
|
Test: checksum: bloblist.c
|
||||||
|
Test: cmd_info: bloblist.c
|
||||||
|
Test: cmd_list: bloblist.c
|
||||||
|
Test: grow: bloblist.c
|
||||||
|
Test: init: bloblist.c
|
||||||
|
Test: reloc: bloblist.c
|
||||||
|
Test: resize_fail: bloblist.c
|
||||||
|
Test: resize_last: bloblist.c
|
||||||
|
Test: shrink: bloblist.c
|
||||||
|
Tests run: 14, 1 ms, average: 0 ms, failures: 0
|
||||||
|
Running 13 mem tests
|
||||||
|
Test: cp_b: mem_copy.c
|
||||||
|
Test: cp_l: mem_copy.c
|
||||||
|
Test: cp_q: mem_copy.c
|
||||||
|
Test: cp_w: mem_copy.c
|
||||||
|
Test: ms_b: mem_search.c
|
||||||
|
Test: ms_cont: mem_search.c
|
||||||
|
Test: ms_cont_end: mem_search.c
|
||||||
|
Test: ms_l: mem_search.c
|
||||||
|
Test: ms_limit: mem_search.c
|
||||||
|
Test: ms_mult: mem_search.c
|
||||||
|
Test: ms_quiet: mem_search.c
|
||||||
|
Test: ms_s: mem_search.c
|
||||||
|
Test: ms_w: mem_search.c
|
||||||
|
Tests run: 13, 13 ms, average: 1 ms, failures: 0
|
||||||
|
Running 10 fdt_overlay tests
|
||||||
|
Test: fdt_overlay_init: cmd_ut_fdt_overlay.c
|
||||||
|
Test: add_node_by_path: cmd_ut_fdt_overlay.c
|
||||||
|
Test: add_node_by_phandle: cmd_ut_fdt_overlay.c
|
||||||
|
Test: add_str_property: cmd_ut_fdt_overlay.c
|
||||||
|
Test: add_subnode_property: cmd_ut_fdt_overlay.c
|
||||||
|
Test: change_int_property: cmd_ut_fdt_overlay.c
|
||||||
|
Test: change_str_property: cmd_ut_fdt_overlay.c
|
||||||
|
Test: local_phandle: cmd_ut_fdt_overlay.c
|
||||||
|
Test: local_phandles: cmd_ut_fdt_overlay.c
|
||||||
|
Test: stacked: cmd_ut_fdt_overlay.c
|
||||||
|
Tests run: 10, 12 ms, average: 1 ms, failures: 0
|
||||||
|
Suites run: 3, total tests run: 37, 26 ms, average: 0 ms, failures: 0
|
||||||
|
Average test time: 0 ms, worst case 'mem' took 1 ms
|
||||||
|
|
|
@ -321,14 +321,16 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
U_BOOT_LONGHELP(ut,
|
U_BOOT_LONGHELP(ut,
|
||||||
"[-r] [-f] [<suite>] - run unit tests\n"
|
"[-rs] [-f] [-I<n>:<one_test>][<suites>] - run unit tests\n"
|
||||||
" -r<runs> Number of times to run each test\n"
|
" -r<runs> Number of times to run each test\n"
|
||||||
" -f Force 'manual' tests to run as well\n"
|
" -f Force 'manual' tests to run as well\n"
|
||||||
" <suite> Test suite to run, or all\n"
|
" -I Test to run after <n> other tests have run\n"
|
||||||
|
" -s Show all suites with ut info\n"
|
||||||
|
" <suites> Comma-separated list of suites to run\n"
|
||||||
"\n"
|
"\n"
|
||||||
"\nOptions for <suite>:"
|
"Options for <suite>:\n"
|
||||||
"\nall - execute all enabled tests"
|
"all - execute all enabled tests\n"
|
||||||
"\ninfo [-s] - show info about tests [and suites]"
|
"info - show info about tests [and suites]"
|
||||||
);
|
);
|
||||||
|
|
||||||
U_BOOT_CMD(
|
U_BOOT_CMD(
|
||||||
|
|
Loading…
Add table
Reference in a new issue