* @cur: Statistics for the current run
* @total: Statistics for all test runs
* @run_count: Number of times ut_run_list() has been called
+ * @worst: Sute which had the first per-text run time
+ * @worst_ms: Time taken by that test
* @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)
struct ut_stats cur;
struct ut_stats total;
int run_count;
+ const struct suite *worst;
+ int worst_ms;
struct mallinfo start;
struct device_node *of_root;
bool of_live;
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[])
{
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);
ret = run_suite(&uts, ste, cmdtp, flag, argc, argv);
}
+ show_stats(&uts);
if (ret)
return ret;
ut_uninit_state(&uts);
void ut_report(struct ut_stats *stats, int run_count)
{
if (run_count > 1)
- printf("Suites run: %d, total tests", run_count);
+ printf("Total tests");
else
printf("Tests");
printf(" run: %d, ", stats->test_count);
- if (stats)
- printf("%ld ms, ", stats->duration_ms);
+ if (stats && stats->test_count) {
+ ulong dur = stats->duration_ms;
+
+ printf("%ld ms, average: %ld ms, ", dur,
+ dur ? dur / stats->test_count : 0);
+ }
if (stats->skip_count)
printf("skipped: %d, ", stats->skip_count);
printf("failures: %d\n", stats->fail_count);