diff options
author | Tomasz Michalec <tm@semihalf.com> | 2021-08-20 12:38:25 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-09-02 22:44:21 +0000 |
commit | 411e9e6eeb4d0d6d918917822b94414d446ec675 (patch) | |
tree | 4d0087744ac15f7de8c1718bed5c50f0de13ff98 | |
parent | a4aab272db12504b88712b15f8ececb78b862628 (diff) | |
download | chrome-ec-411e9e6eeb4d0d6d918917822b94414d446ec675.tar.gz |
zephyr: Add test runner task id
Code calling task_get_current() requires to return from this function
valid task ID. To test this code, new TASK_ID_TEST_RUNNER is introduced.
Test can set current thread as test runner and guarantee that
task_get_current() return valid task ID.
BUG=b:184856919
BRANCH=none
TEST=none
Signed-off-by: Tomasz Michalec <tm@semihalf.com>
Change-Id: Id5470e5337ab2419aad07f0f22de5f1576e870c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3110086
Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r-- | zephyr/shim/include/ec_tasks.h | 8 | ||||
-rw-r--r-- | zephyr/shim/include/shimmed_task_id.h | 3 | ||||
-rw-r--r-- | zephyr/shim/src/tasks.c | 16 |
3 files changed, 27 insertions, 0 deletions
diff --git a/zephyr/shim/include/ec_tasks.h b/zephyr/shim/include/ec_tasks.h index 1f050302a0..6f75bd577e 100644 --- a/zephyr/shim/include/ec_tasks.h +++ b/zephyr/shim/include/ec_tasks.h @@ -19,4 +19,12 @@ /** Starts all of the shimmed EC tasks. Requires CONFIG_SHIMMED_TASKS=y. */ void start_ec_tasks(void); +#ifdef TEST_BUILD +/** + * Set TASK_ID_TEST_RUNNER to current thread tid. Some functions that are tested + * require to run in any task context. + */ +void set_test_runner_tid(void); +#endif + #endif /* __CROS_EC_EC_TASKS_H */ diff --git a/zephyr/shim/include/shimmed_task_id.h b/zephyr/shim/include/shimmed_task_id.h index c25d8c731e..f56edf0806 100644 --- a/zephyr/shim/include/shimmed_task_id.h +++ b/zephyr/shim/include/shimmed_task_id.h @@ -107,6 +107,9 @@ typedef uint8_t task_id_t; enum { TASK_ID_IDLE = -1, /* We don't shim the idle task */ CROS_EC_TASK_LIST +#ifdef TEST_BUILD + TASK_ID_TEST_RUNNER, +#endif TASK_ID_COUNT, TASK_ID_INVALID = 0xff, /* Unable to find the task */ }; diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c index 5b636fc523..9e88b0b452 100644 --- a/zephyr/shim/src/tasks.c +++ b/zephyr/shim/src/tasks.c @@ -84,6 +84,10 @@ static int tasks_started; #undef CROS_EC_TASK #undef TASK_TEST +#ifdef TEST_BUILD +static k_tid_t test_runner_tid; +#endif + task_id_t task_get_current(void) { for (size_t i = 0; i < ARRAY_SIZE(shimmed_tasks); ++i) { @@ -99,6 +103,11 @@ task_id_t task_get_current(void) } #endif /* HAS_TASK_HOOKS */ +#ifdef TEST_BUILD + if (k_current_get() == test_runner_tid) { + return TASK_ID_TEST_RUNNER; + } +#endif __ASSERT(false, "Task index out of bound"); return 0; } @@ -257,6 +266,13 @@ void timer_cancel(task_id_t cros_ec_task_id) k_timer_stop(&ctx->timer); } +#ifdef TEST_BUILD +void set_test_runner_tid(void) +{ + test_runner_tid = k_current_get(); +} +#endif + void start_ec_tasks(void) { for (size_t i = 0; i < ARRAY_SIZE(shimmed_tasks); ++i) { |