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)26static void setup(void) 27 { 28 finit_module_supported_by_kernel(); 29 30 tst_module_exists(MODULE_NAME, &mod_path); 31 32 fd = SAFE_OPEN(mod_path, O_RDONLY|O_CLOEXEC); 33 } 34 run(void)35static void run(void) 36 { 37 TST_EXP_PASS(finit_module(fd, "status=valid", 0)); 38 if (!TST_PASS) 39 return; 40 41 tst_module_unload(MODULE_NAME); 42 } 43 cleanup(void)44static void cleanup(void) 45 { 46 SAFE_CLOSE(fd); 47 } 48 49 static struct tst_test test = { 50 .test_all = run, 51 .setup = setup, 52 .cleanup = cleanup, 53 .needs_root = 1, 54 /* lockdown requires signed modules */ 55 .skip_in_lockdown = 1, 56 }; 57