Skip to content

Commit 40cdd79

Browse files
author
Andrew Boie
committed
tests: poll: reduce memory usage
We can re-use thread/stack objects between cases, no need to have separate ones. Signed-off-by: Andrew Boie <[email protected]>
1 parent 8ed215e commit 40cdd79

File tree

1 file changed

+21
-34
lines changed

1 file changed

+21
-34
lines changed

tests/kernel/poll/src/test_poll.c

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ struct fifo_msg {
1515

1616
#define SIGNAL_RESULT 0x1ee7d00d
1717
#define FIFO_MSG_VALUE 0xdeadbeef
18+
#define STACK_SIZE (1024 + CONFIG_TEST_EXTRA_STACKSIZE)
1819

1920
/* verify k_poll() without waiting */
2021
static struct k_sem no_wait_sem;
2122
static struct k_fifo no_wait_fifo;
2223
static struct k_poll_signal no_wait_signal;
24+
static struct k_thread test_thread;
25+
static struct k_thread test_loprio_thread;
26+
K_THREAD_STACK_DEFINE(test_stack, STACK_SIZE);
27+
K_THREAD_STACK_DEFINE(test_loprio_stack, STACK_SIZE);
2328

2429
/**
2530
* @brief Test cases to verify poll
@@ -113,10 +118,6 @@ static struct k_poll_signal wait_signal =
113118

114119
struct fifo_msg wait_msg = { NULL, FIFO_MSG_VALUE };
115120

116-
static struct k_thread poll_wait_helper_thread;
117-
static K_THREAD_STACK_DEFINE(poll_wait_helper_stack,
118-
KB(1) + CONFIG_TEST_EXTRA_STACKSIZE);
119-
120121
#define TAG_0 10
121122
#define TAG_1 11
122123
#define TAG_2 12
@@ -174,8 +175,8 @@ void test_poll_wait(void)
174175
*/
175176
k_thread_priority_set(k_current_get(), main_low_prio);
176177

177-
k_thread_create(&poll_wait_helper_thread, poll_wait_helper_stack,
178-
K_THREAD_STACK_SIZEOF(poll_wait_helper_stack),
178+
k_thread_create(&test_thread, test_stack,
179+
K_THREAD_STACK_SIZEOF(test_stack),
179180
poll_wait_helper, (void *)1, 0, 0,
180181
main_low_prio - 1, K_USER | K_INHERIT_PERMS, 0);
181182

@@ -230,8 +231,8 @@ void test_poll_wait(void)
230231
*/
231232
k_thread_priority_set(k_current_get(), main_low_prio);
232233

233-
k_thread_create(&poll_wait_helper_thread, poll_wait_helper_stack,
234-
K_THREAD_STACK_SIZEOF(poll_wait_helper_stack),
234+
k_thread_create(&test_thread, test_stack,
235+
K_THREAD_STACK_SIZEOF(test_stack),
235236
poll_wait_helper,
236237
0, 0, 0, main_low_prio - 1, 0, 0);
237238

@@ -265,8 +266,8 @@ void test_poll_wait(void)
265266
wait_events[2].state = K_POLL_STATE_NOT_READY;
266267
wait_signal.signaled = 0U;
267268

268-
k_thread_create(&poll_wait_helper_thread, poll_wait_helper_stack,
269-
K_THREAD_STACK_SIZEOF(poll_wait_helper_stack),
269+
k_thread_create(&test_thread, test_stack,
270+
K_THREAD_STACK_SIZEOF(test_stack),
270271
poll_wait_helper,
271272
(void *)1, 0, 0, old_prio + 1,
272273
K_USER | K_INHERIT_PERMS, 0);
@@ -338,9 +339,6 @@ void test_poll_wait(void)
338339
static struct k_fifo cancel_fifo;
339340
static struct k_fifo non_cancel_fifo;
340341

341-
static struct k_thread poll_cancel_helper_thread;
342-
static K_THREAD_STACK_DEFINE(poll_cancel_helper_stack, 768);
343-
344342
static void poll_cancel_helper(void *p1, void *p2, void *p3)
345343
{
346344
(void)p1; (void)p2; (void)p3;
@@ -386,8 +384,8 @@ void test_poll_cancel(bool is_main_low_prio)
386384
k_thread_priority_set(k_current_get(), main_low_prio);
387385
}
388386

389-
k_thread_create(&poll_cancel_helper_thread, poll_cancel_helper_stack,
390-
K_THREAD_STACK_SIZEOF(poll_cancel_helper_stack),
387+
k_thread_create(&test_thread, test_stack,
388+
K_THREAD_STACK_SIZEOF(test_stack),
391389
poll_cancel_helper, (void *)1, 0, 0,
392390
main_low_prio - 1, K_USER | K_INHERIT_PERMS, 0);
393391

@@ -429,10 +427,6 @@ void test_poll_cancel_main_high_prio(void)
429427
/* verify multiple pollers */
430428
static K_SEM_DEFINE(multi_sem, 0, 1);
431429

432-
static struct k_thread multi_thread_lowprio;
433-
static K_THREAD_STACK_DEFINE(multi_stack_lowprio,
434-
KB(1) + CONFIG_TEST_EXTRA_STACKSIZE);
435-
436430
static void multi_lowprio(void *p1, void *p2, void *p3)
437431
{
438432
(void)p1; (void)p2; (void)p3;
@@ -450,9 +444,6 @@ static void multi_lowprio(void *p1, void *p2, void *p3)
450444

451445
static K_SEM_DEFINE(multi_reply, 0, 1);
452446

453-
static struct k_thread multi_thread;
454-
static K_THREAD_STACK_DEFINE(multi_stack, KB(1) + CONFIG_TEST_EXTRA_STACKSIZE);
455-
456447
static void multi(void *p1, void *p2, void *p3)
457448
{
458449
(void)p1; (void)p2; (void)p3;
@@ -493,17 +484,17 @@ void test_poll_multi(void)
493484

494485
k_thread_priority_set(k_current_get(), main_low_prio);
495486

496-
k_thread_create(&multi_thread, multi_stack,
497-
K_THREAD_STACK_SIZEOF(multi_stack),
487+
k_thread_create(&test_thread, test_stack,
488+
K_THREAD_STACK_SIZEOF(test_stack),
498489
multi, 0, 0, 0, main_low_prio - 1,
499490
K_USER | K_INHERIT_PERMS, 0);
500491

501492
/*
502493
* create additional thread to add multiple(more than one) pending threads
503494
* in events list to improve code coverage
504495
*/
505-
k_thread_create(&multi_thread_lowprio, multi_stack_lowprio,
506-
K_THREAD_STACK_SIZEOF(multi_stack_lowprio),
496+
k_thread_create(&test_loprio_thread, test_loprio_stack,
497+
K_THREAD_STACK_SIZEOF(test_loprio_stack),
507498
multi_lowprio, 0, 0, 0, main_low_prio + 1,
508499
K_USER | K_INHERIT_PERMS, 0);
509500

@@ -527,8 +518,6 @@ void test_poll_multi(void)
527518
k_sleep(250);
528519
}
529520

530-
static struct k_thread signal_thread;
531-
static K_THREAD_STACK_DEFINE(signal_stack, KB(1) + CONFIG_TEST_EXTRA_STACKSIZE);
532521
static struct k_poll_signal signal;
533522

534523
static void threadstate(void *p1, void *p2, void *p3)
@@ -573,8 +562,8 @@ void test_poll_threadstate(void)
573562
k_thread_priority_set(k_current_get(), main_low_prio);
574563
k_tid_t ztest_tid = k_current_get();
575564

576-
k_thread_create(&signal_thread, signal_stack,
577-
K_THREAD_STACK_SIZEOF(signal_stack), threadstate,
565+
k_thread_create(&test_thread, test_stack,
566+
K_THREAD_STACK_SIZEOF(test_stack), threadstate,
578567
ztest_tid, 0, 0, main_low_prio - 1, K_INHERIT_PERMS, 0);
579568

580569
/* wait for spawn thread to take action */
@@ -595,8 +584,6 @@ void test_poll_grant_access(void)
595584
k_thread_access_grant(k_current_get(), &no_wait_sem, &no_wait_fifo,
596585
&no_wait_signal, &wait_sem, &wait_fifo,
597586
&cancel_fifo, &non_cancel_fifo,
598-
&wait_signal, &poll_wait_helper_thread,
599-
&poll_wait_helper_stack, &multi_sem,
600-
&multi_reply, &multi_thread, &multi_stack,
601-
&multi_thread_lowprio, &multi_stack_lowprio);
587+
&wait_signal, &test_thread,
588+
&test_stack, &multi_sem, &multi_reply)
602589
}

0 commit comments

Comments
 (0)