robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 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 |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /************************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
| 19 | * TEST IDENTIFIER : reboot01 |
| 20 | * |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 21 | * EXECUTED BY : root / superuser |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 23 | * TEST TITLE : Basic test for reboot(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 2 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 27 | * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 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. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 36 | * $ |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 37 | * |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 38 | * Setup: |
| 39 | * Setup signal handling. |
| 40 | * Pause for SIGUSR1 if option specified. |
| 41 | * setting the flag value for two tests. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 42 | * |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 43 | * Test: |
| 44 | * Loop if the proper options are given. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 45 | * for two test cases for two flag values |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 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. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 50 | * |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 51 | * Cleanup: |
| 52 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 53 | * |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 54 | * USAGE: <for command-line> |
| 55 | * reboot01 [-c n] [-e] [-i n] [-I x] [-p x] [-t] [-h] [-f] [-p] |
| 56 | * where: |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 57 | * -c n : run the test for n number of times. |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 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: |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 66 | *for lib4 and lib5 reboot(2) system call is implemented as |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 67 | *int reboot(int magic, int magic2, int flag, void *arg); This test case |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 68 | *is written for int reboot(int flag); which is implemented under glibc |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 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" |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 75 | #include <errno.h> |
| 76 | #include <linux/reboot.h> |
| 77 | |
| 78 | static void setup(); |
| 79 | static void cleanup(); |
| 80 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 81 | char *TCID = "reboot01"; |
| 82 | int TST_TOTAL = 2; |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 83 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 84 | static int flag[2] = { LINUX_REBOOT_CMD_CAD_ON, LINUX_REBOOT_CMD_CAD_OFF }; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 85 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | static const char *option_message[] = { "LINUX_REBOOT_CMD_CAD_ON", |
| 87 | "LINUX_REBOOT_CMD_CAD_OFF" |
| 88 | }; |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 89 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | int main(int ac, char **av) |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 91 | { |
| 92 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 93 | int lc, i; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 94 | const char *msg; |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 95 | |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 96 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 97 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 98 | |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 99 | setup(); |
| 100 | |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 101 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 102 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 103 | tst_count = 0; |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 104 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | for (i = 0; i < TST_TOTAL; i++) { |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 106 | |
| 107 | TEST(reboot(flag[i])); |
| 108 | /* check return code */ |
| 109 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 110 | tst_resm(TFAIL, "reboot(2) Failed for " |
| 111 | "option %s", option_message[i]); |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 112 | } else { |
| 113 | tst_resm(TPASS, "reboot(2) Passed for " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 114 | "option %s", option_message[i]); |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 115 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 116 | } /*End of TEST CASE LOOPING */ |
| 117 | } /*End for TEST_LOOPING */ |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 118 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | /*Clean up and exit */ |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 120 | cleanup(); |
| 121 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 122 | tst_exit(); |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* setup() - performs all ONE TIME setup for this test */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 126 | void setup(void) |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 127 | { |
Nicolas Joly | d4ceb37 | 2014-06-22 17:03:57 +0200 | [diff] [blame] | 128 | tst_require_root(NULL); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 129 | |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 130 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 131 | |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 132 | TEST_PAUSE; |
| 133 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 134 | } |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * cleanup() - Performs one time cleanup for this test at |
| 138 | * completion or premature exit |
| 139 | */ |
| 140 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 141 | void cleanup(void) |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 142 | { |
robbiew | 07eb41b | 2002-12-24 17:13:36 +0000 | [diff] [blame] | 143 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 144 | } |