test: Move stats into a struct
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>
diff --git a/include/test/test.h b/include/test/test.h
index 21c0478..bc8f0bb 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -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;
diff --git a/test/test-main.c b/test/test-main.c
index 391d4e7..e8aecd2 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -448,7 +448,7 @@
*/
static int skip_test(struct unit_test_state *uts)
{
- uts->skip_count++;
+ uts->cur.skip_count++;
return -EAGAIN;
}
@@ -460,7 +460,7 @@
* 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 @@
* 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 @@
* 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 @@
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 @@
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 @@
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 @@
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;
}
diff --git a/test/ut.c b/test/ut.c
index 7454da3..a16fdfb 100644
--- a/test/ut.c
+++ b/test/ut.c
@@ -21,7 +21,7 @@
{
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 @@
vprintf(fmt, args);
va_end(args);
putc('\n');
- uts->fail_count++;
+ uts->cur.fail_count++;
}
ulong ut_check_free(void)