Skip to content

Commit 13c25e2

Browse files
committed
stashing
Signed-off-by: Chris Friedt <[email protected]>
1 parent 6c0893a commit 13c25e2

File tree

7 files changed

+53
-8
lines changed

7 files changed

+53
-8
lines changed

include/zephyr/posix/posix_features.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@
9090
#define _POSIX_MESSAGE_PASSING _POSIX_VERSION
9191
#endif
9292

93-
#ifdef CONFIG_POSIX_MONOTONIC_CLOCK
94-
#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION
95-
#endif
93+
// #ifdef CONFIG_POSIX_MONOTONIC_CLOCK
94+
// #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION
95+
// #endif
9696

9797
/* #define _POSIX_PRIORITIZED_IO (-1L) */
9898

@@ -177,9 +177,9 @@
177177
#define _POSIX_TIMEOUTS _POSIX_VERSION
178178
#endif
179179

180-
#ifdef CONFIG_POSIX_TIMERS
181-
#define _POSIX_TIMERS _POSIX_VERSION
182-
#endif
180+
// #ifdef CONFIG_POSIX_TIMERS
181+
// #define _POSIX_TIMERS _POSIX_VERSION
182+
// #endif
183183

184184
/* #define _POSIX_TRACE (-1L) */
185185
/* #define _POSIX_TRACE_EVENT_FILTER (-1L) */

lib/libc/minimal/source/time/gmtime.c

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

7+
#undef _POSIX_C_SOURCE
8+
#define _POSIX_C_SOURCE 200809L
79
#include <time.h>
10+
811
#include <zephyr/sys/libc-hooks.h>
912

1013
#ifdef CONFIG_MINIMAL_LIBC_NON_REENTRANT_FUNCTIONS

lib/libc/newlib/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,12 @@ if(CONFIG_NEWLIB_LIBC_NANO)
4949
-specs=nano.specs
5050
)
5151
endif()
52+
53+
if(CONFIG_POSIX_API)
54+
set(POSIX_VERSION 200809L)
55+
zephyr_compile_options(
56+
-U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=${POSIX_VERSION}
57+
-U_POSIX_TIMERS -D_POSIX_TIMERS=${POSIX_VERSION}
58+
-U__POSIX_VISIBLE -D__POSIX_VISIBLE=${POSIX_VERSION}
59+
)
60+
endif()

lib/posix/options/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
set(POSIX_VERSION 200809L)
4+
set(XOPEN_VERSION 700)
5+
36
set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated)
47

58
zephyr_syscall_header_ifdef(CONFIG_POSIX_CLOCK_SELECTION posix_clock.h)
@@ -125,6 +128,12 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_TIMERS)
125128
timespec_to_timeout.c
126129
)
127130
endif()
131+
zephyr_compile_options_ifdef(CONFIG_POSIX_TIMERS
132+
-U_POSIX_TIMERS -DPOSIX_TIMERS=${POSIX_VERSION}
133+
# Technically _POSIX_MONOTONIC_CLOCK should be selected by CONFIG_POSIX_ADVANCED_REALTIME
134+
# See https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html
135+
-U_POSIX_MONOTONIC_CLOCK -D_POSIX_MONOTONIC_CLOCK=${POSIX_VERSION}
136+
)
128137

129138
if (NOT CONFIG_TC_PROVIDES_POSIX_READER_WRITER_LOCKS)
130139
# Note: the Option is _POSIX_READER_WRITER_LOCKS, while the Option Group is POSIX_RW_LOCKS.

lib/posix/options/clock.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,17 @@ int clock_getres(clockid_t clock_id, struct timespec *res)
3333
CONFIG_SYS_CLOCK_TICKS_PER_SEC <= NSEC_PER_SEC,
3434
"CONFIG_SYS_CLOCK_TICKS_PER_SEC must be > 0 and <= NSEC_PER_SEC");
3535

36-
if (!(clock_id == CLOCK_MONOTONIC || clock_id == CLOCK_REALTIME ||
37-
clock_id == CLOCK_PROCESS_CPUTIME_ID)) {
36+
if (!(
37+
/* FIXME: this should check CONFIG_POSIX_ADVANCED_REALTIME */
38+
#if defined(_POSIX_MONOTONIC_CLOCK)
39+
clock_id == CLOCK_MONOTONIC ||
40+
#endif
41+
clock_id == CLOCK_REALTIME ||
42+
/* FIXME: this should check CONFIG_POSIX_ADVANCED_REALTIME */
43+
#if defined(_POSIX_CPUTIME)
44+
clock_id == CLOCK_PROCESS_CPUTIME_ID ||
45+
#endif
46+
false)) {
3847
errno = EINVAL;
3948
return -1;
4049
}
@@ -117,6 +126,8 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
117126
return 0;
118127
}
119128

129+
/* FIXME: this should check CONFIG_POSIX_ADVANCED_REALTIME */
130+
#if defined(_POSIX_CPUTIME)
120131
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
121132
{
122133
/* We don't allow any process ID but our own. */
@@ -128,3 +139,4 @@ int clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
128139

129140
return 0;
130141
}
142+
#endif

tests/posix/timers/src/clock.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ ZTEST(posix_timers, test_realtime)
157157
zassert_between_inclusive(cma, lo, hi);
158158
}
159159

160+
/* FIXME: this should be moved to a testsuite called advanced_realtime */
160161
ZTEST(posix_timers, test_clock_getcpuclockid)
161162
{
163+
#ifdef _POSIX_CPUTIME
162164
int ret = 0;
163165
clockid_t clock_id = CLOCK_INVALID;
164166

@@ -168,6 +170,7 @@ ZTEST(posix_timers, test_clock_getcpuclockid)
168170

169171
ret = clock_getcpuclockid((pid_t)2482, &clock_id);
170172
zassert_equal(ret, EPERM, "POSIX clock_getcpuclock id failed");
173+
#endif
171174
}
172175

173176
ZTEST(posix_timers, test_clock_getres)
@@ -190,13 +193,21 @@ ZTEST(posix_timers, test_clock_getres)
190193
{CLOCK_INVALID, NULL, -1},
191194
{CLOCK_INVALID, &res, -1},
192195
{CLOCK_REALTIME, NULL, 0},
196+
#if defined(_POSIX_MONOTONIC_CLOCK)
193197
{CLOCK_MONOTONIC, NULL, 0},
198+
#endif
199+
#if defined(_POSIX_CPUTIME)
194200
{CLOCK_PROCESS_CPUTIME_ID, NULL, 0},
201+
#endif
195202

196203
/* all valid inputs */
197204
{CLOCK_REALTIME, &res, 0},
205+
#if defined(_POSIX_MONOTONIC_CLOCK)
198206
{CLOCK_MONOTONIC, &res, 0},
207+
#endif
208+
#if defined(_POSIX_CPUTIME)
199209
{CLOCK_PROCESS_CPUTIME_ID, &res, 0},
210+
#endif
200211
};
201212

202213
ARRAY_FOR_EACH_PTR(args, arg) {

tests/posix/timers/src/timer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <zephyr/ztest.h>
1111
#include <zephyr/logging/log.h>
12+
#include <zephyr/posix/signal.h>
1213

1314
#define SECS_TO_SLEEP 2
1415
#define DURATION_SECS 1

0 commit comments

Comments
 (0)