Skip to content

Commit 06fea49

Browse files
committed
tests: posix: common: separate posix thread base into a standalone test
posix.common contains testsuites that can be separated into smaller groups of tests. This change moves pthread into a singular testsuite at tests/posix/thread_base app directory. Signed-off-by: Marvin Ouma <pancakesdeath@protonmail.com>
1 parent 71a329f commit 06fea49

File tree

10 files changed

+680
-69
lines changed

10 files changed

+680
-69
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(posix_threads_base)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
9+
target_sources(app PRIVATE ${app_sources})
10+
11+
target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)

tests/posix/threads_base/prj.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CONFIG_POSIX_API=y
2+
CONFIG_ZTEST=y
3+
4+
CONFIG_POSIX_AEP_CHOICE_BASE=y
5+
CONFIG_POSIX_THREADS=y
6+
CONFIG_POSIX_PRIORITY_SCHEDULING=y
7+
CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING=y
8+
CONFIG_THREAD_NAME=y
9+
CONFIG_DYNAMIC_THREAD=y
10+
CONFIG_THREAD_STACK_INFO=y
11+
CONFIG_DYNAMIC_THREAD_POOL_SIZE=6
12+
CONFIG_POSIX_THREAD_THREADS_MAX=6
13+
CONFIG_HEAP_MEM_POOL_SIZE=4096
14+
CONFIG_POSIX_THREAD_KEYS_MAX=512
15+
CONFIG_TEST_EXTRA_STACK_SIZE=4096

tests/posix/common/src/cond.c renamed to tests/posix/threads_base/src/cond.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @details Exactly CONFIG_MAX_PTHREAD_COND_COUNT can be in use at once.
1515
*/
16-
ZTEST(cond, test_cond_resource_exhausted)
16+
ZTEST(posix_threads_base, test_cond_resource_exhausted)
1717
{
1818
size_t i;
1919
pthread_cond_t m[CONFIG_MAX_PTHREAD_COND_COUNT + 1];
@@ -37,7 +37,7 @@ ZTEST(cond, test_cond_resource_exhausted)
3737
*
3838
* @details Demonstrate that condition variables may be used over and over again.
3939
*/
40-
ZTEST(cond, test_cond_resource_leak)
40+
ZTEST(posix_threads_base, test_cond_resource_leak)
4141
{
4242
pthread_cond_t cond;
4343

@@ -47,7 +47,7 @@ ZTEST(cond, test_cond_resource_leak)
4747
}
4848
}
4949

50-
ZTEST(cond, test_pthread_condattr)
50+
ZTEST(posix_threads_base, test_pthread_condattr)
5151
{
5252
clockid_t clock_id;
5353
pthread_condattr_t att = {0};

tests/posix/common/src/key.c renamed to tests/posix/threads_base/src/key.c

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <zephyr/sys/util.h>
1010
#include <zephyr/ztest.h>
1111

12-
#define N_THR 2
12+
#define N_THR 2
1313
#define N_KEY 2
1414
#define BUFFSZ 48
1515

@@ -74,7 +74,7 @@ static void make_keys(void)
7474
* multiple keys.
7575
*/
7676

77-
ZTEST(key, test_key_1toN_thread)
77+
ZTEST(posix_threads_base, test_key_1toN_thread)
7878
{
7979
void *retval;
8080
pthread_t newthread[N_THR];
@@ -95,7 +95,7 @@ ZTEST(key, test_key_1toN_thread)
9595
zassert_ok(pthread_key_delete(key), "attempt to delete key failed");
9696
}
9797

98-
ZTEST(key, test_key_Nto1_thread)
98+
ZTEST(posix_threads_base, test_key_Nto1_thread)
9999
{
100100
pthread_t newthread;
101101

@@ -113,7 +113,7 @@ ZTEST(key, test_key_Nto1_thread)
113113
}
114114
}
115115

116-
ZTEST(key, test_key_resource_leak)
116+
ZTEST(posix_threads_base, test_key_resource_leak)
117117
{
118118
pthread_key_t key;
119119

@@ -123,7 +123,7 @@ ZTEST(key, test_key_resource_leak)
123123
}
124124
}
125125

126-
ZTEST(key, test_correct_key_is_deleted)
126+
ZTEST(posix_threads_base, test_correct_key_is_deleted)
127127
{
128128
pthread_key_t key;
129129
size_t j = CONFIG_POSIX_THREAD_KEYS_MAX - 1;
@@ -162,34 +162,21 @@ static void *setspecific_thread(void *count)
162162
return NULL;
163163
}
164164

165-
ZTEST(key, test_thread_specific_data_deallocation)
165+
ZTEST(posix_threads_base, test_thread_specific_data_deallocation)
166166
{
167167
pthread_t thread;
168168
static int alloc_count_t0;
169169
static int alloc_count_t1;
170170

171171
zassert_ok(pthread_create(&thread, NULL, setspecific_thread, &alloc_count_t0),
172-
"attempt to create thread failed");
172+
"attempt to create thread failed");
173173
zassert_ok(pthread_join(thread, NULL), "failed to join thread");
174174
printk("first thread allocated %d keys", alloc_count_t0);
175175

176176
zassert_ok(pthread_create(&thread, NULL, setspecific_thread, &alloc_count_t1),
177-
"attempt to create thread failed");
177+
"attempt to create thread failed");
178178
zassert_ok(pthread_join(thread, NULL), "failed to join thread");
179179
printk("second thread allocated %d keys", alloc_count_t1);
180180

181-
zassert_equal(alloc_count_t0, alloc_count_t1,
182-
"failed to deallocate thread specific data");
183-
}
184-
185-
static void before(void *arg)
186-
{
187-
ARG_UNUSED(arg);
188-
189-
if (!IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
190-
/* skip redundant testing if there is no thread pool / heap allocation */
191-
ztest_test_skip();
192-
}
181+
zassert_equal(alloc_count_t0, alloc_count_t1, "failed to deallocate thread specific data");
193182
}
194-
195-
ZTEST_SUITE(key, NULL, NULL, before, NULL, NULL);

tests/posix/threads_base/src/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2023, Meta
3+
* Copyright (c) 2024, Marvin Ouma <pancakesdeath@protonmail.com>
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <zephyr/ztest.h>
9+
10+
extern void before(void *arg);
11+
extern void after(void *arg);
12+
13+
ZTEST_SUITE(posix_threads_base, NULL, NULL, before, after, NULL);

tests/posix/common/src/mutex.c renamed to tests/posix/threads_base/src/mutex.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void test_mutex_common(int type, void *(*entry)(void *arg))
8585
zassert_ok(pthread_mutex_destroy(&mutex), "Destroying mutex is failed");
8686
}
8787

88-
ZTEST(mutex, test_mutex_prioceiling_stubs)
88+
ZTEST(posix_threads_base, test_mutex_prioceiling_stubs)
8989
{
9090
#ifdef CONFIG_POSIX_THREAD_PRIO_PROTECT
9191
zassert_equal(pthread_mutex_getprioceiling(NULL, NULL), ENOSYS);
@@ -104,7 +104,7 @@ ZTEST(mutex, test_mutex_prioceiling_stubs)
104104
* and pthread_mutex_lock are tested with mutex type being
105105
* normal.
106106
*/
107-
ZTEST(mutex, test_mutex_normal)
107+
ZTEST(posix_threads_base, test_mutex_normal)
108108
{
109109
test_mutex_common(PTHREAD_MUTEX_NORMAL, normal_mutex_entry);
110110
}
@@ -116,7 +116,7 @@ ZTEST(mutex, test_mutex_normal)
116116
* twice and unlocked for the same number of time.
117117
*
118118
*/
119-
ZTEST(mutex, test_mutex_recursive)
119+
ZTEST(posix_threads_base, test_mutex_recursive)
120120
{
121121
test_mutex_common(PTHREAD_MUTEX_RECURSIVE, recursive_mutex_entry);
122122
}
@@ -126,7 +126,7 @@ ZTEST(mutex, test_mutex_recursive)
126126
*
127127
* @details Exactly CONFIG_MAX_PTHREAD_MUTEX_COUNT can be in use at once.
128128
*/
129-
ZTEST(mutex, test_mutex_resource_exhausted)
129+
ZTEST(posix_threads_base, test_mutex_resource_exhausted)
130130
{
131131
size_t i;
132132
pthread_mutex_t m[CONFIG_MAX_PTHREAD_MUTEX_COUNT + 1];
@@ -150,7 +150,7 @@ ZTEST(mutex, test_mutex_resource_exhausted)
150150
*
151151
* @details Demonstrate that mutexes may be used over and over again.
152152
*/
153-
ZTEST(mutex, test_mutex_resource_leak)
153+
ZTEST(posix_threads_base, test_mutex_resource_leak)
154154
{
155155
pthread_mutex_t m;
156156

@@ -189,7 +189,7 @@ static void *test_mutex_timedlock_fn(void *arg)
189189
}
190190

191191
/** @brief Test to verify @ref pthread_mutex_timedlock returns ETIMEDOUT */
192-
ZTEST(mutex, test_mutex_timedlock)
192+
ZTEST(posix_threads_base, test_mutex_timedlock)
193193
{
194194
void *ret;
195195
pthread_t th;
@@ -215,15 +215,3 @@ ZTEST(mutex, test_mutex_timedlock)
215215

216216
zassert_ok(pthread_mutex_destroy(&mutex));
217217
}
218-
219-
static void before(void *arg)
220-
{
221-
ARG_UNUSED(arg);
222-
223-
if (!IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
224-
/* skip redundant testing if there is no thread pool / heap allocation */
225-
ztest_test_skip();
226-
}
227-
}
228-
229-
ZTEST_SUITE(mutex, NULL, NULL, before, NULL, NULL);

tests/posix/common/src/mutex_attr.c renamed to tests/posix/threads_base/src/mutex_attr.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <zephyr/ztest.h>
1111

12-
ZTEST(mutex_attr, test_pthread_mutexattr_init)
12+
ZTEST(posix_threads_base, test_pthread_mutexattr_init)
1313
{
1414
pthread_mutexattr_t attr;
1515

@@ -22,7 +22,7 @@ ZTEST(mutex_attr, test_pthread_mutexattr_init)
2222
zassert_ok(pthread_mutexattr_destroy(&attr));
2323
}
2424

25-
ZTEST(mutex_attr, test_pthread_mutexattr_destroy)
25+
ZTEST(posix_threads_base, test_pthread_mutexattr_destroy)
2626
{
2727
pthread_mutexattr_t attr;
2828

@@ -42,5 +42,3 @@ ZTEST(mutex_attr, test_pthread_mutexattr_destroy)
4242
zassert_equal(EINVAL, pthread_mutexattr_destroy(&attr));
4343
}
4444
}
45-
46-
ZTEST_SUITE(mutex_attr, NULL, NULL, NULL, NULL, NULL);

tests/posix/common/src/pthread.c renamed to tests/posix/threads_base/src/pthread.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static void *thread_top_term(void *p1)
226226
/* Test the internal priority conversion functions */
227227
int zephyr_to_posix_priority(int z_prio, int *policy);
228228
int posix_to_zephyr_priority(int priority, int policy);
229-
ZTEST(pthread, test_pthread_priority_conversion)
229+
ZTEST(posix_threads_base, test_pthread_priority_conversion)
230230
{
231231
/*
232232
* ZEPHYR [-CONFIG_NUM_COOP_PRIORITIES, -1]
@@ -256,7 +256,7 @@ ZTEST(pthread, test_pthread_priority_conversion)
256256
}
257257
}
258258

259-
ZTEST(pthread, test_pthread_execution)
259+
ZTEST(posix_threads_base, test_pthread_execution)
260260
{
261261
int i, ret;
262262
pthread_t newthread[N_THR_E];
@@ -346,7 +346,7 @@ ZTEST(pthread, test_pthread_execution)
346346
printk("Barrier test OK\n");
347347
}
348348

349-
ZTEST(pthread, test_pthread_termination)
349+
ZTEST(posix_threads_base, test_pthread_termination)
350350
{
351351
int32_t i, ret;
352352
pthread_t newthread[N_THR_T] = {0};
@@ -376,7 +376,7 @@ ZTEST(pthread, test_pthread_termination)
376376
zassert_equal(ret, ESRCH, "cancelled a terminated thread!");
377377
}
378378

379-
ZTEST(pthread, test_pthread_tryjoin)
379+
ZTEST(posix_threads_base, test_pthread_tryjoin)
380380
{
381381
pthread_t th = {0};
382382
int sleep_duration_ms = 200;
@@ -396,7 +396,7 @@ ZTEST(pthread, test_pthread_tryjoin)
396396
zassert_ok(pthread_tryjoin_np(th, &retval));
397397
}
398398

399-
ZTEST(pthread, test_pthread_timedjoin)
399+
ZTEST(posix_threads_base, test_pthread_timedjoin)
400400
{
401401
pthread_t th = {0};
402402
int sleep_duration_ms = 200;
@@ -444,7 +444,7 @@ static void *create_thread1(void *p1)
444444
return NULL;
445445
}
446446

447-
ZTEST(pthread, test_pthread_descriptor_leak)
447+
ZTEST(posix_threads_base, test_pthread_descriptor_leak)
448448
{
449449
pthread_t pthread1;
450450

@@ -456,7 +456,7 @@ ZTEST(pthread, test_pthread_descriptor_leak)
456456
}
457457
}
458458

459-
ZTEST(pthread, test_pthread_equal)
459+
ZTEST(posix_threads_base, test_pthread_equal)
460460
{
461461
zassert_true(pthread_equal(pthread_self(), pthread_self()));
462462
zassert_false(pthread_equal(pthread_self(), (pthread_t)4242));
@@ -484,7 +484,7 @@ static void *test_pthread_cleanup_entry(void *arg)
484484
return NULL;
485485
}
486486

487-
ZTEST(pthread, test_pthread_cleanup)
487+
ZTEST(posix_threads_base, test_pthread_cleanup)
488488
{
489489
pthread_t th;
490490

@@ -522,7 +522,7 @@ static void *test_pthread_cancel_fn(void *arg)
522522
return NULL;
523523
}
524524

525-
ZTEST(pthread, test_pthread_testcancel)
525+
ZTEST(posix_threads_base, test_pthread_testcancel)
526526
{
527527
pthread_t th;
528528

@@ -550,22 +550,10 @@ static void *test_pthread_setschedprio_fn(void *arg)
550550
return NULL;
551551
}
552552

553-
ZTEST(pthread, test_pthread_setschedprio)
553+
ZTEST(posix_threads_base, test_pthread_setschedprio)
554554
{
555555
pthread_t th;
556556

557557
zassert_ok(pthread_create(&th, NULL, test_pthread_setschedprio_fn, NULL));
558558
zassert_ok(pthread_join(th, NULL));
559559
}
560-
561-
static void before(void *arg)
562-
{
563-
ARG_UNUSED(arg);
564-
565-
if (!IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
566-
/* skip redundant testing if there is no thread pool / heap allocation */
567-
ztest_test_skip();
568-
}
569-
}
570-
571-
ZTEST_SUITE(pthread, NULL, NULL, before, NULL, NULL);

0 commit comments

Comments
 (0)