tests/kernel/common: add test to verify same tick timeout expiry order
Timeouts, when expiring on the same tick, should be handled in the same order they were queued. Change-Id: I23a8e971a47ca056b32b8b48fe179d481bae27c0 Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
This commit is contained in:
parent
6f4bc80901
commit
d2654d3143
4 changed files with 83 additions and 1 deletions
|
@ -4,3 +4,4 @@ CONFIG_PRINTK=y
|
|||
CONFIG_SYS_LOG=y
|
||||
CONFIG_RANDOM_GENERATOR=y
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
CONFIG_POLL=y
|
||||
|
|
|
@ -7,3 +7,4 @@ obj-y += slist.o
|
|||
obj-y += dlist.o
|
||||
obj-n += bitfield.o
|
||||
obj-y += rand32.o
|
||||
obj-y += timeout_order.o
|
||||
|
|
|
@ -18,6 +18,8 @@ extern void ring_buffer_test(void);
|
|||
extern void slist_test(void);
|
||||
extern void dlist_test(void);
|
||||
extern void rand32_test(void);
|
||||
extern void rand32_test(void);
|
||||
extern void timeout_order_test(void);
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
|
@ -32,7 +34,8 @@ void test_main(void)
|
|||
ztest_unit_test(slist_test),
|
||||
ztest_unit_test(dlist_test),
|
||||
ztest_unit_test(rand32_test),
|
||||
ztest_unit_test(intmath_test)
|
||||
ztest_unit_test(intmath_test),
|
||||
ztest_unit_test(timeout_order_test)
|
||||
);
|
||||
|
||||
ztest_run_test_suite(common_test);
|
||||
|
|
77
tests/kernel/common/src/timeout_order.c
Normal file
77
tests/kernel/common/src/timeout_order.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Wind River Systems, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <kernel.h>
|
||||
#include <misc/printk.h>
|
||||
#include <ztest.h>
|
||||
|
||||
#define NUM_TIMEOUTS 3
|
||||
|
||||
static struct k_timer timer[NUM_TIMEOUTS];
|
||||
static struct k_sem sem[NUM_TIMEOUTS];
|
||||
|
||||
static int results[NUM_TIMEOUTS], cur;
|
||||
|
||||
static void thread(void *p1, void *p2, void *p3)
|
||||
{
|
||||
ARG_UNUSED(p2);
|
||||
ARG_UNUSED(p3);
|
||||
|
||||
uintptr_t id = (uintptr_t)p1;
|
||||
|
||||
k_timer_status_sync(&timer[id]);
|
||||
printk("%s %d synced on timer %d\n", __func__, id, id);
|
||||
|
||||
/* no need to protect cur, all threads have the same prio */
|
||||
results[cur++] = id;
|
||||
|
||||
k_sem_give(&sem[id]);
|
||||
}
|
||||
|
||||
static __noinit __stack char stacks[NUM_TIMEOUTS][512];
|
||||
|
||||
void timeout_order_test(void)
|
||||
{
|
||||
int ii, prio = k_thread_priority_get(k_current_get()) + 1;
|
||||
|
||||
for (ii = 0; ii < NUM_TIMEOUTS; ii++) {
|
||||
(void)k_thread_spawn(stacks[ii], 512, thread,
|
||||
(void *)ii, 0, 0, prio, 0, 0);
|
||||
k_timer_init(&timer[ii], 0, 0);
|
||||
k_sem_init(&sem[ii], 0, 1);
|
||||
results[ii] = -1;
|
||||
}
|
||||
|
||||
|
||||
uint32_t uptime = k_uptime_get_32();
|
||||
|
||||
/* sync on tick */
|
||||
while (uptime == k_uptime_get_32())
|
||||
;
|
||||
|
||||
for (ii = 0; ii < NUM_TIMEOUTS; ii++) {
|
||||
k_timer_start(&timer[ii], 100, 0);
|
||||
}
|
||||
|
||||
struct k_poll_event poll_events[NUM_TIMEOUTS];
|
||||
|
||||
for (ii = 0; ii < NUM_TIMEOUTS; ii++) {
|
||||
k_poll_event_init(&poll_events[ii], K_POLL_TYPE_SEM_AVAILABLE,
|
||||
K_POLL_MODE_NOTIFY_ONLY, &sem[ii]);
|
||||
}
|
||||
|
||||
/* drop prio to get all poll events together */
|
||||
k_thread_priority_set(k_current_get(), prio + 1);
|
||||
|
||||
assert_equal(k_poll(poll_events, NUM_TIMEOUTS, 2000), 0, "");
|
||||
for (ii = 0; ii < NUM_TIMEOUTS; ii++) {
|
||||
assert_equal(poll_events[ii].state,
|
||||
K_POLL_STATE_SEM_AVAILABLE, "");
|
||||
}
|
||||
for (ii = 0; ii < NUM_TIMEOUTS; ii++) {
|
||||
assert_equal(results[ii], ii, "");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue