summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2021-10-12 10:31:14 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-28 19:10:14 +0000
commit11a29a5d8691e1b6acbc135721ffe73fa012bc26 (patch)
tree978979d54be26451738f846bd14e3297fa5e32c7 /common
parent3deccd4a73122a5da91a9d47b4983ec426eca73c (diff)
downloadchrome-ec-11a29a5d8691e1b6acbc135721ffe73fa012bc26.tar.gz
zephyr: test: Make get_time mockable
Some driver code paths require control of the return value of get_time in order to be properly tested. Now get_time can be mocked during tests. BRANCH=none BUG=b:184856083 TEST=zmake testall and make runhosttests Signed-off-by: Aaron Massey <aaronmassey@chromium.org> Change-Id: I7f66542aaef015263af66d872978c40746a77292 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3219471 Commit-Queue: Aaron Massey <aaronmassey@google.com> Tested-by: Aaron Massey <aaronmassey@google.com> Reviewed-by: Yuval Peress <peress@google.com>
Diffstat (limited to 'common')
-rw-r--r--common/timer.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/common/timer.c b/common/timer.c
index d4504f19b7..0490741c4c 100644
--- a/common/timer.c
+++ b/common/timer.c
@@ -211,10 +211,19 @@ void usleep(unsigned us)
evt & ~TASK_EVENT_TIMER);
}
+#ifdef CONFIG_ZTEST
+timestamp_t *get_time_mock;
+#endif /* CONFIG_ZTEST */
+
timestamp_t get_time(void)
{
timestamp_t ts;
+#ifdef CONFIG_ZTEST
+ if (get_time_mock != NULL)
+ return *get_time_mock;
+#endif /* CONFIG_ZTEST */
+
if (IS_ENABLED(CONFIG_HWTIMER_64BIT)) {
ts.val = __hw_clock_source_read64();
} else {