1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 * Copyright (c) 2018 Xiao Yang <yangx.jy@cn.fujitsu.com>
5 */
6
7 /*
8 * AUTHOR: Madhu T L <madhu.tarikere@wipro.com>
9 *
10 * DESCRIPTION:
11 * Basic tests for delete_module(2)
12 * 1) insmod dummy_del_mod.ko
13 * 2) call delete_module(2) to remove dummy_del_mod.ko
14 */
15
16 #include <errno.h>
17 #include "old_module.h"
18 #include "lapi/syscalls.h"
19 #include "tst_test.h"
20
21 #define MODULE_NAME "dummy_del_mod"
22 #define MODULE_NAME_KO "dummy_del_mod.ko"
23
24 static int module_loaded;
25
do_delete_module(void)26 static void do_delete_module(void)
27 {
28 if (module_loaded == 0) {
29 tst_module_load(NULL, MODULE_NAME_KO, NULL);
30 module_loaded = 1;
31 }
32
33 TEST(tst_syscall(__NR_delete_module, MODULE_NAME, 0));
34 if (TST_RET == -1) {
35 tst_res(TFAIL | TTERRNO, "delete_module() failed to "
36 "remove module entry for %s ", MODULE_NAME);
37 return;
38 }
39
40 tst_res(TPASS, "delete_module() successful");
41 module_loaded = 0;
42 }
43
cleanup(void)44 static void cleanup(void)
45 {
46 if (module_loaded == 1)
47 tst_module_unload(NULL, MODULE_NAME_KO);
48 }
49
50 static struct tst_test test = {
51 .needs_root = 1,
52 .cleanup = cleanup,
53 .test_all = do_delete_module,
54 };
55