Skip to content

Commit 6aa760a

Browse files
cfriedtkartben
authored andcommitted
tests: posix: env: colocate with single_process option group
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]>
1 parent 5f30744 commit 6aa760a

File tree

11 files changed

+47
-72
lines changed

11 files changed

+47
-72
lines changed

tests/posix/env/CMakeLists.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/posix/env/prj.conf

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/posix/env/testcase.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/posix/single_process/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ FILE(GLOB app_sources src/*.c)
88

99
target_sources(app PRIVATE ${app_sources})
1010

11+
# For setenv() and unsetenv()
1112
target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)
13+
# For getenv_r() visibility and testing
14+
target_compile_definitions(app PRIVATE _BSD_SOURCE)

tests/posix/single_process/prj.conf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
CONFIG_POSIX_API=y
21
CONFIG_ZTEST=y
3-
4-
CONFIG_POSIX_AEP_CHOICE_BASE=y
52
CONFIG_POSIX_SINGLE_PROCESS=y
3+
4+
# Let's explicitly choose PICOLIBC, so it is used if supported even if it would not have been the
5+
# default (otherwise native targets default to the host C library)
6+
CONFIG_PICOLIBC=y
7+
CONFIG_COMMON_LIBC_MALLOC=y

tests/posix/single_process/src/confstr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66

77
#include <errno.h>
8-
#include <unistd.h>
98

109
#include <zephyr/ztest.h>
10+
#include <zephyr/posix/unistd.h>
1111
#include <zephyr/sys/util.h>
1212

1313
ZTEST(posix_single_process, test_confstr)

tests/posix/env/src/env.c renamed to tests/posix/single_process/src/env.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static DEFINE_ENVIRON(pwd, "PWD", M_PWD);
3333

3434
static char *environ_for_test[] = {home, uid, pwd, NULL};
3535

36-
ZTEST(env, test_getenv)
36+
ZTEST(posix_single_process, test_getenv)
3737
{
3838
zassert_equal(getenv(NULL), NULL);
3939
zassert_equal(getenv(""), NULL);
@@ -46,7 +46,7 @@ ZTEST(env, test_getenv)
4646
zassert_mem_equal(getenv("PWD"), M_PWD, strlen(M_PWD) + 1);
4747
}
4848

49-
ZTEST(env, test_getenv_r)
49+
ZTEST(posix_single_process, test_getenv_r)
5050
{
5151
static char buf[16];
5252
static const int exp_errno[] = {
@@ -74,8 +74,7 @@ ZTEST(env, test_getenv_r)
7474

7575
BUILD_ASSERT(ARRAY_SIZE(exp_errno) == ARRAY_SIZE(args));
7676

77-
ARRAY_FOR_EACH(args, i)
78-
{
77+
ARRAY_FOR_EACH(args, i) {
7978
errno = 0;
8079
zassert_equal(getenv_r(args[i].name, args[i].buf, args[i].size), -1,
8180
"getenv_r(\"%s\", %p, %zu): expected to fail", args[i].name,
@@ -90,7 +89,7 @@ ZTEST(env, test_getenv_r)
9089
zassert_mem_equal(getenv("PWD"), M_PWD, strlen(M_PWD) + 1);
9190
}
9291

93-
ZTEST(env, test_setenv)
92+
ZTEST(posix_single_process, test_setenv)
9493
{
9594
zassert_equal(setenv(NULL, NULL, 0), -1);
9695
zassert_equal(errno, EINVAL);
@@ -114,7 +113,7 @@ ZTEST(env, test_setenv)
114113
zassert_mem_equal(getenv("HOME"), "/root", strlen("/root") + 1);
115114
}
116115

117-
ZTEST(env, test_unsetenv)
116+
ZTEST(posix_single_process, test_unsetenv)
118117
{
119118
/* not hardened / application should fault */
120119
zassert_equal(unsetenv(NULL), -1);
@@ -137,7 +136,7 @@ ZTEST(env, test_unsetenv)
137136
zassert_is_null(getenv("HOME"));
138137
}
139138

140-
ZTEST(env, test_watertight)
139+
ZTEST(posix_single_process, test_watertight)
141140
{
142141
extern size_t posix_env_get_allocated_space(void);
143142

@@ -158,7 +157,7 @@ ZTEST(env, test_watertight)
158157
zassert_equal(posix_env_get_allocated_space(), 0);
159158
}
160159

161-
static void before(void *arg)
160+
void test_env_before(void)
162161
{
163162
old_environ = environ;
164163

@@ -172,9 +171,7 @@ static void before(void *arg)
172171
zassert_equal((environ = environ_for_test), environ_for_test);
173172
}
174173

175-
static void after(void *arg)
174+
void test_env_after(void)
176175
{
177176
environ = old_environ;
178177
}
179-
180-
ZTEST_SUITE(env, NULL, NULL, before, after, NULL);

tests/posix/single_process/src/main.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,17 @@
77

88
#include <zephyr/ztest.h>
99

10-
ZTEST_SUITE(posix_single_process, NULL, NULL, NULL, NULL, NULL);
10+
void test_env_before(void);
11+
void test_env_after(void);
12+
13+
static void before(void *arg)
14+
{
15+
test_env_before();
16+
}
17+
18+
static void after(void *arg)
19+
{
20+
test_env_after();
21+
}
22+
23+
ZTEST_SUITE(posix_single_process, NULL, NULL, before, after, NULL);

tests/posix/single_process/src/sysconf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
#include <zephyr/ztest.h>
9-
#include <unistd.h>
9+
10+
#include <zephyr/posix/unistd.h>
1011

1112
ZTEST(posix_single_process, test_posix_sysconf)
1213
{

tests/posix/single_process/src/uname.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#include <sys/utsname.h>
8-
#include <unistd.h>
9-
7+
#include <zephyr/posix/sys/utsname.h>
8+
#include <zephyr/posix/unistd.h>
109
#include <zephyr/ztest.h>
1110

1211
ZTEST(posix_single_process, test_uname)

0 commit comments

Comments
 (0)