diff options
author | Yuval Peress <peress@chromium.org> | 2020-11-02 12:11:11 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-11-08 19:31:12 +0000 |
commit | c47740eca17a2fe652b7bb13f5b2949687884e79 (patch) | |
tree | e8efbfdac3fc0f01520e0997560f0095297d4b79 /test | |
parent | 25ae7edffcceb662d5d2ebe92d19bf6f191d8bd5 (diff) | |
download | chrome-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')
-rw-r--r-- | test/build.mk | 2 | ||||
-rw-r--r-- | test/irq_locking.c | 83 | ||||
-rw-r--r-- | test/irq_locking.tasklist | 9 |
3 files changed, 94 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk index 0dd01347ed..2dc413c25c 100644 --- a/test/build.mk +++ b/test/build.mk @@ -42,6 +42,7 @@ test-list-host += host_command test-list-host += i2c_bitbang test-list-host += inductive_charging test-list-host += interrupt +test-list-host += irq_locking test-list-host += is_enabled test-list-host += is_enabled_error test-list-host += kasa @@ -150,6 +151,7 @@ host_command-y=host_command.o i2c_bitbang-y=i2c_bitbang.o inductive_charging-y=inductive_charging.o interrupt-y=interrupt.o +irq_locking-y=irq_locking.o is_enabled-y=is_enabled.o kb_8042-y=kb_8042.o kb_mkbp-y=kb_mkbp.o 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(); +} diff --git a/test/irq_locking.tasklist b/test/irq_locking.tasklist new file mode 100644 index 0000000000..2d7fbb0541 --- /dev/null +++ b/test/irq_locking.tasklist @@ -0,0 +1,9 @@ +/* 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. + */ + +/** + * See CONFIG_TASK_LIST in config.h for details. + */ +#define CONFIG_TEST_TASK_LIST /* No test task. */ |