Skip to content

Commit 6b3750f

Browse files
Pancakemkartben
authored andcommitted
tests: posix: common: separate xsi realtime passing to standalone test
posix.common contains testsuites that can be separated into smaller groups of tests. This change moves mqueue into a singular testsuite at tests/posix/message_passing app directory. Signed-off-by: Marvin Ouma <pancakesdeath@protonmail.com>
1 parent 52b8e3d commit 6b3750f

File tree

11 files changed

+200
-130
lines changed

11 files changed

+200
-130
lines changed

tests/posix/fs/src/test_fs_file.c

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -141,45 +141,6 @@ static int test_file_close(void)
141141
return res;
142142
}
143143

144-
static int test_file_fsync(void)
145-
{
146-
int res = 0;
147-
148-
if (file < 0) {
149-
return res;
150-
}
151-
152-
res = fsync(file);
153-
if (res < 0) {
154-
TC_ERROR("Failed to sync file: %d, errno = %d\n", res, errno);
155-
res = TC_FAIL;
156-
}
157-
158-
close(file);
159-
file = -1;
160-
return res;
161-
}
162-
163-
#ifdef CONFIG_POSIX_SYNCHRONIZED_IO
164-
static int test_file_fdatasync(void)
165-
{
166-
int res = 0;
167-
168-
if (file < 0) {
169-
return res;
170-
}
171-
172-
res = fdatasync(file);
173-
if (res < 0) {
174-
TC_ERROR("Failed to sync file: %d, errno = %d\n", res, errno);
175-
res = TC_FAIL;
176-
}
177-
178-
close(file);
179-
file = -1;
180-
return res;
181-
}
182-
#endif /* CONFIG_POSIX_SYNCHRONIZED_IO */
183144

184145
static int test_file_truncate(void)
185146
{
@@ -261,36 +222,6 @@ ZTEST(posix_fs_file_test, test_fs_read)
261222
zassert_true(test_file_read() == TC_PASS);
262223
}
263224

264-
/**
265-
* @brief Test for POSIX fsync API
266-
*
267-
* @details Test sync the file through POSIX fsync API.
268-
*/
269-
ZTEST(posix_fs_file_test, test_fs_sync)
270-
{
271-
/* FIXME: restructure tests as per #46897 */
272-
zassert_true(test_file_open() == TC_PASS);
273-
zassert_true(test_file_write() == TC_PASS);
274-
zassert_true(test_file_fsync() == TC_PASS);
275-
}
276-
277-
/**
278-
* @brief Test for POSIX fdatasync API
279-
*
280-
* @details Test sync the file through POSIX fdatasync API.
281-
*/
282-
ZTEST(posix_fs_file_test, test_fs_datasync)
283-
{
284-
#ifdef CONFIG_POSIX_SYNCHRONIZED_IO
285-
/* FIXME: restructure tests as per #46897 */
286-
zassert_true(test_file_open() == TC_PASS);
287-
zassert_true(test_file_write() == TC_PASS);
288-
zassert_true(test_file_fdatasync() == TC_PASS);
289-
#else
290-
ztest_test_skip();
291-
#endif
292-
}
293-
294225
/**
295226
* @brief Test for POSIX ftruncate API
296227
*

tests/posix/shm/prj.conf

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/posix/shm/testcase.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/posix/shm/CMakeLists.txt renamed to tests/posix/xsi_realtime/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
cmake_minimum_required(VERSION 3.20.0)
44
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5-
project(shm)
5+
project(posix_xsi_realtime)
66

77
FILE(GLOB app_sources src/*.c)
8+
89
target_sources(app PRIVATE ${app_sources})
10+
11+
target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)

tests/posix/xsi_realtime/app.overlay

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2023 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
ramdisk0 {
9+
compatible = "zephyr,ram-disk";
10+
disk-name = "RAM";
11+
sector-size = <512>;
12+
sector-count = <160>;
13+
};
14+
};

tests/posix/xsi_realtime/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_XSI_REALTIME=y
6+
CONFIG_FILE_SYSTEM=y
7+
CONFIG_POSIX_FILE_SYSTEM=y
8+
9+
CONFIG_FAT_FILESYSTEM_ELM=y
10+
CONFIG_MAIN_STACK_SIZE=4096
11+
CONFIG_ZTEST_STACK_SIZE=2048
12+
13+
CONFIG_DYNAMIC_THREAD=y
14+
CONFIG_THREAD_STACK_INFO=y
15+
CONFIG_DYNAMIC_THREAD_POOL_SIZE=6

tests/posix/xsi_realtime/src/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2025 Marvin Ouma <pancakesdeath@protonmail.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
9+
ZTEST_SUITE(xsi_realtime, NULL, NULL, NULL, NULL, NULL);

tests/posix/common/src/mqueue.c renamed to tests/posix/xsi_realtime/src/mqueue.c

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <zephyr/ztest.h>
1414

1515
#define N_THR 2
16-
#define MESSAGE_SIZE 16
16+
#define MESSAGE_SIZE 16
1717
#define MESG_COUNT_PERMQ 4
1818

1919
static char queue[16] = "server";
@@ -40,13 +40,11 @@ static void *sender_thread(void *p1)
4040
zassert_false(mq_timedsend(mqd, send_data, MESSAGE_SIZE, 0, &curtime),
4141
"Not able to send message in timer");
4242
usleep(USEC_PER_MSEC);
43-
zassert_false(mq_close(mqd),
44-
"unable to close message queue descriptor.");
43+
zassert_false(mq_close(mqd), "unable to close message queue descriptor.");
4544
pthread_exit(p1);
4645
return NULL;
4746
}
4847

49-
5048
static void *receiver_thread(void *p1)
5149
{
5250
mqd_t mqd;
@@ -59,13 +57,12 @@ static void *receiver_thread(void *p1)
5957
zassert_false(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
6058
send_data, rec_data);
6159
usleep(USEC_PER_MSEC);
62-
zassert_false(mq_close(mqd),
63-
"unable to close message queue descriptor.");
60+
zassert_false(mq_close(mqd), "unable to close message queue descriptor.");
6461
pthread_exit(p1);
6562
return NULL;
6663
}
6764

68-
ZTEST(mqueue, test_mqueue)
65+
ZTEST(xsi_realtime, test_mqueue)
6966
{
7067
mqd_t mqd;
7168
struct mq_attr attrs;
@@ -91,8 +88,7 @@ ZTEST(mqueue, test_mqueue)
9188
pthread_join(newthread[i], &retval);
9289
}
9390

94-
zassert_false(mq_close(mqd),
95-
"unable to close message queue descriptor.");
91+
zassert_false(mq_close(mqd), "unable to close message queue descriptor.");
9692
zassert_false(mq_unlink(queue), "Not able to unlink Queue");
9793
}
9894

@@ -106,15 +102,15 @@ void notify_function_basic(union sigval val)
106102
mqd = mq_open(queue, O_RDONLY);
107103

108104
mq_receive(mqd, rec_data, MESSAGE_SIZE, 0);
109-
zassert_ok(strcmp(rec_data, send_data),
110-
"Error in data reception. exp: %s act: %s", send_data, rec_data);
105+
zassert_ok(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
106+
send_data, rec_data);
111107

112108
zassert_ok(mq_close(mqd), "Unable to close message queue descriptor.");
113109

114110
*executed = true;
115111
}
116112

117-
ZTEST(mqueue, test_mqueue_notify_basic)
113+
ZTEST(xsi_realtime, test_mqueue_notify_basic)
118114
{
119115
mqd_t mqd;
120116
struct mq_attr attrs = {
@@ -155,15 +151,15 @@ void notify_function_thread(union sigval val)
155151
mqd = mq_open(queue, O_RDONLY);
156152

157153
mq_receive(mqd, rec_data, MESSAGE_SIZE, 0);
158-
zassert_ok(strcmp(rec_data, send_data),
159-
"Error in data reception. exp: %s act: %s", send_data, rec_data);
154+
zassert_ok(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
155+
send_data, rec_data);
160156

161157
zassert_ok(mq_close(mqd), "Unable to close message queue descriptor.");
162158

163159
notification_executed = true;
164160
}
165161

166-
ZTEST(mqueue, test_mqueue_notify_thread)
162+
ZTEST(xsi_realtime, test_mqueue_notify_thread)
167163
{
168164
mqd_t mqd;
169165
struct mq_attr attrs = {
@@ -195,7 +191,7 @@ ZTEST(mqueue, test_mqueue_notify_thread)
195191
zassert_ok(mq_unlink(queue), "Unable to unlink queue");
196192
}
197193

198-
ZTEST(mqueue, test_mqueue_notify_non_empty_queue)
194+
ZTEST(xsi_realtime, test_mqueue_notify_non_empty_queue)
199195
{
200196
mqd_t mqd;
201197
struct mq_attr attrs = {
@@ -222,8 +218,8 @@ ZTEST(mqueue, test_mqueue_notify_non_empty_queue)
222218
zassert_false(notification_executed, "Notification shouldn't be processed.");
223219

224220
mq_receive(mqd, rec_data, MESSAGE_SIZE, 0);
225-
zassert_false(strcmp(rec_data, send_data),
226-
"Error in data reception. exp: %s act: %s", send_data, rec_data);
221+
zassert_false(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
222+
send_data, rec_data);
227223

228224
memset(rec_data, 0, MESSAGE_SIZE);
229225

@@ -235,7 +231,7 @@ ZTEST(mqueue, test_mqueue_notify_non_empty_queue)
235231
zassert_ok(mq_unlink(queue), "Unable to unlink queue");
236232
}
237233

238-
ZTEST(mqueue, test_mqueue_notify_errors)
234+
ZTEST(xsi_realtime, test_mqueue_notify_errors)
239235
{
240236
mqd_t mqd;
241237
struct mq_attr attrs = {
@@ -275,15 +271,3 @@ ZTEST(mqueue, test_mqueue_notify_errors)
275271
zassert_ok(mq_close(mqd), "Unable to close message queue descriptor.");
276272
zassert_ok(mq_unlink(queue), "Unable to unlink queue");
277273
}
278-
279-
static void before(void *arg)
280-
{
281-
ARG_UNUSED(arg);
282-
283-
if (!IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
284-
/* skip redundant testing if there is no thread pool / heap allocation */
285-
ztest_test_skip();
286-
}
287-
}
288-
289-
ZTEST_SUITE(mqueue, NULL, NULL, before, NULL, NULL);

tests/posix/shm/src/main.c renamed to tests/posix/xsi_realtime/src/shm.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BUILD_ASSERT(N >= 2, "CONFIG_ZVFS_OPEN_MAX must be > 4");
3636

3737
#define S_TYPEISSHM(st) (((st)->st_mode & ZVFS_MODE_IFMT) == ZVFS_MODE_IFSHM)
3838

39-
ZTEST(shm, test_shm_open)
39+
ZTEST(xsi_realtime, test_shm_open)
4040
{
4141
int ret;
4242
int fd[N];
@@ -84,7 +84,7 @@ ZTEST(shm, test_shm_open)
8484
}
8585
}
8686

87-
ZTEST(shm, test_shm_unlink)
87+
ZTEST(xsi_realtime, test_shm_unlink)
8888
{
8989
int fd;
9090

@@ -107,7 +107,7 @@ ZTEST(shm, test_shm_unlink)
107107
zassert_not_ok(shm_open(VALID_SHM_PATH, OPEN_FLAGS, VALID_MODE));
108108
}
109109

110-
ZTEST(shm, test_shm_read_write)
110+
ZTEST(xsi_realtime, test_shm_read_write)
111111
{
112112
int fd[N];
113113

@@ -148,7 +148,7 @@ ZTEST(shm, test_shm_read_write)
148148
zassert_ok(shm_unlink(VALID_SHM_PATH));
149149
}
150150

151-
ZTEST(shm, test_shm_mmap)
151+
ZTEST(xsi_realtime, test_shm_mmap)
152152
{
153153
int fd[N];
154154
void *addr[N];
@@ -159,7 +159,7 @@ ZTEST(shm, test_shm_mmap)
159159

160160
for (size_t i = 0; i < N; ++i) {
161161
fd[i] = shm_open(VALID_SHM_PATH, i == 0 ? CREATE_FLAGS : OPEN_FLAGS, VALID_MODE);
162-
zassert_true(fd[i] >= 0, "shm_open(%s, %x, %04o) failed: %d", VALID_SHM_PATH,
162+
zassert_true(fd[i] >= 0, "shm_open(%s, %x, %04o) failed : %d", VALID_SHM_PATH,
163163
VALID_FLAGS, VALID_MODE, errno);
164164

165165
if (i == 0) {
@@ -196,5 +196,3 @@ ZTEST(shm, test_shm_mmap)
196196

197197
zassert_ok(shm_unlink(VALID_SHM_PATH));
198198
}
199-
200-
ZTEST_SUITE(shm, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)