blob: 5014bb8a5456b5fcff19843f6eff586a1697558d [file] [log] [blame]
plars5f30b5d2003-03-12 20:40:32 +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.
plars5f30b5d2003-03-12 20:40:32 +000015 *
16 */
yaberauneyaef772532009-10-09 17:55:43 +000017
Xiaoguang Wang953df032014-02-11 16:08:38 +080018/*
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
plars5f30b5d2003-03-12 20:40:32 +000027#include <errno.h>
plars5f30b5d2003-03-12 20:40:32 +000028#include "test.h"
Xiaoguang Wang953df032014-02-11 16:08:38 +080029#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"
plars5f30b5d2003-03-12 20:40:32 +000035
plars5f30b5d2003-03-12 20:40:32 +000036static void setup(void);
37static void cleanup(void);
38
Xiaoguang Wang953df032014-02-11 16:08:38 +080039
40char *TCID = "delete_module01";
41int TST_TOTAL = 1;
42static int module_loaded;
plars5f30b5d2003-03-12 20:40:32 +000043
Wanlong Gao354ebb42012-12-07 10:10:04 +080044int main(int argc, char **argv)
plars5f30b5d2003-03-12 20:40:32 +000045{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020046 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020047 const char *msg;
plars5f30b5d2003-03-12 20:40:32 +000048
Xiaoguang Wang953df032014-02-11 16:08:38 +080049 msg = parse_opts(argc, argv, NULL, NULL);
50 if (msg != NULL)
Garrett Cooper53740502010-12-16 00:04:01 -080051 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars5f30b5d2003-03-12 20:40:32 +000052
yaberauneyaef772532009-10-09 17:55:43 +000053 setup();
plars5f30b5d2003-03-12 20:40:32 +000054
yaberauneyaef772532009-10-09 17:55:43 +000055 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080056 tst_count = 0;
plars5f30b5d2003-03-12 20:40:32 +000057
Xiaoguang Wang953df032014-02-11 16:08:38 +080058 /* insert dummy_del_mod.ko */
59 if (module_loaded == 0) {
60 tst_module_load(NULL, MODULE_NAME_KO, NULL);
61 module_loaded = 1;
yaberauneyaef772532009-10-09 17:55:43 +000062 }
plars5f30b5d2003-03-12 20:40:32 +000063
Xiaoguang Wang953df032014-02-11 16:08:38 +080064 TEST(ltp_syscall(__NR_delete_module, MODULE_NAME, 0));
yaberauneyaef772532009-10-09 17:55:43 +000065 if (TEST_RETURN == -1) {
Xiaoguang Wang953df032014-02-11 16:08:38 +080066 tst_resm(TFAIL | TTERRNO, "delete_module() failed to "
67 "remove module entry for %s ", MODULE_NAME);
yaberauneyaef772532009-10-09 17:55:43 +000068 } else {
Xiaoguang Wang953df032014-02-11 16:08:38 +080069 tst_resm(TPASS, "delete_module() successful");
70 module_loaded = 0;
Wanlong Gao354ebb42012-12-07 10:10:04 +080071 }
yaberauneyaef772532009-10-09 17:55:43 +000072
73 }
74
yaberauneyaef772532009-10-09 17:55:43 +000075 cleanup();
Xiaoguang Wang953df032014-02-11 16:08:38 +080076 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080077}
plars5f30b5d2003-03-12 20:40:32 +000078
Xiaoguang Wang953df032014-02-11 16:08:38 +080079static void setup(void)
plars5f30b5d2003-03-12 20:40:32 +000080{
Xiaoguang Wang953df032014-02-11 16:08:38 +080081 tst_sig(NOFORK, DEF_HANDLER, cleanup);
Garrett Cooper2c282152010-12-16 00:55:50 -080082
Xiaoguang Wang953df032014-02-11 16:08:38 +080083 tst_require_root(NULL);
plars5f30b5d2003-03-12 20:40:32 +000084
yaberauneyaef772532009-10-09 17:55:43 +000085 TEST_PAUSE;
plars5f30b5d2003-03-12 20:40:32 +000086}
87
Xiaoguang Wang953df032014-02-11 16:08:38 +080088static void cleanup(void)
plars5f30b5d2003-03-12 20:40:32 +000089{
Xiaoguang Wang953df032014-02-11 16:08:38 +080090 if (module_loaded == 1)
91 tst_module_unload(NULL, MODULE_NAME_KO);
Chris Dearmanec6edca2012-10-17 19:54:01 -070092}