[PATCH v3 11/43] test: Report skippped tests

Simon Glass sjg at chromium.org
Fri Oct 21 02:22:48 CEST 2022


At present it is possible for a test to skip itself by returning -EAGAIN
but this is not recorded. An existing example is in test_pre_run() with
the "Console recording disabled" check.

Keep a track of skipped tests and report the total at the end.

Signed-off-by: Simon Glass <sjg at chromium.org>
Acked-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---

Changes in v3:
- Update commit message to mention an existing example

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

diff --git a/include/test/test.h b/include/test/test.h
index 3bbd77c38b5..c1853ce471b 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -13,6 +13,7 @@
  * struct unit_test_state - Entire state of test system
  *
  * @fail_count: Number of tests that failed
+ * @skip_count: Number of tests that were skipped
  * @start: Store the starting mallinfo when doing leak test
  * @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)
@@ -32,6 +33,7 @@
  */
 struct unit_test_state {
 	int fail_count;
+	int skip_count;
 	struct mallinfo start;
 	struct device_node *of_root;
 	bool of_live;
diff --git a/test/test-main.c b/test/test-main.c
index a98a77d68fc..2323cbaece5 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -356,6 +356,19 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
 	return 0;
 }
 
+/**
+ * skip_test() - Handle skipping a test
+ *
+ * @uts: Test state to update
+ * @return -EAGAIN (always)
+ */
+static int skip_test(struct unit_test_state *uts)
+{
+	uts->skip_count++;
+
+	return -EAGAIN;
+}
+
 /**
  * ut_run_test() - Run a single test
  *
@@ -386,11 +399,13 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
 
 	ret = test_pre_run(uts, test);
 	if (ret == -EAGAIN)
-		return -EAGAIN;
+		return skip_test(uts);
 	if (ret)
 		return ret;
 
-	test->func(uts);
+	ret = test->func(uts);
+	if (ret == -EAGAIN)
+		skip_test(uts);
 
 	ret = test_post_run(uts, test);
 	if (ret)
@@ -424,7 +439,7 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
 	int runs;
 
 	if ((test->flags & UT_TESTF_OTHER_FDT) && !IS_ENABLED(CONFIG_SANDBOX))
-		return -EAGAIN;
+		return skip_test(uts);
 
 	/* Run with the live tree if possible */
 	runs = 0;
@@ -558,6 +573,8 @@ int ut_run_list(const char *category, const char *prefix,
 		os_free(uts.other_fdt);
 	}
 
+	if (uts.skip_count)
+		printf("Skipped: %d, ", uts.skip_count);
 	if (ret == -ENOENT)
 		printf("Test '%s' not found\n", select_name);
 	else
-- 
2.38.0.135.g90850a2211-goog



More information about the U-Boot mailing list