robbiew | 8f49c09 | 2002-12-30 18:07:13 +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 | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : iopl01 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | * |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 21 | * EXECUTED BY : superuser |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 23 | * TEST TITLE : Basic test for iopl(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 4 |
| 26 | * |
| 27 | * AUTHOR : Subhab Biswas <subhabrata.biswas@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +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 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_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 41 | * |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 42 | * Test: |
| 43 | * Loop if the proper options are given. |
| 44 | * Execute system call |
| 45 | * Check return code, if system call failed (return=-1) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 46 | * Issue FAIL message with errno. |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 47 | * Otherwise, Issue PASS message. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 48 | * |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 49 | * Cleanup: |
| 50 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 51 | * |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 52 | * 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 | ****************************************************************/ |
robbiew | 4d6995c | 2003-01-10 18:26:33 +0000 | [diff] [blame] | 65 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 66 | char *TCID = "iopl01"; |
robbiew | 4d6995c | 2003-01-10 18:26:33 +0000 | [diff] [blame] | 67 | |
robbiew | 10989ef | 2003-02-12 20:11:13 +0000 | [diff] [blame] | 68 | #if defined __i386__ || defined(__x86_64__) |
robbiew | 4d6995c | 2003-01-10 18:26:33 +0000 | [diff] [blame] | 69 | |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 70 | #include <errno.h> |
| 71 | #include <unistd.h> |
| 72 | #include <sys/io.h> |
| 73 | |
| 74 | #include "test.h" |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 75 | |
| 76 | static void setup(); |
| 77 | static void cleanup(); |
| 78 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 79 | int TST_TOTAL = 4; |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 80 | |
| 81 | int level; /* I/O privilege level of the process */ |
| 82 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 83 | int main(int ac, char **av) |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 84 | { |
| 85 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 86 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 87 | const char *msg; |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 88 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 89 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 90 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 91 | |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 92 | setup(); |
| 93 | |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 94 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 95 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 96 | tst_count = 0; |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Test the system call for possible privelege levels. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 100 | * As the privelge level for a normal process is 0, |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 101 | * start by setting/changing the level to 0. |
| 102 | */ |
| 103 | for (level = 0; level < TST_TOTAL; ++level) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 105 | 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_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 113 | "returned %ld", level, TEST_RETURN); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 114 | } |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 115 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 116 | } |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 117 | |
| 118 | /* cleanup and exit */ |
| 119 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 120 | tst_exit(); |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 121 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 122 | } |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 123 | |
| 124 | /* setup() - performs all ONE TIME setup for this test */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 125 | void setup(void) |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 126 | { |
Nicolas Joly | d4ceb37 | 2014-06-22 17:03:57 +0200 | [diff] [blame] | 127 | tst_require_root(NULL); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 128 | |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 129 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 130 | |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 131 | TEST_PAUSE; |
| 132 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 133 | } |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | *cleanup() - performs all ONE TIME cleanup for this test at |
| 137 | * completion or premature exit. |
| 138 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 139 | void cleanup(void) |
robbiew | 8f49c09 | 2002-12-30 18:07:13 +0000 | [diff] [blame] | 140 | { |
| 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_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 148 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 149 | } |
robbiew | 4d6995c | 2003-01-10 18:26:33 +0000 | [diff] [blame] | 150 | |
| 151 | #else /* __i386__ */ |
| 152 | |
| 153 | #include "test.h" |
robbiew | 4d6995c | 2003-01-10 18:26:33 +0000 | [diff] [blame] | 154 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 155 | int TST_TOTAL = 0; |
robbiew | 4d6995c | 2003-01-10 18:26:33 +0000 | [diff] [blame] | 156 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 157 | int main(void) |
robbiew | 4d6995c | 2003-01-10 18:26:33 +0000 | [diff] [blame] | 158 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 159 | tst_resm(TPASS, |
| 160 | "LSB v1.3 does not specify iopl() for this architecture."); |
robbiew | 4d6995c | 2003-01-10 18:26:33 +0000 | [diff] [blame] | 161 | tst_exit(); |
| 162 | } |
| 163 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 164 | #endif /* __i386__ */ |