• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * Test Name: time02
22  *
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.
26  *
27  * 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)
41  *	Log the errno and Issue a FAIL message.
42  *   Otherwise,
43  *	Verify the Functionality of system call
44  *      if successful,
45  *		Issue Functionality-Pass message.
46  *      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>
52  *  time02 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
53  *	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  *
68  */
69 
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>
76 #include <stdint.h>
77 
78 #include "test.h"
79 
80 void setup();			/* setup function for the test */
81 void cleanup();			/* cleanup function for the test */
82 
83 char *TCID = "time02";
84 int TST_TOTAL = 1;
85 
main(int ac,char ** av)86 int main(int ac, char **av)
87 {
88 	int lc;
89 	time_t tloc;		/* time_t variables for time(2) */
90 
91 	tst_parse_opts(ac, av, NULL, NULL);
92 
93 	setup();
94 
95 	for (lc = 0; TEST_LOOPING(lc); lc++) {
96 
97 		tst_count = 0;
98 
99 		/*
100 		 * Call time() to get the time in seconds$
101 		 * since Epoch.
102 		 */
103 		TEST(time(&tloc));
104 
105 		/* Check return code from time(2) */
106 		if (TEST_RETURN == -1) {
107 			tst_resm(TFAIL, "time(0) Failed, errno=%d : %s",
108 				 TEST_ERRNO, strerror(TEST_ERRNO));
109 		} else {
110 			if (tloc == TEST_RETURN) {
111 				tst_resm(TPASS, "time() returned value "
112 					 "%ld, stored value %jd are same",
113 					 TEST_RETURN, (intmax_t) tloc);
114 			} else {
115 				tst_resm(TFAIL, "time() returned value "
116 					 "%ld, stored value %jd are "
117 					 "different", TEST_RETURN,
118 					 (intmax_t) tloc);
119 			}
120 
121 		}
122 		tst_count++;	/* incr. TEST_LOOP counter */
123 	}
124 
125 	cleanup();
126 	tst_exit();
127 }
128 
129 /*
130  * setup() - performs all ONE TIME setup for this test.
131  */
setup(void)132 void setup(void)
133 {
134 
135 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
136 
137 	TEST_PAUSE;
138 }
139 
140 /*
141  * cleanup() - performs all ONE TIME cleanup for this test at
142  *	       completion or premature exit.
143  */
cleanup(void)144 void cleanup(void)
145 {
146 
147 }
148