]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test: Move stats into a struct
authorSimon Glass <sjg@chromium.org>
Mon, 20 Jan 2025 21:25:59 +0000 (14:25 -0700)
committerTom Rini <trini@konsulko.com>
Fri, 24 Jan 2025 20:34:41 +0000 (14:34 -0600)
Use a struct to hold the stats, since we also want to have the same
stats for all runs as we have for each suite.

Signed-off-by: Simon Glass <sjg@chromium.org>
include/test/test.h
test/test-main.c
test/ut.c

index 21c0478befe02f003f95f6781497c45103355652..bc8f0bbe501eaadf48422fbb63277b173526b030 100644 (file)
@@ -9,11 +9,21 @@
 #include <malloc.h>
 #include <linux/bitops.h>
 
-/*
- * struct unit_test_state - Entire state of test system
+/**
+ * struct ut_stats - Statistics about tests run
  *
  * @fail_count: Number of tests that failed
  * @skip_count: Number of tests that were skipped
+ */
+struct ut_stats {
+       int fail_count;
+       int skip_count;
+};
+
+/*
+ * struct unit_test_state - Entire state of test system
+ *
+ * @cur: Statistics for the current run
  * @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)
@@ -34,8 +44,7 @@
  * @actual_str: Temporary string used to hold actual string value
  */
 struct unit_test_state {
-       int fail_count;
-       int skip_count;
+       struct ut_stats cur;
        struct mallinfo start;
        struct device_node *of_root;
        bool of_live;
index 391d4e7bb0ef14baf312cd42c35ad853ba70ffc5..e8aecd267c7127f98828e476c1bb49af9dd54468 100644 (file)
@@ -448,7 +448,7 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
  */
 static int skip_test(struct unit_test_state *uts)
 {
-       uts->skip_count++;
+       uts->cur.skip_count++;
 
        return -EAGAIN;
 }
@@ -460,7 +460,7 @@ static int skip_test(struct unit_test_state *uts)
  * 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
+ *     the first call to this function. On exit, @uts->cur.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
@@ -510,7 +510,7 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
  * 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
+ *     the first call to this function. On exit, @uts->cur.fail_count is
  *     incremented by the number of failures (0, one hopes)
  * @test: Test to run
  * Return: 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if
@@ -574,7 +574,7 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
  * 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
+ *     the first call to this function. On exit, @uts->cur.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
@@ -632,7 +632,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
                        if (len < 6 || strcmp(test_name + len - 6, "_norun")) {
                                printf("Test '%s' is manual so must have a name ending in _norun\n",
                                       test_name);
-                               uts->fail_count++;
+                               uts->cur.fail_count++;
                                return -EBADF;
                        }
                        if (!uts->force_run) {
@@ -641,23 +641,24 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
                                continue;
                        }
                }
-               old_fail_count = uts->fail_count;
+               old_fail_count = uts->cur.fail_count;
 
                if (one && upto == pos) {
                        ret = ut_run_test_live_flat(uts, one);
-                       if (uts->fail_count != old_fail_count) {
+                       if (uts->cur.fail_count != old_fail_count) {
                                printf("Test '%s' failed %d times (position %d)\n",
                                       one->name,
-                                      uts->fail_count - old_fail_count, pos);
+                                      uts->cur.fail_count - old_fail_count,
+                                      pos);
                        }
                        return -EBADF;
                }
 
                for (i = 0; i < uts->runs_per_test; i++)
                        ret = ut_run_test_live_flat(uts, test);
-               if (uts->fail_count != old_fail_count) {
+               if (uts->cur.fail_count != old_fail_count) {
                        printf("Test '%s' failed %d times\n", test_name,
-                              uts->fail_count - old_fail_count);
+                              uts->cur.fail_count - old_fail_count);
                }
                found++;
                if (ret == -EAGAIN)
@@ -668,7 +669,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
        if (select_name && !found)
                return -ENOENT;
 
-       return uts->fail_count ? -EBADF : 0;
+       return uts->cur.fail_count ? -EBADF : 0;
 }
 
 int ut_run_list(struct unit_test_state *uts, const char *category,
@@ -716,12 +717,12 @@ int ut_run_list(struct unit_test_state *uts, const char *category,
        if (has_dm_tests)
                dm_test_restore(uts->of_root);
 
-       if (uts->skip_count)
-               printf("Skipped: %d, ", uts->skip_count);
+       if (uts->cur.skip_count)
+               printf("Skipped: %d, ", uts->cur.skip_count);
        if (ret == -ENOENT)
                printf("Test '%s' not found\n", select_name);
        else
-               printf("Failures: %d\n", uts->fail_count);
+               printf("Failures: %d\n", uts->cur.fail_count);
 
        return ret;
 }
index 7454da3e001f5953989bd702cec0c14c996fea7d..a16fdfb3a93cdd2e602862d86aa35de3abf1af10 100644 (file)
--- a/test/ut.c
+++ b/test/ut.c
@@ -21,7 +21,7 @@ void ut_fail(struct unit_test_state *uts, const char *fname, int line,
 {
        gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
        printf("%s:%d, %s(): %s\n", fname, line, func, cond);
-       uts->fail_count++;
+       uts->cur.fail_count++;
 }
 
 void ut_failf(struct unit_test_state *uts, const char *fname, int line,
@@ -35,7 +35,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
        vprintf(fmt, args);
        va_end(args);
        putc('\n');
-       uts->fail_count++;
+       uts->cur.fail_count++;
 }
 
 ulong ut_check_free(void)