blob: 8816d97000014d41c5da4138e17c7a9b74de4ddd [file] [log] [blame]
robbiew2db8c7e2003-01-01 20:50: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.
robbiew2db8c7e2003-01-01 20:50:36 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
robbiew2db8c7e2003-01-01 20:50:36 +000019 * TEST IDENTIFIER : ioperm01
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
robbiew2db8c7e2003-01-01 20:50:36 +000021 * EXECUTED BY : superuser
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
robbiew2db8c7e2003-01-01 20:50:36 +000023 * TEST TITLE : Basic test for ioperm(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiew2db8c7e2003-01-01 20:50:36 +000025 * TEST CASE TOTAL : 1
26 *
27 * AUTHOR : Subhab Biswas <subhabrata.biswas@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
robbiew2db8c7e2003-01-01 20:50: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 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.
subrata_modak4bb656a2009-02-26 12:02:09 +000041 *
robbiew2db8c7e2003-01-01 20:50:36 +000042 * Test:
43 * Loop if the proper options are given.
44 * Execute system call
45 * Check return code, if system call failed (return=-1)
subrata_modak4bb656a2009-02-26 12:02:09 +000046 * Issue FAIL message with errno.
robbiew2db8c7e2003-01-01 20:50:36 +000047 * Otherwise, Issue PASS message.
subrata_modak4bb656a2009-02-26 12:02:09 +000048 *
robbiew2db8c7e2003-01-01 20:50:36 +000049 * Cleanup:
50 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
robbiew2db8c7e2003-01-01 20:50:36 +000052 * 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 ****************************************************************/
robbiew4d6995c2003-01-10 18:26:33 +000065
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020066char *TCID = "ioperm01";
robbiew4d6995c2003-01-10 18:26:33 +000067
subrata_modak4bb656a2009-02-26 12:02:09 +000068#if defined __i386__ || defined(__x86_64__)
robbiew4d6995c2003-01-10 18:26:33 +000069
robbiew2db8c7e2003-01-01 20:50:36 +000070#include <errno.h>
71#include <unistd.h>
72#include <sys/io.h>
73
74#include "test.h"
robbiew2db8c7e2003-01-01 20:50:36 +000075
Wanlong Gao354ebb42012-12-07 10:10:04 +080076unsigned long io_addr; /*kernel version dependant io start address */
robbiew2db8c7e2003-01-01 20:50:36 +000077#define NUM_BYTES 3 /* number of bytes from start address */
subrata_modak56207ce2009-03-23 13:35:39 +000078#define TURN_ON 1
robbiew2db8c7e2003-01-01 20:50:36 +000079#define TURN_OFF 0
mridge5814a0e2005-06-01 20:36:41 +000080#ifndef IO_BITMAP_BITS
81#define IO_BITMAP_BITS 1024
82#endif
robbiew2db8c7e2003-01-01 20:50:36 +000083
84static void setup();
85static void cleanup();
86
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020087int TST_TOTAL = 1;
robbiew2db8c7e2003-01-01 20:50:36 +000088
subrata_modak56207ce2009-03-23 13:35:39 +000089int main(int ac, char **av)
robbiew2db8c7e2003-01-01 20:50:36 +000090{
91
Cyril Hrubis89af32a2012-10-24 16:39:11 +020092 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020093 const char *msg;
robbiew2db8c7e2003-01-01 20:50:36 +000094
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080095 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080096 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew2db8c7e2003-01-01 20:50:36 +000097
robbiew2db8c7e2003-01-01 20:50:36 +000098 setup();
99
robbiew2db8c7e2003-01-01 20:50:36 +0000100 for (lc = 0; TEST_LOOPING(lc); lc++) {
101
Caspar Zhangd59a6592013-03-07 14:59:12 +0800102 tst_count = 0;
robbiew2db8c7e2003-01-01 20:50:36 +0000103
104 /*
105 * Test the system call.
106 */
robbiew89e9bf92004-12-20 20:08:18 +0000107 TEST(ioperm(io_addr, NUM_BYTES, TURN_ON));
robbiew2db8c7e2003-01-01 20:50:36 +0000108
109 if (TEST_RETURN == -1) {
110 tst_resm(TFAIL, "ioperm() failed for port address "
subrata_modak923b23f2009-11-02 13:57:16 +0000111 "%lu, errno=%d : %s", io_addr,
robbiew2db8c7e2003-01-01 20:50:36 +0000112 TEST_ERRNO, strerror(TEST_ERRNO));
113 } else {
114 tst_resm(TPASS, "ioperm() passed for port "
subrata_modak923b23f2009-11-02 13:57:16 +0000115 "address %lu, returned %lu",
subrata_modak56207ce2009-03-23 13:35:39 +0000116 io_addr, TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +0000117 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800118 }
robbiew2db8c7e2003-01-01 20:50:36 +0000119
120 /* cleanup and exit */
121 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800122 tst_exit();
robbiew2db8c7e2003-01-01 20:50:36 +0000123
Garrett Cooper2c282152010-12-16 00:55:50 -0800124}
robbiew2db8c7e2003-01-01 20:50:36 +0000125
126/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400127void setup(void)
robbiew2db8c7e2003-01-01 20:50:36 +0000128{
Nicolas Jolyd4ceb372014-06-22 17:03:57 +0200129 tst_require_root(NULL);
subrata_modakbdbaec52009-02-26 12:14:51 +0000130
robbiew2db8c7e2003-01-01 20:50:36 +0000131 tst_sig(NOFORK, DEF_HANDLER, cleanup);
132
robbiew89e9bf92004-12-20 20:08:18 +0000133 /*
subrata_modak4bb656a2009-02-26 12:02:09 +0000134 * The value of IO_BITMAP_BITS (include/asm-i386/processor.h) changed
robbiew89e9bf92004-12-20 20:08:18 +0000135 * from kernel 2.6.8 to permit 16-bits ioperm
136 *
137 * Ricky Ng-Adam, rngadam@yahoo.com
138 * */
subrata_modak56207ce2009-03-23 13:35:39 +0000139 if (tst_kvercmp(2, 6, 8) < 0) {
140 /*get ioperm on 1021, 1022, 1023 */
mridge5814a0e2005-06-01 20:36:41 +0000141 io_addr = IO_BITMAP_BITS - NUM_BYTES;
robbiew89e9bf92004-12-20 20:08:18 +0000142 } else {
subrata_modak56207ce2009-03-23 13:35:39 +0000143 /*get ioperm on 65533, 65534, 65535 */
mridge5814a0e2005-06-01 20:36:41 +0000144 io_addr = IO_BITMAP_BITS - NUM_BYTES;
robbiew89e9bf92004-12-20 20:08:18 +0000145 }
146
robbiew2db8c7e2003-01-01 20:50:36 +0000147 TEST_PAUSE;
148
Garrett Cooper2c282152010-12-16 00:55:50 -0800149}
robbiew2db8c7e2003-01-01 20:50:36 +0000150
151/*
152 *cleanup() - performs all ONE TIME cleanup for this test at
153 * completion or premature exit.
154 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400155void cleanup(void)
robbiew2db8c7e2003-01-01 20:50:36 +0000156{
157
158 /*
159 * Reset I/O privileges for the specified port.
160 */
robbiew89e9bf92004-12-20 20:08:18 +0000161 if ((ioperm(io_addr, NUM_BYTES, TURN_OFF)) == -1) {
Garrett Cooper53740502010-12-16 00:04:01 -0800162 tst_brkm(TBROK, NULL, "ioperm() cleanup failed");
robbiew2db8c7e2003-01-01 20:50:36 +0000163 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000164
Garrett Cooper2c282152010-12-16 00:55:50 -0800165}
robbiew4d6995c2003-01-10 18:26:33 +0000166
167#else /* __i386__ */
168
169#include "test.h"
robbiew4d6995c2003-01-10 18:26:33 +0000170
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200171int TST_TOTAL = 0;
robbiew4d6995c2003-01-10 18:26:33 +0000172
Mike Frysingerc57fba52014-04-09 18:56:30 -0400173int main(void)
robbiew4d6995c2003-01-10 18:26:33 +0000174{
subrata_modak56207ce2009-03-23 13:35:39 +0000175 tst_resm(TPASS,
176 "LSB v1.3 does not specify ioperm() for this architecture.");
robbiew4d6995c2003-01-10 18:26:33 +0000177 tst_exit();
178}
179
Chris Dearmanec6edca2012-10-17 19:54:01 -0700180#endif /* __i386__ */