blob: c44fc9a5c4f56c6fbc274ae0b6b404fb5efbe90a [file] [log] [blame]
robbiew8f49c092002-12-30 18:07:13 +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.
robbiew8f49c092002-12-30 18:07:13 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
robbiew8f49c092002-12-30 18:07:13 +000019 * TEST IDENTIFIER : iopl01
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
robbiew8f49c092002-12-30 18:07:13 +000021 * EXECUTED BY : superuser
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
robbiew8f49c092002-12-30 18:07:13 +000023 * TEST TITLE : Basic test for iopl(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiew8f49c092002-12-30 18:07:13 +000025 * TEST CASE TOTAL : 4
26 *
27 * AUTHOR : Subhab Biswas <subhabrata.biswas@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
robbiew8f49c092002-12-30 18:07:13 +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 iopl(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 *
robbiew8f49c092002-12-30 18:07:13 +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.
robbiew8f49c092002-12-30 18:07:13 +000047 * Otherwise, Issue PASS message.
subrata_modak4bb656a2009-02-26 12:02:09 +000048 *
robbiew8f49c092002-12-30 18:07:13 +000049 * Cleanup:
50 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
robbiew8f49c092002-12-30 18:07:13 +000052 * USAGE: <for command-line>
53 * iopl01 [-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 = "iopl01";
robbiew4d6995c2003-01-10 18:26:33 +000067
robbiew10989ef2003-02-12 20:11:13 +000068#if defined __i386__ || defined(__x86_64__)
robbiew4d6995c2003-01-10 18:26:33 +000069
robbiew8f49c092002-12-30 18:07:13 +000070#include <errno.h>
71#include <unistd.h>
72#include <sys/io.h>
73
74#include "test.h"
robbiew8f49c092002-12-30 18:07:13 +000075
76static void setup();
77static void cleanup();
78
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020079int TST_TOTAL = 4;
robbiew8f49c092002-12-30 18:07:13 +000080
81int level; /* I/O privilege level of the process */
82
subrata_modak56207ce2009-03-23 13:35:39 +000083int main(int ac, char **av)
robbiew8f49c092002-12-30 18:07:13 +000084{
85
Cyril Hrubis89af32a2012-10-24 16:39:11 +020086 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020087 const char *msg;
robbiew8f49c092002-12-30 18:07:13 +000088
Garrett Cooper53740502010-12-16 00:04:01 -080089 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080090 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew8f49c092002-12-30 18:07:13 +000091
robbiew8f49c092002-12-30 18:07:13 +000092 setup();
93
robbiew8f49c092002-12-30 18:07:13 +000094 for (lc = 0; TEST_LOOPING(lc); lc++) {
95
Caspar Zhangd59a6592013-03-07 14:59:12 +080096 tst_count = 0;
robbiew8f49c092002-12-30 18:07:13 +000097
98 /*
99 * Test the system call for possible privelege levels.
subrata_modak4bb656a2009-02-26 12:02:09 +0000100 * As the privelge level for a normal process is 0,
robbiew8f49c092002-12-30 18:07:13 +0000101 * start by setting/changing the level to 0.
102 */
103 for (level = 0; level < TST_TOTAL; ++level) {
subrata_modak56207ce2009-03-23 13:35:39 +0000104
robbiew8f49c092002-12-30 18:07:13 +0000105 TEST(iopl(level));
106
107 if (TEST_RETURN == -1) {
108 tst_resm(TFAIL, "iopl() failed for level %d, "
109 "errno=%d : %s", level,
110 TEST_ERRNO, strerror(TEST_ERRNO));
111 } else {
112 tst_resm(TPASS, "iopl() passed for level %d, "
subrata_modak358c3ee2009-10-26 14:55:46 +0000113 "returned %ld", level, TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +0000114 }
robbiew8f49c092002-12-30 18:07:13 +0000115 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800116 }
robbiew8f49c092002-12-30 18:07:13 +0000117
118 /* cleanup and exit */
119 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800120 tst_exit();
robbiew8f49c092002-12-30 18:07:13 +0000121
Garrett Cooper2c282152010-12-16 00:55:50 -0800122}
robbiew8f49c092002-12-30 18:07:13 +0000123
124/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400125void setup(void)
robbiew8f49c092002-12-30 18:07:13 +0000126{
Nicolas Jolyd4ceb372014-06-22 17:03:57 +0200127 tst_require_root(NULL);
subrata_modakbdbaec52009-02-26 12:14:51 +0000128
robbiew8f49c092002-12-30 18:07:13 +0000129 tst_sig(NOFORK, DEF_HANDLER, cleanup);
130
robbiew8f49c092002-12-30 18:07:13 +0000131 TEST_PAUSE;
132
Garrett Cooper2c282152010-12-16 00:55:50 -0800133}
robbiew8f49c092002-12-30 18:07:13 +0000134
135/*
136 *cleanup() - performs all ONE TIME cleanup for this test at
137 * completion or premature exit.
138 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400139void cleanup(void)
robbiew8f49c092002-12-30 18:07:13 +0000140{
141
142 /*
143 * back to I/O privilege for normal process.
144 */
145 if (iopl(0) == -1) {
146 tst_resm(TWARN, "iopl() cleanup failed");
147 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000148
Garrett Cooper2c282152010-12-16 00:55:50 -0800149}
robbiew4d6995c2003-01-10 18:26:33 +0000150
151#else /* __i386__ */
152
153#include "test.h"
robbiew4d6995c2003-01-10 18:26:33 +0000154
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200155int TST_TOTAL = 0;
robbiew4d6995c2003-01-10 18:26:33 +0000156
Mike Frysingerc57fba52014-04-09 18:56:30 -0400157int main(void)
robbiew4d6995c2003-01-10 18:26:33 +0000158{
subrata_modak56207ce2009-03-23 13:35:39 +0000159 tst_resm(TPASS,
160 "LSB v1.3 does not specify iopl() for this architecture.");
robbiew4d6995c2003-01-10 18:26:33 +0000161 tst_exit();
162}
163
Chris Dearmanec6edca2012-10-17 19:54:01 -0700164#endif /* __i386__ */