summaryrefslogtreecommitdiff
path: root/test/irq_locking.c
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2020-11-02 12:11:11 -0700
committerCommit Bot <commit-bot@chromium.org>2020-11-08 19:31:12 +0000
commitc47740eca17a2fe652b7bb13f5b2949687884e79 (patch)
treee8efbfdac3fc0f01520e0997560f0095297d4b79 /test/irq_locking.c
parent25ae7edffcceb662d5d2ebe92d19bf6f191d8bd5 (diff)
downloadchrome-ec-c47740eca17a2fe652b7bb13f5b2949687884e79.tar.gz
Zephyr: add more compliant implementation for irq_(un)lock
This change replaces the stubbed irq_(un)lock static functions defined in task.h with new functions that behave more like the Zephyr implementation of irq_(un)lock functions. This should make the migration from interrupt_(dis|en)able to Zephyr more seamless. BRANCH=none BUG=b:172060699 TEST=Added unit tests, make runtests -j, and built for various boards: eve, volteer, arcada_ish, atlas, hatch, kohaku, nocturne, samus, and scarlet Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: Ia7ad2b8d7d411a11699353bf5d3cc36a261fad14 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2511720
Diffstat (limited to 'test/irq_locking.c')
-rw-r--r--test/irq_locking.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/irq_locking.c b/test/irq_locking.c
new file mode 100644
index 0000000000..6d08b1175d
--- /dev/null
+++ b/test/irq_locking.c
@@ -0,0 +1,83 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "task.h"
+#include "test_util.h"
+
+static uint32_t interrupt_disable_count;
+static uint32_t interrupt_enable_count;
+
+/** Mock implementation of interrupt_disable. */
+void interrupt_disable(void)
+{
+ ++interrupt_disable_count;
+}
+
+/** Mock implementation of interrupt_enable. */
+void interrupt_enable(void)
+{
+ ++interrupt_enable_count;
+}
+
+static int test_simple_lock_unlock(void)
+{
+ uint32_t key = irq_lock();
+
+ irq_unlock(key);
+
+ TEST_EQ(interrupt_disable_count, 1, "%u");
+ TEST_EQ(interrupt_enable_count, 1, "%u");
+
+ return EC_SUCCESS;
+}
+
+static int test_unlock_when_all_keys_removed(void)
+{
+ uint32_t key0 = irq_lock();
+ uint32_t key1 = irq_lock();
+
+ TEST_EQ(interrupt_disable_count, 2, "%u");
+
+ irq_unlock(key1);
+
+ TEST_EQ(interrupt_enable_count, 0, "%u");
+
+ irq_unlock(key0);
+
+ TEST_EQ(interrupt_enable_count, 1, "%u");
+
+ return EC_SUCCESS;
+}
+
+static int test_unlock_from_root_key(void)
+{
+ uint32_t key0 = irq_lock();
+ uint32_t key1 = irq_lock();
+
+ TEST_NE(key0, key1, "%u");
+ TEST_EQ(interrupt_disable_count, 2, "%u");
+
+ irq_unlock(key0);
+ TEST_EQ(interrupt_enable_count, 1, "%u");
+
+ return EC_SUCCESS;
+}
+
+void before_test(void)
+{
+ interrupt_disable_count = 0;
+ interrupt_enable_count = 0;
+}
+
+void run_test(int argc, char **argv)
+{
+ test_reset();
+
+ RUN_TEST(test_simple_lock_unlock);
+ RUN_TEST(test_unlock_when_all_keys_removed);
+ RUN_TEST(test_unlock_from_root_key);
+
+ test_print_result();
+}