1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
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.
7 *
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.
11 *
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.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 */
32 /* $Id: alarm02.c,v 1.4 2009/08/28 10:57:29 vapier Exp $ */
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
58 * Test Case One - A call to alarm() shall not return an error if
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"
94
95 void setup(void);
96 void cleanup(void);
97 void alarm_received(int sig);
98
99 char *TCID = "alarm02";
100 int TST_TOTAL = 3;
101
102 int received_alarm = 0; /* Indicates a SIGALRM was received */
103
main(int ac,char ** av)104 int main(int ac, char **av)
105 {
106
107 /* Parameters for usc code */
108 int lc;
109
110 /* Parameters for alarm test */
111 char *buf[] = { "-1", "ULONG_MAX", "ULONG_MAX+1" };
112 unsigned long int sec[] = { -1, ULONG_MAX, ULONG_MAX + 1 };
113 int exp[] = { 0, 0, 0 };
114 int i;
115
116 tst_parse_opts(ac, av, NULL, NULL);
117
118 setup();
119
120 for (lc = 0; TEST_LOOPING(lc); lc++) {
121
122 tst_count = 0;
123
124 for (i = 0; i < TST_TOTAL; i++) {
125
126 received_alarm = 0;
127 signal(SIGALRM, alarm_received);
128
129 TEST(alarm(sec[i]));
130 alarm(0);
131 if (TEST_RETURN != 0) {
132 tst_resm(TFAIL,
133 "alarm(%lu) returned %ld, when %u was "
134 "expected for value %s",
135 sec[i], TEST_RETURN, exp[i], buf[i]);
136 } else {
137 if (received_alarm == 1) {
138 tst_resm(TFAIL,
139 "alarm(%lu) returned %ldu but an "
140 "alarm signal was received for "
141 "value %s",
142 sec[i], TEST_RETURN, buf[i]);
143 } else {
144 tst_resm(TPASS,
145 "alarm(%lu) returned %ld as "
146 "expected for value %s",
147 sec[i], TEST_RETURN, buf[i]);
148 }
149
150 }
151 }
152 /*
153 * Reset alarm before cleanup.
154 */
155
156 alarm(0);
157
158 }
159
160 cleanup();
161 tst_exit();
162 }
163
setup(void)164 void setup(void)
165 {
166
167 tst_sig(NOFORK, DEF_HANDLER, cleanup);
168
169 TEST_PAUSE;
170
171 }
172
cleanup(void)173 void cleanup(void)
174 {
175 }
176
alarm_received(int sig)177 void alarm_received(int sig)
178 {
179 received_alarm = 1;
180 }
181