From 6941c8fda9346225efc5f96cce19a2dd054ed78a Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Wed, 12 May 2021 15:10:03 -0700 Subject: [PATCH] tests/kernel/smp: Misc synchronization fixups A few mistakes in recent changes to this test: There was a "LOCK_NO" (i.e. no locking!) case being exercised in test_inc_concurrency, where three threads would race against each other incrementing and decrementing a single count without synchronization. And... it failed on cAVS. Because there was no synchronization. Just remove. The LOCK_IRQ (irq_un/lock()) case of the same test was was casting taking a pointer to an integer (that stored the irq_lock() result) and casting the pointer value to an integer instead of dereferencing it. Also the workq test had a work item on the stack, which is forbidden when KERNEL_COHERENCE=y Fixes #34152 Signed-off-by: Andy Ross --- tests/kernel/smp/src/main.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/kernel/smp/src/main.c b/tests/kernel/smp/src/main.c index cfbb35b7e0b..f5d96f4b7ad 100644 --- a/tests/kernel/smp/src/main.c +++ b/tests/kernel/smp/src/main.c @@ -698,7 +698,7 @@ static void workq_handler(struct k_work *work) */ void test_workq_on_smp(void) { - struct k_work work; + static struct k_work work; k_work_init(&work, workq_handler); @@ -858,7 +858,6 @@ void test_smp_release_global_lock_irq(void) #define LOOP_COUNT 20000 enum sync_t { - LOCK_NO, LOCK_IRQ, LOCK_SEM, LOCK_MUTEX @@ -877,14 +876,12 @@ static void sync_lock_dummy(void *k) static void sync_lock_irq(void *k) { - *((int *)k) = irq_lock(); + *((unsigned int *)k) = irq_lock(); } static void sync_unlock_irq(void *k) { - int key = POINTER_TO_INT(k); - - irq_unlock(key); + irq_unlock(*(unsigned int *)k); } static void sync_lock_sem(void *k) @@ -1006,10 +1003,6 @@ static int run_concurrency(int type, void *func) */ void test_inc_concurrency(void) { - /* increasing global var without lock */ - zassert_false(run_concurrency(LOCK_NO, inc_global_cnt), - "total count %d is wrong", global_cnt); - /* increasing global var with irq lock */ zassert_true(run_concurrency(LOCK_IRQ, inc_global_cnt), "total count %d is wrong(i)", global_cnt);