Skip to content

Commit

Permalink
tests: posix: env: colocate with single_process option group
Browse files Browse the repository at this point in the history
Move the previously singular env testsuite to be with the
other features that are part of the POSIX_SINGLE_PROCESS
Option Group.

Signed-off-by: Chris Friedt <[email protected]>
  • Loading branch information
Chris Friedt committed Nov 22, 2024
1 parent 78c1def commit 123d824
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 72 deletions.
13 changes: 0 additions & 13 deletions tests/posix/env/CMakeLists.txt

This file was deleted.

6 changes: 0 additions & 6 deletions tests/posix/env/prj.conf

This file was deleted.

32 changes: 0 additions & 32 deletions tests/posix/env/testcase.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions tests/posix/single_process/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 5 additions & 3 deletions tests/posix/single_process/prj.conf
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/posix/single_process/src/confstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

#include <errno.h>
#include <unistd.h>

#include <zephyr/ztest.h>
#include <zephyr/posix/unistd.h>
#include <zephyr/sys/util.h>

ZTEST(posix_single_process, test_confstr)
Expand Down
19 changes: 8 additions & 11 deletions tests/posix/env/src/env.c → tests/posix/single_process/src/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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[] = {
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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;

Expand All @@ -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);
15 changes: 14 additions & 1 deletion tests/posix/single_process/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@

#include <zephyr/ztest.h>

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);
3 changes: 2 additions & 1 deletion tests/posix/single_process/src/sysconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

#include <zephyr/ztest.h>
#include <unistd.h>

#include <zephyr/posix/unistd.h>

ZTEST(posix_single_process, test_posix_sysconf)
{
Expand Down
5 changes: 2 additions & 3 deletions tests/posix/single_process/src/uname.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <sys/utsname.h>
#include <unistd.h>

#include <zephyr/posix/sys/utsname.h>
#include <zephyr/posix/unistd.h>
#include <zephyr/ztest.h>

ZTEST(posix_single_process, test_uname)
Expand Down
13 changes: 12 additions & 1 deletion tests/posix/single_process/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 123d824

Please sign in to comment.