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>
diff --git a/test/test-main.c b/test/test-main.c
index 1d821a3..597afa2 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -677,12 +677,16 @@
 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);