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