Skip to content

Commit

Permalink
tests: posix: common: separate xsi realtime passing to standalone test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Pancakem committed Jan 22, 2025
1 parent c057f91 commit 52bac14
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 129 deletions.
69 changes: 0 additions & 69 deletions tests/posix/fs/src/test_fs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,45 +141,6 @@ static int test_file_close(void)
return res;
}

static int test_file_fsync(void)
{
int res = 0;

if (file < 0) {
return res;
}

res = fsync(file);
if (res < 0) {
TC_ERROR("Failed to sync file: %d, errno = %d\n", res, errno);
res = TC_FAIL;
}

close(file);
file = -1;
return res;
}

#ifdef CONFIG_POSIX_SYNCHRONIZED_IO
static int test_file_fdatasync(void)
{
int res = 0;

if (file < 0) {
return res;
}

res = fdatasync(file);
if (res < 0) {
TC_ERROR("Failed to sync file: %d, errno = %d\n", res, errno);
res = TC_FAIL;
}

close(file);
file = -1;
return res;
}
#endif /* CONFIG_POSIX_SYNCHRONIZED_IO */

static int test_file_truncate(void)
{
Expand Down Expand Up @@ -261,36 +222,6 @@ ZTEST(posix_fs_file_test, test_fs_read)
zassert_true(test_file_read() == TC_PASS);
}

/**
* @brief Test for POSIX fsync API
*
* @details Test sync the file through POSIX fsync API.
*/
ZTEST(posix_fs_file_test, test_fs_sync)
{
/* FIXME: restructure tests as per #46897 */
zassert_true(test_file_open() == TC_PASS);
zassert_true(test_file_write() == TC_PASS);
zassert_true(test_file_fsync() == TC_PASS);
}

/**
* @brief Test for POSIX fdatasync API
*
* @details Test sync the file through POSIX fdatasync API.
*/
ZTEST(posix_fs_file_test, test_fs_datasync)
{
#ifdef CONFIG_POSIX_SYNCHRONIZED_IO
/* FIXME: restructure tests as per #46897 */
zassert_true(test_file_open() == TC_PASS);
zassert_true(test_file_write() == TC_PASS);
zassert_true(test_file_fdatasync() == TC_PASS);
#else
ztest_test_skip();
#endif
}

/**
* @brief Test for POSIX ftruncate API
*
Expand Down
4 changes: 0 additions & 4 deletions tests/posix/shm/prj.conf

This file was deleted.

18 changes: 0 additions & 18 deletions tests/posix/shm/testcase.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(shm)
project(posix_xsi_realtime)

FILE(GLOB app_sources src/*.c)

target_sources(app PRIVATE ${app_sources})

target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)
14 changes: 14 additions & 0 deletions tests/posix/xsi_realtime/app.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
ramdisk0 {
compatible = "zephyr,ram-disk";
disk-name = "RAM";
sector-size = <512>;
sector-count = <160>;
};
};
20 changes: 20 additions & 0 deletions tests/posix/xsi_realtime/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CONFIG_POSIX_API=y
CONFIG_ZTEST=y
CONFIG_LOG=y

CONFIG_POSIX_AEP_CHOICE_BASE=y
CONFIG_POSIX_MESSAGE_PASSING=y
CONFIG_POSIX_SHARED_MEMORY_OBJECTS=y
CONFIG_POSIX_SYNCHRONIZED_IO=y

CONFIG_FILE_SYSTEM=y
CONFIG_POSIX_FILE_SYSTEM=y

CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_POSIX_FILE_SYSTEM=y
CONFIG_POSIX_FILE_SYSTEM_R=y
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_ZTEST_STACK_SIZE=2048
CONFIG_EVENTFD=n
CONFIG_DISK_DRIVER_RAM=y
CONFIG_DYNAMIC_THREAD=y
12 changes: 12 additions & 0 deletions tests/posix/xsi_realtime/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2025 Marvin Ouma <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/ztest.h>

extern void before(void *arg);
extern void after(void *arg);

ZTEST_SUITE(xsi_realtime, NULL, NULL, before, after, NULL);
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <zephyr/ztest.h>

#define N_THR 2
#define MESSAGE_SIZE 16
#define MESSAGE_SIZE 16
#define MESG_COUNT_PERMQ 4

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


static void *receiver_thread(void *p1)
{
mqd_t mqd;
Expand All @@ -59,13 +57,12 @@ static void *receiver_thread(void *p1)
zassert_false(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
send_data, rec_data);
usleep(USEC_PER_MSEC);
zassert_false(mq_close(mqd),
"unable to close message queue descriptor.");
zassert_false(mq_close(mqd), "unable to close message queue descriptor.");
pthread_exit(p1);
return NULL;
}

ZTEST(mqueue, test_mqueue)
ZTEST(xsi_realtime, test_mqueue)
{
mqd_t mqd;
struct mq_attr attrs;
Expand All @@ -91,8 +88,7 @@ ZTEST(mqueue, test_mqueue)
pthread_join(newthread[i], &retval);
}

zassert_false(mq_close(mqd),
"unable to close message queue descriptor.");
zassert_false(mq_close(mqd), "unable to close message queue descriptor.");
zassert_false(mq_unlink(queue), "Not able to unlink Queue");
}

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

mq_receive(mqd, rec_data, MESSAGE_SIZE, 0);
zassert_ok(strcmp(rec_data, send_data),
"Error in data reception. exp: %s act: %s", send_data, rec_data);
zassert_ok(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
send_data, rec_data);

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

*executed = true;
}

ZTEST(mqueue, test_mqueue_notify_basic)
ZTEST(xsi_realtime, test_mqueue_notify_basic)
{
mqd_t mqd;
struct mq_attr attrs = {
Expand Down Expand Up @@ -155,15 +151,15 @@ void notify_function_thread(union sigval val)
mqd = mq_open(queue, O_RDONLY);

mq_receive(mqd, rec_data, MESSAGE_SIZE, 0);
zassert_ok(strcmp(rec_data, send_data),
"Error in data reception. exp: %s act: %s", send_data, rec_data);
zassert_ok(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
send_data, rec_data);

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

notification_executed = true;
}

ZTEST(mqueue, test_mqueue_notify_thread)
ZTEST(xsi_realtime, test_mqueue_notify_thread)
{
mqd_t mqd;
struct mq_attr attrs = {
Expand Down Expand Up @@ -195,7 +191,7 @@ ZTEST(mqueue, test_mqueue_notify_thread)
zassert_ok(mq_unlink(queue), "Unable to unlink queue");
}

ZTEST(mqueue, test_mqueue_notify_non_empty_queue)
ZTEST(xsi_realtime, test_mqueue_notify_non_empty_queue)
{
mqd_t mqd;
struct mq_attr attrs = {
Expand All @@ -222,8 +218,8 @@ ZTEST(mqueue, test_mqueue_notify_non_empty_queue)
zassert_false(notification_executed, "Notification shouldn't be processed.");

mq_receive(mqd, rec_data, MESSAGE_SIZE, 0);
zassert_false(strcmp(rec_data, send_data),
"Error in data reception. exp: %s act: %s", send_data, rec_data);
zassert_false(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
send_data, rec_data);

memset(rec_data, 0, MESSAGE_SIZE);

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

ZTEST(mqueue, test_mqueue_notify_errors)
ZTEST(xsi_realtime, test_mqueue_notify_errors)
{
mqd_t mqd;
struct mq_attr attrs = {
Expand Down Expand Up @@ -275,15 +271,3 @@ ZTEST(mqueue, test_mqueue_notify_errors)
zassert_ok(mq_close(mqd), "Unable to close message queue descriptor.");
zassert_ok(mq_unlink(queue), "Unable to unlink queue");
}

static void before(void *arg)
{
ARG_UNUSED(arg);

if (!IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
/* skip redundant testing if there is no thread pool / heap allocation */
ztest_test_skip();
}
}

ZTEST_SUITE(mqueue, NULL, NULL, before, NULL, NULL);
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BUILD_ASSERT(N >= 2, "CONFIG_ZVFS_OPEN_MAX must be > 4");

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

ZTEST(shm, test_shm_open)
ZTEST(xsi_realtime, test_shm_open)
{
int ret;
int fd[N];
Expand Down Expand Up @@ -84,7 +84,7 @@ ZTEST(shm, test_shm_open)
}
}

ZTEST(shm, test_shm_unlink)
ZTEST(xsi_realtime, test_shm_unlink)
{
int fd;

Expand All @@ -107,7 +107,7 @@ ZTEST(shm, test_shm_unlink)
zassert_not_ok(shm_open(VALID_SHM_PATH, OPEN_FLAGS, VALID_MODE));
}

ZTEST(shm, test_shm_read_write)
ZTEST(xsi_realtime, test_shm_read_write)
{
int fd[N];

Expand Down Expand Up @@ -148,7 +148,7 @@ ZTEST(shm, test_shm_read_write)
zassert_ok(shm_unlink(VALID_SHM_PATH));
}

ZTEST(shm, test_shm_mmap)
ZTEST(xsi_realtime, test_shm_mmap)
{
int fd[N];
void *addr[N];
Expand Down Expand Up @@ -196,5 +196,3 @@ ZTEST(shm, test_shm_mmap)

zassert_ok(shm_unlink(VALID_SHM_PATH));
}

ZTEST_SUITE(shm, NULL, NULL, NULL, NULL, NULL);
Loading

0 comments on commit 52bac14

Please sign in to comment.