blob: 02313117402aab8a2aad044e2a12d704ed221e78 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
subrata_modak4bb656a2009-02-26 12:02:09 +000020/*
nstrazfa31d552002-05-14 16:50:06 +000021 * Test Name: time02
plars865695b2001-08-27 22:15:12 +000022 *
23 * Test Description:
24 * Verify that time(2) returns the value of time in seconds since
25 * the Epoch and stores this value in the memory pointed to by the parameter.
subrata_modakbdbaec52009-02-26 12:14:51 +000026 *
plars865695b2001-08-27 22:15:12 +000027 * Expected Result:
28 * time() should return the time (seconds) since the Epoch and this value
29 * should be equal to the value stored in the specified parameter.
30 *
31 * Algorithm:
32 * Setup:
33 * Setup signal handling.
34 * Create temporary directory.
35 * Pause for SIGUSR1 if option specified.
36 *
37 * Test:
38 * Loop if the proper options are given.
39 * Execute system call
40 * Check return code, if system call failed (return=-1)
subrata_modak56207ce2009-03-23 13:35:39 +000041 * Log the errno and Issue a FAIL message.
plars865695b2001-08-27 22:15:12 +000042 * Otherwise,
subrata_modak56207ce2009-03-23 13:35:39 +000043 * Verify the Functionality of system call
plars865695b2001-08-27 22:15:12 +000044 * if successful,
subrata_modak56207ce2009-03-23 13:35:39 +000045 * Issue Functionality-Pass message.
plars865695b2001-08-27 22:15:12 +000046 * Otherwise,
47 * Issue Functionality-Fail message.
48 * Cleanup:
49 * Print errno log and/or timing stats if options given
50 *
51 * Usage: <for command-line>
nstrazfa31d552002-05-14 16:50:06 +000052 * time02 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
plars865695b2001-08-27 22:15:12 +000053 * where, -c n : Run n copies concurrently.
54 * -e : Turn on errno logging.
55 * -f : Turn off functionality Testing.
56 * -i n : Execute test n times.
57 * -I x : Execute test for x seconds.
58 * -P x : Pause for x seconds between iterations.
59 * -t : Turn on syscall timing.
60 *
61 * History
62 * 07/2001 John George
63 * -Ported
64 *
65 * Restrictions:
66 * None.
67 *
subrata_modak4bb656a2009-02-26 12:02:09 +000068 */
plars865695b2001-08-27 22:15:12 +000069
70#include <stdio.h>
71#include <errno.h>
72#include <string.h>
73#include <signal.h>
74#include <time.h>
75#include <sys/types.h>
subrata_modak923b23f2009-11-02 13:57:16 +000076#include <stdint.h>
plars865695b2001-08-27 22:15:12 +000077
78#include "test.h"
plars865695b2001-08-27 22:15:12 +000079
subrata_modak56207ce2009-03-23 13:35:39 +000080void setup(); /* setup function for the test */
81void cleanup(); /* cleanup function for the test */
plars865695b2001-08-27 22:15:12 +000082
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020083char *TCID = "time02";
84int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000085
subrata_modak56207ce2009-03-23 13:35:39 +000086int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000087{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020088 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020089 const char *msg;
plars865695b2001-08-27 22:15:12 +000090 time_t tloc; /* time_t variables for time(2) */
91
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080092 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
plars865695b2001-08-27 22:15:12 +000093 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080094
plars865695b2001-08-27 22:15:12 +000095 setup();
96
subrata_modak56207ce2009-03-23 13:35:39 +000097 for (lc = 0; TEST_LOOPING(lc); lc++) {
Garrett Cooper2c282152010-12-16 00:55:50 -080098
Caspar Zhangd59a6592013-03-07 14:59:12 +080099 tst_count = 0;
subrata_modakbdbaec52009-02-26 12:14:51 +0000100
subrata_modak4bb656a2009-02-26 12:02:09 +0000101 /*
subrata_modak56207ce2009-03-23 13:35:39 +0000102 * Call time() to get the time in seconds$
plars865695b2001-08-27 22:15:12 +0000103 * since Epoch.
104 */
105 TEST(time(&tloc));
subrata_modakbdbaec52009-02-26 12:14:51 +0000106
plars865695b2001-08-27 22:15:12 +0000107 /* Check return code from time(2) */
108 if (TEST_RETURN == -1) {
plars865695b2001-08-27 22:15:12 +0000109 tst_resm(TFAIL, "time(0) Failed, errno=%d : %s",
110 TEST_ERRNO, strerror(TEST_ERRNO));
111 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200112 if (tloc == TEST_RETURN) {
113 tst_resm(TPASS, "time() returned value "
114 "%ld, stored value %jd are same",
115 TEST_RETURN, (intmax_t) tloc);
plars865695b2001-08-27 22:15:12 +0000116 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200117 tst_resm(TFAIL, "time() returned value "
118 "%ld, stored value %jd are "
119 "different", TEST_RETURN,
120 (intmax_t) tloc);
plars865695b2001-08-27 22:15:12 +0000121 }
122
123 }
Caspar Zhangd59a6592013-03-07 14:59:12 +0800124 tst_count++; /* incr. TEST_LOOP counter */
Garrett Cooper2c282152010-12-16 00:55:50 -0800125 }
plars865695b2001-08-27 22:15:12 +0000126
plars865695b2001-08-27 22:15:12 +0000127 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800128 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800129}
plars865695b2001-08-27 22:15:12 +0000130
131/*
132 * setup() - performs all ONE TIME setup for this test.
133 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400134void setup(void)
plars865695b2001-08-27 22:15:12 +0000135{
Garrett Cooper2c282152010-12-16 00:55:50 -0800136
plars865695b2001-08-27 22:15:12 +0000137 tst_sig(NOFORK, DEF_HANDLER, cleanup);
138
plars865695b2001-08-27 22:15:12 +0000139 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -0800140}
plars865695b2001-08-27 22:15:12 +0000141
142/*
143 * cleanup() - performs all ONE TIME cleanup for this test at
subrata_modak56207ce2009-03-23 13:35:39 +0000144 * completion or premature exit.
plars865695b2001-08-27 22:15:12 +0000145 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400146void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000147{
plars865695b2001-08-27 22:15:12 +0000148
Chris Dearmanec6edca2012-10-17 19:54:01 -0700149}