Skip to content

Commit

Permalink
tests: posix: Add CLOCK_THREAD_CPUTIME_ID unittest
Browse files Browse the repository at this point in the history
Added test for 'clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts)'.

Signed-off-by: James Roy <[email protected]>
  • Loading branch information
rruuaanng committed Nov 8, 2024
1 parent 9187f97 commit 0c62f24
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/posix/common/src/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ static const struct timespec ref_ts = {1514821501, NSEC_PER_SEC / 2U};
static const clockid_t clocks[] = {
CLOCK_MONOTONIC,
CLOCK_REALTIME,
#ifdef CONFIG_POSIX_THREAD_CPUTIME
CLOCK_THREAD_CPUTIME_ID,
#endif /* CONFIG_POSIX_THREAD_CPUTIME */
};
static const bool settable[] = {
false,
true,
#ifdef CONFIG_POSIX_THREAD_CPUTIME
false,
#endif /* CONFIG_POSIX_THREAD_CPUTIME */
};

static inline int64_t ts_to_ns(const struct timespec *ts)
Expand Down Expand Up @@ -105,6 +111,9 @@ ZTEST(clock, test_gettimeofday)
/* Validate gettimeofday API */
zassert_ok(gettimeofday(&tv, NULL));
zassert_ok(clock_gettime(CLOCK_REALTIME, &rts));
#ifdef CONFIG_POSIX_THREAD_CPUTIME
zassert_ok(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts));
#endif /* CONFIG_POSIX_THREAD_CPUTIME */

/* TESTPOINT: Check if time obtained from
* gettimeofday is same or more than obtained
Expand Down

0 comments on commit 0c62f24

Please sign in to comment.