summaryrefslogtreecommitdiff
path: root/test/timer.cc
diff options
context:
space:
mode:
authorAndrea Grandi <agrandi@google.com>2022-11-30 14:07:00 -0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-12-07 20:51:23 +0000
commite1cfeb867cc7c8a853198ceff80c375051598f60 (patch)
tree781320faadd1de8e6b8ed0da10ca30e5367469ee /test/timer.cc
parent3a824dc622e29c423e39b1ec3c1b2bac571f23ce (diff)
downloadchrome-ec-e1cfeb867cc7c8a853198ceff80c375051598f60.tar.gz
test: Add timer test
Verify the existing usleep() function in preparation for moving its implementation into the builtin folder. BUG=b:260723169 TEST=test/run_device_tests.py -b bloonchipper -t timer TEST=test/run_device_tests.py -b dartmonkey -t timer TEST=make run-timer BRANCH=none Change-Id: I532fa5ac7abf7b16b4d1a86ea5e961f08fb2f1b7 Signed-off-by: Andrea Grandi <agrandi@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4068487 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'test/timer.cc')
-rw-r--r--test/timer.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/timer.cc b/test/timer.cc
new file mode 100644
index 0000000000..8eb5f87519
--- /dev/null
+++ b/test/timer.cc
@@ -0,0 +1,42 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/** @brief Test functions defined in timer.h, like usleep().
+ *
+ * This test only validates the functionality of code in timer.h and is not
+ * expected to accurately measure/check the timing.
+ */
+
+#include "common.h"
+#include "math_util.h"
+#include "test_util.h"
+
+extern "C" {
+#include "timer.h"
+#include "watchdog.h"
+}
+
+test_static int test_usleep(void)
+{
+ constexpr int expected_duration = 12345;
+
+ timestamp_t start_time = get_time();
+ usleep(expected_duration);
+ int sleep_duration = time_since32(start_time);
+
+ TEST_NEAR(expected_duration, sleep_duration, 20, "%d");
+
+ return EC_SUCCESS;
+}
+
+void run_test(int argc, const char **argv)
+{
+ test_reset();
+ watchdog_reload();
+
+ RUN_TEST(test_usleep);
+
+ test_print_result();
+}