summaryrefslogtreecommitdiff
path: root/test/cmd_ut.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2025-02-07 11:30:36 -0700
committerTom Rini <trini@konsulko.com>2025-02-11 20:10:58 -0600
commitb85df267e1f9f6f53086875975b8e4b24570365d (patch)
tree7304d4ff74aecbcc0f913afd8e3c7bd4f3d49842 /test/cmd_ut.c
parent5f6a59e03eff0f29295ce12b3807cbac7334e0aa (diff)
test: Show the average time per test
Show the average duration of a test, so we can keep track of how it is trending. Report the suite with the longest average test to encourage people to improve it. Add a function to update the stats based on the results from a single suite and another to show the summary information. Make this optional, since sandbox's SPL tests do not have a timer driver and people may want to print results without times. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/cmd_ut.c')
-rw-r--r--test/cmd_ut.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index cc30c517c51..c96277d89a1 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -192,6 +192,36 @@ static int run_suite(struct unit_test_state *uts, struct suite *ste,
return ret;
}
+static void show_stats(struct unit_test_state *uts)
+{
+ if (uts->run_count < 2)
+ return;
+
+ ut_report(&uts->total, uts->run_count);
+ if (CONFIG_IS_ENABLED(UNIT_TEST_DURATION) &&
+ uts->total.test_count && uts->worst) {
+ ulong avg = uts->total.duration_ms / uts->total.test_count;
+
+ printf("Average test time: %ld ms, worst case '%s' took %d ms\n",
+ avg, uts->worst->name, uts->worst_ms);
+ }
+}
+
+static void update_stats(struct unit_test_state *uts, const struct suite *ste)
+{
+ if (CONFIG_IS_ENABLED(UNIT_TEST_DURATION) && uts->cur.test_count) {
+ ulong avg;
+
+ avg = uts->cur.duration_ms ?
+ uts->cur.duration_ms /
+ uts->cur.test_count : 0;
+ if (avg > uts->worst_ms) {
+ uts->worst_ms = avg;
+ uts->worst = ste;
+ }
+ }
+}
+
static int do_ut_all(struct unit_test_state *uts, struct cmd_tbl *cmdtp,
int flag, int argc, char *const argv[])
{
@@ -208,6 +238,7 @@ static int do_ut_all(struct unit_test_state *uts, struct cmd_tbl *cmdtp,
retval = run_suite(uts, ste, cmdtp, flag, 1, argv);
if (!any_fail)
any_fail = retval;
+ update_stats(uts, ste);
}
}
ut_report(&uts->total, uts->run_count);
@@ -306,6 +337,7 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
ret = run_suite(&uts, ste, cmdtp, flag, argc, argv);
}
+ show_stats(&uts);
if (ret)
return ret;
ut_uninit_state(&uts);