From 6b3750f73c24cfd35432f7ab1fa2348593e5132e Mon Sep 17 00:00:00 2001 From: Marvin Ouma Date: Fri, 15 Nov 2024 15:48:49 +0300 Subject: [PATCH] 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 --- tests/posix/fs/src/test_fs_file.c | 69 ------------ tests/posix/shm/prj.conf | 4 - tests/posix/shm/testcase.yaml | 18 --- .../{shm => xsi_realtime}/CMakeLists.txt | 5 +- tests/posix/xsi_realtime/app.overlay | 14 +++ tests/posix/xsi_realtime/prj.conf | 15 +++ tests/posix/xsi_realtime/src/main.c | 9 ++ .../{common => xsi_realtime}/src/mqueue.c | 46 +++----- .../src/main.c => xsi_realtime/src/shm.c} | 12 +- tests/posix/xsi_realtime/src/sync_io.c | 103 ++++++++++++++++++ tests/posix/xsi_realtime/testcase.yaml | 35 ++++++ 11 files changed, 200 insertions(+), 130 deletions(-) delete mode 100644 tests/posix/shm/prj.conf delete mode 100644 tests/posix/shm/testcase.yaml rename tests/posix/{shm => xsi_realtime}/CMakeLists.txt (65%) create mode 100644 tests/posix/xsi_realtime/app.overlay create mode 100644 tests/posix/xsi_realtime/prj.conf create mode 100644 tests/posix/xsi_realtime/src/main.c rename tests/posix/{common => xsi_realtime}/src/mqueue.c (86%) rename tests/posix/{shm/src/main.c => xsi_realtime/src/shm.c} (95%) create mode 100644 tests/posix/xsi_realtime/src/sync_io.c create mode 100644 tests/posix/xsi_realtime/testcase.yaml diff --git a/tests/posix/fs/src/test_fs_file.c b/tests/posix/fs/src/test_fs_file.c index ee1fcd1e058..23496c92b8c 100644 --- a/tests/posix/fs/src/test_fs_file.c +++ b/tests/posix/fs/src/test_fs_file.c @@ -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 * diff --git a/tests/posix/shm/prj.conf b/tests/posix/shm/prj.conf deleted file mode 100644 index 04734c10d7c..00000000000 --- a/tests/posix/shm/prj.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_ZTEST=y - -CONFIG_POSIX_API=y -CONFIG_POSIX_SHARED_MEMORY_OBJECTS=y diff --git a/tests/posix/shm/testcase.yaml b/tests/posix/shm/testcase.yaml deleted file mode 100644 index 1928a6e177c..00000000000 --- a/tests/posix/shm/testcase.yaml +++ /dev/null @@ -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: {} diff --git a/tests/posix/shm/CMakeLists.txt b/tests/posix/xsi_realtime/CMakeLists.txt similarity index 65% rename from tests/posix/shm/CMakeLists.txt rename to tests/posix/xsi_realtime/CMakeLists.txt index 65e1ac9b27f..473d87110d1 100644 --- a/tests/posix/shm/CMakeLists.txt +++ b/tests/posix/xsi_realtime/CMakeLists.txt @@ -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) diff --git a/tests/posix/xsi_realtime/app.overlay b/tests/posix/xsi_realtime/app.overlay new file mode 100644 index 00000000000..87ae21b1e64 --- /dev/null +++ b/tests/posix/xsi_realtime/app.overlay @@ -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>; + }; +}; diff --git a/tests/posix/xsi_realtime/prj.conf b/tests/posix/xsi_realtime/prj.conf new file mode 100644 index 00000000000..c6f5999e0a2 --- /dev/null +++ b/tests/posix/xsi_realtime/prj.conf @@ -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 diff --git a/tests/posix/xsi_realtime/src/main.c b/tests/posix/xsi_realtime/src/main.c new file mode 100644 index 00000000000..3021c9b3706 --- /dev/null +++ b/tests/posix/xsi_realtime/src/main.c @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2025 Marvin Ouma + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +ZTEST_SUITE(xsi_realtime, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/posix/common/src/mqueue.c b/tests/posix/xsi_realtime/src/mqueue.c similarity index 86% rename from tests/posix/common/src/mqueue.c rename to tests/posix/xsi_realtime/src/mqueue.c index ddf14c7a027..d7e9ba75d4b 100644 --- a/tests/posix/common/src/mqueue.c +++ b/tests/posix/xsi_realtime/src/mqueue.c @@ -13,7 +13,7 @@ #include #define N_THR 2 -#define MESSAGE_SIZE 16 +#define MESSAGE_SIZE 16 #define MESG_COUNT_PERMQ 4 static char queue[16] = "server"; @@ -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); diff --git a/tests/posix/shm/src/main.c b/tests/posix/xsi_realtime/src/shm.c similarity index 95% rename from tests/posix/shm/src/main.c rename to tests/posix/xsi_realtime/src/shm.c index 625398e24aa..170902eeae1 100644 --- a/tests/posix/shm/src/main.c +++ b/tests/posix/xsi_realtime/src/shm.c @@ -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]; @@ -159,7 +159,7 @@ ZTEST(shm, test_shm_mmap) for (size_t i = 0; i < N; ++i) { fd[i] = shm_open(VALID_SHM_PATH, i == 0 ? CREATE_FLAGS : OPEN_FLAGS, VALID_MODE); - zassert_true(fd[i] >= 0, "shm_open(%s, %x, %04o) failed: %d", VALID_SHM_PATH, + zassert_true(fd[i] >= 0, "shm_open(%s, %x, %04o) failed : %d", VALID_SHM_PATH, VALID_FLAGS, VALID_MODE, errno); if (i == 0) { @@ -196,5 +196,3 @@ ZTEST(shm, test_shm_mmap) zassert_ok(shm_unlink(VALID_SHM_PATH)); } - -ZTEST_SUITE(shm, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/posix/xsi_realtime/src/sync_io.c b/tests/posix/xsi_realtime/src/sync_io.c new file mode 100644 index 00000000000..09593dbb750 --- /dev/null +++ b/tests/posix/xsi_realtime/src/sync_io.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2018 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +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(); +} diff --git a/tests/posix/xsi_realtime/testcase.yaml b/tests/posix/xsi_realtime/testcase.yaml new file mode 100644 index 00000000000..d3b98962cf2 --- /dev/null +++ b/tests/posix/xsi_realtime/testcase.yaml @@ -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