test: Refactor tests to have a single test runner
v3 cover test: Refactor tests to have a single test runner
At present U-Boot has two broad sets of tests in the C code: driver model tests which do a lot of pre-/post-init and command tests which do not.
This separation makes it slightly harder to write a test, since there are two different test-state structures and different rules for running the two different test types. At present these rules are determined by where the test is (actually its prefix).
All unit tests can be run from the command line with the 'ut' command. Since SPL does not have commands, it currently calls the test runner directly and offers no control of which tests are run.
This seems like a good time to refactor the tests into a unified test runner, allowing U-Boot proper and SPL to use the same path, perhaps with some different conditions along the way.
This series sets up a unified runner called ut_run_list(), which runs a set of tests from a linker_list. Driver model tests are distinguished by a new UT_TESTF_DM flag so that the necessary init and cleanup can still be done.
The runner is modified to support running SPL tests that are not solely for driver model. An example test for FIT loading is added as a demonstration.
In addition, some documentation is added to explain how to write tests.
This series is available at u-boot-dm/test-working
Changes in v3:
- Add new patch to re-enable test_ofplatdata
- Reword the SPL tests section for clarity
- Use test_set_state() throughout test-main.c instead of direct assignment
- Update the pytest collector as well
Changes in v2:
- Use correct rst format for 'Ad-hoc tests' section
- Expand docs on how each type of test is marked
- Put the docs in tests_sandbox since it is more related to sandbox
- Put in a mention of tests_sandbox in the main testing docs
- Add a note that SPL tests can in fact be run individualy
- Document how to run all C tests with 'ut all'
- Fix 'get list' typo
- Fix conditions so non-DM SPL tests are actually run
- Allow for prefix to be NULL, to match function comment
- Add new patches to cover running an SPL test
Simon Glass (41):
doc: Tidy up testing section
doc: Document make tcheck
sandbox: Drop the 'starting...' message unless testing
test: Re-enable test_ofplatdata
doc: Explain how to run tests without pytest
doc: Document how sandbox_spl_tests are run
test: Correct setexpr test prefix
test: Mark all driver model tests with a flag
test: Rename test-main.c to test-dm.c
test: Add an overall test runner
test: Create pre/post-run functions
test: Call test_pre/post_run() from driver model tests
test: Move dm_extended_scan() to test_pre_run()
test: Move do_autoprobe() to test_pre_run()
test: Move dm_scan_plat() to test_pre_run()
test: Drop mallinfo() work-around
test: Move console silencing to test_pre_run()
test: Move delay skipping to test_pre_run()
test: Handle driver model reinit in test_pre_run()
test: Drop struct dm_test_state
test: Move dm_test_init() into test-main.c
test: Move dm_test_destroy() into test-main.c
test: Move test running into a separate function
test: Use ut_run_test() to run driver model tests
test: Drop dm_do_test()
test: Add ut_run_test_live_flat() to run tests twice
test: Use a local variable for test state
test: Run driver-model tests using ut_run_list()
test: Use return values in dm_test_run()
test: Move the devicetree check into ut_run_list()
test: Move restoring of driver model state to ut_run_list()
test: log: Rename log main test file to log_ut.c
test: Add a macros for finding tests in linker_lists
test: Rename all linker lists to have a ut_ prefix
test: Allow SPL to run any available test
sandbox: Update os_find_u_boot() to find the .img file
spl: Convert spl_fit to work with sandbox
doc: Move coccinelle into its own section
spl: test: Add a test for spl_load_simple_fit()
test: sandbox: Move sandbox test docs into doc/develop
doc: Explain briefly how to write new tests
arch/sandbox/cpu/os.c | 8 +-
arch/sandbox/cpu/spl.c | 9 +-
arch/sandbox/cpu/start.c | 15 +-
arch/sandbox/include/asm/state.h | 1 +
common/spl/spl.c | 3 +-
common/spl/spl_fit.c | 27 +-
configs/sandbox_spl_defconfig | 2 +-
doc/arch/sandbox.rst | 48 +---
doc/develop/index.rst | 11 +-
doc/develop/py_testing.rst | 3 +-
doc/develop/testing.rst | 46 +++-
doc/develop/tests_sandbox.rst | 207 ++++++++++++++
doc/develop/tests_writing.rst | 337 +++++++++++++++++++++++
include/dm/test.h | 20 +-
include/os.h | 3 +-
include/spl.h | 9 +
include/test/test.h | 38 ++-
include/test/ut.h | 45 +++
test/Makefile | 3 +
test/bloblist.c | 5 +-
test/bootm.c | 4 +-
test/cmd/mem.c | 4 +-
test/cmd/setexpr.c | 28 +-
test/cmd_ut.c | 38 +--
test/compression.c | 5 +-
test/dm/Makefile | 2 +-
test/dm/core.c | 47 ++--
test/dm/test-dm.c | 50 ++++
test/dm/test-driver.c | 12 +-
test/dm/test-main.c | 229 ----------------
test/dm/test-uclass.c | 10 +-
test/env/cmd_ut_env.c | 4 +-
test/image/Makefile | 5 +
test/image/spl_load.c | 91 ++++++
test/lib/cmd_ut_lib.c | 4 +-
test/log/Makefile | 2 +-
test/log/{test-main.c => log_ut.c} | 4 +-
test/optee/cmd_ut_optee.c | 5 +-
test/overlay/cmd_ut_overlay.c | 5 +-
test/py/conftest.py | 2 +-
test/py/tests/test_log.py | 2 +-
test/py/tests/test_ofplatdata.py | 2 +-
test/str_ut.c | 5 +-
test/test-main.c | 426 +++++++++++++++++++++++++++++
test/unicode_ut.c | 4 +-
test/ut.c | 7 +
46 files changed, 1400 insertions(+), 437 deletions(-)
create mode 100644 doc/develop/tests_sandbox.rst
create mode 100644 doc/develop/tests_writing.rst
create mode 100644 test/dm/test-dm.c
delete mode 100644 test/dm/test-main.c
create mode 100644 test/image/Makefile
create mode 100644 test/image/spl_load.c
rename test/log/{test-main.c => log_ut.c} (75%)
create mode 100644 test/test-main.cSignature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 1/41 doc: Tidy up testing section
Tweak this so the output looks a little better.
---
(no changes since v2)
Changes in v2:
- Use correct rst format for 'Ad-hoc tests' section
doc/develop/testing.rst | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
doc/develop/testing.rst +12 -8
@@ -8,14 +8,14 @@ tested and what tests you should write when adding a new feature. Running tests ------------- -To run most tests on sandbox, type this: +To run most tests on sandbox, type this:: make check in the U-Boot directory. Note that only the pytest suite is run using this command. -Some tests take ages to run. To run just the quick ones, type this: +Some tests take ages to run. To run just the quick ones, type this:: make qcheck
@@ -35,9 +35,9 @@ either on sandbox or on real hardware. It relies on the U-Boot console to inject test commands and check the result. It is slower to run than C code, but provides the ability to unify lots of tests and summarise their results. -You can run the tests on sandbox with: +You can run the tests on sandbox with:: - ./test/py/test.py --bd sandbox --build + ./test/py/test.py --bd sandbox --build This will produce HTML output in build-sandbox/test-log.html
@@ -58,10 +58,14 @@ Ad-hoc tests There are several ad-hoc tests which run outside the pytest environment: - test/fs - File system test (shell script) - test/image - FIT and legacy image tests (shell script and Python) - test/stdint - A test that stdint.h can be used in U-Boot (shell script) - trace - Test for the tracing feature (shell script) +test/fs + File system test (shell script) +test/image + FIT and legacy image tests (shell script and Python) +test/stdint + A test that stdint.h can be used in U-Boot (shell script) +trace + Test for the tracing feature (shell script) TODO: Move these into pytest.
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 2/41 doc: Document make tcheck
In reply to Simon GlassAdd a comment about this option in the documentation. Also mention the script that runs these combinations.
---
(no changes since v2)
Changes in v2:
- Expand docs on how each type of test is marked
doc/develop/testing.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
doc/develop/testing.rst +11 -1
@@ -15,10 +15,20 @@ To run most tests on sandbox, type this:: in the U-Boot directory. Note that only the pytest suite is run using this command. -Some tests take ages to run. To run just the quick ones, type this:: +Some tests take ages to run and are marked with @pytest.mark.slow. To run just +the quick ones, type this:: make qcheck +It is also possible to run just the tests for tools (patman, binman, etc.). +Such tests are included with those tools, i.e. no actual U-Boot unit tests are +run. Type this:: + + make tcheck + +All of the above use the test/run script with a paremeter to select which tests +are run. + Sandbox -------
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 3/41 sandbox: Drop the 'starting...' message unless testing
In reply to Simon GlassThis message is annoying since it is only useful for testing. Add a flag to control whether it is emitted or not, so it can be supressed by default.
---
(no changes since v1)
arch/sandbox/cpu/start.c | 15 +++++++++++++-- arch/sandbox/include/asm/state.h | 1 + test/py/tests/test_log.py | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-)
arch/sandbox/cpu/start.c +13 -2
@@ -388,6 +388,15 @@ static int sandbox_cmdline_cb_select_unittests(struct sandbox_state *state, }SANDBOX_CMDLINE_OPT_SHORT (select_unittests,'k' ,1 ,"Select unit tests to run" ); +static int sandbox_cmdline_cb_log_test (struct sandbox_state *state, +const char *arg) +{ + state->log_test = true; + +return 0 ; +} +SANDBOX_CMDLINE_OPT (log_test,0 ,"Show logging info on startup (for testing)" ); +static void setup_ram_buf (struct sandbox_state *state) {/* Zero the RAM buffer if we didn't read it, to keep valgrind happy */
@@ -488,8 +497,10 @@ int main(int argc, char *argv[]) gd->reloc_off = (ulong )gd->arch.text_base;/* sandbox test: log functions called before log_init in board_init_f */ -log_info ("sandbox: starting...\n" ); -log_debug ("debug: %s\n" , __func__); +if (state->log_test) { +log_info ("sandbox: starting...\n" ); +log_debug ("debug: %s\n" , __func__); + }/* Do pre- and post-relocation init */ board_init_f (0 );
arch/sandbox/include/asm/state.h +1 -0
@@ -105,6 +105,7 @@ struct sandbox_state {struct list_head mapmem_head;/* struct sandbox_mapmem_entry */ bool hwspinlock;/* Hardware Spinlock status */ bool allow_memio;/* Allow readl() etc. to work */ +bool log_test;/* Output some log info for testing */ /* * This struct is getting large.
test/py/tests/test_log.py +1 -1
@@ -43,7 +43,7 @@ def test_log_dropped(u_boot_console): """Test dropped 'log' message when debug_uart is activated""" cons = u_boot_console - cons.restart_uboot() + cons.restart_uboot_with_flags(['--log_test']) output = cons.get_spawn_output().replace('\r', '') assert 'sandbox: starting...' in output assert (not 'debug: main' in output)
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 4/41 test: Re-enable test_ofplatdata
In reply to Simon GlassThis was inadvertently disabled after a recent change. Re-enable it.
---
Changes in v3:
- Add new patch to re-enable test_ofplatdata
test/py/tests/test_ofplatdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
test/py/tests/test_ofplatdata.py +1 -1
@@ -4,7 +4,7 @@ import pytest import u_boot_utils as util - at pytest.mark.boardspec('sandbox') + at pytest.mark.boardspec('sandbox_spl') @pytest.mark.buildconfigspec('spl_of_platdata') def test_spl_devicetree(u_boot_console): """Test content of spl device-tree"""
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 5/41 doc: Explain how to run tests without pytest
In reply to Simon GlassAdd details about how to run a sandbox test directly, without using pytest. This is more convenient for rapid development, since it is faster and allows easier use of a debugger. Also mention sandbox_flattree as an example of the different sandbox builds available.
---
(no changes since v2)
Changes in v2:
- Put the docs in tests_sandbox since it is more related to sandbox
- Put in a mention of tests_sandbox in the main testing docs
doc/develop/index.rst | 1 + doc/develop/testing.rst | 9 ++++ doc/develop/tests_sandbox.rst | 79 +++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 doc/develop/tests_sandbox.rst
doc/develop/index.rst +1 -0
@@ -32,3 +32,4 @@ Testing coccinelle testing py_testing + tests_sandbox
doc/develop/testing.rst +9 -0
@@ -36,6 +36,7 @@ U-Boot can be built as a user-space application (e.g. for Linux). This allows test to be executed without needing target hardware. The 'sandbox' target provides this feature and it is widely used in tests. +See :doc:`tests_sandbox` for more information. Pytest Suite ------------
@@ -51,8 +52,16 @@ You can run the tests on sandbox with:: This will produce HTML output in build-sandbox/test-log.html +Some tests run with other versions of sandbox. For example sandbox_flattree +runs the tests with livetree (the hierachical devicetree) disabled. You can +also select particular tests with -k:: + + ./test/py/test.py --bd sandbox_flattree --build -k hello + See test/py/README.md for more information about the pytest suite. +See :doc:`tests_sandbox` for how to run tests directly (not through pytest). + tbot ----
doc/develop/tests_sandbox.rst new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 6/41 doc: Document how sandbox_spl_tests are run
In reply to Simon GlassAdd a few notes about the sandbox_spl tests, since they are special.
---
Changes in v3:
- Reword the SPL tests section for clarity
Changes in v2:
- Add a note that SPL tests can in fact be run individualy
- Document how to run all C tests with 'ut all'
- Fix 'get list' typo
doc/develop/testing.rst | 5 +++ doc/develop/tests_sandbox.rst | 81 +++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)
doc/develop/testing.rst +5 -0
@@ -58,6 +58,11 @@ also select particular tests with -k:: ./test/py/test.py --bd sandbox_flattree --build -k hello +There are some special tests that run in SPL. For this you need the sandbox_spl +build:: + + ./test/py/test.py --bd sandbox_spl --build -k test_spl + See test/py/README.md for more information about the pytest suite. See :doc:`tests_sandbox` for how to run tests directly (not through pytest).
doc/develop/tests_sandbox.rst +81 -0
84 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 6/41 doc: Document how sandbox_spl_tests are run
Quoted 63 lines · Simon Glass
Add a few notes about the
sandbox_spltests, since they are special.Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Reword the SPL tests section for clarityChanges in v2:
- Add a note that SPL tests can in fact be run individualy
- Document how to run all C tests with 'ut all'
- Fix 'get list' typodoc/develop/testing.rst | 5 +++ doc/develop/tests_sandbox.rst | 81 +++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)doc/develop/testing.rst +5
-0@@ -58,6 +58,11 @@ also select particular tests with -k:: ./test/py/test.py --bd sandbox_flattree --build -k hello +There are some special tests that run in SPL. For this you need the sandbox_spl +build:: + + ./test/py/test.py --bd sandbox_spl --build -k test_spl + See test/py/README.md for more information about the pytest suite. See :doc:`tests_sandbox` for how to run tests directly (not through pytest).doc/develop/tests_sandbox.rst +22
-0@@ -77,3 +77,84 @@ You can easily use gdb on these tests, without needing --gdbserver:: You can then single-step and look at variables as needed. + +Running sandbox_spl tests directly +---------------------------------- + +SPL is the phase before U-Boot proper. It is present in the sandbox_spl build, +so you can run SPL like this:: + + ./spl/u-boot-spl + +SPL tests are special in that they run (only in the SPL phase, of course) if the +-u flag is given:: + + ./spl/u-boot-spl -u + + U-Boot SPL 2021.01-00723-g43c77b51be5-dirty (Jan 24 2021 - 16:38:24 -0700) + Running 5 driver model tests + Test: dm_test_of_plat_base: of_platdata.c (flat tree) + Test: dm_test_of_plat_dev: of_platdata.c (flat tree) + Test: dm_test_of_plat_parent: of_platdata.c (flat tree) + Test: dm_test_of_plat_phandle: of_platdata.c (flat tree) + Test: dm_test_of_plat_props: of_platdata.c (flat tree) + Failures: 0
doc/develop/tests_sandbox.rst You can easily use gdb on these tests, without needing --gdbserver:: · line 111
Quoted 10 lines
doc/develop/tests_sandbox.rst +10
-0+ + + U-Boot 2021.01-00723-g43c77b51be5-dirty (Jan 24 2021 - 16:38:24 -0700) + + DRAM: 128 MiB + ... + +It is not possible to run SPL tests in U-Boot proper, firstly because they are +not built into U-Boot proper and secondly because the environment is very +different, e.g. some SPL tests rely on of-pldata which is only available in SPL.
s/of-pldata/of-platdata/
Other than this,
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
PATCH v3 7/41 test: Correct setexpr test prefix
In reply to Simon GlassThis prefix should be for setexpr, not mem. This means that trying to select just these tests to run does not work. Fix it.
For some reason this provokes an assertion failure due to memory not being freed. Move the env_set() in setexpr_test_str() to before the malloc() heap size size is recorded and disable the rest in setexpr_test_str_oper().
---
(no changes since v1)
test/cmd/setexpr.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
test/cmd/setexpr.c +19 -4
@@ -306,8 +306,8 @@ static int setexpr_test_str(struct unit_test_state *uts)ut_asserteq (1 ,run_command ("setexpr.s fred 0" ,0 ));ut_assertok (ut_check_delta (start_mem)); - start_mem =ut_check_free ();ut_assertok (env_set ("fred" ,"12345" )); + start_mem =ut_check_free ();ut_assertok (run_command ("setexpr.s fred *0" ,0 ));ut_asserteq_str ("hello" ,env_get ("fred" ));ut_assertok (ut_check_delta (start_mem));
@@ -345,7 +345,22 @@ static int setexpr_test_str_oper(struct unit_test_state *uts) start_mem =ut_check_free ();ut_assertok (run_command ("setexpr.s fred *0 + *10" ,0 ));ut_asserteq_str ("hello there" ,env_get ("fred" )); -ut_assertok (ut_check_delta (start_mem)); + +/* +* This check does not work with sandbox_flattree, apparently due to +* memory allocations in env_set(). +* +* The truetype console produces lots of memory allocations even though +* the LCD display is not visible. But even without these, it does not +* work. +* +* A better test would be for dlmalloc to record the allocs and frees +* for a particular caller, but that is not supported. +* +* For now, drop this test. +* +* ut_assertok(ut_check_delta(start_mem)); +*/ unmap_sysmem (buf);
@@ -379,6 +394,6 @@ int do_ut_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) setexpr_test); const int n_ents = ll_entry_count(struct unit_test, setexpr_test); -return cmd_ut_category ("cmd_setexpr" ,"cmd_mem_" , tests, n_ents, argc, - argv); +return cmd_ut_category ("cmd_setexpr" ,"setexpr_test_" , tests, n_ents, + argc, argv); }
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 8/41 test: Mark all driver model tests with a flag
In reply to Simon GlassAdd a flag for driver model tests, so we can do special processing for them.
---
(no changes since v1)
include/dm/test.h | 3 ++- include/test/test.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)
include/dm/test.h +2 -1
@@ -143,7 +143,8 @@ struct dm_test_state { };/* Declare a new driver model test */ -#define DM_TEST (_name, _flags) UNIT_TEST(_name, _flags, dm_test) +#define DM_TEST (_name, _flags) \ + UNIT_TEST(_name, UT_TESTF_DM | (_flags), dm_test)/* * struct sandbox_sdl_plat - Platform data for the SDL video driver
include/test/test.h +2 -0
@@ -36,6 +36,8 @@ enum {UT_TESTF_FLAT_TREE =BIT (3 ),/* test needs flat DT */ UT_TESTF_LIVE_TREE =BIT (4 ),/* needs live device tree */ UT_TESTF_CONSOLE_REC =BIT (5 ),/* needs console recording */ +/* do extra driver model init and uninit */ + UT_TESTF_DM = BIT(6), };/**
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 9/41 test: Rename test-main.c to test-dm.c
In reply to Simon GlassThis is the main test function for driver model but not for other tests. Rename the file and the function so this is clear.
---
(no changes since v1)
arch/sandbox/cpu/spl.c | 2 +-
include/test/test.h | 4 ++--
test/dm/Makefile | 2 +-
test/dm/{test-main.c => test-dm.c} | 4 ++--
4 files changed, 6 insertions(+), 6 deletions(-)
rename test/dm/{test-main.c => test-dm.c} (98%)arch/sandbox/cpu/spl.c +1 -1
@@ -60,7 +60,7 @@ void spl_board_init(void)if (state->run_unittests) {int ret; - ret =dm_test_main (state->select_unittests); + ret =dm_test_run (state->select_unittests);/* continue execution into U-Boot */ } }
include/test/test.h +2 -2
@@ -106,7 +106,7 @@ enum {struct udevice *testbus_get_clear_removed (void );/** -* dm_test_main() - Run driver model tests +* dm_test_run() - Run driver model tests * * Run all the available driver model tests, or a selection *
@@ -114,6 +114,6 @@ struct udevice *testbus_get_clear_removed(void);* "fdt_pre_reloc"), or NULL to run all * @return 0 if all tests passed, 1 if not */ -int dm_test_main (const char *test_name); +int dm_test_run (const char *test_name);#endif /* __TEST_TEST_H */
test/dm/Makefile +1 -1
@@ -2,7 +2,7 @@ # # Copyright (c) 2013 Google, Inc -obj-$(CONFIG_UT_DM) += test-main.o +obj-$(CONFIG_UT_DM) += test-dm.o # Tests for particular subsystems - when enabling driver model for a new # subsystem you must add sandbox tests here.
test/dm/test-dm.c renamed from test/dm/test-main.c +2 -2
@@ -145,7 +145,7 @@ static bool test_matches(const char *test_name, const char *find_name)return false; } -int dm_test_main (const char *test_name) +int dm_test_run (const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test);
@@ -225,5 +225,5 @@ int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])if (argc >1 ) test_name = argv[1 ]; -return dm_test_main (test_name); +return dm_test_run (test_name); }
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 10/41 test: Add an overall test runner
In reply to Simon GlassAdd a new test runner that will eventually be able to run any test. For now, have it run the 'command' unit tests, so that the functionality in cmd_ut_category() moves into it.
---
(no changes since v1)
include/test/ut.h | 42 ++++++++++++++++++++++++++++++ test/Makefile | 2 ++ test/cmd_ut.c | 38 ++++----------------------- test/test-main.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 33 deletions(-) create mode 100644 test/test-main.c
include/test/ut.h +42 -0
@@ -356,4 +356,46 @@ void ut_silence_console(struct unit_test_state *uts);*/ void ut_unsilence_console (struct unit_test_state *uts); +/** +* ut_run_tests() - Run a set of tests +* +* This runs the tests, handling any preparation and clean-up needed. It prints +* the name of each test before running it. +* +* @uts: Test state to update. The caller should ensure that this is zeroed for +* the first call to this function. On exit, @uts->fail_count is +* incremented by the number of failures (0, one hopes) +* @prefix: String prefix for the tests. Any tests that have this prefix will be +* printed without the prefix, so that it is easier to see the unique part +* of the test name. If NULL, no prefix processing is done +* @tests: List of tests to run +* @count: Number of tests to run +* @select_name: Name of a single test to run (from the list provided). If NULL +* then all tests are run +* @return 0 if all tests passed, -ENOENT if test @select_name was not found, +* -EBADF if any failed +*/ +int ut_run_tests (struct unit_test_state *uts,const char *prefix, +struct unit_test *tests,int count,const char *select_name); + +/** +* ut_run_tests() - Run a set of tests +* +* This runs the test, handling any preparation and clean-up needed. It prints +* the name of each test before running it. +* +* @category: Category of these tests. This is a string printed at the start to +* announce the the number of tests +* @prefix: String prefix for the tests. Any tests that have this prefix will be +* printed without the prefix, so that it is easier to see the unique part +* of the test name. If NULL, no prefix processing is done +* @tests: List of tests to run +* @count: Number of tests to run +* @select_name: Name of a single test to run (from the list provided). If NULL +* then all tests are run +* @return 0 if all tests passed, -1 if any failed +*/ +int ut_run_list (const char *name,const char *prefix,struct unit_test *tests, +int count,const char *select_name); +#endif
test/Makefile +2 -0
@@ -2,6 +2,8 @@ # # (C) Copyright 2012 The Chromium Authors +obj-y += test-main.o + ifneq ($(CONFIG_$(SPL_)BLOBLIST),) obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o obj-$(CONFIG_$(SPL_)CMDLINE) += bootm.o
test/cmd_ut.c +5 -33
@@ -9,6 +9,7 @@#include <console.h> #include <test/suites.h> #include <test/test.h> +#include <test/ut.h> static int do_ut_all (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]);
@@ -17,41 +18,12 @@ int cmd_ut_category(const char *name, const char *prefix, struct unit_test *tests, int n_ents, int argc, char *const argv[]) { - struct unit_test_state uts = { .fail_count = 0 }; -struct unit_test *test; -int prefix_len = prefix ?strlen (prefix) :0 ; + int ret; -if (argc ==1 ) -printf ("Running %d %s tests\n" , n_ents, name); + ret =ut_run_list (name, prefix, tests, n_ents, + argc >1 ? argv[1 ] :NULL ); -for (test = tests; test < tests + n_ents; test++) { -const char *test_name = test->name; - -/* Remove the prefix */ -if (prefix && !strncmp (test_name, prefix, prefix_len)) - test_name += prefix_len; - -if (argc >1 &&strcmp (argv[1 ], test_name)) -continue ; -printf ("Test: %s\n" , test->name); - -if (test->flags &UT_TESTF_CONSOLE_REC ) { -int ret =console_record_reset_enable (); - -if (ret) { -printf ("Skipping: Console recording disabled\n" ); -continue ; - } - } - - uts.start =mallinfo (); - - test->func (&uts); - } - -printf ("Failures: %d\n" , uts.fail_count); - -return uts.fail_count ?CMD_RET_FAILURE :0 ; +return ret ?CMD_RET_FAILURE :0 ; } static struct cmd_tbl cmd_ut_sub[] = {
test/test-main.c new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 11/41 test: Create pre/post-run functions
In reply to Simon GlassSplit out the test preparation into a separation function before expanding it. Add a post-run function as well, currently empty.
---
(no changes since v1)
include/test/ut.h | 20 ++++++++++++++++++++ test/test-main.c | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 10 deletions(-)
include/test/ut.h +20 -0
@@ -356,6 +356,26 @@ void ut_silence_console(struct unit_test_state *uts);*/ void ut_unsilence_console (struct unit_test_state *uts); +/** +* test_pre_run() - Handle any preparation needed to run a test +* +* @uts: Test state +* @test: Test to prepare for +* @return 0 if OK, -EAGAIN to skip this test since some required feature is not +* available, other -ve on error (meaning that testing cannot likely +* continue) +*/ +int test_pre_run (struct unit_test_state *uts,struct unit_test *test); + +/** +* test_post_run() - Handle cleaning up after a test +* +* @uts: Test state +* @test: Test to clean up after +* @return 0 if OK, -ve on error (meaning that testing cannot likely continue) +*/ +int test_post_run (struct unit_test_state *uts,struct unit_test *test); +/** * ut_run_tests() - Run a set of tests *
test/test-main.c +31 -10
61 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 12/41 test: Call test_pre/post_run() from driver model tests
In reply to Simon GlassUltimately we want to get rid of the special driver model test init and use test_pre_run() and test_post_run() for all tests. As a first step, use those function to handle console recording.
For now we need a special case for setting uts->start, but that wil go away once all init is in one place.
---
(no changes since v1)
include/dm/test.h | 2 +- test/dm/test-dm.c | 10 +++++----- test/test-main.c | 8 +++++++- 3 files changed, 13 insertions(+), 7 deletions(-)
include/dm/test.h +1 -1
@@ -144,7 +144,7 @@ struct dm_test_state {/* Declare a new driver model test */ #define DM_TEST (_name, _flags) \ - UNIT_TEST(_name, UT_TESTF_DM | (_flags), dm_test) + UNIT_TEST(_name, UT_TESTF_DM | UT_TESTF_CONSOLE_REC | (_flags), dm_test)/* * struct sandbox_sdl_plat - Platform data for the SDL video driver
test/dm/test-dm.c +5 -5
@@ -96,14 +96,14 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test, (test->flags & UT_TESTF_SCAN_FDT))ut_assertok (dm_extended_scan (false)); -/* -* Silence the console and rely on console recording to get -* our output. -*/ -console_record_reset_enable (); +ut_assertok (test_pre_run (uts, test)); +if (!state->show_test_output) gd->flags |=GD_FLG_SILENT ; test->func (uts); + +ut_assertok (test_post_run (uts, test)); + gd->flags &= ~(GD_FLG_SILENT |GD_FLG_RECORD );state_set_skip_delays (false);
test/test-main.c +7 -1
@@ -8,9 +8,13 @@#include <console.h> #include <test/test.h> +DECLARE_GLOBAL_DATA_PTR ; +int test_pre_run (struct unit_test_state *uts,struct unit_test *test) { - uts->start =mallinfo (); +/* DM tests have already done this */ +if (!(test->flags &UT_TESTF_DM )) + uts->start =mallinfo ();if (test->flags &UT_TESTF_CONSOLE_REC ) {int ret =console_record_reset_enable ();
@@ -26,6 +30,8 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test)int test_post_run (struct unit_test_state *uts,struct unit_test *test) { + gd->flags &= ~GD_FLG_RECORD ; +return 0 ; }
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 13/41 test: Move dm_extended_scan() to test_pre_run()
In reply to Simon GlassMove this step over to the pre-run function.
---
(no changes since v1)
test/dm/test-dm.c | 3 --- test/test-main.c | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-)
test/dm/test-dm.c +0 -3
@@ -92,9 +92,6 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,ut_assertok (dm_scan_plat (false));if (test->flags &UT_TESTF_PROBE_TEST )ut_assertok (do_autoprobe (uts)); -if (!CONFIG_IS_ENABLED (OF_PLATDATA ) && - (test->flags &UT_TESTF_SCAN_FDT )) -ut_assertok (dm_extended_scan (false));ut_assertok (test_pre_run (uts, test));
test/test-main.c +7 -0
@@ -6,7 +6,10 @@#include <common.h> #include <console.h> +#include <dm.h> +#include <dm/root.h> #include <test/test.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -16,6 +19,10 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test)if (!(test->flags &UT_TESTF_DM )) uts->start =mallinfo (); +if (!CONFIG_IS_ENABLED (OF_PLATDATA ) && + (test->flags &UT_TESTF_SCAN_FDT )) +ut_assertok (dm_extended_scan (false)); +if (test->flags &UT_TESTF_CONSOLE_REC ) {int ret =console_record_reset_enable ();
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 14/41 test: Move do_autoprobe() to test_pre_run()
In reply to Simon GlassMove this step over to the pre-run function.
---
(no changes since v1)
test/dm/test-dm.c | 17 ----------------- test/test-main.c | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 17 deletions(-)
test/dm/test-dm.c +0 -17
@@ -42,21 +42,6 @@ static int dm_test_init(struct unit_test_state *uts, bool of_live)return 0 ; } -/* Ensure all the test devices are probed */ -static int do_autoprobe (struct unit_test_state *uts) -{ -struct udevice *dev; -int ret; - -/* Scanning the uclass is enough to probe all the devices */ -for (ret =uclass_first_device (UCLASS_TEST , &dev); - dev; - ret =uclass_next_device (&dev)) - ; - -return ret; -} -static int dm_test_destroy (struct unit_test_state *uts) {int id;
@@ -90,8 +75,6 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test, uts->start =mallinfo ();if (test->flags &UT_TESTF_SCAN_PDATA )ut_assertok (dm_scan_plat (false)); -if (test->flags &UT_TESTF_PROBE_TEST ) -ut_assertok (do_autoprobe (uts));ut_assertok (test_pre_run (uts, test));
test/test-main.c +18 -0
@@ -13,12 +13,30 @@DECLARE_GLOBAL_DATA_PTR ; +/* Ensure all the test devices are probed */ +static int do_autoprobe (struct unit_test_state *uts) +{ +struct udevice *dev; +int ret; + +/* Scanning the uclass is enough to probe all the devices */ +for (ret =uclass_first_device (UCLASS_TEST , &dev); + dev; + ret =uclass_next_device (&dev)) + ; + +return ret; +} +int test_pre_run (struct unit_test_state *uts,struct unit_test *test) {/* DM tests have already done this */ if (!(test->flags &UT_TESTF_DM )) uts->start =mallinfo (); +if (test->flags &UT_TESTF_PROBE_TEST ) +ut_assertok (do_autoprobe (uts)); +if (!CONFIG_IS_ENABLED (OF_PLATDATA ) && (test->flags &UT_TESTF_SCAN_FDT ))ut_assertok (dm_extended_scan (false));
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 15/41 test: Move dm_scan_plat() to test_pre_run()
In reply to Simon GlassMove this step over to the pre-run function.
---
(no changes since v1)
test/dm/test-dm.c | 2 -- test/test-main.c | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
test/dm/test-dm.c +0 -2
@@ -73,8 +73,6 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,ut_assertok (dm_test_init (uts, of_live)); uts->start =mallinfo (); -if (test->flags &UT_TESTF_SCAN_PDATA ) -ut_assertok (dm_scan_plat (false));ut_assertok (test_pre_run (uts, test));
test/test-main.c +3 -0
@@ -34,6 +34,9 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test)if (!(test->flags &UT_TESTF_DM )) uts->start =mallinfo (); +if (test->flags &UT_TESTF_SCAN_PDATA ) +ut_assertok (dm_scan_plat (false)); +if (test->flags &UT_TESTF_PROBE_TEST )ut_assertok (do_autoprobe (uts));
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 16/41 test: Drop mallinfo() work-around
In reply to Simon GlassThis is not needed now. Drop it.
---
(no changes since v1)
test/dm/test-dm.c | 2 -- test/test-main.c | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-)
test/dm/test-dm.c +0 -2
@@ -72,8 +72,6 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test, !of_live ? " (flat tree)" : "");ut_assertok (dm_test_init (uts, of_live)); - uts->start =mallinfo (); -ut_assertok (test_pre_run (uts, test));if (!state->show_test_output)
test/test-main.c +1 -3
@@ -30,9 +30,7 @@ static int do_autoprobe(struct unit_test_state *uts)int test_pre_run (struct unit_test_state *uts,struct unit_test *test) { -/* DM tests have already done this */ -if (!(test->flags &UT_TESTF_DM )) - uts->start =mallinfo (); + uts->start =mallinfo ();if (test->flags &UT_TESTF_SCAN_PDATA )ut_assertok (dm_scan_plat (false));
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 17/41 test: Move console silencing to test_pre_run()
In reply to Simon GlassWe already have a function for silencing the console during tests. Use this from test_pre_run() and drop this code from the driver model tests.
---
(no changes since v1)
test/dm/test-dm.c | 4 ---- test/test-main.c | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-)
test/dm/test-dm.c +0 -4
@@ -65,7 +65,6 @@ static int dm_test_destroy(struct unit_test_state *uts)static int dm_do_test (struct unit_test_state *uts,struct unit_test *test,bool of_live) { -struct sandbox_state *state =state_get_current ();const char *fname =strrchr (test->file,'/' ) +1 ; printf("Test: %s: %s%s\n", test->name, fname,
@@ -74,13 +73,10 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,ut_assertok (test_pre_run (uts, test)); -if (!state->show_test_output) - gd->flags |=GD_FLG_SILENT ; test->func (uts);ut_assertok (test_post_run (uts, test)); - gd->flags &= ~(GD_FLG_SILENT |GD_FLG_RECORD );state_set_skip_delays (false);ut_assertok (dm_test_destroy (uts));
test/test-main.c +2 -1
@@ -50,13 +50,14 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test)return -EAGAIN ; } } +ut_silence_console (uts);return 0 ; }int test_post_run (struct unit_test_state *uts,struct unit_test *test) { - gd->flags &= ~GD_FLG_RECORD ; +ut_unsilence_console (uts);return 0 ; }
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 18/41 test: Move delay skipping to test_pre_run()
In reply to Simon GlassThis allows delays to be skipped in sandbox tests. Move it to the common pre-init function.
---
(no changes since v1)
include/test/ut.h | 11 +++++++++++ test/dm/test-dm.c | 2 -- test/test-main.c | 2 ++ test/ut.c | 7 +++++++ 4 files changed, 20 insertions(+), 2 deletions(-)
include/test/ut.h +11 -0
@@ -356,6 +356,17 @@ void ut_silence_console(struct unit_test_state *uts);*/ void ut_unsilence_console (struct unit_test_state *uts); +/** +* ut_set_skip_delays() - Sets whether delays should be skipped +* +* Normally functions like mdelay() cause U-Boot to wait for a while. This +* allows all such delays to be skipped on sandbox, to speed up tests +* +* @uts: Test state (in case in future we want to keep state here) +* @skip_delays: true to skip delays, false to process them normally +*/ +void ut_set_skip_delays (struct unit_test_state *uts,bool skip_delays); +/** * test_pre_run() - Handle any preparation needed to run a test *
test/dm/test-dm.c +0 -2
@@ -77,8 +77,6 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,ut_assertok (test_post_run (uts, test)); -state_set_skip_delays (false); -ut_assertok (dm_test_destroy (uts));return 0 ;
test/test-main.c +2 -0
@@ -30,6 +30,8 @@ static int do_autoprobe(struct unit_test_state *uts)int test_pre_run (struct unit_test_state *uts,struct unit_test *test) { +ut_set_skip_delays (uts, false); + uts->start =mallinfo ();if (test->flags &UT_TESTF_SCAN_PDATA )
test/ut.c +7 -0
@@ -132,3 +132,10 @@ void ut_unsilence_console(struct unit_test_state *uts) { gd->flags &= ~(GD_FLG_SILENT |GD_FLG_RECORD ); } + +void ut_set_skip_delays (struct unit_test_state *uts,bool skip_delays) +{ +#ifdef CONFIG_SANDBOX +state_set_skip_delays (skip_delays); +#endif +}
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 19/41 test: Handle driver model reinit in test_pre_run()
In reply to Simon GlassFor driver model tests we want to reinit the data structures so that everything is in a known state before the test runs. This avoids one test changing something that breaks a subsequent tests.
Move the call for this into test_pre_run().
---
(no changes since v1)
include/test/test.h | 2 ++ include/test/ut.h | 10 ++++++++++ test/dm/test-dm.c | 6 +++--- test/test-main.c | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-)
include/test/test.h +2 -0
@@ -15,6 +15,7 @@* @fail_count: Number of tests that failed * @start: Store the starting mallinfo when doing leak test * @priv: A pointer to some other info some suites want to track +* @of_live: true to use livetree if available, false to use flattree * @of_root: Record of the livetree root node (used for setting up tests) * @expect_str: Temporary string used to hold expected string value * @actual_str: Temporary string used to hold actual string value
@@ -24,6 +25,7 @@ struct unit_test_state {struct mallinfo start;void *priv;struct device_node *of_root; +bool of_live;char expect_str[256 ];char actual_str[256 ]; };
include/test/ut.h +10 -0
@@ -387,6 +387,16 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test);*/ int test_post_run (struct unit_test_state *uts,struct unit_test *test); +/** +* dm_test_init() - Get ready to run a driver model test +* +* This clears out the driver model data structures. For sandbox it resets the +* state structure. +* +* @uts: Test state +*/ +int dm_test_init (struct unit_test_state *uts); +/** * ut_run_tests() - Run a set of tests *
test/dm/test-dm.c +3 -3
@@ -23,10 +23,10 @@ DECLARE_GLOBAL_DATA_PTR;struct unit_test_state global_dm_test_state;static struct dm_test_state _global_priv_dm_test_state; -/* Get ready for testing */ -static int dm_test_init (struct unit_test_state *uts,bool of_live) +int dm_test_init (struct unit_test_state *uts) {struct dm_test_state *dms = uts->priv; +bool of_live = uts->of_live;memset (dms,'\0' ,sizeof (*dms)); gd->dm_root =NULL ;
@@ -69,7 +69,7 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,printf ("Test: %s: %s%s\n" , test->name, fname, !of_live ?" (flat tree)" :"" ); -ut_assertok (dm_test_init (uts, of_live)); + uts->of_live = of_live;ut_assertok (test_pre_run (uts, test));
test/test-main.c +3 -0
@@ -30,6 +30,9 @@ static int do_autoprobe(struct unit_test_state *uts)int test_pre_run (struct unit_test_state *uts,struct unit_test *test) { +if (test->flags &UT_TESTF_DM ) +ut_assertok (dm_test_init (uts)); +ut_set_skip_delays (uts, false); uts->start =mallinfo ();
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 20/41 test: Drop struct dm_test_state
In reply to Simon GlassDriver model is a core part of U-Boot. We don't really need to have a separate test structure for the driver model tests and it makes it harder to write a test if you have to think about which type of test it is.
Subsume the fields from struct dm_test_state into struct unit_test_state and delete the former.
---
(no changes since v1)
include/dm/test.h | 17 ---------------- include/test/test.h | 10 +++++++-- test/dm/core.c | 47 +++++++++++++++++-------------------------- test/dm/test-dm.c | 10 ++++----- test/dm/test-driver.c | 4 +--- test/dm/test-uclass.c | 3 +-- 6 files changed, 34 insertions(+), 57 deletions(-)
include/dm/test.h +0 -17
@@ -125,23 +125,6 @@ extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];extern struct unit_test_state global_dm_test_state; -/* -* struct dm_test_state - Entire state of dm test system -* -* This is often abreviated to dms. -* -* @root: Root device -* @testdev: Test device -* @force_fail_alloc: Force all memory allocs to fail -* @skip_post_probe: Skip uclass post-probe processing -*/ -struct dm_test_state { -struct udevice *root; -struct udevice *testdev; -int force_fail_alloc; -int skip_post_probe; -}; -/* Declare a new driver model test */ #define DM_TEST (_name, _flags) \ UNIT_TEST(_name, UT_TESTF_DM | UT_TESTF_CONSOLE_REC | (_flags), dm_test)
include/test/test.h +8 -2
@@ -14,18 +14,24 @@* * @fail_count: Number of tests that failed * @start: Store the starting mallinfo when doing leak test -* @priv: A pointer to some other info some suites want to track * @of_live: true to use livetree if available, false to use flattree * @of_root: Record of the livetree root node (used for setting up tests) +* @root: Root device +* @testdev: Test device +* @force_fail_alloc: Force all memory allocs to fail +* @skip_post_probe: Skip uclass post-probe processing * @expect_str: Temporary string used to hold expected string value * @actual_str: Temporary string used to hold actual string value */ struct unit_test_state {int fail_count;struct mallinfo start; -void *priv;struct device_node *of_root;bool of_live; +struct udevice *root; +struct udevice *testdev; +int force_fail_alloc; +int skip_post_probe;char expect_str[256 ];char actual_str[256 ]; };
test/dm/core.c +19 -28
189 lines not on this page · raw message
test/dm/test-dm.c +5 -5
@@ -21,14 +21,15 @@DECLARE_GLOBAL_DATA_PTR ;struct unit_test_state global_dm_test_state; -static struct dm_test_state _global_priv_dm_test_state;int dm_test_init (struct unit_test_state *uts) { -struct dm_test_state *dms = uts->priv;bool of_live = uts->of_live; -memset (dms,'\0' ,sizeof (*dms)); + uts->root =NULL ; + uts->testdev =NULL ; + uts->force_fail_alloc = false; + uts->skip_post_probe = false; gd->dm_root =NULL ;if (!CONFIG_IS_ENABLED (OF_PLATDATA ))memset (dm_testdrv_op_count,'\0' ,sizeof (dm_testdrv_op_count));
@@ -37,7 +38,7 @@ int dm_test_init(struct unit_test_state *uts)/* Determine whether to make the live tree available */ gd_set_of_root (of_live ? uts->of_root :NULL );ut_assertok (dm_init (of_live)); - dms->root =dm_root (); + uts->root =dm_root ();return 0 ; }
@@ -123,7 +124,6 @@ int dm_test_run(const char *test_name)struct unit_test *test;int found; - uts->priv = &_global_priv_dm_test_state; uts->fail_count =0 ;if (!CONFIG_IS_ENABLED (OF_PLATDATA )) {
test/dm/test-driver.c +1 -3
@@ -116,10 +116,8 @@ static int test_manual_bind(struct udevice *dev)static int test_manual_probe (struct udevice *dev) { -struct dm_test_state *dms = uts->priv; - dm_testdrv_op_count[DM_TEST_OP_PROBE ]++; -if (!dms->force_fail_alloc) +if (!uts->force_fail_alloc)dev_set_priv (dev,calloc (1 ,sizeof (struct dm_test_priv )));if (!dev_get_priv (dev))return -ENOMEM ;
test/dm/test-uclass.c +1 -2
@@ -71,13 +71,12 @@ static int test_post_probe(struct udevice *dev)struct dm_test_uclass_perdev_priv *priv =dev_get_uclass_priv (dev);struct uclass *uc = dev->uclass; -struct dm_test_state *dms = uts->priv; dm_testdrv_op_count[DM_TEST_OP_POST_PROBE ]++;ut_assert (priv);ut_assert (device_active (dev)); priv->base_add =0 ; -if (dms->skip_post_probe) +if (uts->skip_post_probe)return 0 ;if (&prev->uclass_node != &uc->dev_head) {struct dm_test_uclass_perdev_priv *prev_uc_priv
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 21/41 test: Move dm_test_init() into test-main.c
In reply to Simon GlassMove this function into test-main so that all the init is in one place. Rename it so that its purpose is clearer.
---
(no changes since v1)
include/test/ut.h | 9 --------- test/dm/test-dm.c | 22 ---------------------- test/test-main.c | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 32 deletions(-)
include/test/ut.h +0 -9
@@ -387,15 +387,6 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test);*/ int test_post_run (struct unit_test_state *uts,struct unit_test *test); -/** -* dm_test_init() - Get ready to run a driver model test -* -* This clears out the driver model data structures. For sandbox it resets the -* state structure. -* -* @uts: Test state -*/ -int dm_test_init (struct unit_test_state *uts);/** * ut_run_tests() - Run a set of tests
test/dm/test-dm.c +0 -22
@@ -11,7 +11,6 @@#include <log.h> #include <malloc.h> #include <asm/state.h> -#include <dm/test.h> #include <dm/root.h> #include <dm/uclass-internal.h> #include <test/test.h>
@@ -22,27 +21,6 @@ DECLARE_GLOBAL_DATA_PTR;struct unit_test_state global_dm_test_state; -int dm_test_init (struct unit_test_state *uts) -{ -bool of_live = uts->of_live; - - uts->root =NULL ; - uts->testdev =NULL ; - uts->force_fail_alloc = false; - uts->skip_post_probe = false; - gd->dm_root =NULL ; -if (!CONFIG_IS_ENABLED (OF_PLATDATA )) -memset (dm_testdrv_op_count,'\0' ,sizeof (dm_testdrv_op_count)); -state_reset_for_test (state_get_current ()); - -/* Determine whether to make the live tree available */ -gd_set_of_root (of_live ? uts->of_root :NULL ); -ut_assertok (dm_init (of_live)); - uts->root =dm_root (); - -return 0 ; -} -static int dm_test_destroy (struct unit_test_state *uts) {int id;
test/test-main.c +32 -1
@@ -7,12 +7,43 @@#include <common.h> #include <console.h> #include <dm.h> +#include <asm/state.h> #include <dm/root.h> +#include <dm/test.h> #include <test/test.h> #include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ; +/** +* dm_test_pre_run() - Get ready to run a driver model test +* +* This clears out the driver model data structures. For sandbox it resets the +* state structure +* +* @uts: Test state +*/ +static int dm_test_pre_run (struct unit_test_state *uts) +{ +bool of_live = uts->of_live; + + uts->root =NULL ; + uts->testdev =NULL ; + uts->force_fail_alloc = false; + uts->skip_post_probe = false; + gd->dm_root =NULL ; +if (!CONFIG_IS_ENABLED (OF_PLATDATA )) +memset (dm_testdrv_op_count,'\0' ,sizeof (dm_testdrv_op_count)); +state_reset_for_test (state_get_current ()); + +/* Determine whether to make the live tree available */ +gd_set_of_root (of_live ? uts->of_root :NULL ); +ut_assertok (dm_init (of_live)); + uts->root =dm_root (); + +return 0 ; +} +/* Ensure all the test devices are probed */ static int do_autoprobe (struct unit_test_state *uts) {
@@ -31,7 +62,7 @@ static int do_autoprobe(struct unit_test_state *uts)int test_pre_run (struct unit_test_state *uts,struct unit_test *test) {if (test->flags &UT_TESTF_DM ) -ut_assertok (dm_test_init (uts)); +ut_assertok (dm_test_pre_run (uts));ut_set_skip_delays (uts, false);
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 22/41 test: Move dm_test_destroy() into test-main.c
In reply to Simon GlassMove this function into the common test runner and rename it to dm_test_post_run() so that its purpose is clear.
---
(no changes since v1)
test/dm/test-dm.c | 22 ---------------------- test/test-main.c | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-)
test/dm/test-dm.c +0 -22
@@ -21,26 +21,6 @@ DECLARE_GLOBAL_DATA_PTR;struct unit_test_state global_dm_test_state; -static int dm_test_destroy (struct unit_test_state *uts) -{ -int id; - -for (id =0 ; id <UCLASS_COUNT ; id++) { -struct uclass *uc; - -/* -* If the uclass doesn't exist we don't want to create it. So -* check that here before we call uclass_find_device(). -*/ - uc =uclass_find (id); -if (!uc) -continue ; -ut_assertok (uclass_destroy (uc)); - } - -return 0 ; -} -static int dm_do_test (struct unit_test_state *uts,struct unit_test *test,bool of_live) {
@@ -56,8 +36,6 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,ut_assertok (test_post_run (uts, test)); -ut_assertok (dm_test_destroy (uts)); -return 0 ; }
test/test-main.c +23 -0
@@ -10,6 +10,7 @@#include <asm/state.h> #include <dm/root.h> #include <dm/test.h> +#include <dm/uclass-internal.h> #include <test/test.h> #include <test/ut.h>
@@ -44,6 +45,26 @@ static int dm_test_pre_run(struct unit_test_state *uts)return 0 ; } +static int dm_test_post_run (struct unit_test_state *uts) +{ +int id; + +for (id =0 ; id <UCLASS_COUNT ; id++) { +struct uclass *uc; + +/* +* If the uclass doesn't exist we don't want to create it. So +* check that here before we call uclass_find_device(). +*/ + uc =uclass_find (id); +if (!uc) +continue ; +ut_assertok (uclass_destroy (uc)); + } + +return 0 ; +} +/* Ensure all the test devices are probed */ static int do_autoprobe (struct unit_test_state *uts) {
@@ -94,6 +115,8 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test)int test_post_run (struct unit_test_state *uts,struct unit_test *test) {ut_unsilence_console (uts); +if (test->flags &UT_TESTF_DM ) +ut_assertok (dm_test_post_run (uts));return 0 ; }
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 23/41 test: Move test running into a separate function
In reply to Simon GlassAdd a function to handle the preparation for running a test and the post-test clean-up.
---
(no changes since v1)
include/test/ut.h | 16 ++++++++++++++++ test/test-main.c | 32 +++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-)
include/test/ut.h +16 -0
@@ -387,6 +387,22 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test);*/ int test_post_run (struct unit_test_state *uts,struct unit_test *test); +/** +* ut_run_test() - Run a single test +* +* This runs the test, handling any preparation and clean-up needed. It prints +* the name of each test before running it. +* +* @uts: Test state to update. The caller should ensure that this is zeroed for +* the first call to this function. On exit, @uts->fail_count is +* incremented by the number of failures (0, one hopes) +* @test: Test to run +* @name: Name of test, possibly skipping a prefix that should not be displayed +* @return 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if +* any failed +*/ +int ut_run_test (struct unit_test_state *uts,struct unit_test *test, +const char *name);/** * ut_run_tests() - Run a set of tests
test/test-main.c +23 -9
@@ -121,6 +121,28 @@ int test_post_run(struct unit_test_state *uts, struct unit_test *test)return 0 ; } +int ut_run_test (struct unit_test_state *uts,struct unit_test *test, +const char *test_name) +{ +int ret; + +printf ("Test: %s\n" , test_name); + + ret =test_pre_run (uts, test); +if (ret == -EAGAIN ) +return -EAGAIN ; +if (ret) +return ret; + + test->func (uts); + + ret =test_post_run (uts, test); +if (ret) +return ret; + +return 0 ; +} +int ut_run_tests (struct unit_test_state *uts,const char *prefix,struct unit_test *tests,int count,const char *select_name) {
@@ -138,20 +160,12 @@ int ut_run_tests(struct unit_test_state *uts, const char *prefix,if (select_name &&strcmp (select_name, test_name))continue ; -printf ("Test: %s\n" , test_name); + ret =ut_run_test (uts, test, test_name); found++; - - ret =test_pre_run (uts, test);if (ret == -EAGAIN )continue ;if (ret)return ret; - - test->func (uts); - - ret =test_post_run (uts, test); -if (ret) -return ret; }if (select_name && !found)return -ENOENT ;
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 24/41 test: Use ut_run_test() to run driver model tests
In reply to Simon GlassInstead of having a separate function for running driver model tests, use the common one. Make the pre/post-run functions private since we don't need these outside of test-main.c
---
(no changes since v1)
include/test/ut.h | 20 -------------------- test/dm/test-dm.c | 11 +---------- test/test-main.c | 26 +++++++++++++++++++++++--- 3 files changed, 24 insertions(+), 33 deletions(-)
include/test/ut.h +0 -20
@@ -367,26 +367,6 @@ void ut_unsilence_console(struct unit_test_state *uts);*/ void ut_set_skip_delays (struct unit_test_state *uts,bool skip_delays); -/** -* test_pre_run() - Handle any preparation needed to run a test -* -* @uts: Test state -* @test: Test to prepare for -* @return 0 if OK, -EAGAIN to skip this test since some required feature is not -* available, other -ve on error (meaning that testing cannot likely -* continue) -*/ -int test_pre_run (struct unit_test_state *uts,struct unit_test *test); - -/** -* test_post_run() - Handle cleaning up after a test -* -* @uts: Test state -* @test: Test to clean up after -* @return 0 if OK, -ve on error (meaning that testing cannot likely continue) -*/ -int test_post_run (struct unit_test_state *uts,struct unit_test *test); -/** * ut_run_test() - Run a single test *
test/dm/test-dm.c +1 -10
@@ -24,17 +24,8 @@ struct unit_test_state global_dm_test_state;static int dm_do_test (struct unit_test_state *uts,struct unit_test *test,bool of_live) { -const char *fname =strrchr (test->file,'/' ) +1 ; - -printf ("Test: %s: %s%s\n" , test->name, fname, - !of_live ?" (flat tree)" :"" ); uts->of_live = of_live; - -ut_assertok (test_pre_run (uts, test)); - - test->func (uts); - -ut_assertok (test_post_run (uts, test)); +ut_assertok (ut_run_test (uts, test, test->name));return 0 ; }
test/test-main.c +23 -3
@@ -80,7 +80,16 @@ static int do_autoprobe(struct unit_test_state *uts)return ret; } -int test_pre_run (struct unit_test_state *uts,struct unit_test *test) +/** +* test_pre_run() - Handle any preparation needed to run a test +* +* @uts: Test state +* @test: Test to prepare for +* @return 0 if OK, -EAGAIN to skip this test since some required feature is not +* available, other -ve on error (meaning that testing cannot likely +* continue) +*/ +static int test_pre_run (struct unit_test_state *uts,struct unit_test *test) {if (test->flags &UT_TESTF_DM )ut_assertok (dm_test_pre_run (uts));
@@ -112,7 +121,14 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test)return 0 ; } -int test_post_run (struct unit_test_state *uts,struct unit_test *test) +/** +* test_post_run() - Handle cleaning up after a test +* +* @uts: Test state +* @test: Test to clean up after +* @return 0 if OK, -ve on error (meaning that testing cannot likely continue) +*/ +static int test_post_run (struct unit_test_state *uts,struct unit_test *test) {ut_unsilence_console (uts);if (test->flags &UT_TESTF_DM )
@@ -124,9 +140,13 @@ int test_post_run(struct unit_test_state *uts, struct unit_test *test)int ut_run_test (struct unit_test_state *uts,struct unit_test *test,const char *test_name) { +const char *fname =strrchr (test->file,'/' ) +1 ; +const char *note ="" ;int ret; -printf ("Test: %s\n" , test_name); +if ((test->flags &UT_TESTF_DM ) && !uts->of_live) + note =" (flat tree)" ; +printf ("Test: %s: %s%s\n" , test_name, fname, note); ret =test_pre_run (uts, test);if (ret == -EAGAIN )
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 25/41 test: Drop dm_do_test()
In reply to Simon GlassIn an effort to make use of a common test runner, use ut_run_test() directly to run driver model tests.
---
(no changes since v1)
test/dm/test-dm.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
test/dm/test-dm.c +4 -11
@@ -21,15 +21,6 @@ DECLARE_GLOBAL_DATA_PTR;struct unit_test_state global_dm_test_state; -static int dm_do_test (struct unit_test_state *uts,struct unit_test *test, -bool of_live) -{ - uts->of_live = of_live; -ut_assertok (ut_run_test (uts, test, test->name)); - -return 0 ; -} -/** * dm_test_run_on_flattree() - Check if we should run a test with flat DT *
@@ -102,7 +93,8 @@ int dm_test_run(const char *test_name) runs =0 ;if (CONFIG_IS_ENABLED (OF_LIVE )) {if (!(test->flags &UT_TESTF_FLAT_TREE )) { -ut_assertok (dm_do_test (uts, test, true)); + uts->of_live = true; +ut_assertok (ut_run_test (uts, test, test->name)); runs++; } }
@@ -113,7 +105,8 @@ int dm_test_run(const char *test_name)*/ if (!(test->flags &UT_TESTF_LIVE_TREE ) && (!runs ||dm_test_run_on_flattree (test))) { -ut_assertok (dm_do_test (uts, test, false)); + uts->of_live = false; +ut_assertok (ut_run_test (uts, test, test->name)); runs++; } found++;
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 26/41 test: Add ut_run_test_live_flat() to run tests twice
In reply to Simon GlassDriver model tests are generally run twice, once with livetree enable and again with it disabled. Add a function to handle this and call it from the driver model test runner.
Make ut_run_test() private since it is not used outside test-main.c now.
---
(no changes since v2)
Changes in v2:
- Fix conditions so non-DM SPL tests are actually run
include/test/ut.h | 13 +++++---- test/dm/test-dm.c | 37 +------------------------- test/test-main.c | 67 ++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 73 insertions(+), 44 deletions(-)
include/test/ut.h +8 -5
@@ -368,10 +368,13 @@ void ut_unsilence_console(struct unit_test_state *uts);void ut_set_skip_delays (struct unit_test_state *uts,bool skip_delays);/** -* ut_run_test() - Run a single test +* ut_run_test_live_flat() - Run a test with both live and flat tree * -* This runs the test, handling any preparation and clean-up needed. It prints -* the name of each test before running it. +* This calls ut_run_test() with livetree enabled, which is the standard setup +* for runnig tests. Then, for driver model test, it calls it again with +* livetree disabled. This allows checking of flattree being used when OF_LIVE +* is enabled, as is the case in U-Boot proper before relocation, as well as in +* SPL. * * @uts: Test state to update. The caller should ensure that this is zeroed for * the first call to this function. On exit, @uts->fail_count is
@@ -381,8 +384,8 @@ void ut_set_skip_delays(struct unit_test_state *uts, bool skip_delays);* @return 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if * any failed */ -int ut_run_test (struct unit_test_state *uts,struct unit_test *test, -const char *name); +int ut_run_test_live_flat (struct unit_test_state *uts,struct unit_test *test, +const char *name);/** * ut_run_tests() - Run a set of tests
test/dm/test-dm.c +1 -36
@@ -21,21 +21,6 @@ DECLARE_GLOBAL_DATA_PTR;struct unit_test_state global_dm_test_state; -/** -* dm_test_run_on_flattree() - Check if we should run a test with flat DT -* -* This skips long/slow tests where there is not much value in running a flat -* DT test in addition to a live DT test. -* -* @return true to run the given test on the flat device tree -*/ -static bool dm_test_run_on_flattree (struct unit_test *test) -{ -const char *fname =strrchr (test->file,'/' ) +1 ; - -return !strstr (fname,"video" ) ||strstr (test->name,"video_base" ); -} -static bool test_matches (const char *test_name,const char *find_name) {if (!find_name)
@@ -84,31 +69,11 @@ int dm_test_run(const char *test_name) uts->of_root =gd_of_root ();for (test = tests; test < tests + n_ents; test++) {const char *name = test->name; -int runs;if (!test_matches (name, test_name))continue ; -/* Run with the live tree if possible */ - runs =0 ; -if (CONFIG_IS_ENABLED (OF_LIVE )) { -if (!(test->flags &UT_TESTF_FLAT_TREE )) { - uts->of_live = true; -ut_assertok (ut_run_test (uts, test, test->name)); - runs++; - } - } - -/* -* Run with the flat tree if we couldn't run it with live tree, -* or it is a core test. -*/ -if (!(test->flags &UT_TESTF_LIVE_TREE ) && - (!runs ||dm_test_run_on_flattree (test))) { - uts->of_live = false; -ut_assertok (ut_run_test (uts, test, test->name)); - runs++; - } +ut_assertok (ut_run_test_live_flat (uts, test, test->name)); found++; }
test/test-main.c +64 -3
91 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 27/41 test: Use a local variable for test state
In reply to Simon GlassAt present we use a global test state for all driver-model tests. Make use of a local struct like we do with the other tests.
To make this work, add functions to get and set this state. When a test starts, the state is set (so it can be used in the test). When a test finishes, the state is unset, so it cannot be used by mistake.
---
Changes in v3:
- Use test_set_state() throughout test-main.c instead of direct assignment
include/test/ut.h | 14 ++++++++++++++ test/dm/test-dm.c | 4 +--- test/dm/test-driver.c | 10 +++++++++- test/dm/test-uclass.c | 7 +++++-- test/test-main.c | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-)
include/test/ut.h +14 -0
@@ -367,6 +367,20 @@ void ut_unsilence_console(struct unit_test_state *uts);*/ void ut_set_skip_delays (struct unit_test_state *uts,bool skip_delays); +/** +* test_get_state() - Get the active test state +* +* @return the currently active test state, or NULL if none +*/ +struct unit_test_state *test_get_state (void ); + +/** +* test_set_state() - Set the active test state +* +* @uts: Test state to use as currently active test state, or NULL if none +*/ +void test_set_state (struct unit_test_state *uts); +/** * ut_run_test_live_flat() - Run a test with both live and flat tree *
test/dm/test-dm.c +1 -3
@@ -19,8 +19,6 @@DECLARE_GLOBAL_DATA_PTR ; -struct unit_test_state global_dm_test_state; -static bool test_matches (const char *test_name,const char *find_name) {if (!find_name)
@@ -43,7 +41,7 @@ int dm_test_run(const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test); -struct unit_test_state *uts = &global_dm_test_state; +struct unit_test_state uts_s = { .fail_count =0 }, *uts = &uts_s;struct unit_test *test;int found;
test/dm/test-driver.c +9 -1
@@ -18,7 +18,6 @@#include <test/ut.h> int dm_testdrv_op_count[DM_TEST_OP_COUNT ]; -static struct unit_test_state *uts = &global_dm_test_state;static int testdrv_ping (struct udevice *dev,int pingval,int *pingret) {
@@ -37,6 +36,8 @@ static const struct test_ops test_ops = {static int test_bind (struct udevice *dev) { +struct unit_test_state *uts =test_get_state (); +/* Private data should not be allocated */ ut_assert (!dev_get_priv (dev));
@@ -46,6 +47,7 @@ static int test_bind(struct udevice *dev)static int test_probe (struct udevice *dev) { +struct unit_test_state *uts =test_get_state ();struct dm_test_priv *priv =dev_get_priv (dev);/* Private data should be allocated */
@@ -58,6 +60,8 @@ static int test_probe(struct udevice *dev)static int test_remove (struct udevice *dev) { +struct unit_test_state *uts =test_get_state (); +/* Private data should still be allocated */ ut_assert (dev_get_priv (dev));
@@ -67,6 +71,8 @@ static int test_remove(struct udevice *dev)static int test_unbind (struct udevice *dev) { +struct unit_test_state *uts =test_get_state (); +/* Private data should not be allocated */ ut_assert (!dev_get_priv (dev));
@@ -116,6 +122,8 @@ static int test_manual_bind(struct udevice *dev)static int test_manual_probe (struct udevice *dev) { +struct unit_test_state *uts =test_get_state (); + dm_testdrv_op_count[DM_TEST_OP_PROBE ]++;if (!uts->force_fail_alloc)dev_set_priv (dev,calloc (1 ,sizeof (struct dm_test_priv )));
test/dm/test-uclass.c +5 -2
@@ -17,8 +17,6 @@#include <test/test.h> #include <test/ut.h> -static struct unit_test_state *uts = &global_dm_test_state; -int test_ping (struct udevice *dev,int pingval,int *pingret) {const struct test_ops *ops =device_get_ops (dev);
@@ -31,6 +29,7 @@ int test_ping(struct udevice *dev, int pingval, int *pingret)static int test_post_bind (struct udevice *dev) { +struct unit_test_state *uts =test_get_state ();struct dm_test_perdev_uc_pdata *uc_pdata; dm_testdrv_op_count[DM_TEST_OP_POST_BIND ]++;
@@ -56,6 +55,7 @@ static int test_pre_unbind(struct udevice *dev)static int test_pre_probe (struct udevice *dev) {struct dm_test_uclass_perdev_priv *priv =dev_get_uclass_priv (dev); +struct unit_test_state *uts =test_get_state (); dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE ]++;ut_assert (priv);
@@ -66,6 +66,7 @@ static int test_pre_probe(struct udevice *dev)static int test_post_probe (struct udevice *dev) { +struct unit_test_state *uts =test_get_state ();struct udevice *prev =list_entry (dev->uclass_node.prev, struct udevice, uclass_node);
@@ -100,6 +101,8 @@ static int test_pre_remove(struct udevice *dev)static int test_init (struct uclass *uc) { +struct unit_test_state *uts =test_get_state (); + dm_testdrv_op_count[DM_TEST_OP_INIT ]++;ut_assert (uclass_get_priv (uc));
test/test-main.c +18 -0
@@ -16,6 +16,19 @@DECLARE_GLOBAL_DATA_PTR ; +/* This is valid when a test is running, NULL otherwise */ +static struct unit_test_state *cur_test_state; + +struct unit_test_state *test_get_state (void ) +{ +return cur_test_state; +} + +void test_set_state (struct unit_test_state *uts) +{ + cur_test_state = uts; +} +/** * dm_test_pre_run() - Get ready to run a driver model test *
@@ -180,6 +193,9 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, note =" (flat tree)" ;printf ("Test: %s: %s%s\n" , test_name, fname, note); +/* Allow access to test state from drivers */ +test_set_state (uts); + ret =test_pre_run (uts, test);if (ret == -EAGAIN )return -EAGAIN ;
@@ -192,6 +208,8 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,if (ret)return ret; +test_set_state (NULL ); +return 0 ; }
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 28/41 test: Run driver-model tests using ut_run_list()
In reply to Simon GlassUse this function instead of implementing it separately for driver model.
Make ut_run_tests() private since it is only used in test-main.c
---
(no changes since v2)
Changes in v2:
- Allow for prefix to be NULL, to match function comment
include/test/ut.h | 42 ----------------------- test/dm/test-dm.c | 45 +++--------------------- test/test-main.c | 87 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 81 insertions(+), 93 deletions(-)
include/test/ut.h +0 -42
@@ -381,48 +381,6 @@ struct unit_test_state *test_get_state(void);*/ void test_set_state (struct unit_test_state *uts); -/** -* ut_run_test_live_flat() - Run a test with both live and flat tree -* -* This calls ut_run_test() with livetree enabled, which is the standard setup -* for runnig tests. Then, for driver model test, it calls it again with -* livetree disabled. This allows checking of flattree being used when OF_LIVE -* is enabled, as is the case in U-Boot proper before relocation, as well as in -* SPL. -* -* @uts: Test state to update. The caller should ensure that this is zeroed for -* the first call to this function. On exit, @uts->fail_count is -* incremented by the number of failures (0, one hopes) -* @test: Test to run -* @name: Name of test, possibly skipping a prefix that should not be displayed -* @return 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if -* any failed -*/ -int ut_run_test_live_flat (struct unit_test_state *uts,struct unit_test *test, -const char *name); - -/** -* ut_run_tests() - Run a set of tests -* -* This runs the tests, handling any preparation and clean-up needed. It prints -* the name of each test before running it. -* -* @uts: Test state to update. The caller should ensure that this is zeroed for -* the first call to this function. On exit, @uts->fail_count is -* incremented by the number of failures (0, one hopes) -* @prefix: String prefix for the tests. Any tests that have this prefix will be -* printed without the prefix, so that it is easier to see the unique part -* of the test name. If NULL, no prefix processing is done -* @tests: List of tests to run -* @count: Number of tests to run -* @select_name: Name of a single test to run (from the list provided). If NULL -* then all tests are run -* @return 0 if all tests passed, -ENOENT if test @select_name was not found, -* -EBADF if any failed -*/ -int ut_run_tests (struct unit_test_state *uts,const char *prefix, -struct unit_test *tests,int count,const char *select_name); -/** * ut_run_tests() - Run a set of tests *
test/dm/test-dm.c +5 -40
65 lines not on this page · raw message
test/test-main.c +76 -11
120 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 29/41 test: Use return values in dm_test_run()
In reply to Simon GlassUpdate this function to use the return value of ut_run_list() to check for success/failure, so that they are in sync. Also return a command success code so that the caller gets what it expects.
---
(no changes since v1)
test/dm/test-dm.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
test/dm/test-dm.c +6 -8
@@ -19,16 +19,13 @@DECLARE_GLOBAL_DATA_PTR ; -struct unit_test_state global_dm_test_state; -int dm_test_run (const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test);struct unit_test_state uts_s = { .fail_count =0 }, *uts = &uts_s;struct device_node *of_root; - - uts->fail_count =0 ; +int ret;if (!CONFIG_IS_ENABLED (OF_PLATDATA )) {/*
@@ -38,22 +35,23 @@ int dm_test_run(const char *test_name)if (!gd->fdt_blob ||fdt_next_node (gd->fdt_blob,0 ,NULL ) <0 ) {puts ("Please run with test device tree:\n" " ./u-boot -d arch/sandbox/dts/test.dtb\n" ); -ut_assert (gd->fdt_blob); +return CMD_RET_FAILURE ; } } of_root =gd_of_root (); -ut_run_list ("driver model" ,"dm_test_" , tests, n_ents, test_name); + ret =ut_run_list ("driver model" ,"dm_test_" , tests, n_ents, test_name);/* Put everything back to normal so that sandbox works as expected */ gd_set_of_root (of_root); gd->dm_root =NULL ; -ut_assertok (dm_init (CONFIG_IS_ENABLED (OF_LIVE ))); +if (dm_init (CONFIG_IS_ENABLED (OF_LIVE ))) +return CMD_RET_FAILURE ;dm_scan_plat (false);if (!CONFIG_IS_ENABLED (OF_PLATDATA ))dm_scan_fdt (false); -return uts->fail_count ?CMD_RET_FAILURE :0 ; +return ret ?CMD_RET_FAILURE :0 ; }int do_ut_dm (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[])
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 30/41 test: Move the devicetree check into ut_run_list()
In reply to Simon GlassAdd a check to ut_run_list() as to whether a list has driver model tests. Move the logic for the test devicetree into that function, in an effort to eventually remove all logic from dm_test_run().
---
(no changes since v1)
test/dm/test-dm.c | 13 ------------- test/test-main.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 13 deletions(-)
test/dm/test-dm.c +0 -13
@@ -23,22 +23,9 @@ int dm_test_run(const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test); -struct unit_test_state uts_s = { .fail_count =0 }, *uts = &uts_s;struct device_node *of_root;int ret; -if (!CONFIG_IS_ENABLED (OF_PLATDATA )) { -/* -* If we have no device tree, or it only has a root node, then -* these * tests clearly aren't going to work... -*/ -if (!gd->fdt_blob ||fdt_next_node (gd->fdt_blob,0 ,NULL ) <0 ) { -puts ("Please run with test device tree:\n" -" ./u-boot -d arch/sandbox/dts/test.dtb\n" ); -return CMD_RET_FAILURE ; - } - } - of_root =gd_of_root (); ret =ut_run_list ("driver model" ,"dm_test_" , tests, n_ents, test_name);
test/test-main.c +32 -0
@@ -143,6 +143,25 @@ static bool test_matches(const char *prefix, const char *test_name,return false; } +/* +* ut_list_has_dm_tests() - Check if a list of tests has driver model ones +* +* @tests: List of tests to run +* @count: Number of tests to ru +* @return true if any of the tests have the UT_TESTF_DM flag +*/ +static bool ut_list_has_dm_tests (struct unit_test *tests,int count) +{ +struct unit_test *test; + +for (test = tests; test < tests + count; test++) { +if (test->flags &UT_TESTF_DM ) +return true; + } + +return false; +} +/** * test_pre_run() - Handle any preparation needed to run a test *
@@ -342,6 +361,19 @@ int ut_run_list(const char *category, const char *prefix,struct unit_test_state uts = { .fail_count =0 };int ret; +if (!CONFIG_IS_ENABLED (OF_PLATDATA ) && +ut_list_has_dm_tests (tests, count)) { +/* +* If we have no device tree, or it only has a root node, then +* these * tests clearly aren't going to work... +*/ +if (!gd->fdt_blob ||fdt_next_node (gd->fdt_blob,0 ,NULL ) <0 ) { +puts ("Please run with test device tree:\n" +" ./u-boot -d arch/sandbox/dts/test.dtb\n" ); +return CMD_RET_FAILURE ; + } + } +if (!select_name)printf ("Running %d %s tests\n" , count, category);
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 31/41 test: Move restoring of driver model state to ut_run_list()
In reply to Simon GlassAdd this functionality to ut_run_list() so it can be removed from dm_test_run().
At this point all tests are run through ut_run_list().
---
(no changes since v1)
test/dm/test-dm.c | 11 ----------- test/test-main.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 12 deletions(-)
test/dm/test-dm.c +0 -11
@@ -23,21 +23,10 @@ int dm_test_run(const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test); -struct device_node *of_root;int ret; - of_root =gd_of_root (); ret =ut_run_list ("driver model" ,"dm_test_" , tests, n_ents, test_name); -/* Put everything back to normal so that sandbox works as expected */ -gd_set_of_root (of_root); - gd->dm_root =NULL ; -if (dm_init (CONFIG_IS_ENABLED (OF_LIVE ))) -return CMD_RET_FAILURE ; -dm_scan_plat (false); -if (!CONFIG_IS_ENABLED (OF_PLATDATA )) -dm_scan_fdt (false); -return ret ?CMD_RET_FAILURE :0 ; }
test/test-main.c +29 -1
@@ -143,7 +143,7 @@ static bool test_matches(const char *prefix, const char *test_name,return false; } -/* +/** * ut_list_has_dm_tests() - Check if a list of tests has driver model ones * * @tests: List of tests to run
@@ -162,6 +162,28 @@ static bool ut_list_has_dm_tests(struct unit_test *tests, int count)return false; } +/** +* dm_test_restore() Put things back to normal so sandbox works as expected +* +* @of_root: Value to set for of_root +* @return 0 if OK, -ve on error +*/ +static int dm_test_restore (struct device_node *of_root) +{ +int ret; + +gd_set_of_root (of_root); + gd->dm_root =NULL ; + ret =dm_init (CONFIG_IS_ENABLED (OF_LIVE )); +if (ret) +return ret; +dm_scan_plat (false); +if (!CONFIG_IS_ENABLED (OF_PLATDATA )) +dm_scan_fdt (false); + +return 0 ; +} +/** * test_pre_run() - Handle any preparation needed to run a test *
@@ -359,10 +381,12 @@ int ut_run_list(const char *category, const char *prefix, struct unit_test *tests, int count, const char *select_name) { struct unit_test_state uts = { .fail_count = 0 }; +bool has_dm_tests = false;int ret;if (!CONFIG_IS_ENABLED (OF_PLATDATA ) &&ut_list_has_dm_tests (tests, count)) { + has_dm_tests = true;/* * If we have no device tree, or it only has a root node, then * these * tests clearly aren't going to work...
@@ -385,5 +409,9 @@ int ut_run_list(const char *category, const char *prefix,else printf ("Failures: %d\n" , uts.fail_count); +/* Best efforts only...ignore errors */ +if (has_dm_tests) +dm_test_restore (uts.of_root); +return ret; }
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 32/41 test: log: Rename log main test file to log_ut.c
In reply to Simon GlassThe current name is the same as the main test runner file. Rename it to avoid confusion.
---
(no changes since v1)
test/log/Makefile | 2 +-
test/log/{test-main.c => log_ut.c} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename test/log/{test-main.c => log_ut.c} (100%)test/log/Makefile +1 -1
@@ -7,7 +7,7 @@ obj-$(CONFIG_CMD_LOG) += log_filter.o ifdef CONFIG_UT_LOG -obj-y += test-main.o +obj-y += log_ut.o ifdef CONFIG_SANDBOX obj-$(CONFIG_LOG_SYSLOG) += syslog_test.o
test/log/log_ut.c renamed from test/log/test-main.c +0 -0
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 33/41 test: Add a macros for finding tests in linker_lists
In reply to Simon GlassAt present we use the linker list directly. This is not very friendly, so add a helpful macro instead. This will also allow us to change the naming later without updating this code.
---
(no changes since v1)
include/test/test.h | 6 ++++++ test/bloblist.c | 5 ++--- test/bootm.c | 4 ++-- test/cmd/mem.c | 4 ++-- test/cmd/setexpr.c | 5 ++--- test/compression.c | 5 ++--- test/dm/test-dm.c | 4 ++-- test/env/cmd_ut_env.c | 4 ++-- test/lib/cmd_ut_lib.c | 4 ++-- test/log/log_ut.c | 4 ++-- test/optee/cmd_ut_optee.c | 5 ++--- test/overlay/cmd_ut_overlay.c | 5 ++--- test/str_ut.c | 5 ++--- test/unicode_ut.c | 4 ++-- 14 files changed, 32 insertions(+), 32 deletions(-)
include/test/test.h +6 -0
@@ -93,6 +93,12 @@ struct unit_test { .func = _name, \ } +/* Get the start of a list of unit tests for a particular category */ +#define UNIT_TEST_SUITE_START (_suite) \ + ll_entry_start(struct unit_test, _suite) +#define UNIT_TEST_SUITE_COUNT (_suite) \ + ll_entry_count(struct unit_test, _suite) +/* Sizes for devres tests */ enum {TEST_DEVRES_SIZE =100 ,
test/bloblist.c +2 -3
@@ -386,9 +386,8 @@ BLOBLIST_TEST(bloblist_test_reloc, 0);int do_ut_bloblist (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, - bloblist_test); - const int n_ents = ll_entry_count(struct unit_test, bloblist_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (bloblist_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (bloblist_test);return cmd_ut_category ("bloblist" ,"bloblist_test_" , tests, n_ents, argc, argv);
test/bootm.c +2 -2
@@ -239,8 +239,8 @@ BOOTM_TEST(bootm_test_subst_both, 0);int do_ut_bootm (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, bootm_test); - const int n_ents = ll_entry_count(struct unit_test, bootm_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (bootm_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (bootm_test);return cmd_ut_category ("bootm" ,"bootm_test_" , tests, n_ents, argc, argv);
test/cmd/mem.c +2 -2
@@ -12,8 +12,8 @@int do_ut_mem (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, mem_test); - const int n_ents = ll_entry_count(struct unit_test, mem_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (mem_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (mem_test);return cmd_ut_category ("cmd_mem" ,"mem_test_" , tests, n_ents, argc, argv);
test/cmd/setexpr.c +2 -3
@@ -390,9 +390,8 @@ SETEXPR_TEST(setexpr_test_str_long, UT_TESTF_CONSOLE_REC);int do_ut_setexpr (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, - setexpr_test); - const int n_ents = ll_entry_count(struct unit_test, setexpr_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (setexpr_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (setexpr_test);return cmd_ut_category ("cmd_setexpr" ,"setexpr_test_" , tests, n_ents, argc, argv);
test/compression.c +2 -3
@@ -539,9 +539,8 @@ COMPRESSION_TEST(compression_test_bootm_none, 0);int do_ut_compression (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, - compression_test); - const int n_ents = ll_entry_count(struct unit_test, compression_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (compression_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (compression_test);return cmd_ut_category ("compression" ,"compression_test_" , tests, n_ents, argc, argv);
test/dm/test-dm.c +2 -2
@@ -21,8 +21,8 @@ DECLARE_GLOBAL_DATA_PTR;int dm_test_run (const char *test_name) { - struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); - const int n_ents = ll_entry_count(struct unit_test, dm_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (dm_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (dm_test);int ret; ret =ut_run_list ("driver model" ,"dm_test_" , tests, n_ents, test_name);
test/env/cmd_ut_env.c +2 -2
@@ -12,8 +12,8 @@int do_ut_env (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, env_test); - const int n_ents = ll_entry_count(struct unit_test, env_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (env_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (env_test);return cmd_ut_category ("environment" ,"env_test_" , tests, n_ents, argc, argv);
test/lib/cmd_ut_lib.c +2 -2
@@ -13,8 +13,8 @@int do_ut_lib (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, lib_test); - const int n_ents = ll_entry_count(struct unit_test, lib_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (lib_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (lib_test);return cmd_ut_category ("lib" ,"lib_test_" , tests, n_ents, argc, argv); }
test/log/log_ut.c +2 -2
@@ -13,8 +13,8 @@int do_ut_log (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, log_test); - const int n_ents = ll_entry_count(struct unit_test, log_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (log_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (log_test);return cmd_ut_category ("log" ,"log_test_" , tests, n_ents, argc, argv);
test/optee/cmd_ut_optee.c +2 -3
@@ -94,9 +94,8 @@ OPTEE_TEST(optee_fdt_protected_memory, 0);int do_ut_optee (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, - optee_test); - const int n_ents = ll_entry_count(struct unit_test, optee_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (optee_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (optee_test);struct unit_test_state *uts;void *fdt_optee = &__dtb_test_optee_optee_begin;void *fdt_no_optee = &__dtb_test_optee_no_optee_begin;
test/overlay/cmd_ut_overlay.c +2 -3
@@ -213,9 +213,8 @@ OVERLAY_TEST(fdt_overlay_stacked, 0);int do_ut_overlay (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, - overlay_test); - const int n_ents = ll_entry_count(struct unit_test, overlay_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (overlay_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (overlay_test);struct unit_test_state *uts;void *fdt_base = &__dtb_test_fdt_base_begin;void *fdt_overlay = &__dtb_test_fdt_overlay_begin;
test/str_ut.c +2 -3
@@ -107,9 +107,8 @@ STR_TEST(str_simple_strtoul, 0);int do_ut_str (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, - str_test); - const int n_ents = ll_entry_count(struct unit_test, str_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (str_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (str_test);return cmd_ut_category ("str" ,"str_" , tests, n_ents, argc, argv); }
test/unicode_ut.c +2 -2
@@ -615,8 +615,8 @@ UNICODE_TEST(unicode_test_efi_create_indexed_name);int do_ut_unicode (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, unicode_test); - const int n_ents = ll_entry_count(struct unit_test, unicode_test); +struct unit_test *tests =UNIT_TEST_SUITE_START (unicode_test); +const int n_ents =UNIT_TEST_SUITE_COUNT (unicode_test);return cmd_ut_category ("Unicode" ,"unicode_test_" , tests, n_ents, argc, argv);
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 34/41 test: Rename all linker lists to have a ut_ prefix
In reply to Simon GlassAt present each test suite has its own portion of the linker_list section of the image, but other lists are interspersed. This makes it hard to enumerate all the available tests without knowing the suites that each one is in.
Place all tests together in a single contiguous list by giving them common prefix not used elsewhere in U-Boot. This makes it possible to find the start and end of all tests.
---
Changes in v3:
- Update the pytest collector as well
include/test/test.h | 8 ++++---- test/py/conftest.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
include/test/test.h +4 -4
@@ -86,18 +86,18 @@ struct unit_test {* @_suite: name of the test suite concatenated with "_test" */ #define UNIT_TEST (_name, _flags, _suite) \ - ll_entry_declare(struct unit_test, _name, _suite) = { \ + ll_entry_declare(struct unit_test, _name, ut_ ## _suite) = { \ .file = __FILE__, \ .name = #_name, \ .flags = _flags, \ .func = _name, \ } -/* Get the start of a list of unit tests for a particular category */ +/* Get the start of a list of unit tests for a particular suite */ #define UNIT_TEST_SUITE_START (_suite) \ - ll_entry_start(struct unit_test, _suite) + ll_entry_start(struct unit_test, ut_ ## _suite)#define UNIT_TEST_SUITE_COUNT (_suite) \ - ll_entry_count(struct unit_test, _suite) + ll_entry_count(struct unit_test, ut_ ## _suite)/* Sizes for devres tests */ enum {
test/py/conftest.py +1 -1
@@ -226,7 +226,7 @@ def pytest_configure(config): import u_boot_console_exec_attach console = u_boot_console_exec_attach.ConsoleExecAttach(log, ubconfig) -re_ut_test_list = re.compile(r'_u_boot_list_2_(.*)_test_2_\1_test_(.*)\s*$') +re_ut_test_list = re.compile(r'_u_boot_list_2_ut_(.*)_test_2_\1_test_(.*)\s*$') def generate_ut_subtest(metafunc, fixture_name, sym_path): """Provide parametrization for a ut_subtest fixture.
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 35/41 test: Allow SPL to run any available test
In reply to Simon GlassAt present SPL only runs driver model tests. Update it to run all available tests, i.e. in any test suite.
---
(no changes since v1)
arch/sandbox/cpu/spl.c | 7 +++++-- include/test/test.h | 16 +++++----------- test/dm/test-dm.c | 11 ++++++++++- test/test-main.c | 17 +++++++++++++---- 4 files changed, 33 insertions(+), 18 deletions(-)
arch/sandbox/cpu/spl.c +5 -2
@@ -12,7 +12,7 @@#include <spl.h> #include <asm/spl.h> #include <asm/state.h> -#include <test/test.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -58,9 +58,12 @@ void spl_board_init(void)preloader_console_init ();if (state->run_unittests) { +struct unit_test *tests =UNIT_TEST_ALL_START (); +const int count =UNIT_TEST_ALL_COUNT ();int ret; - ret =dm_test_run (state->select_unittests); + ret =ut_run_list ("spl" ,NULL , tests, count, + state->select_unittests);/* continue execution into U-Boot */ } }
include/test/test.h +5 -11
@@ -99,6 +99,11 @@ struct unit_test {#define UNIT_TEST_SUITE_COUNT (_suite) \ ll_entry_count(struct unit_test, ut_ ## _suite) +/* Use ! and ~ so that all tests will be sorted between these two values */ +#define UNIT_TEST_ALL_START () ll_entry_start(struct unit_test, ut_!) +#define UNIT_TEST_ALL_END () ll_entry_start(struct unit_test, ut_~) +#define UNIT_TEST_ALL_COUNT () (UNIT_TEST_ALL_END() - UNIT_TEST_ALL_START()) +/* Sizes for devres tests */ enum {TEST_DEVRES_SIZE =100 ,
@@ -119,15 +124,4 @@ enum {*/ struct udevice *testbus_get_clear_removed (void ); -/** -* dm_test_run() - Run driver model tests -* -* Run all the available driver model tests, or a selection -* -* @test_name: Name of single test to run (e.g. "dm_test_fdt_pre_reloc" or just -* "fdt_pre_reloc"), or NULL to run all -* @return 0 if all tests passed, 1 if not -*/ -int dm_test_run (const char *test_name); -#endif /* __TEST_TEST_H */
test/dm/test-dm.c +10 -1
@@ -19,7 +19,16 @@DECLARE_GLOBAL_DATA_PTR ; -int dm_test_run (const char *test_name) +/** +* dm_test_run() - Run driver model tests +* +* Run all the available driver model tests, or a selection +* +* @test_name: Name of single test to run (e.g. "dm_test_fdt_pre_reloc" or just +* "fdt_pre_reloc"), or NULL to run all +* @return 0 if all tests passed, 1 if not +*/ +static int dm_test_run (const char *test_name) {struct unit_test *tests =UNIT_TEST_SUITE_START (dm_test);const int n_ents =UNIT_TEST_SUITE_COUNT (dm_test);
test/test-main.c +13 -4
@@ -119,7 +119,8 @@ static bool ut_test_run_on_flattree(struct unit_test *test)* * @prefix: String prefix for the tests. Any tests that have this prefix will be * printed without the prefix, so that it is easier to see the unique part -* of the test name. If NULL, no prefix processing is done +* of the test name. If NULL, any suite name (xxx_test) is considered to be +* a prefix. * @test_name: Name of current test * @select_name: Name of test to run (or NULL for all) * @return true to run this test, false to skip it
@@ -133,9 +134,17 @@ static bool test_matches(const char *prefix, const char *test_name,if (!strcmp (test_name, select_name))return true; -/* All tests have this prefix */ -if (prefix && !strncmp (test_name, prefix,strlen (prefix))) - test_name +=strlen (prefix); +if (!prefix) { +const char *p =strstr (test_name,"_test_" ); + +/* convert xxx_test_yyy to yyy, i.e. remove the suite name */ +if (p) + test_name = p +6 ; + }else { +/* All tests have this prefix */ +if (!strncmp (test_name, prefix,strlen (prefix))) + test_name +=strlen (prefix); + }if (!strcmp (test_name, select_name))return true;
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 36/41 sandbox: Update os_find_u_boot() to find the .img file
In reply to Simon GlassAt present this function can only locate the u-boot ELF file. For SPL it is handy to be able to locate u-boot.img since this is what would normally be loaded by SPL.
Add another argument to allow this to be selected.
While we are here, update the function to load SPL when running in TPL, since that is the next stage.
---
(no changes since v1)
arch/sandbox/cpu/os.c | 8 +++++--- arch/sandbox/cpu/spl.c | 2 +- include/os.h | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-)
arch/sandbox/cpu/os.c +5 -3
@@ -729,7 +729,7 @@ int os_jump_to_image(const void *dest, int size)return os_jump_to_file (fname); } -int os_find_u_boot (char *fname,int maxlen) +int os_find_u_boot (char *fname,int maxlen,bool use_img) {struct sandbox_state *state =state_get_current ();const char *progname = state->argv[0 ];
@@ -753,8 +753,8 @@ int os_find_u_boot(char *fname, int maxlen)return 0 ; } -/* Look for 'u-boot-tpl' in the tpl/ directory */ - p =strstr (fname,"/tpl/" ); +/* Look for 'u-boot-spl' in the spl/ directory */ + p =strstr (fname,"/spl/" );if (p) { p[1 ] ='s' ; fd =os_open (fname,O_RDONLY );
@@ -781,6 +781,8 @@ int os_find_u_boot(char *fname, int maxlen)if (p) {/* Remove the "spl" characters */ memmove (p, p +4 ,strlen (p +4 ) +1 ); +if (use_img) +strcat (p,".img" ); fd =os_open (fname,O_RDONLY );if (fd >=0 ) {close (fd);
arch/sandbox/cpu/spl.c +1 -1
@@ -36,7 +36,7 @@ static int spl_board_load_image(struct spl_image_info *spl_image,char fname[256 ];int ret; - ret =os_find_u_boot (fname,sizeof (fname)); + ret =os_find_u_boot (fname,sizeof (fname), false);if (ret) {printf ("(%s not found, error %d)\n" , fname, ret);return ret;
include/os.h +2 -1
@@ -313,9 +313,10 @@ int os_jump_to_image(const void *dest, int size);* * @fname: place to put full path to U-Boot * @maxlen: maximum size of @fname +* @use_img: select the 'u-boot.img' file instead of the 'u-boot' ELF file * Return: 0 if OK, -NOSPC if the filename is too large, -ENOENT if not found */ -int os_find_u_boot (char *fname,int maxlen); +int os_find_u_boot (char *fname,int maxlen,bool use_img);/** * os_spl_to_uboot() - Run U-Boot proper
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 37/41 spl: Convert spl_fit to work with sandbox
In reply to Simon GlassAt present this casts addresses to pointers so cannot work with sandbox. Update the code to use map_sysmem() instead.
As part of this change, the existing load_ptr is renamed to src_ptr since it is not a pointer to load_addr. It is confusing to use a similar name for something that is not actually related. For the alignment code, ALIGN() is used instead of open-coded alignment. Add a comment to the line that casts away a const.
Use a (new) load_ptr variable to access memory at address load_addr.
---
(no changes since v1)
common/spl/spl.c | 3 ++- common/spl/spl_fit.c | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-)
common/spl/spl.c +2 -1
@@ -16,6 +16,7 @@#include <init.h> #include <irq_func.h> #include <log.h> +#include <mapmem.h> #include <serial.h> #include <spl.h> #include <asm/u-boot.h>
@@ -167,7 +168,7 @@ __weak void spl_board_prepare_for_boot(void)__weak struct image_header *spl_get_load_buffer (ssize_t offset,size_t size) { -return (struct image_header *)(CONFIG_SYS_TEXT_BASE + offset); +return map_sysmem (CONFIG_SYS_TEXT_BASE + offset,0 ); }void spl_set_header_raw_uboot (struct spl_image_info *spl_image)
common/spl/spl_fit.c +15 -12
@@ -11,6 +11,7 @@#include <image.h> #include <log.h> #include <malloc.h> +#include <mapmem.h> #include <spl.h> #include <sysinfo.h> #include <asm/cache.h>
@@ -245,11 +246,11 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,size_t length;int len;ulong size; -ulong load_addr, load_ptr; +ulong load_addr; +void *load_ptr;void *src;ulong overhead;int nr_sectors; -int align_len =ARCH_DMA_MINALIGN -1 ;uint8_t image_comp =-1 , type =-1 ;const void *data;bool external_data = false;
@@ -278,11 +279,13 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector, }if (external_data) { +void *src_ptr; +/* External data */ if (fit_image_get_data_size (fit, node, &len))return -ENOENT ; - load_ptr = (load_addr + align_len) & ~align_len; + src_ptr =map_sysmem (ALIGN (load_addr,ARCH_DMA_MINALIGN ), len); length = len; overhead =get_aligned_image_overhead (info, offset);
@@ -290,12 +293,12 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,if (info->read (info, sector +get_aligned_image_offset (info, offset), - nr_sectors, (void *)load_ptr) != nr_sectors) + nr_sectors, src_ptr) != nr_sectors)return -EIO ; -debug ("External data: dst=%lx, offset=%x, size=%lx\n" , - load_ptr, offset, (unsigned long )length); - src = (void *)load_ptr + overhead; +debug ("External data: dst=%p, offset=%x, size=%lx\n" , + src_ptr, offset, (unsigned long )length); + src = src_ptr + overhead; }else {/* Embedded data */ if (fit_image_get_data (fit, node, &data, &length)) {
@@ -304,7 +307,7 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector, }debug ("Embedded data: dst=%lx, size=%lx\n" , load_addr, (unsigned long )length); - src = (void *)data; + src = (void *)data;/* cast away const */ }#ifdef CONFIG_SPL_FIT_SIGNATURE
@@ -320,16 +323,16 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,board_fit_image_post_process (&src, &length);#endif + load_ptr =map_sysmem (load_addr, length);if (IS_ENABLED (CONFIG_SPL_GZIP ) && image_comp ==IH_COMP_GZIP ) { size = length; -if (gunzip ((void *)load_addr,CONFIG_SYS_BOOTM_LEN , - src, &size)) { +if (gunzip (load_ptr,CONFIG_SYS_BOOTM_LEN , src, &size)) {puts ("Uncompressing error\n" );return -EIO ; } length = size; }else { -memcpy ((void *)load_addr, src, length); +memcpy (load_ptr, src, length); }if (image_info) {
@@ -382,7 +385,7 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image, }/* Make the load-address of the FDT available for the SPL framework */ - spl_image->fdt_addr = (void *)image_info.load_addr; + spl_image->fdt_addr =map_sysmem (image_info.load_addr,0 );#if !CONFIG_IS_ENABLED (FIT_IMAGE_TINY )if (CONFIG_IS_ENABLED (LOAD_FIT_APPLY_OVERLAY )) {void *tmpbuffer =NULL ;
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 38/41 doc: Move coccinelle into its own section
In reply to Simon GlassThis tool has nothing to do with testing. Create a new section for 'refactoring' and move it into there. It is likely that other topics may fall under the same heading, such as using moveconfig and search/replace tools.
---
(no changes since v1)
doc/develop/index.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
doc/develop/index.rst +8 -1
@@ -29,7 +29,14 @@ Testing .. toctree:: :maxdepth: 1 - coccinelle testing py_testing tests_sandbox + +Refactoring +----------- + +.. toctree:: + :maxdepth: 1 + + coccinelle
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 39/41 spl: test: Add a test for spl_load_simple_fit()
In reply to Simon GlassAs an example of an SPL test, add a new test for loading a FIT within SPL. This runs on sandbox_spl. For this to work, the text base is adjusted so that there is plenty of space available.
While we are here, document struct spl_load_info properly, since this is currently ambiguous.
This test only verifies the logic path. It does not actually check that the image is loaded correctly. It is not possible for sandbox's SPL to actually run u-boot.img since it currently includes u-boot.bin rather than u-boot. Further work could expand the test in that direction.
The need for this was noted at:
http://patchwork.ozlabs.org/project/uboot/patch/20201216000944.2832585-3-mr.nuke.me at gmail.com/
---
(no changes since v1)
configs/sandbox_spl_defconfig | 2 +- doc/arch/sandbox.rst | 4 +- include/spl.h | 9 ++++ test/Makefile | 1 + test/image/Makefile | 5 ++ test/image/spl_load.c | 91 +++++++++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 test/image/Makefile create mode 100644 test/image/spl_load.c
configs/sandbox_spl_defconfig +1 -1
@@ -1,4 +1,4 @@ -CONFIG_SYS_TEXT_BASE=0 +CONFIG_SYS_TEXT_BASE=0x200000 CONFIG_SPL_LIBCOMMON_SUPPORT=y CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_NR_DRAM_BANKS=1
doc/arch/sandbox.rst +3 -1
@@ -537,5 +537,7 @@ Addr Config Usage e000 CONFIG_BLOBLIST_ADDR Blob list 10000 CONFIG_MALLOC_F_ADDR Early memory allocation f0000 CONFIG_PRE_CON_BUF_ADDR Pre-console buffer - 100000 CONFIG_TRACE_EARLY_ADDR Early trace buffer (if enabled) + 100000 CONFIG_TRACE_EARLY_ADDR Early trace buffer (if enabled). Also used + as the SPL load buffer in spl_test_load(). + 200000 CONFIG_SYS_TEXT_BASE Load buffer for U-Boot (sandbox_spl only) ======= ======================== ===============================
include/spl.h +9 -0
@@ -222,6 +222,15 @@ struct spl_load_info {void *priv;int bl_len;const char *filename; +/** +* read() - Read from device +* +* @load: Information about the load state +* @sector: Sector number to read from (each @load->bl_len bytes) +* @count: Number of sectors to read +* @buf: Buffer to read into +* @return number of sectors read, 0 on error +*/ ulong (*read)(struct spl_load_info *load,ulong sector,ulong count,void *buf); };
test/Makefile +1 -0
@@ -3,6 +3,7 @@ # (C) Copyright 2012 The Chromium Authors obj-y += test-main.o +obj-$(CONFIG_SANDBOX) += image/ ifneq ($(CONFIG_$(SPL_)BLOBLIST),) obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o
test/image/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2021 Google LLC + +obj-$(CONFIG_SPL_BUILD) += spl_load.o
test/image/spl_load.c new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 40/41 test: sandbox: Move sandbox test docs into doc/develop
In reply to Simon GlassAt present some of the documentation about running sandbox tests is in the sandbox docs. It makes more sense to put it in with the other testing docs, with a link there from sandbox. Update the documentation accordingly.
Also add a paragraph explaining why sandbox exists and the test philosophy that it uses.
---
(no changes since v1)
doc/arch/sandbox.rst | 44 +++++++---------------------------- doc/develop/tests_sandbox.rst | 44 +++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 37 deletions(-)
doc/arch/sandbox.rst +9 -35
@@ -17,6 +17,12 @@ of the sandbox U-Boot. The purpose of running U-Boot under Linux is to test all the generic code, not specific to any one architecture. The idea is to create unit tests which we can run to test this upper level code. +Sandbox allows development of many types of new features in a traditional way, +rather than needing to test each iteration on real hardware. Many U-Boot +features were developed on sandbox, including the core driver model, most +uclasses, verified boot, bloblist, logging and dozens of others. Sandbox has +enabled many large-scale code refactors as well. + CONFIG_SANDBOX is defined when building a native board. The board name is 'sandbox' but the vendor name is unset, so there is a
@@ -486,42 +492,10 @@ Testing ------- U-Boot sandbox can be used to run various tests, mostly in the test/ -directory. These include: - -command_ut: - Unit tests for command parsing and handling -compression: - Unit tests for U-Boot's compression algorithms, useful for - security checking. It supports gzip, bzip2, lzma and lzo. -driver model: - Run this pytest:: - - ./test/py/test.py --bd sandbox --build -k ut_dm -v - -image: - Unit tests for images: - test/image/test-imagetools.sh - multi-file images - test/image/test-fit.py - FIT images -tracing: - test/trace/test-trace.sh tests the tracing system (see README.trace) -verified boot: - See test/vboot/vboot_test.sh for this - -If you change or enhance any of the above subsystems, you shold write or -expand a test and include it with your patch series submission. Test -coverage in U-Boot is limited, as we need to work to improve it. - -Note that many of these tests are implemented as commands which you can -run natively on your board if desired (and enabled). - -To run all tests use "make check". - -To run a single test in an existing sandbox build, you can use -T to use the -test device tree, and -c to select the test: - - /tmp/b/sandbox/u-boot -T -c "ut dm pci_busdev" +directory. -This runs dm_test_pci_busdev() which is in test/dm/pci.c +See :doc:`../develop/tests_sandbox` for more information and +:doc:`../develop/testing` for information about testing generally. Memory Map
doc/develop/tests_sandbox.rst +42 -2
49 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 41/41 doc: Explain briefly how to write new tests
In reply to Simon GlassAdd a second on writing tests, covering when to use Python and C, where to put the tests, etc. Add a link to the existing Python test documentation.
---
(no changes since v2)
Changes in v2:
- Add new patches to cover running an SPL test
doc/develop/index.rst | 1 + doc/develop/py_testing.rst | 3 +- doc/develop/testing.rst | 2 + doc/develop/tests_sandbox.rst | 7 + doc/develop/tests_writing.rst | 337 ++++++++++++++++++++++++++++++++++ 5 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 doc/develop/tests_writing.rst
doc/develop/index.rst +1 -0
@@ -31,6 +31,7 @@ Testing testing py_testing + tests_writing tests_sandbox Refactoring
doc/develop/py_testing.rst +2 -1
@@ -13,7 +13,8 @@ results. Advantages of this approach are: U-Boot; there can be no disconnect. - There is no need to write or embed test-related code into U-Boot itself. It is asserted that writing test-related code in Python is simpler and more - flexible than writing it all in C. + flexible than writing it all in C. But see :doc:`tests_writing` for caveats + and more discussion / analysis. - It is reasonably simple to interact with U-Boot in this way. Requirements
doc/develop/testing.rst +2 -0
@@ -117,6 +117,8 @@ or is covered sparingly. So here are some suggestions: is much easier to add onto a test - writing a new large test can seem daunting to most contributors. +See doc:`tests_writing` for how to write tests. + Future work -----------
doc/develop/tests_sandbox.rst +7 -0
@@ -198,3 +198,10 @@ linker_list:: 000000000001f240 D _u_boot_list_2_dm_test_2_dm_test_of_plat_parent 000000000001f260 D _u_boot_list_2_dm_test_2_dm_test_of_plat_phandle 000000000001f280 D _u_boot_list_2_dm_test_2_dm_test_of_plat_props + + +Writing tests +------------- + +See :doc:`tests_writing` for how to write new tests. +
doc/develop/tests_writing.rst new file +337 -0
337 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
v3 cover test: Refactor tests to have a single test runner
In reply to Simon GlassQuoted 35 lines · Simon Glass
At present U-Boot has two broad sets of tests in the C code: driver model tests which do a lot of pre-/post-init and command tests which do not.
This separation makes it slightly harder to write a test, since there are two different test-state structures and different rules for running the two different test types. At present these rules are determined by where the test is (actually its prefix).
All unit tests can be run from the command line with the 'ut' command. Since SPL does not have commands, it currently calls the test runner directly and offers no control of which tests are run.
This seems like a good time to refactor the tests into a unified test runner, allowing U-Boot proper and SPL to use the same path, perhaps with some different conditions along the way.
This series sets up a unified runner called
ut_run_list(), which runs a set of tests from alinker_list. Driver model tests are distinguished by a newUT_TESTF_DMflag so that the necessary init and cleanup can still be done.The runner is modified to support running SPL tests that are not solely for driver model. An example test for FIT loading is added as a demonstration.
In addition, some documentation is added to explain how to write tests.
This series is available at u-boot-dm/test-working
Changes in v3:
- Add new patch to re-enabletest_ofplatdata
- Reword the SPL tests section for clarity
- Usetest_set_state()throughouttest-main.cinstead of direct assignment
- Update the pytest collector as well
Quoted 11 lines
Changes in v2:
- Use correct rst format for 'Ad-hoc tests' section
- Expand docs on how each type of test is marked
- Put the docs intests_sandboxsince it is more related to sandbox
- Put in a mention oftests_sandboxin the main testing docs
- Add a note that SPL tests can in fact be run individualy
- Document how to run all C tests with 'ut all'
- Fix 'get list' typo
- Fix conditions so non-DM SPL tests are actually run
- Allow for prefix to be NULL, to match function comment
- Add new patches to cover running an SPL test
There was a small problem applying one or two of these patches that I fixed up. But then when testing locally (Ubuntu 18.04, but virtualenv setup and populated with test/py/requirements.txt) like 200 tests failed to run for Sandbox. Please check this and that CI runs.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/f9c2baca/attachment.sig>
v3 cover test: Refactor tests to have a single test runner
Quoted 49 lines · Tom Rini
Quoted 35 lines · Simon Glass
At present U-Boot has two broad sets of tests in the C code: driver model tests which do a lot of pre-/post-init and command tests which do not.
This separation makes it slightly harder to write a test, since there are two different test-state structures and different rules for running the two different test types. At present these rules are determined by where the test is (actually its prefix).
All unit tests can be run from the command line with the 'ut' command. Since SPL does not have commands, it currently calls the test runner directly and offers no control of which tests are run.
This seems like a good time to refactor the tests into a unified test runner, allowing U-Boot proper and SPL to use the same path, perhaps with some different conditions along the way.
This series sets up a unified runner called
ut_run_list(), which runs a set of tests from alinker_list. Driver model tests are distinguished by a newUT_TESTF_DMflag so that the necessary init and cleanup can still be done.The runner is modified to support running SPL tests that are not solely for driver model. An example test for FIT loading is added as a demonstration.
In addition, some documentation is added to explain how to write tests.
This series is available at u-boot-dm/test-working
Changes in v3:
- Add new patch to re-enabletest_ofplatdata
- Reword the SPL tests section for clarity
- Usetest_set_state()throughouttest-main.cinstead of direct assignment
- Update the pytest collector as wellQuoted 11 lines
Changes in v2:
- Use correct rst format for 'Ad-hoc tests' section
- Expand docs on how each type of test is marked
- Put the docs intests_sandboxsince it is more related to sandbox
- Put in a mention oftests_sandboxin the main testing docs
- Add a note that SPL tests can in fact be run individualy
- Document how to run all C tests with 'ut all'
- Fix 'get list' typo
- Fix conditions so non-DM SPL tests are actually run
- Allow for prefix to be NULL, to match function comment
- Add new patches to cover running an SPL test
Quoted 4 lines
There was a small problem applying one or two of these patches that I fixed up. But then when testing locally (Ubuntu 18.04, but virtualenv setup and populated with
test/py/requirements.txt) like 200 tests failed to run for Sandbox. Please check this and that CI runs.
Er, something has gone odd for me locally, please disregard.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/06d8956b/attachment.sig>
v3 cover test: Refactor tests to have a single test runner
Quoted 50 lines · Tom Rini
Quoted 49 lines · Tom Rini
Quoted 46 lines · Simon Glass
At present U-Boot has two broad sets of tests in the C code: driver model tests which do a lot of pre-/post-init and command tests which do not.
This separation makes it slightly harder to write a test, since there are two different test-state structures and different rules for running the two different test types. At present these rules are determined by where the test is (actually its prefix).
All unit tests can be run from the command line with the 'ut' command. Since SPL does not have commands, it currently calls the test runner directly and offers no control of which tests are run.
This seems like a good time to refactor the tests into a unified test runner, allowing U-Boot proper and SPL to use the same path, perhaps with some different conditions along the way.
This series sets up a unified runner called
ut_run_list(), which runs a set of tests from alinker_list. Driver model tests are distinguished by a newUT_TESTF_DMflag so that the necessary init and cleanup can still be done.The runner is modified to support running SPL tests that are not solely for driver model. An example test for FIT loading is added as a demonstration.
In addition, some documentation is added to explain how to write tests.
This series is available at u-boot-dm/test-working
Changes in v3:
- Add new patch to re-enabletest_ofplatdata
- Reword the SPL tests section for clarity
- Usetest_set_state()throughouttest-main.cinstead of direct assignment
- Update the pytest collector as wellChanges in v2:
- Use correct rst format for 'Ad-hoc tests' section
- Expand docs on how each type of test is marked
- Put the docs intests_sandboxsince it is more related to sandbox
- Put in a mention oftests_sandboxin the main testing docs
- Add a note that SPL tests can in fact be run individualy
- Document how to run all C tests with 'ut all'
- Fix 'get list' typo
- Fix conditions so non-DM SPL tests are actually run
- Allow for prefix to be NULL, to match function comment
- Add new patches to cover running an SPL test
Quoted 6 lines
Quoted 4 lines
There was a small problem applying one or two of these patches that I fixed up. But then when testing locally (Ubuntu 18.04, but virtualenv setup and populated with
test/py/requirements.txt) like 200 tests failed to run for Sandbox. Please check this and that CI runs.Er, something has gone odd for me locally, please disregard.
Two problems! One, this series IS breaking tests for me. Fresh venv, ~260 tests fail to run. Two, I didn't notice a fail-to-build in my build+pytest script, so the binary from this really really failed with the current pytest scripts :)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/7885fbee/attachment.sig>
v3 cover test: Refactor tests to have a single test runner
Hi Tom,
Quoted 57 lines · Tom Rini
Quoted 55 lines · Tom Rini
Quoted 53 lines · Tom Rini
Quoted 35 lines · Simon Glass
At present U-Boot has two broad sets of tests in the C code: driver model tests which do a lot of pre-/post-init and command tests which do not.
This separation makes it slightly harder to write a test, since there are two different test-state structures and different rules for running the two different test types. At present these rules are determined by where the test is (actually its prefix).
All unit tests can be run from the command line with the 'ut' command. Since SPL does not have commands, it currently calls the test runner directly and offers no control of which tests are run.
This seems like a good time to refactor the tests into a unified test runner, allowing U-Boot proper and SPL to use the same path, perhaps with some different conditions along the way.
This series sets up a unified runner called
ut_run_list(), which runs a set of tests from alinker_list. Driver model tests are distinguished by a newUT_TESTF_DMflag so that the necessary init and cleanup can still be done.The runner is modified to support running SPL tests that are not solely for driver model. An example test for FIT loading is added as a demonstration.
In addition, some documentation is added to explain how to write tests.
This series is available at u-boot-dm/test-working
Changes in v3:
- Add new patch to re-enabletest_ofplatdata
- Reword the SPL tests section for clarity
- Usetest_set_state()throughouttest-main.cinstead of direct assignment
- Update the pytest collector as wellQuoted 11 lines
Changes in v2:
- Use correct rst format for 'Ad-hoc tests' section
- Expand docs on how each type of test is marked
- Put the docs intests_sandboxsince it is more related to sandbox
- Put in a mention oftests_sandboxin the main testing docs
- Add a note that SPL tests can in fact be run individualy
- Document how to run all C tests with 'ut all'
- Fix 'get list' typo
- Fix conditions so non-DM SPL tests are actually run
- Allow for prefix to be NULL, to match function comment
- Add new patches to cover running an SPL testThere was a small problem applying one or two of these patches that I fixed up. But then when testing locally (Ubuntu 18.04, but virtualenv setup and populated with
test/py/requirements.txt) like 200 tests failed to run for Sandbox. Please check this and that CI runs.
Quoted 6 lines
Quoted 1 line
Er, something has gone odd for me locally, please disregard.
Two problems! One, this series IS breaking tests for me. Fresh venv, ~260 tests fail to run. Two, I didn't notice a fail-to-build in my build+pytest script, so the binary from this really really failed with the current pytest scripts :)
Sorry about that...it needs a fix which I had already brought into dm/master when I was intending for this series to go to the current release, but have not sent a pull request for. They are in dm/master now too and I'll send a pull request for master (that you should also apply to -next).
http://patchwork.ozlabs.org/project/uboot/patch/20210204042944.2636812-1-sjg at chromium.org/? ?
Basically there is a crash in sandbox_spl in a rather obscure case with of-platdata. Finding that was one of the fruits of adding the SPL tests.
Regards,
Simon