Skip to content

Commit 015b4f7

Browse files
Andy Rossnashif
authored andcommitted
tests/kernel: Coherence: no shared data on stacks
A fairly common idiom in our test code is to put test-local data structures onto the stack, even when they are to be used from another thread. But stacks are incoherent memory on some platforms, which means that such things may not get a consistent view of memory between threads. Just make these things static. A few of these spots were causing test failures on intel_adsp_cavs15. More were found by inspection while hunting for mistakes. Signed-off-by: Andy Ross <[email protected]>
1 parent 1ba7414 commit 015b4f7

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

tests/kernel/common/src/timeout_order.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void test_timeout_order(void)
7676
k_timer_start(&timer[ii], K_MSEC(100), K_NO_WAIT);
7777
}
7878

79-
struct k_poll_event poll_events[NUM_TIMEOUTS];
79+
static struct k_poll_event poll_events[NUM_TIMEOUTS];
8080

8181
for (ii = 0; ii < NUM_TIMEOUTS; ii++) {
8282
k_poll_event_init(&poll_events[ii], K_POLL_TYPE_SEM_AVAILABLE,

tests/kernel/lifo/lifo_api/src/test_lifo_fail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
void test_lifo_get_fail(void *p1, void *p2, void *p3)
2424
{
25-
struct k_lifo lifo;
25+
static struct k_lifo lifo;
2626

2727
k_lifo_init(&lifo);
2828
/**TESTPOINT: lifo get returns NULL*/

tests/kernel/mbox/mbox_usage/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static enum mmsg_type {
2727

2828
static void msg_sender(struct k_mbox *pmbox, k_timeout_t timeout)
2929
{
30-
struct k_mbox_msg mmsg;
30+
static struct k_mbox_msg mmsg;
3131

3232
(void)memset(&mmsg, 0, sizeof(mmsg));
3333

@@ -53,8 +53,8 @@ static void msg_sender(struct k_mbox *pmbox, k_timeout_t timeout)
5353
static void msg_receiver(struct k_mbox *pmbox, k_tid_t thd_id,
5454
k_timeout_t timeout)
5555
{
56-
struct k_mbox_msg mmsg;
57-
char rxdata[MAIL_LEN];
56+
static struct k_mbox_msg mmsg;
57+
static char rxdata[MAIL_LEN];
5858

5959
switch (info_type) {
6060
case PUT_GET_NULL:

tests/kernel/msgq/msgq_api/src/test_msgq_contexts.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static void msgq_isr(struct k_msgq *pmsgq)
159159

160160
static void thread_entry_get_data(void *p1, void *p2, void *p3)
161161
{
162-
uint32_t rx_buf[MSGQ_LEN];
162+
static uint32_t rx_buf[MSGQ_LEN];
163163
int i = 0;
164164

165165
while (k_msgq_get(p1, &rx_buf[i], K_NO_WAIT) != 0) {
@@ -201,7 +201,7 @@ static void msgq_thread_data_passing(struct k_msgq *pmsgq)
201201
static void get_empty_entry(void *p1, void *p2, void *p3)
202202
{
203203
int ret;
204-
uint32_t rx_buf[MSGQ_LEN];
204+
static uint32_t rx_buf[MSGQ_LEN];
205205

206206
/* make sure there is no message in the queue */
207207
ret = k_msgq_peek(p1, rx_buf);
@@ -324,7 +324,7 @@ void test_msgq_user_thread_overflow(void)
324324
*/
325325
void test_msgq_isr(void)
326326
{
327-
struct k_msgq stack_msgq;
327+
static struct k_msgq stack_msgq;
328328

329329
/**TESTPOINT: init via k_msgq_init*/
330330
k_msgq_init(&stack_msgq, tbuffer, MSG_SIZE, MSGQ_LEN);

tests/kernel/queue/src/test_queue_contexts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void test_queue_poll_race(void)
385385
void test_multiple_queues(void)
386386
{
387387
/*define multiple queues*/
388-
struct k_queue queues[QUEUE_NUM];
388+
static struct k_queue queues[QUEUE_NUM];
389389

390390
for (int i = 0; i < QUEUE_NUM; i++) {
391391
k_queue_init(&queues[i]);

tests/kernel/queue/src/test_queue_fail.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static struct k_thread tdata;
2121
*/
2222
void test_queue_get_fail(void)
2323
{
24-
struct k_queue queue;
24+
static struct k_queue queue;
2525

2626
k_queue_init(&queue);
2727
/**TESTPOINT: queue get returns NULL*/
@@ -54,7 +54,7 @@ static void tThread_entry(void *p1, void *p2, void *p3)
5454
void test_queue_append_list_error(void)
5555
{
5656
qdata_t data_l[2];
57-
struct k_queue queue;
57+
static struct k_queue queue;
5858
qdata_t *head = NULL, *tail = &data_l[1];
5959

6060
k_queue_init(&queue);
@@ -97,7 +97,7 @@ void test_queue_append_list_error(void)
9797
void test_queue_merge_list_error(void)
9898
{
9999
qdata_t data_sl[2];
100-
struct k_queue queue;
100+
static struct k_queue queue;
101101
sys_slist_t slist;
102102

103103
k_queue_init(&queue);

0 commit comments

Comments
 (0)