diff options
Diffstat (limited to 'zephyr/test/drivers/host_command_thread/src/main.c')
-rw-r--r-- | zephyr/test/drivers/host_command_thread/src/main.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/zephyr/test/drivers/host_command_thread/src/main.c b/zephyr/test/drivers/host_command_thread/src/main.c index 8b315dd950..bcd1b97074 100644 --- a/zephyr/test/drivers/host_command_thread/src/main.c +++ b/zephyr/test/drivers/host_command_thread/src/main.c @@ -21,15 +21,16 @@ #define CUSTOM_COMMAND_ID 0x0088 -/* Pointer to the main thread, defined in kernel/init.c */ -extern struct k_thread z_main_thread; +/* Thread id of fake main thread */ +static k_tid_t fake_main_tid; /* 0 - did not run, 1 - true, -1 - false */ static int last_check_main_thread_result; static enum ec_status check_main_thread(struct host_cmd_handler_args *args) { - last_check_main_thread_result = in_host_command_main() ? 1 : -1; + last_check_main_thread_result = + (k_current_get() == get_main_thread() ? 1 : -1); return EC_RES_SUCCESS; } @@ -42,6 +43,15 @@ static void fake_main_thread(void *a, void *b, void *c) K_THREAD_STACK_DEFINE(fake_main_thread_stack, 4000); +/* Override get_hostcmd_thread() from shim/src/tasks.c so + * task_get_current() returns TASK_ID_HOSTCMD when fake main thread + * is running. + */ +k_tid_t get_hostcmd_thread(void) +{ + return fake_main_tid; +} + ZTEST_SUITE(host_cmd_thread, drivers_predicate_post_main, NULL, NULL, NULL, NULL); @@ -51,7 +61,8 @@ ZTEST(host_cmd_thread, test_takeover) BUILD_HOST_COMMAND_SIMPLE(CUSTOM_COMMAND_ID, 0); const char expected_thread_name[] = "HOSTCMD"; struct k_thread fake_main_thread_data; - k_tid_t tid = k_thread_create( + + fake_main_tid = k_thread_create( &fake_main_thread_data, fake_main_thread_stack, K_THREAD_STACK_SIZEOF(fake_main_thread_stack), fake_main_thread, NULL, NULL, NULL, 1, 0, K_NO_WAIT); @@ -60,11 +71,11 @@ ZTEST(host_cmd_thread, test_takeover) k_msleep(500); /* Get the name of the thread (must be done after the sleep) */ - const char *main_thread_name = k_thread_name_get(&z_main_thread); + const char *main_thread_name = k_thread_name_get(get_main_thread()); /* Verify that the thread is not the hostcmd thread */ zassert_equal(EC_TASK_PRIORITY(EC_TASK_HOSTCMD_PRIO), - k_thread_priority_get(&z_main_thread)); + k_thread_priority_get(get_main_thread())); zassert_equal(strlen(expected_thread_name), strlen(main_thread_name)); zassert_mem_equal(expected_thread_name, main_thread_name, strlen(expected_thread_name)); @@ -79,5 +90,5 @@ ZTEST(host_cmd_thread, test_takeover) zassert_equal(-1, last_check_main_thread_result); /* Kill the extra thread */ - k_thread_abort(tid); + k_thread_abort(fake_main_tid); } |