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