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 * Copyright (c) Linux Test Project, 2002-2023
6 * Author: Madhu T L <madhu.tarikere@wipro.com>
7 */
8
9/*\
10 * [Description]
11 *
12 * Basic test for delete_module(2).
13 *
14 * Install dummy_del_mod.ko and delete it with delete_module(2).
15 */
16
17#include "tst_test.h"
18#include "tst_module.h"
19#include "lapi/syscalls.h"
20
21#define MODULE_NAME	"dummy_del_mod"
22#define MODULE_NAME_KO	MODULE_NAME ".ko"
23
24static int module_loaded;
25
26static void do_delete_module(void)
27{
28	if (!module_loaded) {
29		tst_module_load(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,
36			"delete_module() failed to remove module entry for %s",
37			MODULE_NAME);
38		return;
39	}
40
41	tst_res(TPASS, "delete_module() successful");
42	module_loaded = 0;
43}
44
45static void cleanup(void)
46{
47	if (module_loaded)
48		tst_module_unload(MODULE_NAME_KO);
49}
50
51static struct tst_test test = {
52	.needs_root = 1,
53	/* lockdown and SecureBoot requires signed modules */
54	.skip_in_lockdown = 1,
55	.skip_in_secureboot = 1,
56	.cleanup = cleanup,
57	.test_all = do_delete_module,
58};
59