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 <limits.h>
11 #include <sys/time.h>
12 #include <unistd.h>
13 
14 #include <zephyr/ztest.h>
15 #include <zephyr/logging/log.h>
16 
ZTEST(clock,test_gettimeofday)17 ZTEST(clock, test_gettimeofday)
18 {
19 	struct timeval tv;
20 	struct timespec ts;
21 	struct timespec rts;
22 
23 	if (false) {
24 		/* undefined behaviour */
25 		errno = 0;
26 		zassert_equal(gettimeofday(NULL, NULL), -1);
27 		zassert_equal(errno, EINVAL);
28 	}
29 
30 	/* Validate gettimeofday API */
31 	zassert_ok(gettimeofday(&tv, NULL));
32 	zassert_ok(clock_gettime(CLOCK_REALTIME, &rts));
33 
34 	/* TESTPOINT: Check if time obtained from
35 	 * gettimeofday is same or more than obtained
36 	 * from clock_gettime
37 	 */
38 	tv_to_ts(&tv, &ts);
39 	zassert_true(tp_ge(&rts, &ts));
40 }
41 
42 ZTEST_SUITE(clock, NULL, NULL, NULL, NULL, NULL);
43