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>
This commit is contained in:
parent
52b8e3d370
commit
6b3750f73c
11 changed files with 200 additions and 130 deletions
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
*
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
CONFIG_ZTEST=y
|
||||
|
||||
CONFIG_POSIX_API=y
|
||||
CONFIG_POSIX_SHARED_MEMORY_OBJECTS=y
|
|
@ -1,18 +0,0 @@
|
|||
common:
|
||||
filter: not CONFIG_NATIVE_LIBC
|
||||
tags:
|
||||
- posix
|
||||
- shm
|
||||
# 1 tier0 platform per supported architecture
|
||||
platform_key:
|
||||
- arch
|
||||
- simulation
|
||||
platform_exclude:
|
||||
# linker_zephyr_pre0.cmd:140: syntax error (??)
|
||||
- qemu_xtensa/dc233c
|
||||
# CONFIG_MMU=y but no arch_mem_map() or arch_mem_unmap()
|
||||
- intel_ish_5_4_1
|
||||
- intel_ish_5_6_0
|
||||
- intel_ish_5_8_0
|
||||
tests:
|
||||
portability.posix.shm: {}
|
|
@ -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
tests/posix/xsi_realtime/app.overlay
Normal file
14
tests/posix/xsi_realtime/app.overlay
Normal file
|
@ -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>;
|
||||
};
|
||||
};
|
15
tests/posix/xsi_realtime/prj.conf
Normal file
15
tests/posix/xsi_realtime/prj.conf
Normal file
|
@ -0,0 +1,15 @@
|
|||
CONFIG_POSIX_API=y
|
||||
CONFIG_ZTEST=y
|
||||
|
||||
CONFIG_POSIX_AEP_CHOICE_BASE=y
|
||||
CONFIG_XSI_REALTIME=y
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_POSIX_FILE_SYSTEM=y
|
||||
|
||||
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||
CONFIG_MAIN_STACK_SIZE=4096
|
||||
CONFIG_ZTEST_STACK_SIZE=2048
|
||||
|
||||
CONFIG_DYNAMIC_THREAD=y
|
||||
CONFIG_THREAD_STACK_INFO=y
|
||||
CONFIG_DYNAMIC_THREAD_POOL_SIZE=6
|
9
tests/posix/xsi_realtime/src/main.c
Normal file
9
tests/posix/xsi_realtime/src/main.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Marvin Ouma <pancakesdeath@protonmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
ZTEST_SUITE(xsi_realtime, NULL, NULL, NULL, NULL, NULL);
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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 = {
|
||||
|
@ -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 = {
|
||||
|
@ -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 = {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 = {
|
||||
|
@ -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);
|
|
@ -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];
|
||||
|
@ -84,7 +84,7 @@ ZTEST(shm, test_shm_open)
|
|||
}
|
||||
}
|
||||
|
||||
ZTEST(shm, test_shm_unlink)
|
||||
ZTEST(xsi_realtime, test_shm_unlink)
|
||||
{
|
||||
int fd;
|
||||
|
||||
|
@ -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];
|
||||
|
||||
|
@ -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];
|
||||
|
@ -196,5 +196,3 @@ ZTEST(shm, test_shm_mmap)
|
|||
|
||||
zassert_ok(shm_unlink(VALID_SHM_PATH));
|
||||
}
|
||||
|
||||
ZTEST_SUITE(shm, NULL, NULL, NULL, NULL, NULL);
|
103
tests/posix/xsi_realtime/src/sync_io.c
Normal file
103
tests/posix/xsi_realtime/src/sync_io.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <ff.h>
|
||||
#include <zephyr/fs/fs.h>
|
||||
#include <zephyr/posix/unistd.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
static const char test_str[] = "Hello World!";
|
||||
|
||||
#define FATFS_MNTP "/RAM:"
|
||||
#define TEST_FILE FATFS_MNTP "/testfile.txt"
|
||||
|
||||
static FATFS fat_fs;
|
||||
|
||||
static struct fs_mount_t fatfs_mnt = {
|
||||
.type = FS_FATFS,
|
||||
.mnt_point = FATFS_MNTP,
|
||||
.fs_data = &fat_fs,
|
||||
};
|
||||
|
||||
static void test_mount(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = fs_mount(&fatfs_mnt);
|
||||
zassert_ok(res, "Error mounting fs [%d]\n", res);
|
||||
}
|
||||
|
||||
void test_unmount(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = fs_unmount(&fatfs_mnt);
|
||||
zassert_ok(res, "Error unmounting fs [%d]", res);
|
||||
}
|
||||
|
||||
static int file_open(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = open(TEST_FILE, O_CREAT | O_RDWR, 0660);
|
||||
zassert_not_equal(res, -1, "Error opening file [%d], errno [%d]", res, errno);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int file_write(int file)
|
||||
{
|
||||
ssize_t brw;
|
||||
off_t res;
|
||||
|
||||
res = lseek(file, 0, SEEK_SET);
|
||||
zassert_ok((int)res, "lseek failed [%d]\n", (int)res);
|
||||
|
||||
brw = write(file, (char *)test_str, strlen(test_str));
|
||||
zassert_ok((int)res, "Failed writing to file [%d]\n", (int)brw);
|
||||
|
||||
zassert_ok(brw < strlen(test_str),
|
||||
"Unable to complete write. Volume full. Number of bytes written: [%d]\n",
|
||||
(int)brw);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test for POSIX fsync API
|
||||
*
|
||||
* @details Test sync the file through POSIX fsync API.
|
||||
*/
|
||||
ZTEST(xsi_realtime, test_fs_sync)
|
||||
{
|
||||
test_mount();
|
||||
int res = 0;
|
||||
int file = file_open();
|
||||
|
||||
res = file_write(file);
|
||||
res = fsync(file);
|
||||
zassert_ok(res, "Failed to sync file: %d, errno = %d\n", res, errno);
|
||||
zassert_ok(close(file), "Failed to close file");
|
||||
test_unmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test for POSIX fdatasync API
|
||||
*
|
||||
* @details Test sync the file through POSIX fdatasync API.
|
||||
*/
|
||||
ZTEST(xsi_realtime, test_fs_datasync)
|
||||
{
|
||||
test_mount();
|
||||
int res = 0;
|
||||
int file = file_open();
|
||||
|
||||
res = file_write(file);
|
||||
res = fdatasync(file);
|
||||
zassert_ok(res, "Failed to sync file: %d, errno = %d\n", res, errno);
|
||||
zassert_ok(close(file), "Failed to close file");
|
||||
test_unmount();
|
||||
}
|
35
tests/posix/xsi_realtime/testcase.yaml
Normal file
35
tests/posix/xsi_realtime/testcase.yaml
Normal file
|
@ -0,0 +1,35 @@
|
|||
common:
|
||||
filter: not CONFIG_NATIVE_LIBC
|
||||
tags:
|
||||
- posix
|
||||
- xsi_realtime
|
||||
# 1 tier0 platform per supported architecture
|
||||
platform_key:
|
||||
- arch
|
||||
- simulation
|
||||
min_flash: 64
|
||||
min_ram: 32
|
||||
timeout: 240
|
||||
platform_exclude:
|
||||
# linker_zephyr_pre0.cmd:140: syntax error (??)
|
||||
- qemu_xtensa/dc233c
|
||||
# CONFIG_MMU=y but no arch_mem_map() or arch_mem_unmap()
|
||||
- intel_ish_5_4_1
|
||||
- intel_ish_5_6_0
|
||||
- intel_ish_5_8_0
|
||||
- native_sim
|
||||
- native_sim/native/64
|
||||
tests:
|
||||
portability.posix.xsi_realtime: {}
|
||||
portability.posix.xsi_realtime.minimal:
|
||||
extra_configs:
|
||||
- CONFIG_MINIMAL_LIBC=y
|
||||
portability.posix.xsi_realtime.newlib:
|
||||
filter: TOOLCHAIN_HAS_NEWLIB == 1
|
||||
extra_configs:
|
||||
- CONFIG_NEWLIB_LIBC=y
|
||||
portability.posix.xsi_realtime.picolibc:
|
||||
tags: picolibc
|
||||
filter: CONFIG_PICOLIBC_SUPPORTED
|
||||
extra_configs:
|
||||
- CONFIG_PICOLIBC=y
|
Loading…
Add table
Add a link
Reference in a new issue