blob: 1b75e34f67c82c8b5db6421db9f87b1c98a15fea [file] [log] [blame]
robbiew07eb41b2002-12-24 17:13:36 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. 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 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiew07eb41b2002-12-24 17:13:36 +000015 *
16 */
17/**************************************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
19 * TEST IDENTIFIER : reboot01
20 *
robbiew07eb41b2002-12-24 17:13:36 +000021 * EXECUTED BY : root / superuser
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
robbiew07eb41b2002-12-24 17:13:36 +000023 * TEST TITLE : Basic test for reboot(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiew07eb41b2002-12-24 17:13:36 +000025 * TEST CASE TOTAL : 2
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
robbiew07eb41b2002-12-24 17:13:36 +000027 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
robbiew07eb41b2002-12-24 17:13:36 +000029 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
32 *
33 * DESCRIPTION
34 * This is a Phase I test for the reboot(2) system call.
35 * It is intended to provide a limited exposure of the system call.
subrata_modak56207ce2009-03-23 13:35:39 +000036 * $
subrata_modak4bb656a2009-02-26 12:02:09 +000037 *
robbiew07eb41b2002-12-24 17:13:36 +000038 * Setup:
39 * Setup signal handling.
40 * Pause for SIGUSR1 if option specified.
41 * setting the flag value for two tests.
subrata_modak4bb656a2009-02-26 12:02:09 +000042 *
robbiew07eb41b2002-12-24 17:13:36 +000043 * Test:
44 * Loop if the proper options are given.
subrata_modak4bb656a2009-02-26 12:02:09 +000045 * for two test cases for two flag values
robbiew07eb41b2002-12-24 17:13:36 +000046 * Execute system call
47 * Check return code, if system call failed (return=-1)
48 * Log the errno and Issue a FAIL message.
49 * Otherwise, Issue a PASS message.
subrata_modak4bb656a2009-02-26 12:02:09 +000050 *
robbiew07eb41b2002-12-24 17:13:36 +000051 * Cleanup:
52 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000053 *
robbiew07eb41b2002-12-24 17:13:36 +000054 * USAGE: <for command-line>
55 * reboot01 [-c n] [-e] [-i n] [-I x] [-p x] [-t] [-h] [-f] [-p]
56 * where:
subrata_modak4bb656a2009-02-26 12:02:09 +000057 * -c n : run the test for n number of times.
robbiew07eb41b2002-12-24 17:13:36 +000058 * -e : Turn on errno logging.
59 * -i n : Execute test n times.
60 * -I x : Execute test for x seconds.
61 * -p : Pause for SIGUSR1 before starting
62 * -P x : Pause for x seconds between iterations.
63 * -t : Turn on syscall timing.
64 *
65 *RESTRICTIONS:
subrata_modak4bb656a2009-02-26 12:02:09 +000066 *for lib4 and lib5 reboot(2) system call is implemented as
robbiew07eb41b2002-12-24 17:13:36 +000067 *int reboot(int magic, int magic2, int flag, void *arg); This test case
subrata_modak4bb656a2009-02-26 12:02:09 +000068 *is written for int reboot(int flag); which is implemented under glibc
robbiew07eb41b2002-12-24 17:13:36 +000069 *Therefore this testcase may not work under libc4 and libc5 libraries
70 *****************************************************************************/
71
72#include <unistd.h>
73#include <sys/reboot.h>
74#include "test.h"
robbiew07eb41b2002-12-24 17:13:36 +000075#include <errno.h>
76#include <linux/reboot.h>
77
78static void setup();
79static void cleanup();
80
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020081char *TCID = "reboot01";
82int TST_TOTAL = 2;
robbiew07eb41b2002-12-24 17:13:36 +000083
subrata_modak56207ce2009-03-23 13:35:39 +000084static int flag[2] = { LINUX_REBOOT_CMD_CAD_ON, LINUX_REBOOT_CMD_CAD_OFF };
Wanlong Gao354ebb42012-12-07 10:10:04 +080085
subrata_modak56207ce2009-03-23 13:35:39 +000086static const char *option_message[] = { "LINUX_REBOOT_CMD_CAD_ON",
87 "LINUX_REBOOT_CMD_CAD_OFF"
88};
robbiew07eb41b2002-12-24 17:13:36 +000089
subrata_modak56207ce2009-03-23 13:35:39 +000090int main(int ac, char **av)
robbiew07eb41b2002-12-24 17:13:36 +000091{
92
Cyril Hrubis89af32a2012-10-24 16:39:11 +020093 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020094 const char *msg;
robbiew07eb41b2002-12-24 17:13:36 +000095
Garrett Coopera9e49f12010-12-16 10:54:03 -080096 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080097 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew07eb41b2002-12-24 17:13:36 +000098
robbiew07eb41b2002-12-24 17:13:36 +000099 setup();
100
robbiew07eb41b2002-12-24 17:13:36 +0000101 for (lc = 0; TEST_LOOPING(lc); lc++) {
102
Caspar Zhangd59a6592013-03-07 14:59:12 +0800103 tst_count = 0;
robbiew07eb41b2002-12-24 17:13:36 +0000104
subrata_modak56207ce2009-03-23 13:35:39 +0000105 for (i = 0; i < TST_TOTAL; i++) {
robbiew07eb41b2002-12-24 17:13:36 +0000106
107 TEST(reboot(flag[i]));
108 /* check return code */
109 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000110 tst_resm(TFAIL, "reboot(2) Failed for "
111 "option %s", option_message[i]);
robbiew07eb41b2002-12-24 17:13:36 +0000112 } else {
113 tst_resm(TPASS, "reboot(2) Passed for "
subrata_modak56207ce2009-03-23 13:35:39 +0000114 "option %s", option_message[i]);
robbiew07eb41b2002-12-24 17:13:36 +0000115 }
subrata_modak56207ce2009-03-23 13:35:39 +0000116 } /*End of TEST CASE LOOPING */
117 } /*End for TEST_LOOPING */
robbiew07eb41b2002-12-24 17:13:36 +0000118
subrata_modak56207ce2009-03-23 13:35:39 +0000119 /*Clean up and exit */
robbiew07eb41b2002-12-24 17:13:36 +0000120 cleanup();
121
Garrett Cooper53740502010-12-16 00:04:01 -0800122 tst_exit();
robbiew07eb41b2002-12-24 17:13:36 +0000123}
124
125/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400126void setup(void)
robbiew07eb41b2002-12-24 17:13:36 +0000127{
Nicolas Jolyd4ceb372014-06-22 17:03:57 +0200128 tst_require_root(NULL);
Garrett Cooper2c282152010-12-16 00:55:50 -0800129
robbiew07eb41b2002-12-24 17:13:36 +0000130 tst_sig(NOFORK, DEF_HANDLER, cleanup);
131
robbiew07eb41b2002-12-24 17:13:36 +0000132 TEST_PAUSE;
133
Garrett Cooper2c282152010-12-16 00:55:50 -0800134}
robbiew07eb41b2002-12-24 17:13:36 +0000135
136/*
137 * cleanup() - Performs one time cleanup for this test at
138 * completion or premature exit
139 */
140
Mike Frysingerc57fba52014-04-09 18:56:30 -0400141void cleanup(void)
robbiew07eb41b2002-12-24 17:13:36 +0000142{
robbiew07eb41b2002-12-24 17:13:36 +0000143
Chris Dearmanec6edca2012-10-17 19:54:01 -0700144}