All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/30] test: Refactor tests to have a single test runner
@ 2021-01-28 15:11 Simon Glass
  2021-01-28 15:11 ` [PATCH 01/30] doc: Tidy up testing section Simon Glass
                   ` (29 more replies)
  0 siblings, 30 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

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.

This should make it easier to add SPL tests. A future series may tweak
those as well.

This series is available at u-boot-dm/test-working



Simon Glass (30):
  doc: Tidy up testing section
  doc: Document make tcheck
  sandbox: Drop the 'starting...' message unless testing
  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()

 arch/sandbox/cpu/spl.c           |   2 +-
 arch/sandbox/cpu/start.c         |  15 +-
 arch/sandbox/include/asm/state.h |   1 +
 doc/develop/index.rst            |   1 +
 doc/develop/testing.rst          |  34 ++-
 doc/develop/tests_under.rst      | 138 ++++++++++
 include/dm/test.h                |  20 +-
 include/test/test.h              |  18 +-
 include/test/ut.h                |  45 ++++
 test/Makefile                    |   2 +
 test/cmd/setexpr.c               |  23 +-
 test/cmd_ut.c                    |  38 +--
 test/dm/Makefile                 |   2 +-
 test/dm/core.c                   |  47 ++--
 test/dm/test-dm.c                |  41 +++
 test/dm/test-driver.c            |  12 +-
 test/dm/test-main.c              | 229 -----------------
 test/dm/test-uclass.c            |  10 +-
 test/py/tests/test_log.py        |   2 +-
 test/test-main.c                 | 416 +++++++++++++++++++++++++++++++
 test/ut.c                        |   7 +
 21 files changed, 767 insertions(+), 336 deletions(-)
 create mode 100644 doc/develop/tests_under.rst
 create mode 100644 test/dm/test-dm.c
 delete mode 100644 test/dm/test-main.c
 create mode 100644 test/test-main.c

-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH 01/30] doc: Tidy up testing section
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 16:18   ` Heinrich Schuchardt
  2021-01-28 15:11 ` [PATCH 02/30] doc: Document make tcheck Simon Glass
                   ` (28 subsequent siblings)
  29 siblings, 1 reply; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Tweak this so the output looks a little better.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/develop/testing.rst | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/doc/develop/testing.rst b/doc/develop/testing.rst
index 4bc9ca3a6ae..7a395ee9d83 100644
--- a/doc/develop/testing.rst
+++ b/doc/develop/testing.rst
@@ -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,11 @@ 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.
 
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 02/30] doc: Document make tcheck
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
  2021-01-28 15:11 ` [PATCH 01/30] doc: Tidy up testing section Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 16:22   ` Heinrich Schuchardt
  2021-01-28 15:11 ` [PATCH 03/30] sandbox: Drop the 'starting...' message unless testing Simon Glass
                   ` (27 subsequent siblings)
  29 siblings, 1 reply; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Add a comment about this option in the documentation. Also mention the
script that runs these combinations.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/develop/testing.rst | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/doc/develop/testing.rst b/doc/develop/testing.rst
index 7a395ee9d83..a2a2c276374 100644
--- a/doc/develop/testing.rst
+++ b/doc/develop/testing.rst
@@ -19,6 +19,12 @@ Some tests take ages to run. To run just the quick ones, type this::
 
     make qcheck
 
+To run just the tests for tools (patman, binman, etc.), type this::
+
+    make tcheck
+
+All of the above use the test/run script with a paremeter to select which tests
+are run.
 
 Sandbox
 -------
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 03/30] sandbox: Drop the 'starting...' message unless testing
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
  2021-01-28 15:11 ` [PATCH 01/30] doc: Tidy up testing section Simon Glass
  2021-01-28 15:11 ` [PATCH 02/30] doc: Document make tcheck Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 04/30] doc: Explain how to run tests without pytest Simon Glass
                   ` (26 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

This 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 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(-)

diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 25425809747..dc7797ae109 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -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);
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index bca13069824..d0e7fdbd5b0 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -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.
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
index f889120f2b3..e2955ab0770 100644
--- a/test/py/tests/test_log.py
+++ b/test/py/tests/test_log.py
@@ -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)
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 04/30] doc: Explain how to run tests without pytest
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (2 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 03/30] sandbox: Drop the 'starting...' message unless testing Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 05/30] doc: Document how sandbox_spl_tests are run Simon Glass
                   ` (25 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Add 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/develop/index.rst       |  1 +
 doc/develop/testing.rst     |  6 +++
 doc/develop/tests_under.rst | 79 +++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+)
 create mode 100644 doc/develop/tests_under.rst

diff --git a/doc/develop/index.rst b/doc/develop/index.rst
index beaa64d8d90..cc930c9add4 100644
--- a/doc/develop/index.rst
+++ b/doc/develop/index.rst
@@ -32,3 +32,4 @@ Testing
    coccinelle
    testing
    py_testing
+   tests_under
diff --git a/doc/develop/testing.rst b/doc/develop/testing.rst
index a2a2c276374..593ca50de36 100644
--- a/doc/develop/testing.rst
+++ b/doc/develop/testing.rst
@@ -47,6 +47,12 @@ 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.
 
 
diff --git a/doc/develop/tests_under.rst b/doc/develop/tests_under.rst
new file mode 100644
index 00000000000..85bbd4f6734
--- /dev/null
+++ b/doc/develop/tests_under.rst
@@ -0,0 +1,79 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Tests Under the Hood
+====================
+
+Running sandbox tests directly
+------------------------------
+
+Typically tests are run using the pytest suite. This is easy and always gets
+things right.
+
+But it is also possible to run some sandbox tests directly. For example, this
+runs the dm_test_gpio() test which you can find in test/dm/gpio.c::
+
+   $ ./u-boot -T -c "ut dm gpio"
+
+
+   U-Boot 2021.01
+
+   Model: sandbox
+   DRAM:  128 MiB
+   WDT:   Started with servicing (60s timeout)
+   MMC:   mmc2: 2 (SD), mmc1: 1 (SD), mmc0: 0 (SD)
+   In:    serial
+   Out:   vidconsole
+   Err:   vidconsole
+   Model: sandbox
+   SCSI:
+   Net:   eth0: eth at 10002000, eth5: eth at 10003000, eth3: sbe5, eth6: eth at 10004000
+   Test: dm_test_gpio: gpio.c
+   Test: dm_test_gpio: gpio.c (flat tree)
+   Failures: 0
+
+The -T option tells U-Boot to run with the 'test' devicetree (test.dts) instead
+of -D which selects the normal sandbox.dts - this is necessary because many
+tests rely on things in the test devicetree. If you try running tests without
+-T then you may see failures, like::
+
+   $ ./u-boot -c "ut dm gpio"
+
+
+   U-Boot 2021.01
+
+   DRAM:  128 MiB
+   WDT:   Not found!
+   MMC:
+   In:    serial
+   Out:   serial
+   Err:   serial
+   SCSI:
+   Net:   No ethernet found.
+   Please run with test device tree:
+       ./u-boot -d arch/sandbox/dts/test.dtb
+   Test: dm_test_gpio: gpio.c
+   test/dm/gpio.c:37, dm_test_gpio(): 0 == gpio_lookup_name("b4", &dev, &offset, &gpio): Expected 0x0 (0), got 0xffffffea (-22)
+   Test: dm_test_gpio: gpio.c (flat tree)
+   test/dm/gpio.c:37, dm_test_gpio(): 0 == gpio_lookup_name("b4", &dev, &offset, &gpio): Expected 0x0 (0), got 0xffffffea (-22)
+   Failures: 2
+
+The message above should provide a hint if you forget. Even running with -D
+will produce different results.
+
+You can easily use gdb on these tests, without needing --gdbserver::
+
+   $ gdb u-boot --args -T -c "ut dm gpio"
+   ...
+   (gdb) break dm_test_gpio
+   Breakpoint 1 at 0x1415bd: file test/dm/gpio.c, line 37.
+   (gdb) run -T -c "ut dm gpio"
+   Starting program: u-boot -T -c "ut dm gpio"
+   Test: dm_test_gpio: gpio.c
+
+   Breakpoint 1, dm_test_gpio (uts=0x5555558029a0 <global_dm_test_state>)
+       at files/test/dm/gpio.c:37
+   37		ut_assertok(gpio_lookup_name("b4", &dev, &offset, &gpio));
+   (gdb)
+
+You can then single-step and look at variables as needed.
+
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 05/30] doc: Document how sandbox_spl_tests are run
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (3 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 04/30] doc: Explain how to run tests without pytest Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 16:33   ` Heinrich Schuchardt
  2021-01-28 15:11 ` [PATCH 06/30] test: Correct setexpr test prefix Simon Glass
                   ` (24 subsequent siblings)
  29 siblings, 1 reply; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Add a few notes about the sandbox_spl tests, since they are special.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/develop/testing.rst     |  5 ++++
 doc/develop/tests_under.rst | 59 +++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/doc/develop/testing.rst b/doc/develop/testing.rst
index 593ca50de36..46e8d20322f 100644
--- a/doc/develop/testing.rst
+++ b/doc/develop/testing.rst
@@ -53,6 +53,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.
 
 
diff --git a/doc/develop/tests_under.rst b/doc/develop/tests_under.rst
index 85bbd4f6734..ca9003f18bd 100644
--- a/doc/develop/tests_under.rst
+++ b/doc/develop/tests_under.rst
@@ -77,3 +77,62 @@ 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 run in the SPL phase, if the -u flag is given.
+There is no way to select which tests run: all of them are run::
+
+   ./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
+
+
+   U-Boot 2021.01-00723-g43c77b51be5-dirty (Jan 24 2021 - 16:38:24 -0700)
+
+   DRAM:  128 MiB
+   ...
+
+
+Note that after running, SPL continues to boot into U-Boot proper. You can add
+'-c exit' to make U-Boot quit without doing anything further. It is not
+currently possible to run SPL tests and then stop, since the pytests require
+that U-Boot produces the expected banner.
+
+Of course you can use gdb with sandbox_spl, just as with sandbox.
+
+
+What tests are built in?
+------------------------
+
+Whatever sandbox build is used, which tests are present is determined by which
+source files are built. For sandbox_spl, the of_platdata tests are built
+because of the build rule in test/dm/Makefile::
+
+   ifeq ($(CONFIG_SPL_BUILD),y)
+   obj-$(CONFIG_SPL_OF_PLATDATA) += of_platdata.o
+   else
+   ...other tests for non-spl
+   endif
+
+You can get list of tests in a U-Boot ELF file by looking for the linker_list::
+
+   nm /tmp/b/sandbox_spl/spl/u-boot-spl |grep 2_dm_test
+   000000000001f200 D _u_boot_list_2_dm_test_2_dm_test_of_plat_base
+   000000000001f220 D _u_boot_list_2_dm_test_2_dm_test_of_plat_dev
+   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
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 06/30] test: Correct setexpr test prefix
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (4 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 05/30] doc: Document how sandbox_spl_tests are run Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 07/30] test: Mark all driver model tests with a flag Simon Glass
                   ` (23 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

This 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().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/cmd/setexpr.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
index fd6d869c0ed..b483069ff0f 100644
--- a/test/cmd/setexpr.c
+++ b/test/cmd/setexpr.c
@@ -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);
 }
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 07/30] test: Mark all driver model tests with a flag
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (5 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 06/30] test: Correct setexpr test prefix Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 08/30] test: Rename test-main.c to test-dm.c Simon Glass
                   ` (22 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Add a flag for driver model tests, so we can do special processing for
them.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/dm/test.h   | 3 ++-
 include/test/test.h | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/dm/test.h b/include/dm/test.h
index 6ac6672cd6f..dfbc82c756d 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -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
diff --git a/include/test/test.h b/include/test/test.h
index 3fdaa2b5e51..27585507d8c 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -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),
 };
 
 /**
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 08/30] test: Rename test-main.c to test-dm.c
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (6 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 07/30] test: Mark all driver model tests with a flag Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 09/30] test: Add an overall test runner Simon Glass
                   ` (21 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

This is the main test function for driver model but not for other tests.
Rename the file and the function so this is clear.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 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%)

diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 9a77da15619..fa5055bb9fc 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -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 */
 	}
 }
diff --git a/include/test/test.h b/include/test/test.h
index 27585507d8c..d282cb2362d 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -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 */
diff --git a/test/dm/Makefile b/test/dm/Makefile
index afcabfacc1b..c2533e308df 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -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.
diff --git a/test/dm/test-main.c b/test/dm/test-dm.c
similarity index 98%
rename from test/dm/test-main.c
rename to test/dm/test-dm.c
index 69458d62c86..74e12bd8bcc 100644
--- a/test/dm/test-main.c
+++ b/test/dm/test-dm.c
@@ -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);
 }
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 09/30] test: Add an overall test runner
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (7 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 08/30] test: Rename test-main.c to test-dm.c Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 10/30] test: Create pre/post-run functions Simon Glass
                   ` (20 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Add 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 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

diff --git a/include/test/ut.h b/include/test/ut.h
index 17400c73ea9..88e75ab791c 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
diff --git a/test/Makefile b/test/Makefile
index 3c7bc8b549f..5c978b9fa07 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -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
 endif
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index fad1c899a4e..e698cd35495 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -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[] = {
diff --git a/test/test-main.c b/test/test-main.c
new file mode 100644
index 00000000000..376e7ebd3d2
--- /dev/null
+++ b/test/test-main.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <console.h>
+#include <test/test.h>
+
+int ut_run_tests(struct unit_test_state *uts, const char *prefix,
+		 struct unit_test *tests, int count, const char *select_name)
+{
+	struct unit_test *test;
+	int prefix_len = prefix ? strlen(prefix) : 0;
+	int found = 0;
+
+	for (test = tests; test < tests + count; test++) {
+		const char *test_name = test->name;
+
+		/* Remove the prefix */
+		if (prefix && !strncmp(test_name, prefix, prefix_len))
+			test_name += prefix_len;
+
+		if (select_name && strcmp(select_name, test_name))
+			continue;
+		printf("Test: %s\n", test_name);
+		found++;
+
+		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);
+	}
+	if (select_name && !found)
+		return -ENOENT;
+
+	return uts->fail_count ? -EBADF : 0;
+}
+
+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 };
+	int ret;
+
+	if (!select_name)
+		printf("Running %d %s tests\n", count, category);
+
+	ret = ut_run_tests(&uts, prefix, tests, count, select_name);
+
+	if (ret == -ENOENT)
+		printf("Test '%s' not found\n", select_name);
+	else
+		printf("Failures: %d\n", uts.fail_count);
+
+	return ret;
+}
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 10/30] test: Create pre/post-run functions
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (8 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 09/30] test: Add an overall test runner Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 11/30] test: Call test_pre/post_run() from driver model tests Simon Glass
                   ` (19 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Split out the test preparation into a separation function before
expanding it. Add a post-run function as well, currently empty.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/test/ut.h | 20 ++++++++++++++++++++
 test/test-main.c  | 41 +++++++++++++++++++++++++++++++----------
 2 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index 88e75ab791c..7cb5e10f3af 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
  *
diff --git a/test/test-main.c b/test/test-main.c
index 376e7ebd3d2..7961fd8aa3e 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -8,6 +8,27 @@
 #include <console.h>
 #include <test/test.h>
 
+int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
+{
+	uts->start = mallinfo();
+
+	if (test->flags & UT_TESTF_CONSOLE_REC) {
+		int ret = console_record_reset_enable();
+
+		if (ret) {
+			printf("Skipping: Console recording disabled\n");
+			return -EAGAIN;
+		}
+	}
+
+	return 0;
+}
+
+int test_post_run(struct unit_test_state *uts, struct unit_test *test)
+{
+	return 0;
+}
+
 int ut_run_tests(struct unit_test_state *uts, const char *prefix,
 		 struct unit_test *tests, int count, const char *select_name)
 {
@@ -17,6 +38,7 @@ int ut_run_tests(struct unit_test_state *uts, const char *prefix,
 
 	for (test = tests; test < tests + count; test++) {
 		const char *test_name = test->name;
+		int ret;
 
 		/* Remove the prefix */
 		if (prefix && !strncmp(test_name, prefix, prefix_len))
@@ -27,18 +49,17 @@ int ut_run_tests(struct unit_test_state *uts, const char *prefix,
 		printf("Test: %s\n", test_name);
 		found++;
 
-		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();
+		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;
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 11/30] test: Call test_pre/post_run() from driver model tests
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (9 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 10/30] test: Create pre/post-run functions Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 12/30] test: Move dm_extended_scan() to test_pre_run() Simon Glass
                   ` (18 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Ultimately 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/dm/test.h |  2 +-
 test/dm/test-dm.c | 10 +++++-----
 test/test-main.c  |  8 +++++++-
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/include/dm/test.h b/include/dm/test.h
index dfbc82c756d..c0b463cc0f1 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -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
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 74e12bd8bcc..3b1460327ad 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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);
 
diff --git a/test/test-main.c b/test/test-main.c
index 7961fd8aa3e..9c600094740 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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;
 }
 
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 12/30] test: Move dm_extended_scan() to test_pre_run()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (10 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 11/30] test: Call test_pre/post_run() from driver model tests Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 13/30] test: Move do_autoprobe() " Simon Glass
                   ` (17 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Move this step over to the pre-run function.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 3 ---
 test/test-main.c  | 7 +++++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 3b1460327ad..3f9ce3d6fa8 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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));
 
diff --git a/test/test-main.c b/test/test-main.c
index 9c600094740..a971fe0e9c8 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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();
 
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 13/30] test: Move do_autoprobe() to test_pre_run()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (11 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 12/30] test: Move dm_extended_scan() to test_pre_run() Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 14/30] test: Move dm_scan_plat() " Simon Glass
                   ` (16 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Move this step over to the pre-run function.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 17 -----------------
 test/test-main.c  | 18 ++++++++++++++++++
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 3f9ce3d6fa8..3f76a1dc2c2 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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));
 
diff --git a/test/test-main.c b/test/test-main.c
index a971fe0e9c8..bd2f08a2b42 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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));
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 14/30] test: Move dm_scan_plat() to test_pre_run()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (12 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 13/30] test: Move do_autoprobe() " Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 15/30] test: Drop mallinfo() work-around Simon Glass
                   ` (15 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

Move this step over to the pre-run function.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 2 --
 test/test-main.c  | 3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 3f76a1dc2c2..65b89dbb936 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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));
 
diff --git a/test/test-main.c b/test/test-main.c
index bd2f08a2b42..fe96d739dc4 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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));
 
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 15/30] test: Drop mallinfo() work-around
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (13 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 14/30] test: Move dm_scan_plat() " Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 16/30] test: Move console silencing to test_pre_run() Simon Glass
                   ` (14 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

This is not needed now. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 2 --
 test/test-main.c  | 4 +---
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 65b89dbb936..57785e503ff 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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)
diff --git a/test/test-main.c b/test/test-main.c
index fe96d739dc4..db0d82e36c3 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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));
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 16/30] test: Move console silencing to test_pre_run()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (14 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 15/30] test: Drop mallinfo() work-around Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 17/30] test: Move delay skipping " Simon Glass
                   ` (13 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

We 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 4 ----
 test/test-main.c  | 3 ++-
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 57785e503ff..3ffbc382358 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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));
diff --git a/test/test-main.c b/test/test-main.c
index db0d82e36c3..e273777b6e2 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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;
 }
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 17/30] test: Move delay skipping to test_pre_run()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (15 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 16/30] test: Move console silencing to test_pre_run() Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:11 ` [PATCH 18/30] test: Handle driver model reinit in test_pre_run() Simon Glass
                   ` (12 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

This allows delays to be skipped in sandbox tests. Move it to the
common pre-init function.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 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(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index 7cb5e10f3af..e5ec18e60b0 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
  *
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 3ffbc382358..398216b6c76 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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;
diff --git a/test/test-main.c b/test/test-main.c
index e273777b6e2..6f0d32f7e27 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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)
diff --git a/test/ut.c b/test/ut.c
index 44ed1ba2d31..e18d85e556c 100644
--- a/test/ut.c
+++ b/test/ut.c
@@ -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
+}
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 18/30] test: Handle driver model reinit in test_pre_run()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (16 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 17/30] test: Move delay skipping " Simon Glass
@ 2021-01-28 15:11 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 19/30] test: Drop struct dm_test_state Simon Glass
                   ` (11 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:11 UTC (permalink / raw)
  To: u-boot

For 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().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 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(-)

diff --git a/include/test/test.h b/include/test/test.h
index d282cb2362d..6997568cc07 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -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];
 };
diff --git a/include/test/ut.h b/include/test/ut.h
index e5ec18e60b0..6e56ca99c31 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
  *
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 398216b6c76..88feb6537f1 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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));
 
diff --git a/test/test-main.c b/test/test-main.c
index 6f0d32f7e27..f14b7b09f79 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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();
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 19/30] test: Drop struct dm_test_state
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (17 preceding siblings ...)
  2021-01-28 15:11 ` [PATCH 18/30] test: Handle driver model reinit in test_pre_run() Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 20/30] test: Move dm_test_init() into test-main.c Simon Glass
                   ` (10 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Driver 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 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(-)

diff --git a/include/dm/test.h b/include/dm/test.h
index c0b463cc0f1..fe1cc2e278c 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -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)
diff --git a/include/test/test.h b/include/test/test.h
index 6997568cc07..5eeec35f525 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -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];
 };
diff --git a/test/dm/core.c b/test/dm/core.c
index 1f5ca570dc7..f8e47591a13 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -108,14 +108,13 @@ int dm_leak_check_end(struct unit_test_state *uts)
 /* Test that binding with plat occurs correctly */
 static int dm_test_autobind(struct unit_test_state *uts)
 {
-	struct dm_test_state *dms = uts->priv;
 	struct udevice *dev;
 
 	/*
 	 * We should have a single class (UCLASS_ROOT) and a single root
 	 * device with no children.
 	 */
-	ut_assert(dms->root);
+	ut_assert(uts->root);
 	ut_asserteq(1, list_count_items(gd->uclass_root));
 	ut_asserteq(0, list_count_items(&gd->dm_root->child_head));
 	ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
@@ -198,7 +197,6 @@ DM_TEST(dm_test_autobind_uclass_pdata_valid, UT_TESTF_SCAN_PDATA);
 /* Test that autoprobe finds all the expected devices */
 static int dm_test_autoprobe(struct unit_test_state *uts)
 {
-	struct dm_test_state *dms = uts->priv;
 	int expected_base_add;
 	struct udevice *dev;
 	struct uclass *uc;
@@ -212,7 +210,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
 	ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]);
 
 	/* The root device should not be activated until needed */
-	ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED);
+	ut_assert(dev_get_flags(uts->root) & DM_FLAG_ACTIVATED);
 
 	/*
 	 * We should be able to find the three test devices, and they should
@@ -232,7 +230,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
 
 		/* Activating a device should activate the root device */
 		if (!i)
-			ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED);
+			ut_assert(dev_get_flags(uts->root) & DM_FLAG_ACTIVATED);
 	}
 
 	/*
@@ -284,7 +282,6 @@ DM_TEST(dm_test_plat, UT_TESTF_SCAN_PDATA);
 /* Test that we can bind, probe, remove, unbind a driver */
 static int dm_test_lifecycle(struct unit_test_state *uts)
 {
-	struct dm_test_state *dms = uts->priv;
 	int op_count[DM_TEST_OP_COUNT];
 	struct udevice *dev, *test_dev;
 	int pingret;
@@ -292,7 +289,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
 
 	memcpy(op_count, dm_testdrv_op_count, sizeof(op_count));
 
-	ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+	ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
 					&dev));
 	ut_assert(dev);
 	ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND]
@@ -300,7 +297,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
 	ut_assert(!dev_get_priv(dev));
 
 	/* Probe the device - it should fail allocating private data */
-	dms->force_fail_alloc = 1;
+	uts->force_fail_alloc = 1;
 	ret = device_probe(dev);
 	ut_assert(ret == -ENOMEM);
 	ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
@@ -308,7 +305,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
 	ut_assert(!dev_get_priv(dev));
 
 	/* Try again without the alloc failure */
-	dms->force_fail_alloc = 0;
+	uts->force_fail_alloc = 0;
 	ut_assertok(device_probe(dev));
 	ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
 			== op_count[DM_TEST_OP_PROBE] + 2);
@@ -340,19 +337,18 @@ DM_TEST(dm_test_lifecycle, UT_TESTF_SCAN_PDATA | UT_TESTF_PROBE_TEST);
 /* Test that we can bind/unbind and the lists update correctly */
 static int dm_test_ordering(struct unit_test_state *uts)
 {
-	struct dm_test_state *dms = uts->priv;
 	struct udevice *dev, *dev_penultimate, *dev_last, *test_dev;
 	int pingret;
 
-	ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+	ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
 					&dev));
 	ut_assert(dev);
 
 	/* Bind two new devices (numbers 4 and 5) */
-	ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+	ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
 					&dev_penultimate));
 	ut_assert(dev_penultimate);
-	ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+	ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
 					&dev_last));
 	ut_assert(dev_last);
 
@@ -367,7 +363,7 @@ static int dm_test_ordering(struct unit_test_state *uts)
 	ut_assert(dev_last == test_dev);
 
 	/* Add back the original device 3, now in position 5 */
-	ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+	ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
 					&dev));
 	ut_assert(dev);
 
@@ -559,7 +555,6 @@ static int create_children(struct unit_test_state *uts, struct udevice *parent,
 
 static int dm_test_children(struct unit_test_state *uts)
 {
-	struct dm_test_state *dms = uts->priv;
 	struct udevice *top[NODE_COUNT];
 	struct udevice *child[NODE_COUNT];
 	struct udevice *grandchild[NODE_COUNT];
@@ -569,12 +564,12 @@ static int dm_test_children(struct unit_test_state *uts)
 	int i;
 
 	/* We don't care about the numbering for this test */
-	dms->skip_post_probe = 1;
+	uts->skip_post_probe = 1;
 
 	ut_assert(NODE_COUNT > 5);
 
 	/* First create 10 top-level children */
-	ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top));
+	ut_assertok(create_children(uts, uts->root, NODE_COUNT, 0, top));
 
 	/* Now a few have their own children */
 	ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL));
@@ -645,7 +640,6 @@ DM_TEST(dm_test_children, 0);
 
 static int dm_test_device_reparent(struct unit_test_state *uts)
 {
-	struct dm_test_state *dms = uts->priv;
 	struct udevice *top[NODE_COUNT];
 	struct udevice *child[NODE_COUNT];
 	struct udevice *grandchild[NODE_COUNT];
@@ -655,12 +649,12 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	int i;
 
 	/* We don't care about the numbering for this test */
-	dms->skip_post_probe = 1;
+	uts->skip_post_probe = 1;
 
 	ut_assert(NODE_COUNT > 5);
 
 	/* First create 10 top-level children */
-	ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top));
+	ut_assertok(create_children(uts, uts->root, NODE_COUNT, 0, top));
 
 	/* Now a few have their own children */
 	ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL));
@@ -806,15 +800,14 @@ DM_TEST(dm_test_device_reparent, 0);
 /* Test that pre-relocation devices work as expected */
 static int dm_test_pre_reloc(struct unit_test_state *uts)
 {
-	struct dm_test_state *dms = uts->priv;
 	struct udevice *dev;
 
 	/* The normal driver should refuse to bind before relocation */
-	ut_asserteq(-EPERM, device_bind_by_name(dms->root, true,
+	ut_asserteq(-EPERM, device_bind_by_name(uts->root, true,
 						&driver_info_manual, &dev));
 
 	/* But this one is marked pre-reloc */
-	ut_assertok(device_bind_by_name(dms->root, true,
+	ut_assertok(device_bind_by_name(uts->root, true,
 					&driver_info_pre_reloc, &dev));
 
 	return 0;
@@ -827,10 +820,9 @@ DM_TEST(dm_test_pre_reloc, 0);
  */
 static int dm_test_remove_active_dma(struct unit_test_state *uts)
 {
-	struct dm_test_state *dms = uts->priv;
 	struct udevice *dev;
 
-	ut_assertok(device_bind_by_name(dms->root, false, &driver_info_act_dma,
+	ut_assertok(device_bind_by_name(uts->root, false, &driver_info_act_dma,
 					&dev));
 	ut_assert(dev);
 
@@ -863,7 +855,7 @@ static int dm_test_remove_active_dma(struct unit_test_state *uts)
 	 * the active DMA remove call
 	 */
 	ut_assertok(device_unbind(dev));
-	ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+	ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
 					&dev));
 	ut_assert(dev);
 
@@ -1038,11 +1030,10 @@ DM_TEST(dm_test_uclass_names, UT_TESTF_SCAN_PDATA);
 
 static int dm_test_inactive_child(struct unit_test_state *uts)
 {
-	struct dm_test_state *dms = uts->priv;
 	struct udevice *parent, *dev1, *dev2;
 
 	/* Skip the behaviour in test_post_probe() */
-	dms->skip_post_probe = 1;
+	uts->skip_post_probe = 1;
 
 	ut_assertok(uclass_first_device_err(UCLASS_TEST, &parent));
 
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 88feb6537f1..ad64f5bdcb3 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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)) {
diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c
index a67f5d3f982..49c1c310963 100644
--- a/test/dm/test-driver.c
+++ b/test/dm/test-driver.c
@@ -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;
diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c
index f1b7aaa727f..f4b540c9278 100644
--- a/test/dm/test-uclass.c
+++ b/test/dm/test-uclass.c
@@ -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
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 20/30] test: Move dm_test_init() into test-main.c
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (18 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 19/30] test: Drop struct dm_test_state Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 21/30] test: Move dm_test_destroy() " Simon Glass
                   ` (9 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Move this function into test-main so that all the init is in one place.
Rename it so that its purpose is clearer.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/test/ut.h |  9 ---------
 test/dm/test-dm.c | 22 ----------------------
 test/test-main.c  | 33 ++++++++++++++++++++++++++++++++-
 3 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index 6e56ca99c31..4e0aba9f700 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index ad64f5bdcb3..378c6506303 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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;
diff --git a/test/test-main.c b/test/test-main.c
index f14b7b09f79..8b0121bdcec 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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);
 
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 21/30] test: Move dm_test_destroy() into test-main.c
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (19 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 20/30] test: Move dm_test_init() into test-main.c Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 22/30] test: Move test running into a separate function Simon Glass
                   ` (8 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Move this function into the common test runner and rename it to
dm_test_post_run() so that its purpose is clear.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 22 ----------------------
 test/test-main.c  | 23 +++++++++++++++++++++++
 2 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 378c6506303..90da143bc51 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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;
 }
 
diff --git a/test/test-main.c b/test/test-main.c
index 8b0121bdcec..3806c2ad89c 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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;
 }
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 22/30] test: Move test running into a separate function
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (20 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 21/30] test: Move dm_test_destroy() " Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 23/30] test: Use ut_run_test() to run driver model tests Simon Glass
                   ` (7 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Add a function to handle the preparation for running a test and the
post-test clean-up.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/test/ut.h | 16 ++++++++++++++++
 test/test-main.c  | 32 +++++++++++++++++++++++---------
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index 4e0aba9f700..98f699cbba2 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
diff --git a/test/test-main.c b/test/test-main.c
index 3806c2ad89c..dee28d35d82 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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;
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 23/30] test: Use ut_run_test() to run driver model tests
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (21 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 22/30] test: Move test running into a separate function Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 24/30] test: Drop dm_do_test() Simon Glass
                   ` (6 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Instead 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

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/test/ut.h | 20 --------------------
 test/dm/test-dm.c | 11 +----------
 test/test-main.c  | 26 +++++++++++++++++++++++---
 3 files changed, 24 insertions(+), 33 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index 98f699cbba2..adef0b7e1cf 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
  *
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 90da143bc51..38505c2e7a0 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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;
 }
diff --git a/test/test-main.c b/test/test-main.c
index dee28d35d82..32c4d4b1996 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -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)
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 24/30] test: Drop dm_do_test()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (22 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 23/30] test: Use ut_run_test() to run driver model tests Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 25/30] test: Add ut_run_test_live_flat() to run tests twice Simon Glass
                   ` (5 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

In an effort to make use of a common test runner, use ut_run_test()
directly to run driver model tests.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 38505c2e7a0..3cb4d5c5035 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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++;
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 25/30] test: Add ut_run_test_live_flat() to run tests twice
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (23 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 24/30] test: Drop dm_do_test() Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 26/30] test: Use a local variable for test state Simon Glass
                   ` (4 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Driver 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/test/ut.h | 13 ++++++----
 test/dm/test-dm.c | 37 +-------------------------
 test/test-main.c  | 66 ++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 72 insertions(+), 44 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index adef0b7e1cf..d06bc5089be 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 3cb4d5c5035..48dca289de3 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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++;
 	}
 
diff --git a/test/test-main.c b/test/test-main.c
index 32c4d4b1996..2dc2ac02866 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -80,6 +80,21 @@ static int do_autoprobe(struct unit_test_state *uts)
 	return ret;
 }
 
+/*
+ * ut_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 ut_test_run_on_flattree(struct unit_test *test)
+{
+	const char *fname = strrchr(test->file, '/') + 1;
+
+	return !strstr(fname, "video") || strstr(test->name, "video_base");
+}
+
 /**
  * test_pre_run() - Handle any preparation needed to run a test
  *
@@ -137,8 +152,22 @@ static 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)
+/**
+ * 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_name: 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
+ */
+static 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 = "";
@@ -163,6 +192,37 @@ int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
 	return 0;
 }
 
+int ut_run_test_live_flat(struct unit_test_state *uts, struct unit_test *test,
+			  const char *name)
+{
+	int runs;
+
+	/* 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_DM) {
+		if (!(test->flags & UT_TESTF_LIVE_TREE) &&
+		    (!runs || ut_test_run_on_flattree(test))) {
+			uts->of_live = false;
+			ut_assertok(ut_run_test(uts, test, test->name));
+			runs++;
+		}
+	}
+
+	return 0;
+}
+
 int ut_run_tests(struct unit_test_state *uts, const char *prefix,
 		 struct unit_test *tests, int count, const char *select_name)
 {
@@ -180,7 +240,7 @@ int ut_run_tests(struct unit_test_state *uts, const char *prefix,
 
 		if (select_name && strcmp(select_name, test_name))
 			continue;
-		ret = ut_run_test(uts, test, test_name);
+		ret = ut_run_test_live_flat(uts, test, test_name);
 		found++;
 		if (ret == -EAGAIN)
 			continue;
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 26/30] test: Use a local variable for test state
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (24 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 25/30] test: Add ut_run_test_live_flat() to run tests twice Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 27/30] test: Run driver-model tests using ut_run_list() Simon Glass
                   ` (3 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

At 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 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      | 17 +++++++++++++++++
 5 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index d06bc5089be..bed0e6eb5f6 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
  *
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 48dca289de3..6f9906a510a 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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;
 
diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c
index 49c1c310963..ad2b44c405c 100644
--- a/test/dm/test-driver.c
+++ b/test/dm/test-driver.c
@@ -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)));
diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c
index f4b540c9278..067701734a0 100644
--- a/test/dm/test-uclass.c
+++ b/test/dm/test-uclass.c
@@ -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));
 
diff --git a/test/test-main.c b/test/test-main.c
index 2dc2ac02866..b911c669e54 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -16,6 +16,18 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+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
  *
@@ -177,6 +189,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 */
+	cur_test_state = uts;
+
 	ret = test_pre_run(uts, test);
 	if (ret == -EAGAIN)
 		return -EAGAIN;
@@ -189,6 +204,8 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
 	if (ret)
 		return ret;
 
+	cur_test_state = NULL;
+
 	return 0;
 }
 
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 27/30] test: Run driver-model tests using ut_run_list()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (25 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 26/30] test: Use a local variable for test state Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 28/30] test: Use return values in dm_test_run() Simon Glass
                   ` (2 subsequent siblings)
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Use this function instead of implementing it separately for driver model.

Make ut_run_tests() private since it is only used in test-main.c

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/test/ut.h | 42 -----------------------
 test/dm/test-dm.c | 45 +++---------------------
 test/test-main.c  | 87 +++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 81 insertions(+), 93 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index bed0e6eb5f6..fbbba286ee0 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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
  *
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 6f9906a510a..252c3e88328 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -19,31 +19,14 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static bool test_matches(const char *test_name, const char *find_name)
-{
-	if (!find_name)
-		return true;
-
-	if (!strcmp(test_name, find_name))
-		return true;
-
-	/* All tests have this prefix */
-	if (!strncmp(test_name, "dm_test_", 8))
-		test_name += 8;
-
-	if (!strcmp(test_name, find_name))
-		return true;
-
-	return false;
-}
+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 unit_test *test;
-	int found;
+	struct device_node *of_root;
 
 	uts->fail_count = 0;
 
@@ -59,29 +42,11 @@ int dm_test_run(const char *test_name)
 		}
 	}
 
-	if (!test_name)
-		printf("Running %d driver model tests\n", n_ents);
-	else
-
-	found = 0;
-	uts->of_root = gd_of_root();
-	for (test = tests; test < tests + n_ents; test++) {
-		const char *name = test->name;
-
-		if (!test_matches(name, test_name))
-			continue;
-
-		ut_assertok(ut_run_test_live_flat(uts, test, test->name));
-		found++;
-	}
-
-	if (test_name && !found)
-		printf("Test '%s' not found\n", test_name);
-	else
-		printf("Failures: %d\n", uts->fail_count);
+	of_root = gd_of_root();
+	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(uts->of_root);
+	gd_set_of_root(of_root);
 	gd->dm_root = NULL;
 	ut_assertok(dm_init(CONFIG_IS_ENABLED(OF_LIVE)));
 	dm_scan_plat(false);
diff --git a/test/test-main.c b/test/test-main.c
index b911c669e54..0f34f785098 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -107,6 +107,38 @@ static bool ut_test_run_on_flattree(struct unit_test *test)
 	return !strstr(fname, "video") || strstr(test->name, "video_base");
 }
 
+/**
+ * test_matches() - Check if a test should be run
+ *
+ * This checks if the a test should be run. In the normal case of running all
+ * tests, @select_name is NULL.
+ *
+ * @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
+ * @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
+ */
+static bool test_matches(const char *prefix, const char *test_name,
+			 const char *select_name)
+{
+	if (!select_name)
+		return true;
+
+	if (!strcmp(test_name, select_name))
+		return true;
+
+	/* All tests have this prefix */
+	if (!strncmp(test_name, prefix, strlen(prefix)))
+		test_name += strlen(prefix);
+
+	if (!strcmp(test_name, select_name))
+		return true;
+
+	return false;
+}
+
 /**
  * test_pre_run() - Handle any preparation needed to run a test
  *
@@ -209,8 +241,25 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
 	return 0;
 }
 
-int ut_run_test_live_flat(struct unit_test_state *uts, struct unit_test *test,
-			  const char *name)
+/**
+ * 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
+ */
+static int ut_run_test_live_flat(struct unit_test_state *uts,
+				 struct unit_test *test, const char *name)
 {
 	int runs;
 
@@ -240,24 +289,39 @@ int ut_run_test_live_flat(struct unit_test_state *uts, struct unit_test *test,
 	return 0;
 }
 
-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 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
+ */
+static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
+			struct unit_test *tests, int count,
+			const char *select_name)
 {
 	struct unit_test *test;
-	int prefix_len = prefix ? strlen(prefix) : 0;
 	int found = 0;
 
 	for (test = tests; test < tests + count; test++) {
 		const char *test_name = test->name;
 		int ret;
 
-		/* Remove the prefix */
-		if (prefix && !strncmp(test_name, prefix, prefix_len))
-			test_name += prefix_len;
-
-		if (select_name && strcmp(select_name, test_name))
+		if (!test_matches(prefix, test_name, select_name))
 			continue;
-		ret = ut_run_test_live_flat(uts, test, test_name);
+		ret = ut_run_test_live_flat(uts, test, select_name);
 		found++;
 		if (ret == -EAGAIN)
 			continue;
@@ -279,6 +343,7 @@ int ut_run_list(const char *category, const char *prefix,
 	if (!select_name)
 		printf("Running %d %s tests\n", count, category);
 
+	uts.of_root = gd_of_root();
 	ret = ut_run_tests(&uts, prefix, tests, count, select_name);
 
 	if (ret == -ENOENT)
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 28/30] test: Use return values in dm_test_run()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (26 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 27/30] test: Run driver-model tests using ut_run_list() Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 29/30] test: Move the devicetree check into ut_run_list() Simon Glass
  2021-01-28 15:12 ` [PATCH 30/30] test: Move restoring of driver model state to ut_run_list() Simon Glass
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Update 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 252c3e88328..1df0676915f 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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[])
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 29/30] test: Move the devicetree check into ut_run_list()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (27 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 28/30] test: Use return values in dm_test_run() Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  2021-01-28 15:12 ` [PATCH 30/30] test: Move restoring of driver model state to ut_run_list() Simon Glass
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Add 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().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 13 -------------
 test/test-main.c  | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 1df0676915f..30046c71509 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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);
 
diff --git a/test/test-main.c b/test/test-main.c
index 0f34f785098..3b1c471d46f 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -139,6 +139,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
  *
@@ -340,6 +359,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);
 
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 30/30] test: Move restoring of driver model state to ut_run_list()
  2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
                   ` (28 preceding siblings ...)
  2021-01-28 15:12 ` [PATCH 29/30] test: Move the devicetree check into ut_run_list() Simon Glass
@ 2021-01-28 15:12 ` Simon Glass
  29 siblings, 0 replies; 34+ messages in thread
From: Simon Glass @ 2021-01-28 15:12 UTC (permalink / raw)
  To: u-boot

Add 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().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/test-dm.c | 11 -----------
 test/test-main.c  | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 30046c71509..4f7d5736a53 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -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;
 }
 
diff --git a/test/test-main.c b/test/test-main.c
index 3b1c471d46f..893cbf45630 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -139,7 +139,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
@@ -158,6 +158,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
  *
@@ -357,10 +379,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...
@@ -375,6 +399,7 @@ int ut_run_list(const char *category, const char *prefix,
 	if (!select_name)
 		printf("Running %d %s tests\n", count, category);
 
+
 	uts.of_root = gd_of_root();
 	ret = ut_run_tests(&uts, prefix, tests, count, select_name);
 
@@ -383,5 +408,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;
 }
-- 
2.30.0.280.ga3ce27912f-goog

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 01/30] doc: Tidy up testing section
  2021-01-28 15:11 ` [PATCH 01/30] doc: Tidy up testing section Simon Glass
@ 2021-01-28 16:18   ` Heinrich Schuchardt
  0 siblings, 0 replies; 34+ messages in thread
From: Heinrich Schuchardt @ 2021-01-28 16:18 UTC (permalink / raw)
  To: u-boot

On 28.01.21 16:11, Simon Glass wrote:
> Tweak this so the output looks a little better.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  doc/develop/testing.rst | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/doc/develop/testing.rst b/doc/develop/testing.rst
> index 4bc9ca3a6ae..7a395ee9d83 100644
> --- a/doc/develop/testing.rst
> +++ b/doc/develop/testing.rst
> @@ -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,11 @@ 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)

Proper reStructered text style would be

test/fs
    File system test (shell script)

test/image
    FIT and legacy image tests (shell script and Python)

The first line of each paragraph will be in bold.

Best regards

Heinrich

>
>  TODO: Move these into pytest.
>
>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH 02/30] doc: Document make tcheck
  2021-01-28 15:11 ` [PATCH 02/30] doc: Document make tcheck Simon Glass
@ 2021-01-28 16:22   ` Heinrich Schuchardt
  0 siblings, 0 replies; 34+ messages in thread
From: Heinrich Schuchardt @ 2021-01-28 16:22 UTC (permalink / raw)
  To: u-boot

On 28.01.21 16:11, Simon Glass wrote:
> Add a comment about this option in the documentation. Also mention the
> script that runs these combinations.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  doc/develop/testing.rst | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/doc/develop/testing.rst b/doc/develop/testing.rst
> index 7a395ee9d83..a2a2c276374 100644
> --- a/doc/develop/testing.rst
> +++ b/doc/develop/testing.rst
> @@ -19,6 +19,12 @@ Some tests take ages to run. To run just the quick ones, type this::
>
>      make qcheck

Where do we describe what qualifies a test to be run by qcheck.

>
> +To run just the tests for tools (patman, binman, etc.), type this::
> +
> +    make tcheck

Same for tcheck.

Best regards

Heinrich

> +
> +All of the above use the test/run script with a paremeter to select which tests
> +are run.
>
>  Sandbox
>  -------
>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH 05/30] doc: Document how sandbox_spl_tests are run
  2021-01-28 15:11 ` [PATCH 05/30] doc: Document how sandbox_spl_tests are run Simon Glass
@ 2021-01-28 16:33   ` Heinrich Schuchardt
  0 siblings, 0 replies; 34+ messages in thread
From: Heinrich Schuchardt @ 2021-01-28 16:33 UTC (permalink / raw)
  To: u-boot

On 28.01.21 16:11, Simon Glass wrote:
> Add a few notes about the sandbox_spl tests, since they are special.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  doc/develop/testing.rst     |  5 ++++
>  doc/develop/tests_under.rst | 59 +++++++++++++++++++++++++++++++++++++
>  2 files changed, 64 insertions(+)
>
> diff --git a/doc/develop/testing.rst b/doc/develop/testing.rst
> index 593ca50de36..46e8d20322f 100644
> --- a/doc/develop/testing.rst
> +++ b/doc/develop/testing.rst
> @@ -53,6 +53,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.
>
>
> diff --git a/doc/develop/tests_under.rst b/doc/develop/tests_under.rst
> index 85bbd4f6734..ca9003f18bd 100644
> --- a/doc/develop/tests_under.rst
> +++ b/doc/develop/tests_under.rst
> @@ -77,3 +77,62 @@ 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 run in the SPL phase, if the -u flag is given.
> +There is no way to select which tests run: all of them are run::
> +
> +   ./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
> +
> +
> +   U-Boot 2021.01-00723-g43c77b51be5-dirty (Jan 24 2021 - 16:38:24 -0700)
> +
> +   DRAM:  128 MiB
> +   ...
> +
> +
> +Note that after running, SPL continues to boot into U-Boot proper. You can add
> +'-c exit' to make U-Boot quit without doing anything further. It is not
> +currently possible to run SPL tests and then stop, since the pytests require
> +that U-Boot produces the expected banner.
> +
> +Of course you can use gdb with sandbox_spl, just as with sandbox.
> +
> +
> +What tests are built in?
> +------------------------
> +
> +Whatever sandbox build is used, which tests are present is determined by which
> +source files are built. For sandbox_spl, the of_platdata tests are built
> +because of the build rule in test/dm/Makefile::
> +
> +   ifeq ($(CONFIG_SPL_BUILD),y)
> +   obj-$(CONFIG_SPL_OF_PLATDATA) += of_platdata.o
> +   else
> +   ...other tests for non-spl
> +   endif
> +
> +You can get list of tests in a U-Boot ELF file by looking for the linker_list::

get a list

Regards

Heinrich

> +
> +   nm /tmp/b/sandbox_spl/spl/u-boot-spl |grep 2_dm_test
> +   000000000001f200 D _u_boot_list_2_dm_test_2_dm_test_of_plat_base
> +   000000000001f220 D _u_boot_list_2_dm_test_2_dm_test_of_plat_dev
> +   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
>

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2021-01-28 16:33 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28 15:11 [PATCH 00/30] test: Refactor tests to have a single test runner Simon Glass
2021-01-28 15:11 ` [PATCH 01/30] doc: Tidy up testing section Simon Glass
2021-01-28 16:18   ` Heinrich Schuchardt
2021-01-28 15:11 ` [PATCH 02/30] doc: Document make tcheck Simon Glass
2021-01-28 16:22   ` Heinrich Schuchardt
2021-01-28 15:11 ` [PATCH 03/30] sandbox: Drop the 'starting...' message unless testing Simon Glass
2021-01-28 15:11 ` [PATCH 04/30] doc: Explain how to run tests without pytest Simon Glass
2021-01-28 15:11 ` [PATCH 05/30] doc: Document how sandbox_spl_tests are run Simon Glass
2021-01-28 16:33   ` Heinrich Schuchardt
2021-01-28 15:11 ` [PATCH 06/30] test: Correct setexpr test prefix Simon Glass
2021-01-28 15:11 ` [PATCH 07/30] test: Mark all driver model tests with a flag Simon Glass
2021-01-28 15:11 ` [PATCH 08/30] test: Rename test-main.c to test-dm.c Simon Glass
2021-01-28 15:11 ` [PATCH 09/30] test: Add an overall test runner Simon Glass
2021-01-28 15:11 ` [PATCH 10/30] test: Create pre/post-run functions Simon Glass
2021-01-28 15:11 ` [PATCH 11/30] test: Call test_pre/post_run() from driver model tests Simon Glass
2021-01-28 15:11 ` [PATCH 12/30] test: Move dm_extended_scan() to test_pre_run() Simon Glass
2021-01-28 15:11 ` [PATCH 13/30] test: Move do_autoprobe() " Simon Glass
2021-01-28 15:11 ` [PATCH 14/30] test: Move dm_scan_plat() " Simon Glass
2021-01-28 15:11 ` [PATCH 15/30] test: Drop mallinfo() work-around Simon Glass
2021-01-28 15:11 ` [PATCH 16/30] test: Move console silencing to test_pre_run() Simon Glass
2021-01-28 15:11 ` [PATCH 17/30] test: Move delay skipping " Simon Glass
2021-01-28 15:11 ` [PATCH 18/30] test: Handle driver model reinit in test_pre_run() Simon Glass
2021-01-28 15:12 ` [PATCH 19/30] test: Drop struct dm_test_state Simon Glass
2021-01-28 15:12 ` [PATCH 20/30] test: Move dm_test_init() into test-main.c Simon Glass
2021-01-28 15:12 ` [PATCH 21/30] test: Move dm_test_destroy() " Simon Glass
2021-01-28 15:12 ` [PATCH 22/30] test: Move test running into a separate function Simon Glass
2021-01-28 15:12 ` [PATCH 23/30] test: Use ut_run_test() to run driver model tests Simon Glass
2021-01-28 15:12 ` [PATCH 24/30] test: Drop dm_do_test() Simon Glass
2021-01-28 15:12 ` [PATCH 25/30] test: Add ut_run_test_live_flat() to run tests twice Simon Glass
2021-01-28 15:12 ` [PATCH 26/30] test: Use a local variable for test state Simon Glass
2021-01-28 15:12 ` [PATCH 27/30] test: Run driver-model tests using ut_run_list() Simon Glass
2021-01-28 15:12 ` [PATCH 28/30] test: Use return values in dm_test_run() Simon Glass
2021-01-28 15:12 ` [PATCH 29/30] test: Move the devicetree check into ut_run_list() Simon Glass
2021-01-28 15:12 ` [PATCH 30/30] test: Move restoring of driver model state to ut_run_list() Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.