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 <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2021-03-01 16:55:37 -08:00 committed by Anas Nashif
commit 2197d46a43
2 changed files with 9 additions and 9 deletions

View file

@ -310,7 +310,7 @@ static void test_timeout_non_empty_lifo(void)
static void test_timeout_lifo_thread(void) static void test_timeout_lifo_thread(void)
{ {
void *packet, *scratch_packet; void *packet, *scratch_packet;
struct reply_packet reply_packet; static volatile struct reply_packet reply_packet;
uint32_t start_time, timeout; 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, tid[0] = k_thread_create(&ttdata[0], ttstack[0], TSTACK_SIZE,
test_thread_timeout_reply_values, test_thread_timeout_reply_values,
&reply_packet, NULL, NULL, (void *)&reply_packet, NULL, NULL,
LIFO_THREAD_PRIO, K_INHERIT_PERMS, K_NO_WAIT); LIFO_THREAD_PRIO, K_INHERIT_PERMS, K_NO_WAIT);
k_yield(); k_yield();
@ -357,7 +357,7 @@ static void test_timeout_lifo_thread(void)
tid[0] = k_thread_create(&ttdata[0], ttstack[0], TSTACK_SIZE, tid[0] = k_thread_create(&ttdata[0], ttstack[0], TSTACK_SIZE,
test_thread_timeout_reply_values, test_thread_timeout_reply_values,
&reply_packet, NULL, NULL, (void *)&reply_packet, NULL, NULL,
LIFO_THREAD_PRIO, K_INHERIT_PERMS, K_NO_WAIT); LIFO_THREAD_PRIO, K_INHERIT_PERMS, K_NO_WAIT);
k_yield(); k_yield();
@ -377,7 +377,7 @@ static void test_timeout_lifo_thread(void)
tid[0] = k_thread_create(&ttdata[0], ttstack[0], TSTACK_SIZE, tid[0] = k_thread_create(&ttdata[0], ttstack[0], TSTACK_SIZE,
test_thread_timeout_reply_values_wfe, test_thread_timeout_reply_values_wfe,
&reply_packet, NULL, NULL, (void *)&reply_packet, NULL, NULL,
LIFO_THREAD_PRIO, K_INHERIT_PERMS, K_NO_WAIT); LIFO_THREAD_PRIO, K_INHERIT_PERMS, K_NO_WAIT);
packet = k_lifo_get(&timeout_order_lifo, K_FOREVER); packet = k_lifo_get(&timeout_order_lifo, K_FOREVER);

View file

@ -334,22 +334,22 @@ static void queue_poll_race_consume(void *p1, void *p2, void *p3)
void test_queue_poll_race(void) void test_queue_poll_race(void)
{ {
int prio = k_thread_priority_get(k_current_get()); 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_queue_init(&queue);
k_thread_create(&tdata, tstack, STACK_SIZE, k_thread_create(&tdata, tstack, STACK_SIZE,
queue_poll_race_consume, queue_poll_race_consume,
&queue, &mid_count, NULL, &queue, (void *)&mid_count, NULL,
prio + 1, 0, K_NO_WAIT); prio + 1, 0, K_NO_WAIT);
k_thread_create(&tdata1, tstack1, STACK_SIZE, k_thread_create(&tdata1, tstack1, STACK_SIZE,
queue_poll_race_consume, queue_poll_race_consume,
&queue, &low_count, NULL, &queue, (void *)&low_count, NULL,
prio + 2, 0, K_NO_WAIT); prio + 2, 0, K_NO_WAIT);
/* Let them initialize and block */ /* 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 /* Insert two items. This will wake up both threads, but the
* higher priority thread (tdata1) might (if CONFIG_POLL) * 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(low_count == 0, NULL);
zassert_true(mid_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); zassert_true(low_count + mid_count == 2, NULL);