1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
4 */
5
6 /*\
7 * [Description]
8 *
9 * Basic finit_module() tests.
10 *
11 * [Algorithm]
12 *
13 * Inserts a simple module after opening and mmaping the module file.
14 */
15
16 #include <errno.h>
17 #include "lapi/init_module.h"
18 #include "tst_module.h"
19
20 #define MODULE_NAME "finit_module.ko"
21
22 static int fd;
23
24 static char *mod_path;
25
setup(void)26 static void setup(void)
27 {
28 tst_module_exists(MODULE_NAME, &mod_path);
29
30 fd = SAFE_OPEN(mod_path, O_RDONLY|O_CLOEXEC);
31 }
32
run(void)33 static void run(void)
34 {
35 TST_EXP_PASS(finit_module(fd, "status=valid", 0));
36 if (!TST_PASS)
37 return;
38
39 tst_module_unload(MODULE_NAME);
40 }
41
cleanup(void)42 static void cleanup(void)
43 {
44 SAFE_CLOSE(fd);
45 }
46
47 static struct tst_test test = {
48 .test_all = run,
49 .setup = setup,
50 .cleanup = cleanup,
51 .needs_root = 1,
52 /* lockdown and SecureBoot requires signed modules */
53 .skip_in_lockdown = 1,
54 .skip_in_secureboot = 1,
55 };
56