blob: d416a713d4df178058e76102e1711bf0da245663 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
subrata_modak4bb656a2009-02-26 12:02:09 +00003 *
plars865695b2001-08-27 22:15:12 +00004 * 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_modak4bb656a2009-02-26 12:02:09 +00007 *
plars865695b2001-08-27 22:15:12 +00008 * 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_modak4bb656a2009-02-26 12:02:09 +000011 *
plars865695b2001-08-27 22:15:12 +000012 * 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_modak4bb656a2009-02-26 12:02:09 +000018 *
plars865695b2001-08-27 22:15:12 +000019 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
plars865695b2001-08-27 22:15:12 +000023 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
subrata_modak4bb656a2009-02-26 12:02:09 +000025 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
plars865695b2001-08-27 22:15:12 +000030 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 */
vapier8dc646d2009-08-28 10:54:04 +000032/* $Id: alarm02.c,v 1.4 2009/08/28 10:57:29 vapier Exp $ */
plars865695b2001-08-27 22:15:12 +000033/**********************************************************
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_modak4bb656a2009-02-26 12:02:09 +000058 * Test Case One - A call to alarm() shall not return an error if
plars865695b2001-08-27 22:15:12 +000059 * 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"
plars865695b2001-08-27 22:15:12 +000094
Mike Frysingerc57fba52014-04-09 18:56:30 -040095void setup(void);
96void cleanup(void);
Mike Frysingere61ddba2014-04-09 23:24:32 -040097void alarm_received(int sig);
plars865695b2001-08-27 22:15:12 +000098
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020099char *TCID = "alarm02";
100int TST_TOTAL = 3;
plars865695b2001-08-27 22:15:12 +0000101
subrata_modak56207ce2009-03-23 13:35:39 +0000102int received_alarm = 0; /* Indicates a SIGALRM was received */
plars865695b2001-08-27 22:15:12 +0000103
subrata_modak56207ce2009-03-23 13:35:39 +0000104int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +0000105{
106
subrata_modak56207ce2009-03-23 13:35:39 +0000107 /* Parameters for usc code */
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200108 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200109 const char *msg;
plars865695b2001-08-27 22:15:12 +0000110
subrata_modak56207ce2009-03-23 13:35:39 +0000111 /* 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;
plars865695b2001-08-27 22:15:12 +0000116
Garrett Cooper203d18a2010-12-13 18:12:24 -0800117 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +0000118 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +0000119
subrata_modak56207ce2009-03-23 13:35:39 +0000120 setup();
plars865695b2001-08-27 22:15:12 +0000121
subrata_modak56207ce2009-03-23 13:35:39 +0000122 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000123
Caspar Zhangd59a6592013-03-07 14:59:12 +0800124 tst_count = 0;
subrata_modak4bb656a2009-02-26 12:02:09 +0000125
subrata_modak56207ce2009-03-23 13:35:39 +0000126 for (i = 0; i < TST_TOTAL; i++) {
127
subrata_modak56207ce2009-03-23 13:35:39 +0000128 received_alarm = 0;
129 signal(SIGALRM, alarm_received);
130
131 TEST(alarm(sec[i]));
subrata_modak56207ce2009-03-23 13:35:39 +0000132 alarm(0);
Cyril Hrubise38b9612014-06-02 17:20:57 +0200133 if (TEST_RETURN != 0) {
subrata_modak56207ce2009-03-23 13:35:39 +0000134 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800135 "alarm(%lu) returned %ld, when %u was "
136 "expected for value %s",
137 sec[i], TEST_RETURN, exp[i], buf[i]);
Cyril Hrubise38b9612014-06-02 17:20:57 +0200138 } else {
subrata_modak56207ce2009-03-23 13:35:39 +0000139 if (received_alarm == 1) {
140 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800141 "alarm(%lu) returned %ldu but an "
142 "alarm signal was received for "
143 "value %s",
144 sec[i], TEST_RETURN, buf[i]);
subrata_modak56207ce2009-03-23 13:35:39 +0000145 } else {
146 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800147 "alarm(%lu) returned %ld as "
148 "expected for value %s",
149 sec[i], TEST_RETURN, buf[i]);
subrata_modak56207ce2009-03-23 13:35:39 +0000150 }
plars865695b2001-08-27 22:15:12 +0000151
Garrett Cooper2c282152010-12-16 00:55:50 -0800152 }
153 }
subrata_modak56207ce2009-03-23 13:35:39 +0000154 /*
155 * Reset alarm before cleanup.
156 */
plars865695b2001-08-27 22:15:12 +0000157
subrata_modak56207ce2009-03-23 13:35:39 +0000158 alarm(0);
159
Garrett Cooper2c282152010-12-16 00:55:50 -0800160 }
subrata_modak56207ce2009-03-23 13:35:39 +0000161
162 cleanup();
Garrett Cooper6b66d952010-12-17 20:42:35 -0800163 tst_exit();
plars865695b2001-08-27 22:15:12 +0000164}
165
Mike Frysingerc57fba52014-04-09 18:56:30 -0400166void setup(void)
plars865695b2001-08-27 22:15:12 +0000167{
168
subrata_modak56207ce2009-03-23 13:35:39 +0000169 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000170
subrata_modak56207ce2009-03-23 13:35:39 +0000171 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000172
plars865695b2001-08-27 22:15:12 +0000173}
174
Mike Frysingerc57fba52014-04-09 18:56:30 -0400175void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000176{
plars865695b2001-08-27 22:15:12 +0000177}
178
Mike Frysingere61ddba2014-04-09 23:24:32 -0400179void alarm_received(int sig)
plars865695b2001-08-27 22:15:12 +0000180{
subrata_modak56207ce2009-03-23 13:35:39 +0000181 received_alarm = 1;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700182}