1 /* 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 13 * with this program; if not, write the Free Software Foundation, Inc., 14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 15 * 16 */ 17 /************************************************************************** 18 * 19 * TEST IDENTIFIER : reboot01 20 * 21 * EXECUTED BY : root / superuser 22 * 23 * TEST TITLE : Basic test for reboot(2) 24 * 25 * TEST CASE TOTAL : 2 26 * 27 * AUTHOR : Aniruddha Marathe <aniruddha.marathe (at) wipro.com> 28 * 29 * 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. 36 * $ 37 * 38 * Setup: 39 * Setup signal handling. 40 * Pause for SIGUSR1 if option specified. 41 * setting the flag value for two tests. 42 * 43 * Test: 44 * Loop if the proper options are given. 45 * for two test cases for two flag values 46 * 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. 50 * 51 * Cleanup: 52 * Print errno log and/or timing stats if options given 53 * 54 * USAGE: <for command-line> 55 * reboot01 [-c n] [-e] [-i n] [-I x] [-p x] [-t] [-h] [-f] [-p] 56 * where: 57 * -c n : run the test for n number of times. 58 * -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: 66 *for lib4 and lib5 reboot(2) system call is implemented as 67 *int reboot(int magic, int magic2, int flag, void *arg); This test case 68 *is written for int reboot(int flag); which is implemented under glibc 69 *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" 75 #include <errno.h> 76 #include <linux/reboot.h> 77 78 static void setup(); 79 static void cleanup(); 80 81 char *TCID = "reboot01"; 82 int TST_TOTAL = 2; 83 84 static int flag[2] = { LINUX_REBOOT_CMD_CAD_ON, LINUX_REBOOT_CMD_CAD_OFF }; 85 86 static const char *option_message[] = { "LINUX_REBOOT_CMD_CAD_ON", 87 "LINUX_REBOOT_CMD_CAD_OFF" 88 }; 89 90 int main(int ac, char **av) 91 { 92 93 int lc, i; 94 95 tst_parse_opts(ac, av, NULL, NULL); 96 97 setup(); 98 99 for (lc = 0; TEST_LOOPING(lc); lc++) { 100 101 tst_count = 0; 102 103 for (i = 0; i < TST_TOTAL; i++) { 104 105 TEST(reboot(flag[i])); 106 /* check return code */ 107 if (TEST_RETURN == -1) { 108 tst_resm(TFAIL, "reboot(2) Failed for " 109 "option %s", option_message[i]); 110 } else { 111 tst_resm(TPASS, "reboot(2) Passed for " 112 "option %s", option_message[i]); 113 } 114 } /*End of TEST CASE LOOPING */ 115 } /*End for TEST_LOOPING */ 116 117 /*Clean up and exit */ 118 cleanup(); 119 120 tst_exit(); 121 } 122 123 /* setup() - performs all ONE TIME setup for this test */ 124 void setup(void) 125 { 126 tst_require_root(); 127 128 tst_sig(NOFORK, DEF_HANDLER, cleanup); 129 130 TEST_PAUSE; 131 132 } 133 134 /* 135 * cleanup() - Performs one time cleanup for this test at 136 * completion or premature exit 137 */ 138 139 void cleanup(void) 140 { 141 142 } 143