diff options
-rw-r--r-- | zephyr/shim/src/tasks.c | 24 | ||||
-rw-r--r-- | zephyr/test/drivers/default/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/default/prj.conf | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/default/src/task.c | 84 |
4 files changed, 98 insertions, 12 deletions
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c index ba43e8ac66..a03cf4daa8 100644 --- a/zephyr/shim/src/tasks.c +++ b/zephyr/shim/src/tasks.c @@ -156,12 +156,12 @@ uint32_t task_wait_event(int timeout_us) if (events == 0) { const int64_t ticks_left = tick_deadline - k_uptime_ticks(); + events |= TASK_EVENT_TIMER; + if (ticks_left > 0) { return task_wait_event( k_ticks_to_us_near64(ticks_left)); } - - events |= TASK_EVENT_TIMER; } return events; @@ -313,18 +313,26 @@ int task_start_called(void) { return tasks_started; } - +/* + * TODO(b/190203712): Implement this + * LCOV_EXCL_START + */ void task_disable_task(task_id_t tskid) { - /* TODO(b/190203712): Implement this */ } +/* LCOV_EXCL_STOP */ +/* + * This function cannot be tested since it is architecture specific. + * LCOV_EXCL_START + */ void task_clear_pending_irq(int irq) { #if CONFIG_ITE_IT8XXX2_INTC ite_intc_isr_clear(irq); #endif } +/* LCOV_EXCL_STOP */ void task_enable_irq(int irq) { @@ -343,11 +351,3 @@ inline bool in_deferred_context(void) */ return (k_current_get() == &k_sys_work_q.thread); } - -#if IS_ENABLED(CONFIG_KERNEL_SHELL) && IS_ENABLED(CONFIG_THREAD_MONITOR) -static int taskinfo(const struct shell *shell, size_t argc, char **argv) -{ - return shell_execute_cmd(shell, "kernel threads"); -} -SHELL_CMD_REGISTER(taskinfo, NULL, "Threads statistics", taskinfo); -#endif diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt index 8f79160878..445ee50e37 100644 --- a/zephyr/test/drivers/default/CMakeLists.txt +++ b/zephyr/test/drivers/default/CMakeLists.txt @@ -82,6 +82,7 @@ target_sources(app PRIVATE src/smart.c src/stm_mems_common.c src/tablet_mode.c + src/task.c src/tcpci.c src/tcpci_test_common.c src/tcs3400.c diff --git a/zephyr/test/drivers/default/prj.conf b/zephyr/test/drivers/default/prj.conf index 9c112a6ced..c544afd4e7 100644 --- a/zephyr/test/drivers/default/prj.conf +++ b/zephyr/test/drivers/default/prj.conf @@ -9,5 +9,6 @@ CONFIG_PLATFORM_EC_LED_DT=y CONFIG_PLATFORM_EC_RTC=y CONFIG_PLATFORM_EC_VOLUME_BUTTONS=y CONFIG_PLATFORM_EC_CONSOLE_CHANNEL=y +CONFIG_TASK_HOSTCMD_THREAD_MAIN=y CONFIG_SYSTEM_FAKE=y diff --git a/zephyr/test/drivers/default/src/task.c b/zephyr/test/drivers/default/src/task.c new file mode 100644 index 0000000000..1f29a4f2f2 --- /dev/null +++ b/zephyr/test/drivers/default/src/task.c @@ -0,0 +1,84 @@ +/* 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. + */ + +#include <zephyr/ztest.h> + +#include "task.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" +#include "timer.h" + +struct tasks_fixture { + timestamp_t fake_time; +}; + +static void *setup(void) +{ + static struct tasks_fixture fixture; + + return &fixture; +} + +static void before(void *f) +{ + struct tasks_fixture *fixture = f; + + fixture->fake_time.val = 0; +} + +static void after(void *f) +{ + ARG_UNUSED(f); + + get_time_mock = NULL; +} + +ZTEST_SUITE(tasks, drivers_predicate_post_main, setup, before, after, NULL); + +ZTEST(tasks, test_enable_irq) +{ + arch_irq_disable(0); + task_enable_irq(0); + zassert_true(arch_irq_is_enabled(0)); +} + +ZTEST(tasks, test_interrupt_context) +{ + zassert_false(in_interrupt_context()); +} + +ZTEST_F(tasks, test_timer_arm_before_now) +{ + timestamp_t deadline = { + .val = 5, + }; + + fixture->fake_time.val = 15; + get_time_mock = &fixture->fake_time; + + zassert_ok(timer_arm(deadline, TASK_ID_MOTIONSENSE)); + zassert_equal(*task_get_event_bitmap(TASK_ID_MOTIONSENSE) & + TASK_EVENT_TIMER, + TASK_EVENT_TIMER); +} + +ZTEST_F(tasks, test_timer_arm_busy) +{ + timestamp_t deadline = { + .val = UINT64_C(5000000), + }; + + fixture->fake_time.val = 0; + get_time_mock = &fixture->fake_time; + + zassert_ok(timer_arm(deadline, TASK_ID_MOTIONSENSE)); + zassert_equal(EC_ERROR_BUSY, timer_arm(deadline, TASK_ID_MOTIONSENSE)); +} + +ZTEST(tasks, test_get_event_bitmap_invalid_tid) +{ + zassert_is_null( + task_get_event_bitmap(TASK_ID_COUNT + EXTRA_TASK_COUNT)); +} |