*/
unsigned long get_timer_us_long(unsigned long base);
-/*
+/**
* timer_test_add_offset()
*
* Allow tests to add to the time reported through lib/time.c functions
*/
void timer_test_add_offset(unsigned long offset);
+#ifdef CONFIG_SANDBOX
+/**
+ * timer_test_get_offset()
+ *
+ * Get the total offset currently being added the time
+ *
+ * Return:: number of milliseconds the system time has been advanced
+ */
+ulong timer_test_get_offset(void);
+#else
+static inline ulong timer_test_get_offset(void) { return 0; }
+#endif
+
/**
* usec_to_tick() - convert microseconds to clock ticks
*
of-platdata and SPL handover. To run these tests with the sandbox_spl
board, use the -u (unit test) option.
+config UNIT_TEST_DURATION
+ bool "Report unit-test duration"
+ depends on UNIT_TEST
+ default y
+ help
+ Enable this short the time taken by each test suite. This is reported
+ after the suite runs, alongside the pass/fail results. In addition,
+ an overall total is reported if multiple suites are run.
+
config UT_LIB
bool "Unit tests for library functions"
depends on UNIT_TEST
#include <net.h>
#include <of_live.h>
#include <os.h>
+#include <spl.h>
#include <usb.h>
#include <dm/ofnode.h>
#include <dm/root.h>
else
printf("Tests");
printf(" run: %d, ", stats->test_count);
+ if (stats)
+ printf("%ld ms, ", stats->duration_ms);
if (stats->skip_count)
printf("skipped: %d, ", stats->skip_count);
printf("failures: %d\n", stats->fail_count);
{
;
bool has_dm_tests = false;
+ ulong start_offset = 0;
+ ulong test_offset = 0;
int ret;
memset(&uts->cur, '\0', sizeof(struct ut_stats));
+ if (CONFIG_IS_ENABLED(UNIT_TEST_DURATION)) {
+ uts->cur.start = get_timer(0);
+ start_offset = timer_test_get_offset();
+ }
if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
ut_list_has_dm_tests(tests, count, prefix, select_name)) {
if (has_dm_tests)
dm_test_restore(uts->of_root);
- ut_report(&uts->cur, 1);
if (ret == -ENOENT)
printf("Test '%s' not found\n", select_name);
+ if (CONFIG_IS_ENABLED(UNIT_TEST_DURATION)) {
+ test_offset = timer_test_get_offset() - start_offset;
+
+ uts->cur.duration_ms = get_timer(uts->cur.start) - test_offset;
+ }
+ ut_report(&uts->cur, 1);
uts->total.skip_count += uts->cur.skip_count;
uts->total.fail_count += uts->cur.fail_count;
uts->total.test_count += uts->cur.test_count;
+ uts->total.duration_ms += uts->cur.duration_ms;
uts->run_count++;
return ret;