tests/kernel/workq: Fix semaphore counting
This test case will call k_sem_give() twice and expect both to be received by k_sem_take(), yet the semaphore is initialized with a maximum count of one! The reason this worked was an undocumented misfeature of k_sem: if k_sem_take() was called on a semaphore with a pended thread, it would wake up that thread synchronously instead of incrementing the count. So you could call it once to wake up the thread and again to queue the count and not overflow. The problem is that this is a priority bug (a high priority runnable thread should have the chance to run and call k_sem_take() before a low priority thread that got woken). Zync corrects that, and so needs to have two slots if you want two semaphore events. Signed-off-by: Andy Ross <andyross@google.com>
This commit is contained in:
parent
6fa4d722a6
commit
6a1f721dda
|
@ -1308,8 +1308,11 @@ static bool try_queue_no_yield(struct k_work_q *wq)
|
|||
/* Verify that no-yield policy works */
|
||||
ZTEST(work_1cpu, test_1cpu_queue_no_yield)
|
||||
{
|
||||
/* This test needs two slots available in the sem! */
|
||||
k_sem_init(&sync_sem, 0, 2);
|
||||
zassert_equal(try_queue_no_yield(&coophi_queue), true);
|
||||
zassert_equal(try_queue_no_yield(&cooplo_queue), false);
|
||||
k_sem_init(&sync_sem, 0, 1);
|
||||
}
|
||||
|
||||
/* Basic functionality with the system work queue. */
|
||||
|
|
Loading…
Reference in a new issue