plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | /* |
nstraz | fa31d55 | 2002-05-14 16:50:06 +0000 | [diff] [blame] | 21 | * Test Name: time02 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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. |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 26 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 41 | * Log the errno and Issue a FAIL message. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 42 | * Otherwise, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 43 | * Verify the Functionality of system call |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 44 | * if successful, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 45 | * Issue Functionality-Pass message. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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> |
nstraz | fa31d55 | 2002-05-14 16:50:06 +0000 | [diff] [blame] | 52 | * time02 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t] |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 | * |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 68 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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> |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 76 | #include <stdint.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | |
| 78 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 80 | void setup(); /* setup function for the test */ |
| 81 | void cleanup(); /* cleanup function for the test */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 82 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 83 | char *TCID = "time02"; |
| 84 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 85 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 88 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 89 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | time_t tloc; /* time_t variables for time(2) */ |
| 91 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 92 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 94 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | setup(); |
| 96 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 97 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 98 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 99 | tst_count = 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 100 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 101 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 102 | * Call time() to get the time in seconds$ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | * since Epoch. |
| 104 | */ |
| 105 | TEST(time(&tloc)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 106 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 107 | /* Check return code from time(2) */ |
| 108 | if (TEST_RETURN == -1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 109 | tst_resm(TFAIL, "time(0) Failed, errno=%d : %s", |
| 110 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 111 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 112 | if (tloc == TEST_RETURN) { |
| 113 | tst_resm(TPASS, "time() returned value " |
| 114 | "%ld, stored value %jd are same", |
| 115 | TEST_RETURN, (intmax_t) tloc); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 117 | tst_resm(TFAIL, "time() returned value " |
| 118 | "%ld, stored value %jd are " |
| 119 | "different", TEST_RETURN, |
| 120 | (intmax_t) tloc); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | } |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 124 | tst_count++; /* incr. TEST_LOOP counter */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 125 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 127 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 128 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 129 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * setup() - performs all ONE TIME setup for this test. |
| 133 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 134 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 135 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 136 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 137 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 138 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | TEST_PAUSE; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 140 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * cleanup() - performs all ONE TIME cleanup for this test at |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 144 | * completion or premature exit. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 145 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 146 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 147 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 148 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 149 | } |