blob: bba3671b2beee9be33c2fe0811db20d3f7aea16f [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: alarm01.c,v 1.6 2009/08/28 10:57:29 vapier Exp $ */
plars865695b2001-08-27 22:15:12 +000033/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000034 *
plars865695b2001-08-27 22:15:12 +000035 * OS Test - Silicon Graphics, Inc.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
plars865695b2001-08-27 22:15:12 +000037 * TEST IDENTIFIER : alarm01
subrata_modak4bb656a2009-02-26 12:02:09 +000038 *
plars865695b2001-08-27 22:15:12 +000039 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000040 *
plars865695b2001-08-27 22:15:12 +000041 * TEST TITLE : Basic test for alarm(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000042 *
plars865695b2001-08-27 22:15:12 +000043 * PARENT DOCUMENT : usctpl01
subrata_modak4bb656a2009-02-26 12:02:09 +000044 *
plars865695b2001-08-27 22:15:12 +000045 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000046 *
plars865695b2001-08-27 22:15:12 +000047 * WALL CLOCK TIME : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000048 *
plars865695b2001-08-27 22:15:12 +000049 * CPU TYPES : ALL
subrata_modak4bb656a2009-02-26 12:02:09 +000050 *
plars865695b2001-08-27 22:15:12 +000051 * AUTHOR : William Roske
subrata_modak4bb656a2009-02-26 12:02:09 +000052 *
plars865695b2001-08-27 22:15:12 +000053 * CO-PILOT : Dave Fenner
subrata_modak4bb656a2009-02-26 12:02:09 +000054 *
plars865695b2001-08-27 22:15:12 +000055 * DATE STARTED : 03/30/92
subrata_modak4bb656a2009-02-26 12:02:09 +000056 *
plars865695b2001-08-27 22:15:12 +000057 * INITIAL RELEASE : UNICOS 7.0
subrata_modak4bb656a2009-02-26 12:02:09 +000058 *
plars865695b2001-08-27 22:15:12 +000059 * TEST CASES
subrata_modak4bb656a2009-02-26 12:02:09 +000060 *
plars865695b2001-08-27 22:15:12 +000061 * 1.) alarm(2) returns...(See Description)
subrata_modakbdbaec52009-02-26 12:14:51 +000062 *
plars865695b2001-08-27 22:15:12 +000063 * INPUT SPECIFICATIONS
64 * The standard options for system call tests are accepted.
65 * (See the parse_opts(3) man page).
subrata_modak4bb656a2009-02-26 12:02:09 +000066 *
plars865695b2001-08-27 22:15:12 +000067 * OUTPUT SPECIFICATIONS
subrata_modak56207ce2009-03-23 13:35:39 +000068 *$
plars865695b2001-08-27 22:15:12 +000069 * DURATION
70 * Terminates - with frequency and infinite modes.
subrata_modak4bb656a2009-02-26 12:02:09 +000071 *
plars865695b2001-08-27 22:15:12 +000072 * SIGNALS
73 * Uses SIGUSR1 to pause before test if option set.
74 * (See the parse_opts(3) man page).
75 *
76 * RESOURCES
77 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000078 *
plars865695b2001-08-27 22:15:12 +000079 * ENVIRONMENTAL NEEDS
subrata_modak4bb656a2009-02-26 12:02:09 +000080 * The libcuts.a and libsys.a libraries must be included in
plars865695b2001-08-27 22:15:12 +000081 * the compilation of this test.
subrata_modak4bb656a2009-02-26 12:02:09 +000082 *
plars865695b2001-08-27 22:15:12 +000083 * SPECIAL PROCEDURAL REQUIREMENTS
84 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000085 *
plars865695b2001-08-27 22:15:12 +000086 * INTERCASE DEPENDENCIES
87 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000088 *
plars865695b2001-08-27 22:15:12 +000089 * DETAILED DESCRIPTION
90 * This is a Phase I test for the alarm(2) system call. It is intended
91 * to provide a limited exposure of the system call, for now. It
92 * should/will be extended when full functional tests are written for
93 * alarm(2).
subrata_modak4bb656a2009-02-26 12:02:09 +000094 *
plars865695b2001-08-27 22:15:12 +000095 * Setup:
96 * Setup signal handling.
97 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000098 *
plars865695b2001-08-27 22:15:12 +000099 * Test:
100 * Loop if the proper options are given.
101 * Execute system call
102 * Check return code, if system call failed (return=-1)
103 * Log the errno and Issue a FAIL message.
104 * Otherwise, Issue a PASS message.
subrata_modak4bb656a2009-02-26 12:02:09 +0000105 *
plars865695b2001-08-27 22:15:12 +0000106 * Cleanup:
107 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +0000108 *
109 *
plars865695b2001-08-27 22:15:12 +0000110 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
111
112#include <errno.h>
113#include <string.h>
114#include <signal.h>
115#include "test.h"
plars865695b2001-08-27 22:15:12 +0000116
vapieraa354722006-05-26 06:26:37 +0000117void setup();
118void cleanup();
plars865695b2001-08-27 22:15:12 +0000119
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200120char *TCID = "alarm01";
121int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +0000122
subrata_modak56207ce2009-03-23 13:35:39 +0000123int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +0000124{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200125 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200126 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +0000127
Garrett Cooper203d18a2010-12-13 18:12:24 -0800128 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +0000129 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +0000130
subrata_modak56207ce2009-03-23 13:35:39 +0000131 setup();
plars865695b2001-08-27 22:15:12 +0000132
subrata_modak56207ce2009-03-23 13:35:39 +0000133 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000134
Caspar Zhangd59a6592013-03-07 14:59:12 +0800135 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000136
subrata_modak56207ce2009-03-23 13:35:39 +0000137 /*
138 * Call alarm(2)
139 */
140 TEST(alarm(1));
subrata_modakbdbaec52009-02-26 12:14:51 +0000141
subrata_modak56207ce2009-03-23 13:35:39 +0000142 /* check return code */
Garrett Cooperf2844e52010-12-17 04:01:17 -0800143 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800144 tst_resm(TFAIL | TTERRNO, "alarm(1) failed");
Garrett Cooperf2844e52010-12-17 04:01:17 -0800145 else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200146 tst_resm(TPASS, "alarm(1) returned %ld",
147 TEST_RETURN);
subrata_modak56207ce2009-03-23 13:35:39 +0000148 }
plars865695b2001-08-27 22:15:12 +0000149
Garrett Cooper2c282152010-12-16 00:55:50 -0800150 }
plars865695b2001-08-27 22:15:12 +0000151
subrata_modak56207ce2009-03-23 13:35:39 +0000152 cleanup();
Garrett Cooperf2844e52010-12-17 04:01:17 -0800153 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800154}
plars865695b2001-08-27 22:15:12 +0000155
Mike Frysingerc57fba52014-04-09 18:56:30 -0400156void setup(void)
plars865695b2001-08-27 22:15:12 +0000157{
subrata_modak56207ce2009-03-23 13:35:39 +0000158 void trapper();
plars865695b2001-08-27 22:15:12 +0000159
subrata_modak56207ce2009-03-23 13:35:39 +0000160 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000161
subrata_modak56207ce2009-03-23 13:35:39 +0000162 signal(SIGALRM, trapper);
plars865695b2001-08-27 22:15:12 +0000163
subrata_modak56207ce2009-03-23 13:35:39 +0000164 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -0800165}
plars865695b2001-08-27 22:15:12 +0000166
167/***************************************************************
168 * cleanup() - performs all ONE TIME cleanup for this test at
169 * completion or premature exit.
170 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400171void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000172{
Garrett Cooper2c282152010-12-16 00:55:50 -0800173}
plars865695b2001-08-27 22:15:12 +0000174
Garrett Cooper203d18a2010-12-13 18:12:24 -0800175void trapper(int sig)
plars865695b2001-08-27 22:15:12 +0000176{
subrata_modak56207ce2009-03-23 13:35:39 +0000177 signal(SIGALRM, trapper);
Chris Dearmanec6edca2012-10-17 19:54:01 -0700178}