xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/time/time01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker /*\
7*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
8*49cdfc7eSAndroid Build Coastguard Worker  * - Basic test for the time(2) system call. It is intended to provide a
9*49cdfc7eSAndroid Build Coastguard Worker  * limited exposure of the system call.
10*49cdfc7eSAndroid Build Coastguard Worker  * - Verify that time(2) returns the value of time in seconds since the Epoch
11*49cdfc7eSAndroid Build Coastguard Worker  * and stores this value in the memory pointed to by the parameter.
12*49cdfc7eSAndroid Build Coastguard Worker  */
13*49cdfc7eSAndroid Build Coastguard Worker 
14*49cdfc7eSAndroid Build Coastguard Worker #include <time.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
16*49cdfc7eSAndroid Build Coastguard Worker 
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
18*49cdfc7eSAndroid Build Coastguard Worker 
19*49cdfc7eSAndroid Build Coastguard Worker time_t tlocal;
20*49cdfc7eSAndroid Build Coastguard Worker time_t *targs[] = {
21*49cdfc7eSAndroid Build Coastguard Worker 	NULL, &tlocal,
22*49cdfc7eSAndroid Build Coastguard Worker };
23*49cdfc7eSAndroid Build Coastguard Worker 
verify_time(unsigned int i)24*49cdfc7eSAndroid Build Coastguard Worker static void verify_time(unsigned int i)
25*49cdfc7eSAndroid Build Coastguard Worker {
26*49cdfc7eSAndroid Build Coastguard Worker 	time_t *tloc = targs[i];
27*49cdfc7eSAndroid Build Coastguard Worker 
28*49cdfc7eSAndroid Build Coastguard Worker 	TEST(time(tloc));
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_RET == -1) {
31*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL | TTERRNO, "time()");
32*49cdfc7eSAndroid Build Coastguard Worker 		return;
33*49cdfc7eSAndroid Build Coastguard Worker 	}
34*49cdfc7eSAndroid Build Coastguard Worker 
35*49cdfc7eSAndroid Build Coastguard Worker 	if (!tloc)
36*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TPASS, "time() returned value %ld", TST_RET);
37*49cdfc7eSAndroid Build Coastguard Worker 	else if (*tloc == TST_RET)
38*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TPASS,
39*49cdfc7eSAndroid Build Coastguard Worker 			"time() returned value %ld, stored value %jd are same",
40*49cdfc7eSAndroid Build Coastguard Worker 			TST_RET, (intmax_t) *tloc);
41*49cdfc7eSAndroid Build Coastguard Worker 	else
42*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL,
43*49cdfc7eSAndroid Build Coastguard Worker 			"time() returned value %ld, stored value %jd are different",
44*49cdfc7eSAndroid Build Coastguard Worker 			TST_RET, (intmax_t) *tloc);
45*49cdfc7eSAndroid Build Coastguard Worker }
46*49cdfc7eSAndroid Build Coastguard Worker 
47*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
48*49cdfc7eSAndroid Build Coastguard Worker 	.test = verify_time,
49*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(targs),
50*49cdfc7eSAndroid Build Coastguard Worker };
51