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 | */ |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 17 | |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 18 | /* |
| 19 | * AUTHOR: Madhu T L <madhu.tarikere@wipro.com> |
| 20 | * |
| 21 | * DESCRIPTION: |
| 22 | * Basic tests for delete_module(2) |
| 23 | * 1) insmod dummy_del_mod.ko |
| 24 | * 2) call delete_module(2) to remove dummy_del_mod.ko |
| 25 | */ |
| 26 | |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 27 | #include <errno.h> |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 28 | #include "test.h" |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 29 | #include "tst_module.h" |
| 30 | #include "safe_macros.h" |
| 31 | #include "linux_syscall_numbers.h" |
| 32 | |
| 33 | #define MODULE_NAME "dummy_del_mod" |
| 34 | #define MODULE_NAME_KO "dummy_del_mod.ko" |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 35 | |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 36 | static void setup(void); |
| 37 | static void cleanup(void); |
| 38 | |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 39 | |
| 40 | char *TCID = "delete_module01"; |
| 41 | int TST_TOTAL = 1; |
| 42 | static int module_loaded; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 43 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 44 | int main(int argc, char **argv) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 45 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 46 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 47 | const char *msg; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 48 | |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 49 | msg = parse_opts(argc, argv, NULL, NULL); |
| 50 | if (msg != NULL) |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 51 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 52 | |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 53 | setup(); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 54 | |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 55 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 56 | tst_count = 0; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 57 | |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 58 | /* insert dummy_del_mod.ko */ |
| 59 | if (module_loaded == 0) { |
| 60 | tst_module_load(NULL, MODULE_NAME_KO, NULL); |
| 61 | module_loaded = 1; |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 62 | } |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 63 | |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 64 | TEST(ltp_syscall(__NR_delete_module, MODULE_NAME, 0)); |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 65 | if (TEST_RETURN == -1) { |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 66 | tst_resm(TFAIL | TTERRNO, "delete_module() failed to " |
| 67 | "remove module entry for %s ", MODULE_NAME); |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 68 | } else { |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 69 | tst_resm(TPASS, "delete_module() successful"); |
| 70 | module_loaded = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 71 | } |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 72 | |
| 73 | } |
| 74 | |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 75 | cleanup(); |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 76 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 77 | } |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 78 | |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 79 | static void setup(void) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 80 | { |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 81 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 82 | |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 83 | tst_require_root(NULL); |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 84 | |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 85 | TEST_PAUSE; |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 88 | static void cleanup(void) |
plars | 5f30b5d | 2003-03-12 20:40:32 +0000 | [diff] [blame] | 89 | { |
Xiaoguang Wang | 953df03 | 2014-02-11 16:08:38 +0800 | [diff] [blame] | 90 | if (module_loaded == 1) |
| 91 | tst_module_unload(NULL, MODULE_NAME_KO); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 92 | } |