plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 3 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 7 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 11 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | */ |
vapier | 8dc646d | 2009-08-28 10:54:04 +0000 | [diff] [blame] | 32 | /* $Id: alarm02.c,v 1.4 2009/08/28 10:57:29 vapier Exp $ */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 33 | /********************************************************** |
| 34 | * |
| 35 | * OS Test - Silicon Graphics, Inc. |
| 36 | * |
| 37 | * TEST IDENTIFIER : alarm02 |
| 38 | * |
| 39 | * TEST TITLE : Boundary Value Test for alarm(2) |
| 40 | * |
| 41 | * PARENT DOCUMENT : almtds02 |
| 42 | * |
| 43 | * TEST CASE TOTAL : 3 |
| 44 | * |
| 45 | * WALL CLOCK TIME : 1 |
| 46 | * |
| 47 | * CPU TYPES : ALL |
| 48 | * |
| 49 | * AUTHOR : Billy Jean Horne |
| 50 | * |
| 51 | * CO-PILOT : Kathy Olmsted |
| 52 | * |
| 53 | * DATE STARTED : 06/01/92 |
| 54 | * |
| 55 | * INITIAL RELEASE : UNICOS 7.0 |
| 56 | * |
| 57 | * TEST CASES |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 58 | * Test Case One - A call to alarm() shall not return an error if |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 59 | * seconds is a -1. |
| 60 | * Test FAILS if a non-zero value is returned. |
| 61 | * Test Case Two - A call to alarm() shall not return an error if |
| 62 | * seconds is the maximum unsigned integer (2**63). |
| 63 | * Test FAILS if a non-zero value is returned. |
| 64 | * Test Case Three - A call to alarm() shall not return an error if |
| 65 | * seconds is the maximum unsigned integer plus 1 ((2**63)+1). |
| 66 | * Test FAILS if a non-zero value is returned. |
| 67 | * |
| 68 | * ENVIRONMENTAL NEEDS |
| 69 | * The libcuts.a and libsys.a libraries must be included in |
| 70 | * the compilation of this test. |
| 71 | * |
| 72 | * DETAILED DESCRIPTION |
| 73 | * |
| 74 | * Setup: |
| 75 | * Define a cleanup function. |
| 76 | * |
| 77 | * Test: |
| 78 | * Loop for each test case. |
| 79 | * Execute alarm (0) system call to clear previous alarm. |
| 80 | * Check return code, if system call failed (return=-1) |
| 81 | * Issue a FAIL message and exit the test. |
| 82 | * Call alarm() with boundary values for seconds. |
| 83 | * Verify that returned value is as expected. |
| 84 | * Report results. |
| 85 | * |
| 86 | * Cleanup: |
| 87 | * |
| 88 | */ |
| 89 | #include <sys/types.h> |
| 90 | #include <errno.h> |
| 91 | #include <sys/signal.h> |
| 92 | #include <limits.h> |
| 93 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 95 | void setup(void); |
| 96 | void cleanup(void); |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 97 | void alarm_received(int sig); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 99 | char *TCID = "alarm02"; |
| 100 | int TST_TOTAL = 3; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 102 | int received_alarm = 0; /* Indicates a SIGALRM was received */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | { |
| 106 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 107 | /* Parameters for usc code */ |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 108 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 109 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 111 | /* Parameters for alarm test */ |
| 112 | char *buf[] = { "-1", "ULONG_MAX", "ULONG_MAX+1" }; |
| 113 | unsigned long int sec[] = { -1, ULONG_MAX, ULONG_MAX + 1 }; |
| 114 | int exp[] = { 0, 0, 0 }; |
| 115 | int i; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | |
Garrett Cooper | 203d18a | 2010-12-13 18:12:24 -0800 | [diff] [blame] | 117 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 119 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 122 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 123 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 124 | tst_count = 0; |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 125 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 126 | for (i = 0; i < TST_TOTAL; i++) { |
| 127 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 128 | received_alarm = 0; |
| 129 | signal(SIGALRM, alarm_received); |
| 130 | |
| 131 | TEST(alarm(sec[i])); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | alarm(0); |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 133 | if (TEST_RETURN != 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 134 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 135 | "alarm(%lu) returned %ld, when %u was " |
| 136 | "expected for value %s", |
| 137 | sec[i], TEST_RETURN, exp[i], buf[i]); |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 138 | } else { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | if (received_alarm == 1) { |
| 140 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 141 | "alarm(%lu) returned %ldu but an " |
| 142 | "alarm signal was received for " |
| 143 | "value %s", |
| 144 | sec[i], TEST_RETURN, buf[i]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 145 | } else { |
| 146 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 147 | "alarm(%lu) returned %ld as " |
| 148 | "expected for value %s", |
| 149 | sec[i], TEST_RETURN, buf[i]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 150 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 151 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 152 | } |
| 153 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 154 | /* |
| 155 | * Reset alarm before cleanup. |
| 156 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 157 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 158 | alarm(0); |
| 159 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 160 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 161 | |
| 162 | cleanup(); |
Garrett Cooper | 6b66d95 | 2010-12-17 20:42:35 -0800 | [diff] [blame] | 163 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 166 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 167 | { |
| 168 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 169 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 170 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 171 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 172 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 175 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 176 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 179 | void alarm_received(int sig) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 180 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 181 | received_alarm = 1; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 182 | } |