Skip to content

Commit 8673d74

Browse files
cfriedtnashif
authored andcommitted
tests: posix: add test for the xsi_single_process option group
Add tests for the XSI_SINGLE_PROCESS Option Group. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
1 parent cfae041 commit 8673d74

File tree

7 files changed

+186
-0
lines changed

7 files changed

+186
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(xsi_single_process)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
9+
target_sources(app PRIVATE ${app_sources})
10+
11+
target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)
12+
target_compile_options(app PRIVATE -U_XOPEN_SOURCE -D_XOPEN_SOURCE=700)
13+
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/lib/posix/options)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_ZTEST=y
2+
3+
CONFIG_POSIX_API=y
4+
CONFIG_XSI_SINGLE_PROCESS=y
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2025 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <unistd.h>
7+
8+
#include <zephyr/ztest.h>
9+
10+
ZTEST(xsi_single_process, test_gethostid)
11+
{
12+
long id = gethostid();
13+
14+
if (id == -ENOSYS) {
15+
printk("CONFIG_HWINFO not implemented for %s\n", CONFIG_BOARD);
16+
ztest_test_skip();
17+
}
18+
19+
uint32_t id32 = gethostid();
20+
21+
zassert_equal((uint32_t)id, id32, "gethostid() returned inconsistent values", (uint32_t)id,
22+
id32);
23+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2018 Intel Corporation
3+
* Copyright (c) 2023, Meta
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include "posix_clock.h"
9+
10+
#include <sys/time.h>
11+
#include <time.h>
12+
#include <unistd.h>
13+
14+
#include <zephyr/ztest.h>
15+
16+
ZTEST(xsi_single_process, test_gettimeofday)
17+
{
18+
struct timeval tv;
19+
struct timespec ts;
20+
struct timespec rts;
21+
22+
if (false) {
23+
/* undefined behaviour */
24+
errno = 0;
25+
zassert_equal(gettimeofday(NULL, NULL), -1);
26+
zassert_equal(errno, EINVAL);
27+
}
28+
29+
/* Validate gettimeofday API */
30+
zassert_ok(gettimeofday(&tv, NULL));
31+
zassert_ok(clock_gettime(CLOCK_REALTIME, &rts));
32+
33+
/* TESTPOINT: Check if time obtained from
34+
* gettimeofday is same or more than obtained
35+
* from clock_gettime
36+
*/
37+
tv_to_ts(&tv, &ts);
38+
zassert_true(tp_ge(&rts, &ts));
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2025 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
9+
ZTEST_SUITE(xsi_single_process, NULL, NULL, NULL, NULL, NULL);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2025 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <errno.h>
7+
#include <stdlib.h>
8+
9+
#include <zephyr/ztest.h>
10+
11+
ZTEST(xsi_single_process, test_putenv)
12+
{
13+
char buf[64];
14+
15+
{
16+
/* degenerate cases */
17+
static const char *const cases[] = {
18+
NULL, "", "=", "abc", "42", "=abc",
19+
/*
20+
* Note:
21+
* There are many poorly-formatted environment variable names and values
22+
* that are invalid (from the perspective of a POSIX shell), but still
23+
* accepted by setenv() and subsequently putenv().
24+
*
25+
* See also tests/posix/single_process/src/env.c
26+
* See also lib/posix/shell/env.c:101
27+
*/
28+
};
29+
30+
ARRAY_FOR_EACH(cases, i) {
31+
char *s;
32+
33+
if (cases[i] == NULL) {
34+
s = NULL;
35+
} else {
36+
strncpy(buf, cases[i], sizeof(buf));
37+
buf[sizeof(buf) - 1] = '\0';
38+
s = buf;
39+
}
40+
41+
errno = 0;
42+
zexpect_equal(-1, putenv(s), "putenv(%s) unexpectedly succeeded", s);
43+
zexpect_not_equal(0, errno, "putenv(%s) did not set errno", s);
44+
}
45+
}
46+
47+
{
48+
/* valid cases */
49+
static const char *const cases[] = {
50+
"FOO=bar",
51+
};
52+
53+
ARRAY_FOR_EACH(cases, i) {
54+
strncpy(buf, cases[i], sizeof(buf));
55+
buf[sizeof(buf) - 1] = '\0';
56+
57+
zexpect_ok(putenv(buf), "putenv(%s) failed: %d", buf, errno);
58+
}
59+
}
60+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
common:
2+
filter: not CONFIG_NATIVE_LIBC
3+
tags:
4+
- posix
5+
- xsi
6+
- single_process
7+
# 1 tier0 platform per supported architecture
8+
platform_key:
9+
- arch
10+
- simulation
11+
integration_platforms:
12+
- qemu_cortex_m0
13+
tests:
14+
portability.xsi.single_process:
15+
extra_configs:
16+
- CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256
17+
portability.xsi.single_process.armclang_std_libc:
18+
toolchain_allow: armclang
19+
extra_configs:
20+
- CONFIG_ARMCLANG_STD_LIBC=y
21+
portability.xsi.single_process.arcmwdtlib:
22+
toolchain_allow: arcmwdt
23+
extra_configs:
24+
- CONFIG_ARCMWDT_LIBC=y
25+
portability.xsi.single_process.minimal:
26+
extra_configs:
27+
- CONFIG_MINIMAL_LIBC=y
28+
- CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256
29+
portability.xsi.single_process.newlib:
30+
filter: TOOLCHAIN_HAS_NEWLIB == 1
31+
extra_configs:
32+
- CONFIG_NEWLIB_LIBC=y
33+
- CONFIG_NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE=256
34+
portability.xsi.single_process.picolibc:
35+
tags: picolibc
36+
filter: CONFIG_PICOLIBC_SUPPORTED
37+
extra_configs:
38+
- CONFIG_PICOLIBC=y

0 commit comments

Comments
 (0)