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 : ioperm01 20 * 21 * EXECUTED BY : superuser 22 * 23 * TEST TITLE : Basic test for ioperm(2) 24 * 25 * TEST CASE TOTAL : 1 26 * 27 * AUTHOR : Subhab Biswas <subhabrata.biswas (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 ioperm(2) system call. 35 * It is intended to provide a limited exposure of the system call. 36 * 37 * Setup: 38 * Setup signal handling. 39 * Test caller is superuser 40 * Pause for SIGUSR1 if option specified. 41 * 42 * Test: 43 * Loop if the proper options are given. 44 * Execute system call 45 * Check return code, if system call failed (return=-1) 46 * Issue FAIL message with errno. 47 * Otherwise, Issue PASS message. 48 * 49 * Cleanup: 50 * Print errno log and/or timing stats if options given 51 * 52 * USAGE: <for command-line> 53 * ioperm01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p] 54 * where, -c n : Run n copies concurrently. 55 * -e : Turn on errno logging. 56 * -h : Show help screen 57 * -f : Turn off functional testing 58 * -i n : Execute test n times. 59 * -I x : Execute test for x seconds. 60 * -p : Pause for SIGUSR1 before starting 61 * -P x : Pause for x seconds between iterations. 62 * -t : Turn on syscall timing. 63 * 64 ****************************************************************/ 65 66 char *TCID = "ioperm01"; 67 68 #if defined __i386__ || defined(__x86_64__) 69 70 #include <errno.h> 71 #include <unistd.h> 72 #include <sys/io.h> 73 74 #include "test.h" 75 76 unsigned long io_addr; /*kernel version dependant io start address */ 77 #define NUM_BYTES 3 /* number of bytes from start address */ 78 #define TURN_ON 1 79 #define TURN_OFF 0 80 #ifndef IO_BITMAP_BITS 81 #define IO_BITMAP_BITS 1024 82 #endif 83 84 static void setup(); 85 static void cleanup(); 86 87 int TST_TOTAL = 1; 88 89 int main(int ac, char **av) 90 { 91 92 int lc; 93 94 tst_parse_opts(ac, av, NULL, NULL); 95 96 setup(); 97 98 for (lc = 0; TEST_LOOPING(lc); lc++) { 99 100 tst_count = 0; 101 102 /* 103 * Test the system call. 104 */ 105 TEST(ioperm(io_addr, NUM_BYTES, TURN_ON)); 106 107 if (TEST_RETURN == -1) { 108 tst_resm(TFAIL, "ioperm() failed for port address " 109 "%lu, errno=%d : %s", io_addr, 110 TEST_ERRNO, strerror(TEST_ERRNO)); 111 } else { 112 tst_resm(TPASS, "ioperm() passed for port " 113 "address %lu, returned %lu", 114 io_addr, TEST_RETURN); 115 } 116 } 117 118 /* cleanup and exit */ 119 cleanup(); 120 tst_exit(); 121 122 } 123 124 /* setup() - performs all ONE TIME setup for this test */ 125 void setup(void) 126 { 127 tst_require_root(); 128 129 tst_sig(NOFORK, DEF_HANDLER, cleanup); 130 131 /* 132 * The value of IO_BITMAP_BITS (include/asm-i386/processor.h) changed 133 * from kernel 2.6.8 to permit 16-bits ioperm 134 * 135 * Ricky Ng-Adam, rngadam (at) yahoo.com 136 * */ 137 if (tst_kvercmp(2, 6, 8) < 0) { 138 /*get ioperm on 1021, 1022, 1023 */ 139 io_addr = IO_BITMAP_BITS - NUM_BYTES; 140 } else { 141 /*get ioperm on 65533, 65534, 65535 */ 142 io_addr = IO_BITMAP_BITS - NUM_BYTES; 143 } 144 145 TEST_PAUSE; 146 147 } 148 149 /* 150 *cleanup() - performs all ONE TIME cleanup for this test at 151 * completion or premature exit. 152 */ 153 void cleanup(void) 154 { 155 156 /* 157 * Reset I/O privileges for the specified port. 158 */ 159 if ((ioperm(io_addr, NUM_BYTES, TURN_OFF)) == -1) { 160 tst_brkm(TBROK, NULL, "ioperm() cleanup failed"); 161 } 162 163 } 164 165 #else /* __i386__ */ 166 167 #include "test.h" 168 169 int TST_TOTAL = 0; 170 171 int main(void) 172 { 173 tst_resm(TPASS, 174 "LSB v1.3 does not specify ioperm() for this architecture."); 175 tst_exit(); 176 } 177 178 #endif /* __i386__ */ 179