[PATCH 39/43] test: Move stat-printing into its own function

Simon Glass sjg at chromium.org
Wed Jan 15 14:31:09 CET 2025


Add a function to show the stats, so we can decide when to print it.

This slightly adjusts the output, so that any 'test not found' message
appears on its own line after all other output.

The 'failures' message now appears in lower case so update pytest
accordingly.

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

 arch/sandbox/cpu/spl.c    |  1 +
 include/test/ut.h         |  8 ++++++++
 test/py/tests/test_spl.py |  2 +-
 test/py/tests/test_upl.py |  2 +-
 test/py/tests/test_ut.py  |  2 +-
 test/py/tests/test_vbe.py |  2 +-
 test/py/tests/test_vpl.py |  2 +-
 test/test-main.c          | 14 +++++++++-----
 8 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 0ad23e4ba95..544ea8717eb 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -153,6 +153,7 @@ void spl_board_init(void)
 		ut_init_state(&uts);
 		ret = ut_run_list(&uts, "spl", NULL, tests, count,
 				  state->select_unittests, 1, false, NULL);
+		ut_report(&uts.cur, "Tests");
 		ut_uninit_state(&uts);
 		/* continue execution into U-Boot */
 	}
diff --git a/include/test/ut.h b/include/test/ut.h
index a51defc3b90..55bb5aa2092 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -530,4 +530,12 @@ int ut_run_list(struct unit_test_state *uts, const char *category,
 		const char *select_name, int runs_per_test, bool force_run,
 		const char *test_insert);
 
+/**
+ * ut_report() - Report stats on a test run
+ *
+ * @stats: Stats to show
+ * @prefix: Name of this run type, e.g. "Tests" or "Total tests"
+ */
+void ut_report(struct ut_stats *stats, const char *prefix);
+
 #endif
diff --git a/test/py/tests/test_spl.py b/test/py/tests/test_spl.py
index 42e4c4342b2..474f430a344 100644
--- a/test/py/tests/test_spl.py
+++ b/test/py/tests/test_spl.py
@@ -36,7 +36,7 @@ def test_spl(u_boot_console, ut_spl_subtest):
         cons = u_boot_console
         cons.restart_uboot_with_flags(['-u', '-k', ut_spl_subtest.split()[1]])
         output = cons.get_spawn_output().replace('\r', '')
-        assert 'Failures: 0' in output
+        assert 'failures: 0' in output
     finally:
         # Restart afterward in case a non-SPL test is run next. This should not
         # happen since SPL tests are run in their own invocation of test.py, but
diff --git a/test/py/tests/test_upl.py b/test/py/tests/test_upl.py
index 3164bda6b71..d94359d8b9b 100644
--- a/test/py/tests/test_upl.py
+++ b/test/py/tests/test_upl.py
@@ -35,4 +35,4 @@ def test_upl_handoff(u_boot_console):
 
     # Check the FIT offsets look correct
     output = cons.run_command('ut upl -f upl_test_info_norun')
-    assert 'Failures: 0' in output
+    assert 'failures: 0' in output
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index cacf11f7c0a..d2d8ce10755 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -607,4 +607,4 @@ def test_ut(u_boot_console, ut_subtest):
         assert 'Unknown command \'quux\' - try \'help\'' in output
     else:
         output = u_boot_console.run_command('ut ' + ut_subtest)
-    assert output.endswith('Failures: 0')
+    assert output.endswith('failures: 0')
diff --git a/test/py/tests/test_vbe.py b/test/py/tests/test_vbe.py
index 50b6c1cd911..861df3f8266 100644
--- a/test/py/tests/test_vbe.py
+++ b/test/py/tests/test_vbe.py
@@ -117,4 +117,4 @@ def test_vbe(u_boot_console):
     with cons.log.section('Kernel load'):
         output = cons.run_command_list(cmd.splitlines())
 
-    assert 'Failures: 0' in output[-1]
+    assert 'failures: 0' in output[-1]
diff --git a/test/py/tests/test_vpl.py b/test/py/tests/test_vpl.py
index 4af578b9173..8c472ca7a92 100644
--- a/test/py/tests/test_vpl.py
+++ b/test/py/tests/test_vpl.py
@@ -26,7 +26,7 @@ def test_vpl(u_boot_console, ut_vpl_subtest):
         cons = u_boot_console
         cons.restart_uboot_with_flags(['-u', '-k', ut_vpl_subtest.split()[1]])
         output = cons.get_spawn_output().replace('\r', '')
-        assert 'Failures: 0' in output
+        assert 'failures: 0' in output
     finally:
         # Restart afterward in case a non-VPL test is run next. This should not
         # happen since VPL tests are run in their own invocation of test.py, but
diff --git a/test/test-main.c b/test/test-main.c
index e36bc37d29e..a0a3f6086ef 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -673,6 +673,14 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
 	return uts->cur.fail_count ? -EBADF : 0;
 }
 
+void ut_report(struct ut_stats *stats, const char *prefix)
+{
+	printf("%s run: %d, ", prefix, stats->test_count);
+	if (stats->skip_count)
+		printf("skipped: %d, ", stats->skip_count);
+	printf("failures: %d\n", stats->fail_count);
+}
+
 int ut_run_list(struct unit_test_state *uts, const char *category,
 		const char *prefix, struct unit_test *tests, int count,
 		const char *select_name, int runs_per_test, bool force_run,
@@ -718,13 +726,9 @@ int ut_run_list(struct unit_test_state *uts, const char *category,
 	if (has_dm_tests)
 		dm_test_restore(uts->of_root);
 
-	printf("Tests run: %d, ", uts->cur.test_count);
-	if (uts->cur.skip_count)
-		printf("Skipped: %d, ", uts->cur.skip_count);
+	ut_report(&uts->cur, "Tests");
 	if (ret == -ENOENT)
 		printf("Test '%s' not found\n", select_name);
-	else
-		printf("Failures: %d\n", uts->cur.fail_count);
 
 	return ret;
 }
-- 
2.34.1



More information about the U-Boot mailing list