diff --git a/tests/posix/env/CMakeLists.txt b/tests/posix/env/CMakeLists.txt deleted file mode 100644 index 6cd1e565dcc6..000000000000 --- a/tests/posix/env/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(posix_common) - -FILE(GLOB app_sources src/*.c) - -target_sources(app PRIVATE ${app_sources}) -# For setenv() and unsetenv() -target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L) -# For getenv_r() visibility and testing -target_compile_definitions(app PRIVATE _BSD_SOURCE) diff --git a/tests/posix/env/prj.conf b/tests/posix/env/prj.conf deleted file mode 100644 index fcf68903a722..000000000000 --- a/tests/posix/env/prj.conf +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_POSIX_SINGLE_PROCESS=y -# Let's explicitly choose PICOLIBC, so it is used if supported even if it would not have been the -# default (otherwise native targets default to the host C library) -CONFIG_PICOLIBC=y -CONFIG_COMMON_LIBC_MALLOC=y diff --git a/tests/posix/env/testcase.yaml b/tests/posix/env/testcase.yaml deleted file mode 100644 index b347479976c9..000000000000 --- a/tests/posix/env/testcase.yaml +++ /dev/null @@ -1,32 +0,0 @@ -common: - filter: not CONFIG_NATIVE_LIBC - integration_platforms: - - qemu_riscv64 - tags: posix -tests: - portability.posix.env: - extra_configs: - - CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256 - portability.posix.env.armclang_std_libc: - toolchain_allow: armclang - extra_configs: - - CONFIG_ARMCLANG_STD_LIBC=y - portability.posix.env.arcmwdtlib: - toolchain_allow: arcmwdt - extra_configs: - - CONFIG_ARCMWDT_LIBC=y - portability.posix.env.minimal: - extra_configs: - - CONFIG_MINIMAL_LIBC=y - - CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256 - portability.posix.env.newlib: - platform_exclude: - - hifive1 - filter: TOOLCHAIN_HAS_NEWLIB == 1 - extra_configs: - - CONFIG_NEWLIB_LIBC=y - portability.posix.env.picolibc: - tags: picolibc - filter: CONFIG_PICOLIBC_SUPPORTED - extra_configs: - - CONFIG_PICOLIBC=y diff --git a/tests/posix/single_process/CMakeLists.txt b/tests/posix/single_process/CMakeLists.txt index b7f056b2bbc3..a8cfbed34437 100644 --- a/tests/posix/single_process/CMakeLists.txt +++ b/tests/posix/single_process/CMakeLists.txt @@ -8,4 +8,7 @@ FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) +# For setenv() and unsetenv() target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L) +# For getenv_r() visibility and testing +target_compile_definitions(app PRIVATE _BSD_SOURCE) diff --git a/tests/posix/single_process/prj.conf b/tests/posix/single_process/prj.conf index 472780a18063..7422432b9d0b 100644 --- a/tests/posix/single_process/prj.conf +++ b/tests/posix/single_process/prj.conf @@ -1,5 +1,7 @@ -CONFIG_POSIX_API=y CONFIG_ZTEST=y - -CONFIG_POSIX_AEP_CHOICE_BASE=y CONFIG_POSIX_SINGLE_PROCESS=y + +# Let's explicitly choose PICOLIBC, so it is used if supported even if it would not have been the +# default (otherwise native targets default to the host C library) +CONFIG_PICOLIBC=y +CONFIG_COMMON_LIBC_MALLOC=y diff --git a/tests/posix/single_process/src/confstr.c b/tests/posix/single_process/src/confstr.c index f11ccf1ba89a..1dd9ad1434f3 100644 --- a/tests/posix/single_process/src/confstr.c +++ b/tests/posix/single_process/src/confstr.c @@ -5,9 +5,9 @@ */ #include -#include #include +#include #include ZTEST(posix_single_process, test_confstr) diff --git a/tests/posix/env/src/env.c b/tests/posix/single_process/src/env.c similarity index 93% rename from tests/posix/env/src/env.c rename to tests/posix/single_process/src/env.c index 1d121a244388..ebe19b752280 100644 --- a/tests/posix/env/src/env.c +++ b/tests/posix/single_process/src/env.c @@ -33,7 +33,7 @@ static DEFINE_ENVIRON(pwd, "PWD", M_PWD); static char *environ_for_test[] = {home, uid, pwd, NULL}; -ZTEST(env, test_getenv) +ZTEST(posix_single_process, test_getenv) { zassert_equal(getenv(NULL), NULL); zassert_equal(getenv(""), NULL); @@ -46,7 +46,7 @@ ZTEST(env, test_getenv) zassert_mem_equal(getenv("PWD"), M_PWD, strlen(M_PWD) + 1); } -ZTEST(env, test_getenv_r) +ZTEST(posix_single_process, test_getenv_r) { static char buf[16]; static const int exp_errno[] = { @@ -74,8 +74,7 @@ ZTEST(env, test_getenv_r) BUILD_ASSERT(ARRAY_SIZE(exp_errno) == ARRAY_SIZE(args)); - ARRAY_FOR_EACH(args, i) - { + ARRAY_FOR_EACH(args, i) { errno = 0; zassert_equal(getenv_r(args[i].name, args[i].buf, args[i].size), -1, "getenv_r(\"%s\", %p, %zu): expected to fail", args[i].name, @@ -90,7 +89,7 @@ ZTEST(env, test_getenv_r) zassert_mem_equal(getenv("PWD"), M_PWD, strlen(M_PWD) + 1); } -ZTEST(env, test_setenv) +ZTEST(posix_single_process, test_setenv) { zassert_equal(setenv(NULL, NULL, 0), -1); zassert_equal(errno, EINVAL); @@ -114,7 +113,7 @@ ZTEST(env, test_setenv) zassert_mem_equal(getenv("HOME"), "/root", strlen("/root") + 1); } -ZTEST(env, test_unsetenv) +ZTEST(posix_single_process, test_unsetenv) { /* not hardened / application should fault */ zassert_equal(unsetenv(NULL), -1); @@ -137,7 +136,7 @@ ZTEST(env, test_unsetenv) zassert_is_null(getenv("HOME")); } -ZTEST(env, test_watertight) +ZTEST(posix_single_process, test_watertight) { extern size_t posix_env_get_allocated_space(void); @@ -158,7 +157,7 @@ ZTEST(env, test_watertight) zassert_equal(posix_env_get_allocated_space(), 0); } -static void before(void *arg) +void test_env_before(void) { old_environ = environ; @@ -172,9 +171,7 @@ static void before(void *arg) zassert_equal((environ = environ_for_test), environ_for_test); } -static void after(void *arg) +void test_env_after(void) { environ = old_environ; } - -ZTEST_SUITE(env, NULL, NULL, before, after, NULL); diff --git a/tests/posix/single_process/src/main.c b/tests/posix/single_process/src/main.c index 421af54891d4..c3384de60486 100644 --- a/tests/posix/single_process/src/main.c +++ b/tests/posix/single_process/src/main.c @@ -7,4 +7,17 @@ #include -ZTEST_SUITE(posix_single_process, NULL, NULL, NULL, NULL, NULL); +void test_env_before(void); +void test_env_after(void); + +static void before(void *arg) +{ + test_env_before(); +} + +static void after(void *arg) +{ + test_env_after(); +} + +ZTEST_SUITE(posix_single_process, NULL, NULL, before, after, NULL); diff --git a/tests/posix/single_process/src/sysconf.c b/tests/posix/single_process/src/sysconf.c index 7689ff04600a..bedfe21403ae 100644 --- a/tests/posix/single_process/src/sysconf.c +++ b/tests/posix/single_process/src/sysconf.c @@ -6,7 +6,8 @@ */ #include -#include + +#include ZTEST(posix_single_process, test_posix_sysconf) { diff --git a/tests/posix/single_process/src/uname.c b/tests/posix/single_process/src/uname.c index 1d6b09d8c7ee..fcc52e02be51 100644 --- a/tests/posix/single_process/src/uname.c +++ b/tests/posix/single_process/src/uname.c @@ -4,9 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include - +#include +#include #include ZTEST(posix_single_process, test_uname) diff --git a/tests/posix/single_process/testcase.yaml b/tests/posix/single_process/testcase.yaml index ce226e9dc9da..70abb822269e 100644 --- a/tests/posix/single_process/testcase.yaml +++ b/tests/posix/single_process/testcase.yaml @@ -10,10 +10,21 @@ common: min_flash: 64 min_ram: 32 tests: - portability.single_process: {} + portability.posix.single_process: + extra_configs: + - CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256 + portability.posix.single_process.armclang_std_libc: + toolchain_allow: armclang + extra_configs: + - CONFIG_ARMCLANG_STD_LIBC=y + portability.posix.single_process.arcmwdtlib: + toolchain_allow: arcmwdt + extra_configs: + - CONFIG_ARCMWDT_LIBC=y portability.posix.single_process.minimal: extra_configs: - CONFIG_MINIMAL_LIBC=y + - CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256 portability.posix.single_process.newlib: filter: TOOLCHAIN_HAS_NEWLIB == 1 extra_configs: