summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2014-10-01 14:43:15 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-10 18:48:29 +0000
commit41cd36cc213b7d9f37448c5591915d3c6374dd20 (patch)
tree93b6e885d12e6f1896c68984bcacafab3a3f65e5
parent70b657b81646728d5204ad3ac044697b6571a603 (diff)
downloadchrome-ec-41cd36cc213b7d9f37448c5591915d3c6374dd20.tar.gz
CHERRY-PICK: Slow down time when running unit tests
When a timing sensitive test run on a heavily loaded system, sometimes a task runs for longer than it usually does and causes the test to fail. All the timing requirements in the unit tests are trying to verify the various delays in our codebase, and mostly we don't care about the time taken by active running code (as they are very quick.) To improve the stability of tests, let's slow down the time. To a test, it's as if the code runs faster. If a test uses udelay() and exceeds the 10-second time limit, we can make that single test faster by setting the time scale. BUG=None TEST=Repeatedly run 'make runtests' BRANCH=None Change-Id: Ie890e16310197a46c9c0f0f81f73a1b307d9ecdc Original-Change-Id: I9bc5c77e0d34d04c8630d495387a751ef29c7bd5 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/220717 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/222870 Reviewed-by: Mohammed Habibulla <moch@chromium.org> Commit-Queue: Mohammed Habibulla <moch@chromium.org> Tested-by: Mohammed Habibulla <moch@chromium.org>
-rw-r--r--core/host/stack_trace.c1
-rw-r--r--core/host/timer.c17
-rw-r--r--test/build.mk1
3 files changed, 15 insertions, 4 deletions
diff --git a/core/host/stack_trace.c b/core/host/stack_trace.c
index 67ceac5891..2d63efd625 100644
--- a/core/host/stack_trace.c
+++ b/core/host/stack_trace.c
@@ -84,7 +84,6 @@ static void __attribute__((noinline)) _task_dump_trace_dispatch(int sig)
pthread_kill(task_get_thread(running), SIGNAL_TRACE_DUMP);
} else {
_task_dump_trace_impl(SIGNAL_TRACE_OFFSET);
- udelay(100 * MSEC); /* Leave time for stderr to flush */
exit(1);
}
}
diff --git a/core/host/timer.c b/core/host/timer.c
index ff17ddf068..124f17c14f 100644
--- a/core/host/timer.c
+++ b/core/host/timer.c
@@ -15,14 +15,25 @@
#include "util.h"
/*
- * For test that need to test for longer than 10 seconds, adjust
- * its time scale in test/build.mk by specifying
+ * For test that need to test for longer than the default time limit,
+ * adjust its time scale in test/build.mk by specifying
* <test_name>-scale=<new scale>.
*/
#ifndef TEST_TIME_SCALE
#define TEST_TIME_SCALE 1
#endif
+/*
+ * To increase the stability of timing sensitive unit tests, slow
+ * down the time by 10x. This only affects active run time (including
+ * udelay() calls). To an unit test, the only effect is increased code
+ * execution speed. However, this comes at the cost of prolonged test
+ * run time for tests that use udelay(). Fortunately, most of our tests
+ * use usleep/msleep, and for tests that use udelay(), we can scale
+ * the time as mentioned above.
+ */
+#define TEST_TIME_SLOW_DOWN 10
+
static timestamp_t boot_time;
static int time_set;
@@ -45,7 +56,7 @@ timestamp_t _get_time(void)
timestamp_t ret;
clock_gettime(CLOCK_MONOTONIC, &ts);
ret.val = (1000000000 * (uint64_t)ts.tv_sec + ts.tv_nsec) *
- TEST_TIME_SCALE / 1000;
+ TEST_TIME_SCALE / 1000 / TEST_TIME_SLOW_DOWN;
return ret;
}
diff --git a/test/build.mk b/test/build.mk
index a2094ba112..f503188410 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -44,6 +44,7 @@ hooks-y=hooks.o
host_command-y=host_command.o
inductive_charging-y=inductive_charging.o
interrupt-y=interrupt.o
+interrupt-scale=10
kb_8042-y=kb_8042.o
kb_mkbp-y=kb_mkbp.o
kb_scan-y=kb_scan.o