summaryrefslogtreecommitdiff
path: root/zephyr/shim/src/tasks.c
diff options
context:
space:
mode:
authorTomasz Michalec <tm@semihalf.com>2021-08-20 12:38:25 +0200
committerCommit Bot <commit-bot@chromium.org>2021-09-02 22:44:21 +0000
commit411e9e6eeb4d0d6d918917822b94414d446ec675 (patch)
tree4d0087744ac15f7de8c1718bed5c50f0de13ff98 /zephyr/shim/src/tasks.c
parenta4aab272db12504b88712b15f8ececb78b862628 (diff)
downloadchrome-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>
Diffstat (limited to 'zephyr/shim/src/tasks.c')
-rw-r--r--zephyr/shim/src/tasks.c16
1 files changed, 16 insertions, 0 deletions
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) {