Skip to content

Commit d0f497c

Browse files
Christopher Friedtcarlescufi
authored andcommitted
tests: posix: use new ztest api
* Convert test suite declaration to `ZTEST_SUITE()` and test case declaration to `ZTEST()`. * add `CONFIG_ZTEST_NEW_API=y` to prj.conf Fixes #46793 Signed-off-by: Christopher Friedt <[email protected]>
1 parent 8b1d50b commit d0f497c

File tree

24 files changed

+157
-199
lines changed

24 files changed

+157
-199
lines changed

tests/posix/common/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ CONFIG_PTHREAD_IPC=y
22
CONFIG_POSIX_API=y
33
CONFIG_MAX_PTHREAD_COUNT=20
44
CONFIG_ZTEST=y
5+
CONFIG_ZTEST_NEW_API=y
56
CONFIG_SEM_VALUE_MAX=32767
67
CONFIG_POSIX_MQUEUE=y
78
CONFIG_HEAP_MEM_POOL_SIZE=4096

tests/posix/common/src/clock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define SLEEP_SECONDS 1
1212
#define CLOCK_INVALID -1
1313

14-
void test_posix_clock(void)
14+
ZTEST(posix_apis, test_posix_clock)
1515
{
1616
int64_t nsecs_elapsed, secs_elapsed;
1717
struct timespec ts, te;
@@ -44,7 +44,7 @@ void test_posix_clock(void)
4444
printk("POSIX clock APIs test done\n");
4545
}
4646

47-
void test_posix_realtime(void)
47+
ZTEST(posix_apis, test_posix_realtime)
4848
{
4949
int ret;
5050
struct timespec rts, mts;

tests/posix/common/src/main.c

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,4 @@
77
#include <ztest.h>
88
#include <pthread.h>
99

10-
extern void test_posix_clock(void);
11-
extern void test_posix_mqueue(void);
12-
extern void test_posix_normal_mutex(void);
13-
extern void test_posix_recursive_mutex(void);
14-
extern void test_posix_semaphore(void);
15-
extern void test_posix_rw_lock(void);
16-
extern void test_posix_realtime(void);
17-
extern void test_posix_timer(void);
18-
extern void test_posix_pthread_execution(void);
19-
extern void test_posix_pthread_error_condition(void);
20-
extern void test_posix_pthread_create_negative(void);
21-
extern void test_posix_pthread_termination(void);
22-
extern void test_posix_multiple_threads_single_key(void);
23-
extern void test_posix_single_thread_multiple_keys(void);
24-
extern void test_posix_thread_attr_stacksize(void);
25-
extern void test_nanosleep_NULL_NULL(void);
26-
extern void test_nanosleep_NULL_notNULL(void);
27-
extern void test_nanosleep_notNULL_NULL(void);
28-
extern void test_nanosleep_notNULL_notNULL(void);
29-
extern void test_nanosleep_req_is_rem(void);
30-
extern void test_nanosleep_n1_0(void);
31-
extern void test_nanosleep_0_n1(void);
32-
extern void test_nanosleep_n1_n1(void);
33-
extern void test_nanosleep_0_1(void);
34-
extern void test_nanosleep_0_1001(void);
35-
extern void test_nanosleep_0_1000000000(void);
36-
extern void test_nanosleep_0_500000000(void);
37-
extern void test_nanosleep_1_0(void);
38-
extern void test_nanosleep_1_1(void);
39-
extern void test_nanosleep_1_1001(void);
40-
41-
void test_main(void)
42-
{
43-
ztest_test_suite(posix_apis,
44-
ztest_unit_test(test_posix_pthread_execution),
45-
ztest_unit_test(test_posix_pthread_error_condition),
46-
ztest_unit_test(test_posix_pthread_termination),
47-
ztest_unit_test(test_posix_multiple_threads_single_key),
48-
ztest_unit_test(test_posix_single_thread_multiple_keys),
49-
ztest_unit_test(test_posix_thread_attr_stacksize),
50-
ztest_unit_test(test_posix_clock),
51-
ztest_unit_test(test_posix_semaphore),
52-
ztest_unit_test(test_posix_normal_mutex),
53-
ztest_unit_test(test_posix_recursive_mutex),
54-
ztest_unit_test(test_posix_mqueue),
55-
ztest_unit_test(test_posix_realtime),
56-
ztest_unit_test(test_posix_timer),
57-
ztest_unit_test(test_posix_rw_lock),
58-
ztest_unit_test(test_nanosleep_NULL_NULL),
59-
ztest_unit_test(test_nanosleep_NULL_notNULL),
60-
ztest_unit_test(test_nanosleep_notNULL_NULL),
61-
ztest_unit_test(test_nanosleep_notNULL_notNULL),
62-
ztest_unit_test(test_nanosleep_req_is_rem),
63-
ztest_unit_test(test_nanosleep_n1_0),
64-
ztest_unit_test(test_nanosleep_0_n1),
65-
ztest_unit_test(test_nanosleep_n1_n1),
66-
ztest_unit_test(test_nanosleep_0_1),
67-
ztest_unit_test(test_nanosleep_0_1001),
68-
ztest_unit_test(test_nanosleep_0_500000000),
69-
ztest_unit_test(test_nanosleep_1_0),
70-
ztest_unit_test(test_nanosleep_1_1),
71-
ztest_unit_test(test_nanosleep_1_1001),
72-
ztest_unit_test(test_posix_pthread_create_negative)
73-
);
74-
ztest_run_test_suite(posix_apis);
75-
}
10+
ZTEST_SUITE(posix_apis, NULL, NULL, NULL, NULL, NULL);

tests/posix/common/src/mqueue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void *receiver_thread(void *p1)
6060
return NULL;
6161
}
6262

63-
void test_posix_mqueue(void)
63+
ZTEST(posix_apis, test_posix_mqueue)
6464
{
6565
mqd_t mqd;
6666
struct mq_attr attrs;

tests/posix/common/src/mutex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void *recursive_mutex_entry(void *p1)
5858
* and pthread_mutex_lock are tested with mutex type being
5959
* normal.
6060
*/
61-
void test_posix_normal_mutex(void)
61+
ZTEST(posix_apis, test_posix_normal_mutex)
6262
{
6363
pthread_t thread_1;
6464
pthread_attr_t attr;
@@ -117,7 +117,7 @@ void test_posix_normal_mutex(void)
117117
* twice and unlocked for the same number of time.
118118
*
119119
*/
120-
void test_posix_recursive_mutex(void)
120+
ZTEST(posix_apis, test_posix_recursive_mutex)
121121
{
122122
pthread_t thread_2;
123123
pthread_attr_t attr2;

tests/posix/common/src/nanosleep.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <zephyr/sys_clock.h>
1212

1313
/** req and rem are both NULL */
14-
void test_nanosleep_NULL_NULL(void)
14+
ZTEST(posix_apis, test_nanosleep_NULL_NULL)
1515
{
1616
int r = nanosleep(NULL, NULL);
1717

@@ -24,7 +24,7 @@ void test_nanosleep_NULL_NULL(void)
2424
*
2525
* Expect rem to be the same when function returns
2626
*/
27-
void test_nanosleep_NULL_notNULL(void)
27+
ZTEST(posix_apis, test_nanosleep_NULL_notNULL)
2828
{
2929
struct timespec rem = {};
3030

@@ -45,7 +45,7 @@ void test_nanosleep_NULL_notNULL(void)
4545
*
4646
* Expect req to be the same when function returns
4747
*/
48-
void test_nanosleep_notNULL_NULL(void)
48+
ZTEST(posix_apis, test_nanosleep_notNULL_NULL)
4949
{
5050
struct timespec req = {};
5151

@@ -65,7 +65,7 @@ void test_nanosleep_notNULL_NULL(void)
6565
*
6666
* Expect req & rem to be the same when function returns
6767
*/
68-
void test_nanosleep_notNULL_notNULL(void)
68+
ZTEST(posix_apis, test_nanosleep_notNULL_notNULL)
6969
{
7070
struct timespec req = {};
7171
struct timespec rem = {};
@@ -91,7 +91,7 @@ void test_nanosleep_notNULL_notNULL(void)
9191
* Normative spec says they may be the same.
9292
* Expect rem to be zero after returning.
9393
*/
94-
void test_nanosleep_req_is_rem(void)
94+
ZTEST(posix_apis, test_nanosleep_req_is_rem)
9595
{
9696
struct timespec ts = {0, 1};
9797

@@ -107,7 +107,7 @@ void test_nanosleep_req_is_rem(void)
107107
}
108108

109109
/** req tv_sec is -1 */
110-
void test_nanosleep_n1_0(void)
110+
ZTEST(posix_apis, test_nanosleep_n1_0)
111111
{
112112
struct timespec req = {-1, 0};
113113

@@ -119,7 +119,7 @@ void test_nanosleep_n1_0(void)
119119
}
120120

121121
/** req tv_nsec is -1 */
122-
void test_nanosleep_0_n1(void)
122+
ZTEST(posix_apis, test_nanosleep_0_n1)
123123
{
124124
struct timespec req = {0, -1};
125125

@@ -131,7 +131,7 @@ void test_nanosleep_0_n1(void)
131131
}
132132

133133
/** req tv_sec and tv_nsec are both -1 */
134-
void test_nanosleep_n1_n1(void)
134+
ZTEST(posix_apis, test_nanosleep_n1_n1)
135135
{
136136
struct timespec req = {-1, -1};
137137

@@ -143,7 +143,7 @@ void test_nanosleep_n1_n1(void)
143143
}
144144

145145
/** req tv_sec is 0 tv_nsec is 10^9 */
146-
void test_nanosleep_0_1000000000(void)
146+
ZTEST(posix_apis, test_nanosleep_0_1000000000)
147147
{
148148
struct timespec req = {0, 1000000000};
149149

@@ -191,37 +191,37 @@ static void common(const uint32_t s, uint32_t ns)
191191
}
192192

193193
/** sleep for 1ns */
194-
void test_nanosleep_0_1(void)
194+
ZTEST(posix_apis, test_nanosleep_0_1)
195195
{
196196
common(0, 1);
197197
}
198198

199199
/** sleep for 1us + 1ns */
200-
void test_nanosleep_0_1001(void)
200+
ZTEST(posix_apis, test_nanosleep_0_1001)
201201
{
202202
common(0, 1001);
203203
}
204204

205205
/** sleep for 500000000ns */
206-
void test_nanosleep_0_500000000(void)
206+
ZTEST(posix_apis, test_nanosleep_0_500000000)
207207
{
208208
common(0, 500000000);
209209
}
210210

211211
/** sleep for 1s */
212-
void test_nanosleep_1_0(void)
212+
ZTEST(posix_apis, test_nanosleep_1_0)
213213
{
214214
common(1, 0);
215215
}
216216

217217
/** sleep for 1s + 1ns */
218-
void test_nanosleep_1_1(void)
218+
ZTEST(posix_apis, test_nanosleep_1_1)
219219
{
220220
common(1, 1);
221221
}
222222

223223
/** sleep for 1s + 1us + 1ns */
224-
void test_nanosleep_1_1001(void)
224+
ZTEST(posix_apis, test_nanosleep_1_1001)
225225
{
226226
common(1, 1001);
227227
}

tests/posix/common/src/posix_rwlock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void *thread_top(void *p1)
5353
return NULL;
5454
}
5555

56-
void test_posix_rw_lock(void)
56+
ZTEST(posix_apis, test_posix_rw_lock)
5757
{
5858
int32_t i, ret;
5959
pthread_attr_t attr[N_THR];

tests/posix/common/src/pthread.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void *thread_top_term(void *p1)
229229
return NULL;
230230
}
231231

232-
void test_posix_pthread_execution(void)
232+
ZTEST(posix_apis, test_posix_pthread_execution)
233233
{
234234
int i, ret, min_prio, max_prio;
235235
int dstate, policy;
@@ -403,7 +403,7 @@ void test_posix_pthread_execution(void)
403403
printk("Barrier test OK\n");
404404
}
405405

406-
void test_posix_pthread_error_condition(void)
406+
ZTEST(posix_apis, test_posix_pthread_error_condition)
407407
{
408408
pthread_attr_t attr;
409409
struct sched_param param;
@@ -468,7 +468,7 @@ void test_posix_pthread_error_condition(void)
468468
"get detach state error");
469469
}
470470

471-
void test_posix_pthread_termination(void)
471+
ZTEST(posix_apis, test_posix_pthread_termination)
472472
{
473473
int32_t i, ret;
474474
int oldstate, policy;
@@ -531,7 +531,7 @@ void test_posix_pthread_termination(void)
531531
zassert_equal(ret, ESRCH, "got attr from terminated thread!");
532532
}
533533

534-
void test_posix_thread_attr_stacksize(void)
534+
ZTEST(posix_apis, test_posix_thread_attr_stacksize)
535535
{
536536
size_t act_size;
537537
pthread_attr_t attr;
@@ -559,7 +559,7 @@ static void *create_thread1(void *p1)
559559
return NULL;
560560
}
561561

562-
void test_posix_pthread_create_negative(void)
562+
ZTEST(posix_apis, test_posix_pthread_create_negative)
563563
{
564564
int ret;
565565
pthread_t pthread1;

tests/posix/common/src/pthread_key.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void make_keys(void)
122122
* multiple keys.
123123
*/
124124

125-
void test_posix_multiple_threads_single_key(void)
125+
ZTEST(posix_apis, test_posix_multiple_threads_single_key)
126126
{
127127
int i, ret = -1;
128128

@@ -171,7 +171,7 @@ void test_posix_multiple_threads_single_key(void)
171171
printk("\n");
172172
}
173173

174-
void test_posix_single_thread_multiple_keys(void)
174+
ZTEST(posix_apis, test_posix_single_thread_multiple_keys)
175175
{
176176
int i, ret = -1;
177177

tests/posix/common/src/semaphore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void initialize_thread_attr(pthread_attr_t *attr)
4444
pthread_attr_setschedparam(attr, &schedparam);
4545
}
4646

47-
void test_posix_semaphore(void)
47+
ZTEST(posix_apis, test_posix_semaphore)
4848
{
4949
pthread_t thread1, thread2;
5050
pthread_attr_t attr1, attr2;

0 commit comments

Comments
 (0)