vapier | d13d74b | 2006-02-11 07:24:00 +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. |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /************************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : munlock01 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 21 | * EXECUTED BY : root / superuser |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 23 | * TEST TITLE : Basic test for munlock(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 4 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 27 | * AUTHOR : Nirmala Devi Dhanasekar <nirmala.devi@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +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 munlock(2) system call. |
| 35 | * It is intended to provide a limited exposure of the system call. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 36 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 37 | * Setup: |
| 38 | * Setup signal handling. |
| 39 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 40 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 41 | * Test: |
| 42 | * Loop if the proper options are given. |
| 43 | * Execute system call |
| 44 | * Check return code, if system call failed (return=-1) |
| 45 | * Log the errno and Issue a FAIL message. |
| 46 | * Otherwise, Issue a PASS message. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 47 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 48 | * Cleanup: |
| 49 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 50 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 51 | * USAGE: <for command-line> |
| 52 | * munlock01 [-c n] [-e] [-i n] [-I x] [-p x] [-t] |
| 53 | * where, -c n : Run n copies concurrently |
| 54 | * -e : Turn on errno logging. |
| 55 | * -h : Show this help screen |
| 56 | * -i n : Execute test n times. |
| 57 | * -I x : Execute test for x seconds. |
| 58 | * -p : Pause for SIGUSR1 before starting |
| 59 | * -P x : Pause for x seconds between iterations. |
| 60 | * -t : Turn on syscall timing. |
| 61 | * |
| 62 | * RESTRICTIONS |
| 63 | * Must be root/superuser to run it. |
| 64 | *****************************************************************************/ |
| 65 | |
| 66 | #include <errno.h> |
| 67 | #include <unistd.h> |
| 68 | #include <sys/mman.h> |
| 69 | #include "test.h" |
| 70 | #include "usctest.h" |
| 71 | |
| 72 | void setup(); |
| 73 | void setup1(int); |
| 74 | void cleanup(); |
| 75 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 76 | char *TCID = "munlock01"; |
| 77 | int TST_TOTAL = 4; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 78 | |
| 79 | int exp_enos[] = { 0 }; |
| 80 | |
| 81 | void *addr1; |
| 82 | |
| 83 | struct test_case_t { |
| 84 | void **addr; |
| 85 | int len; |
| 86 | void (*setupfunc) (); |
| 87 | } TC[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 88 | { |
| 89 | &addr1, 1, setup1}, { |
| 90 | &addr1, 1024, setup1}, { |
| 91 | &addr1, 1024 * 1024, setup1}, { |
| 92 | &addr1, 1024 * 1024 * 10, setup1} |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | int main(int ac, char **av) |
| 96 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 97 | int lc, i; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame^] | 98 | const char *msg; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 99 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 100 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 101 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 102 | tst_exit(); |
| 103 | } |
| 104 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 105 | setup(); |
| 106 | |
| 107 | /* check looping state */ |
| 108 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 109 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 110 | tst_count = 0; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 111 | |
| 112 | for (i = 0; i < TST_TOTAL; i++) { |
| 113 | |
| 114 | if (TC[i].setupfunc != NULL) |
| 115 | TC[i].setupfunc(i); |
| 116 | |
| 117 | TEST(munlock(*(TC[i].addr), TC[i].len)); |
| 118 | |
| 119 | /* check return code */ |
| 120 | if (TEST_RETURN == -1) { |
| 121 | TEST_ERROR_LOG(TEST_ERRNO); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 122 | tst_resm(TFAIL | TTERRNO, |
| 123 | "mlock(%p, %d) Failed with " |
| 124 | "return=%ld", TC[i].addr, TC[i].len, |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 125 | TEST_RETURN); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 126 | } else { |
| 127 | tst_resm(TPASS, "test %d passed length = %d", |
| 128 | i, TC[i].len); |
| 129 | } |
| 130 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 131 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 132 | |
| 133 | /* cleanup and exit */ |
| 134 | cleanup(); |
| 135 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 136 | tst_exit(); |
| 137 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 138 | |
| 139 | void setup1(int i) |
| 140 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 141 | addr1 = (char *)malloc(TC[i].len); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 142 | if (addr1 == NULL) |
| 143 | tst_brkm(TFAIL, cleanup, "malloc failed"); |
| 144 | TEST(mlock(*(TC[i].addr), TC[i].len)); |
| 145 | |
| 146 | /* check return code */ |
| 147 | if (TEST_RETURN == -1) { |
| 148 | TEST_ERROR_LOG(TEST_ERRNO); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 149 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 150 | "mlock(%p, %d) Failed with return=%ld", TC[i].addr, |
| 151 | TC[i].len, TEST_RETURN); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 152 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* setup() - performs all ONE TIME setup for this test. */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 156 | void setup(void) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 157 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 158 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 159 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 160 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 161 | /* Check whether we are root */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 162 | if (geteuid() != 0) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 163 | tst_brkm(TBROK, NULL, "Test must be run as root"); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /* set the expected errnos... */ |
| 167 | TEST_EXP_ENOS(exp_enos); |
| 168 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 169 | TEST_PAUSE; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 174 | * completion or premature exit. |
| 175 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 176 | void cleanup(void) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 177 | { |
| 178 | TEST_CLEANUP; |
| 179 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 180 | } |