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