From 2197d46a43c1a8475a9957470d9e24aa6ce7ad40 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Mon, 1 Mar 2021 16:55:37 -0800 Subject: [PATCH] tests/queue: tests/lifo_usage: Address ADSP/coherence issues These tests would pass pointers to data on their own stacks to other threads, which is forbidden when CONFIG_KERNEL_COHERENCE (because stack memory isn't cache-coherent). Make the variables static. Also, queue had two sleeps of 2 ticks (having been written in an era where that meant "20-30ms"), and on a device with a 50 kHz tick rate that's not very much time at all. It would sometimes fail spuriously because the spawned threads didn't consume the queue entries in time. How about 10ms of real time instead? Signed-off-by: Andy Ross --- tests/kernel/lifo/lifo_usage/src/main.c | 8 ++++---- tests/kernel/queue/src/test_queue_contexts.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/kernel/lifo/lifo_usage/src/main.c b/tests/kernel/lifo/lifo_usage/src/main.c index a035b2d38a9..4b34fa6590d 100644 --- a/tests/kernel/lifo/lifo_usage/src/main.c +++ b/tests/kernel/lifo/lifo_usage/src/main.c @@ -310,7 +310,7 @@ static void test_timeout_non_empty_lifo(void) static void test_timeout_lifo_thread(void) { void *packet, *scratch_packet; - struct reply_packet reply_packet; + static volatile struct reply_packet reply_packet; uint32_t start_time, timeout; /* @@ -338,7 +338,7 @@ static void test_timeout_lifo_thread(void) */ tid[0] = k_thread_create(&ttdata[0], ttstack[0], TSTACK_SIZE, test_thread_timeout_reply_values, - &reply_packet, NULL, NULL, + (void *)&reply_packet, NULL, NULL, LIFO_THREAD_PRIO, K_INHERIT_PERMS, K_NO_WAIT); k_yield(); @@ -357,7 +357,7 @@ static void test_timeout_lifo_thread(void) tid[0] = k_thread_create(&ttdata[0], ttstack[0], TSTACK_SIZE, test_thread_timeout_reply_values, - &reply_packet, NULL, NULL, + (void *)&reply_packet, NULL, NULL, LIFO_THREAD_PRIO, K_INHERIT_PERMS, K_NO_WAIT); k_yield(); @@ -377,7 +377,7 @@ static void test_timeout_lifo_thread(void) tid[0] = k_thread_create(&ttdata[0], ttstack[0], TSTACK_SIZE, test_thread_timeout_reply_values_wfe, - &reply_packet, NULL, NULL, + (void *)&reply_packet, NULL, NULL, LIFO_THREAD_PRIO, K_INHERIT_PERMS, K_NO_WAIT); packet = k_lifo_get(&timeout_order_lifo, K_FOREVER); diff --git a/tests/kernel/queue/src/test_queue_contexts.c b/tests/kernel/queue/src/test_queue_contexts.c index 66d32d20da6..bdb558d32d2 100644 --- a/tests/kernel/queue/src/test_queue_contexts.c +++ b/tests/kernel/queue/src/test_queue_contexts.c @@ -334,22 +334,22 @@ static void queue_poll_race_consume(void *p1, void *p2, void *p3) void test_queue_poll_race(void) { int prio = k_thread_priority_get(k_current_get()); - int mid_count = 0, low_count = 0; + static volatile int mid_count, low_count; k_queue_init(&queue); k_thread_create(&tdata, tstack, STACK_SIZE, queue_poll_race_consume, - &queue, &mid_count, NULL, + &queue, (void *)&mid_count, NULL, prio + 1, 0, K_NO_WAIT); k_thread_create(&tdata1, tstack1, STACK_SIZE, queue_poll_race_consume, - &queue, &low_count, NULL, + &queue, (void *)&low_count, NULL, prio + 2, 0, K_NO_WAIT); /* Let them initialize and block */ - k_sleep(K_TICKS(2)); + k_sleep(K_MSEC(10)); /* Insert two items. This will wake up both threads, but the * higher priority thread (tdata1) might (if CONFIG_POLL) @@ -362,7 +362,7 @@ void test_queue_poll_race(void) zassert_true(low_count == 0, NULL); zassert_true(mid_count == 0, NULL); - k_sleep(K_TICKS(2)); + k_sleep(K_MSEC(10)); zassert_true(low_count + mid_count == 2, NULL);