Skip to content

Commit 76e1fc7

Browse files
cfriedtkartben
authored andcommitted
tests: posix: move tv_to_ts to posix_clock.h
Move the private static inline function tv_to_ts() to posix_clock.h . Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
1 parent c497088 commit 76e1fc7

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

lib/posix/options/posix_clock.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <zephyr/sys_clock.h>
1717
#include <zephyr/sys/__assert.h>
18+
#include <zephyr/posix/sys/time.h>
1819

1920
#ifdef __cplusplus
2021
extern "C" {
@@ -38,6 +39,12 @@ static inline int64_t ts_to_ms(const struct timespec *ts)
3839
return ts->tv_sec * MSEC_PER_SEC + ts->tv_nsec / NSEC_PER_MSEC;
3940
}
4041

42+
static inline void tv_to_ts(const struct timeval *tv, struct timespec *ts)
43+
{
44+
ts->tv_sec = tv->tv_sec;
45+
ts->tv_nsec = tv->tv_usec * NSEC_PER_USEC;
46+
}
47+
4148
static inline bool tp_ge(const struct timespec *a, const struct timespec *b)
4249
{
4350
return ts_to_ns(a) >= ts_to_ns(b);

tests/posix/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ zephyr_include_directories(${ZEPHYR_BASE}/lib/posix)
1010
target_sources(app PRIVATE ${app_sources})
1111

1212
target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)
13+
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/lib/posix/options)

tests/posix/common/src/clock.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,16 @@
44
*
55
* SPDX-License-Identifier: Apache-2.0
66
*/
7+
8+
#include "posix_clock.h"
9+
10+
#include <limits.h>
711
#include <sys/time.h>
8-
#include <time.h>
912
#include <unistd.h>
1013

1114
#include <zephyr/ztest.h>
1215
#include <zephyr/logging/log.h>
1316

14-
static inline int64_t ts_to_ns(const struct timespec *ts)
15-
{
16-
return ts->tv_sec * NSEC_PER_SEC + ts->tv_nsec;
17-
}
18-
19-
static inline void tv_to_ts(const struct timeval *tv, struct timespec *ts)
20-
{
21-
ts->tv_sec = tv->tv_sec;
22-
ts->tv_nsec = tv->tv_usec * NSEC_PER_USEC;
23-
}
24-
25-
#define _tp_op(_a, _b, _op) (ts_to_ns(_a) _op ts_to_ns(_b))
26-
27-
#define _decl_op(_type, _name, _op) \
28-
static inline _type _name(const struct timespec *_a, const struct timespec *_b) \
29-
{ \
30-
return _tp_op(_a, _b, _op); \
31-
}
32-
33-
_decl_op(bool, tp_ge, >=); /* a >= b */
34-
3517
ZTEST(clock, test_gettimeofday)
3618
{
3719
struct timeval tv;

0 commit comments

Comments
 (0)