plars | 5f30b5d | 2003-03-12 20:40:32 +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. |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : query_module01 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 21 | * EXECUTED BY : root / superuser |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 23 | * TEST TITLE : Checking functionality of query_module(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 6 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 27 | * AUTHOR : Madhu T L <madhu.tarikere@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +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 | * Verify that, |
| 35 | * 1. query_module(2) is successful for NULL module name, which argument |
| 36 | * set to 0. |
| 37 | * 2. query_module(2) is successful for NULL module name, which argument |
| 38 | * set to QM_MODULES. |
| 39 | * 3. query_module(2) is successful for valid module name, which argument |
| 40 | * set to QM_DEPS. |
| 41 | * 4. query_module(2) is successful for valid module name, which argument |
| 42 | * set to QM_REFS. |
| 43 | * 5. query_module(2) is successful for valid module name, which argument |
| 44 | * set to QM_INFO. |
| 45 | * 6. query_module(2) is successful for valid module name, which argument |
| 46 | * set to QM_SYMBOLS. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 47 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 48 | * Setup: |
| 49 | * Setup signal handling. |
| 50 | * Test caller is superuser |
| 51 | * Initialize long module name |
| 52 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 53 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 54 | * Test: |
| 55 | * Loop if the proper options are given. |
| 56 | * Execute system call |
| 57 | * Check return value and functionality, if success, |
| 58 | * Issue PASS message |
| 59 | * Otherwise, |
| 60 | * Issue FAIL message |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 61 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 62 | * Cleanup: |
| 63 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 64 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 65 | * USAGE: <for command-line> |
| 66 | * query_module01 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t] |
| 67 | * where, -c n : Run n copies concurrently. |
| 68 | * -e : Turn on errno logging. |
| 69 | * -f : Turn off functional testing |
| 70 | * -h : Show help screen |
| 71 | * -i n : Execute test n times. |
| 72 | * -I x : Execute test for x seconds. |
| 73 | * -p : Pause for SIGUSR1 before starting |
| 74 | * -P x : Pause for x seconds between iterations. |
| 75 | * -t : Turn on syscall timing. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 76 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 77 | * RESTRICTIONS |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 78 | * -c option has no effect for this testcase, even if used allows only |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 79 | * one instance to run at a time. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 80 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 81 | * CHANGES |
| 82 | * |
| 83 | * 12/03/02 Added "force" to insmod to ignore kernel version. |
| 84 | * -Robbie Williamson <robbiew@us.ibm.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 85 | * |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 86 | ****************************************************************/ |
| 87 | |
| 88 | #include <errno.h> |
| 89 | #include <pwd.h> |
| 90 | #include <sys/types.h> |
subrata_modak | 024988b | 2008-09-24 12:55:33 +0000 | [diff] [blame] | 91 | #include <unistd.h> |
| 92 | #include <limits.h> |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 93 | #include <asm/atomic.h> |
| 94 | #include <linux/module.h> |
| 95 | #include "test.h" |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 96 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 97 | #ifndef PAGE_SIZE |
subrata_modak | 024988b | 2008-09-24 12:55:33 +0000 | [diff] [blame] | 98 | #define PAGE_SIZE sysconf(_SC_PAGE_SIZE) |
| 99 | #endif |
| 100 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 101 | #define LONGMODNAMECHAR 'm' /* Arbitrarily selected */ |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 102 | #define MODNAMEMAX (PAGE_SIZE + 1) |
| 103 | #define EXP_RET_VAL 0 |
| 104 | #define DUMMY_MOD "dummy_query_mod" |
| 105 | #define DUMMY_MOD_DEP "dummy_query_mod_dep" |
| 106 | #define QM_INVALID (QM_INFO + 100) |
| 107 | |
| 108 | /* Name of exported function in DUMMY_MOD */ |
| 109 | #define EXP_FUNC_NAME "dummy_func_test" |
| 110 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 111 | struct test_case_t { /* test case structure */ |
| 112 | char *modname; |
| 113 | int which; |
| 114 | char *desc; |
| 115 | int (*setup) (void); /* Individual setup routine */ |
| 116 | void (*cleanup) (void); /* Individual cleanup routine */ |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | char *TCID = "query_module01"; |
| 120 | static char longmodname[MODNAMEMAX]; |
| 121 | static int testno; |
| 122 | static char out_buf[PAGE_SIZE]; |
| 123 | static size_t ret; |
| 124 | |
| 125 | static int test_functionality(int, char *, size_t, size_t); |
| 126 | static void setup(void); |
| 127 | static void cleanup(void); |
| 128 | static int setup1(void); |
| 129 | static void cleanup1(void); |
| 130 | static int setup2(void); |
| 131 | static void cleanup2(void); |
| 132 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 133 | static struct test_case_t tdat[] = { |
| 134 | {NULL, 0, "module name: NULL, which: 0", NULL, NULL}, |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 135 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 136 | {NULL, QM_MODULES, "NULL module name, which: QM_MODULES", |
| 137 | setup1, cleanup1}, |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 138 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 139 | {DUMMY_MOD_DEP, QM_DEPS, "valid module name, which: QM_DEPS", |
| 140 | setup2, cleanup2}, |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 141 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 142 | {DUMMY_MOD, QM_REFS, "valid module name, which: QM_REFS", |
| 143 | setup2, cleanup2}, |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 144 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 145 | {DUMMY_MOD, QM_INFO, "valid module name, which: QM_INFO", |
| 146 | setup1, cleanup1}, |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 147 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 148 | {DUMMY_MOD, QM_SYMBOLS, "valid module name, which: QM_SYMBOLS", |
| 149 | setup1, cleanup1}, |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]); |
| 153 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 154 | int main(int argc, char **argv) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 155 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 156 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 157 | const char *msg; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 158 | size_t buflen = sizeof(out_buf); |
| 159 | |
Cyril Hrubis | cf0d626 | 2014-09-23 14:03:31 +0200 | [diff] [blame] | 160 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 161 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 162 | } |
| 163 | |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 164 | tst_tmpdir(); |
| 165 | setup(); |
| 166 | |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 167 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 168 | /* reset tst_count in case we are looping */ |
| 169 | tst_count = 0; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 170 | |
| 171 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Garrett Cooper | 8fb1cdb | 2010-11-28 22:56:35 -0800 | [diff] [blame] | 172 | if ((tdat[testno].setup) && (tdat[testno].setup())) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 173 | /* setup() failed, skip this test */ |
| 174 | continue; |
| 175 | } |
| 176 | |
| 177 | TEST(query_module(tdat[testno].modname, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 178 | tdat[testno].which, (void *)out_buf, |
| 179 | buflen, &ret)); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 180 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 181 | if ((TEST_RETURN == EXP_RET_VAL) && |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 182 | !test_functionality(tdat[testno].which, |
| 183 | out_buf, buflen, ret)) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 184 | tst_resm(TPASS, "query_module() successful " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 185 | "for %s", tdat[testno].desc); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 186 | } else { |
| 187 | tst_resm(TFAIL, "query_module() failed for " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 188 | "%s ; returned" |
| 189 | " %d (expected %d), errno %d (expected" |
| 190 | " 0)", tdat[testno].desc, |
| 191 | TEST_RETURN, EXP_RET_VAL, TEST_ERRNO); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 192 | } |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 193 | if (tdat[testno].cleanup) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 194 | tdat[testno].cleanup(); |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | cleanup(); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 199 | tst_exit(); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 202 | int test_functionality(int which, char *buf, size_t bufsize, size_t ret) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 203 | { |
| 204 | int i = 0; |
| 205 | char *modname; |
| 206 | unsigned long *vals; |
| 207 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 208 | switch (which) { |
| 209 | case 0: |
| 210 | /* Always return SUCCESS */ |
| 211 | return 0; |
| 212 | |
| 213 | case QM_MODULES: |
| 214 | case QM_DEPS: |
| 215 | /* Return SUCCESS if found DUMMY_MOD entry */ |
| 216 | modname = DUMMY_MOD; |
| 217 | break; |
| 218 | |
| 219 | case QM_REFS: |
| 220 | /* Return SUCCESS if found DUMMY_MOD_DEP entry */ |
| 221 | modname = DUMMY_MOD_DEP; |
| 222 | break; |
| 223 | |
| 224 | case QM_INFO: |
| 225 | /* |
| 226 | * Since module is already loaded, flags should show |
| 227 | * MOD_RUNNING |
| 228 | */ |
| 229 | if (((struct module_info *)buf)->flags & MOD_RUNNING) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 230 | return 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 231 | } |
| 232 | return 1; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 233 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 234 | case QM_SYMBOLS: |
| 235 | vals = (unsigned long *)buf; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 236 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 237 | /* |
| 238 | * Find entry for atleast one symbol, checking for |
| 239 | * EXP_FUNC_NAME symbol, if found return SUCCESS. |
| 240 | */ |
| 241 | for (i = 0; i < ret; i++, vals += 2) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 242 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 243 | /* buf + vals[1] - address of symbol name */ |
| 244 | if (!strcmp(buf + vals[1], EXP_FUNC_NAME)) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 245 | return 0; |
| 246 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 247 | } |
| 248 | return 1; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 249 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 250 | default: |
| 251 | /* Unknown which type */ |
| 252 | return 1; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /* Return SUCCESS if found entry */ |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 256 | for (i = 0; i != ret; i++) { |
| 257 | if (strcmp(buf, modname)) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 258 | buf += strlen(buf) + 1; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 259 | } else { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 260 | return 0; |
| 261 | } |
| 262 | } |
| 263 | return 1; |
| 264 | |
| 265 | } |
| 266 | |
| 267 | /* Insert a module of name mod */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 268 | int insert_mod(char *mod) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 269 | { |
| 270 | char cmd[80]; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 271 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 272 | if (sprintf(cmd, "cp `which %s.o` ./", mod) == -1) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 273 | tst_resm(TBROK, "sprintf failed"); |
| 274 | return 1; |
| 275 | } |
Garrett Cooper | 8fb1cdb | 2010-11-28 22:56:35 -0800 | [diff] [blame] | 276 | if (system(cmd) != 0) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 277 | tst_resm(TBROK, "Failed to copy %s module", mod); |
| 278 | return 1; |
| 279 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 280 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 281 | /* Should use force to ignore kernel version & insure loading */ |
| 282 | /* -RW */ |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 283 | /* if (sprintf(cmd, "insmod %s.o", mod) == -1) { */ |
| 284 | if (sprintf(cmd, "insmod --force -q %s.o >/dev/null 2>&1", mod) == -1) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 285 | tst_resm(TBROK, "sprintf failed"); |
| 286 | return 1; |
| 287 | } |
Garrett Cooper | 8fb1cdb | 2010-11-28 22:56:35 -0800 | [diff] [blame] | 288 | if (system(cmd) != 0) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 289 | tst_resm(TBROK, "Failed to load %s module", mod); |
| 290 | return 1; |
| 291 | } |
| 292 | return 0; |
| 293 | } |
| 294 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 295 | int setup1(void) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 296 | { |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 297 | if (insert_mod(DUMMY_MOD)) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 298 | /* Failed */ |
| 299 | return 1; |
| 300 | } else { |
| 301 | return 0; |
| 302 | } |
| 303 | } |
| 304 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 305 | int setup2(void) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 306 | { |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 307 | if (insert_mod(DUMMY_MOD)) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 308 | /* Failed */ |
| 309 | return 1; |
| 310 | } |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 311 | if (insert_mod(DUMMY_MOD_DEP)) { |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 312 | /* Falied to load DUMMY_MOD_DEP, unload DUMMY_MOD */ |
| 313 | cleanup1(); |
| 314 | return 1; |
| 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 319 | void cleanup1(void) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 320 | { |
| 321 | /* Remove the loadable module - DUMMY_MOD */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 322 | if (system("rmmod " DUMMY_MOD) != 0) { |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 323 | tst_brkm(TBROK, cleanup, "Failed to unload module %s", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 324 | DUMMY_MOD); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 328 | void cleanup2(void) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 329 | { |
| 330 | /* Remove the loadable module - DUMMY_MOD_DEP */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 331 | if (system("rmmod " DUMMY_MOD_DEP) != 0) { |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 332 | tst_brkm(TBROK, cleanup, "Failed to unload module %s", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 333 | DUMMY_MOD_DEP); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 334 | } |
| 335 | /* Remove the loadable module - DUMMY_MOD */ |
| 336 | cleanup1(); |
| 337 | } |
| 338 | |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 339 | /* |
| 340 | * setup() |
| 341 | * performs all ONE TIME setup for this test |
| 342 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 343 | void setup(void) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 344 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 345 | |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 346 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 347 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 348 | tst_require_root(NULL); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 349 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 350 | if (tst_kvercmp(2, 5, 48) >= 0) |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 351 | tst_brkm(TCONF, NULL, "This test will not work on " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 352 | "kernels after 2.5.48"); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 353 | |
| 354 | /* Initialize longmodname to LONGMODNAMECHAR character */ |
| 355 | memset(longmodname, LONGMODNAMECHAR, MODNAMEMAX - 1); |
| 356 | |
| 357 | /* Pause if that option was specified |
| 358 | * TEST_PAUSE contains the code to fork the test with the -c option. |
| 359 | */ |
| 360 | TEST_PAUSE; |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | * cleanup() |
| 365 | * performs all ONE TIME cleanup for this test at |
| 366 | * completion or premature exit |
| 367 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 368 | void cleanup(void) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 369 | { |
| 370 | /* |
| 371 | * print timing stats if that option was specified. |
| 372 | * print errno log if that option was specified. |
| 373 | */ |
| 374 | |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 375 | tst_rmdir(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 376 | } |