1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
3*49cdfc7eSAndroid Build Coastguard Worker *
4*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or
5*49cdfc7eSAndroid Build Coastguard Worker * modify it under the terms of the GNU General Public License as
6*49cdfc7eSAndroid Build Coastguard Worker * published by the Free Software Foundation; either version 2 of
7*49cdfc7eSAndroid Build Coastguard Worker * the License, or (at your option) any later version.
8*49cdfc7eSAndroid Build Coastguard Worker *
9*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it would be useful,
10*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*49cdfc7eSAndroid Build Coastguard Worker * GNU General Public License for more details.
13*49cdfc7eSAndroid Build Coastguard Worker *
14*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
15*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write the Free Software Foundation,
16*49cdfc7eSAndroid Build Coastguard Worker * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17*49cdfc7eSAndroid Build Coastguard Worker *
18*49cdfc7eSAndroid Build Coastguard Worker * Author:
19*49cdfc7eSAndroid Build Coastguard Worker * Alexey Kodanev <[email protected]>
20*49cdfc7eSAndroid Build Coastguard Worker *
21*49cdfc7eSAndroid Build Coastguard Worker * These functions help to load and unload kernel modules in the tests.
22*49cdfc7eSAndroid Build Coastguard Worker *
23*49cdfc7eSAndroid Build Coastguard Worker * tst_module_load function already includes tst_module_exists function,
24*49cdfc7eSAndroid Build Coastguard Worker * which is checking the following possible module's locations:
25*49cdfc7eSAndroid Build Coastguard Worker *
26*49cdfc7eSAndroid Build Coastguard Worker * 1. Current working directory
27*49cdfc7eSAndroid Build Coastguard Worker *
28*49cdfc7eSAndroid Build Coastguard Worker * 2. LTP installation path (using env LTPROOT, which is usually /opt/ltp)
29*49cdfc7eSAndroid Build Coastguard Worker *
30*49cdfc7eSAndroid Build Coastguard Worker * 3. If tmp directory created, it'll look at the test start working directory
31*49cdfc7eSAndroid Build Coastguard Worker *
32*49cdfc7eSAndroid Build Coastguard Worker */
33*49cdfc7eSAndroid Build Coastguard Worker
34*49cdfc7eSAndroid Build Coastguard Worker #ifndef TST_MODULE
35*49cdfc7eSAndroid Build Coastguard Worker #define TST_MODULE
36*49cdfc7eSAndroid Build Coastguard Worker
37*49cdfc7eSAndroid Build Coastguard Worker void tst_module_exists_(void (cleanup_fn)(void), const char *mod_name,
38*49cdfc7eSAndroid Build Coastguard Worker char **mod_path);
39*49cdfc7eSAndroid Build Coastguard Worker
40*49cdfc7eSAndroid Build Coastguard Worker void tst_module_load_(void (cleanup_fn)(void), const char *mod_name,
41*49cdfc7eSAndroid Build Coastguard Worker char *const argv[]);
42*49cdfc7eSAndroid Build Coastguard Worker
43*49cdfc7eSAndroid Build Coastguard Worker void tst_module_unload_(void (cleanup_fn)(void), const char *mod_name);
44*49cdfc7eSAndroid Build Coastguard Worker
45*49cdfc7eSAndroid Build Coastguard Worker /*
46*49cdfc7eSAndroid Build Coastguard Worker * Check module existence.
47*49cdfc7eSAndroid Build Coastguard Worker *
48*49cdfc7eSAndroid Build Coastguard Worker * @mod_name: module's file name.
49*49cdfc7eSAndroid Build Coastguard Worker * @mod_path: if it is not NULL, then tst_module_exists places the found
50*49cdfc7eSAndroid Build Coastguard Worker * module's path into the location pointed to by *mod_path. It must be freed
51*49cdfc7eSAndroid Build Coastguard Worker * with free() when it is no longer needed.
52*49cdfc7eSAndroid Build Coastguard Worker *
53*49cdfc7eSAndroid Build Coastguard Worker * In case of failure, test'll call cleanup_fn and exit with TCONF return value.
54*49cdfc7eSAndroid Build Coastguard Worker */
tst_module_exists(void (cleanup_fn)(void),const char * mod_name,char ** mod_path)55*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_module_exists(void (cleanup_fn)(void),
56*49cdfc7eSAndroid Build Coastguard Worker const char *mod_name, char **mod_path)
57*49cdfc7eSAndroid Build Coastguard Worker {
58*49cdfc7eSAndroid Build Coastguard Worker tst_module_exists_(cleanup_fn, mod_name, mod_path);
59*49cdfc7eSAndroid Build Coastguard Worker }
60*49cdfc7eSAndroid Build Coastguard Worker
61*49cdfc7eSAndroid Build Coastguard Worker /*
62*49cdfc7eSAndroid Build Coastguard Worker * Load a module using insmod program.
63*49cdfc7eSAndroid Build Coastguard Worker *
64*49cdfc7eSAndroid Build Coastguard Worker * @mod_name: module's file name.
65*49cdfc7eSAndroid Build Coastguard Worker * @argv: an array of pointers to null-terminated strings that represent the
66*49cdfc7eSAndroid Build Coastguard Worker * additional parameters to the module. The array of pointers must be
67*49cdfc7eSAndroid Build Coastguard Worker * terminated by a NULL pointer. If argv points to NULL, it will be ignored.
68*49cdfc7eSAndroid Build Coastguard Worker *
69*49cdfc7eSAndroid Build Coastguard Worker * In case of insmod failure, test will call cleanup_fn and exit with TBROK
70*49cdfc7eSAndroid Build Coastguard Worker * return value.
71*49cdfc7eSAndroid Build Coastguard Worker */
tst_module_load(void (cleanup_fn)(void),const char * mod_name,char * const argv[])72*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_module_load(void (cleanup_fn)(void),
73*49cdfc7eSAndroid Build Coastguard Worker const char *mod_name, char *const argv[])
74*49cdfc7eSAndroid Build Coastguard Worker {
75*49cdfc7eSAndroid Build Coastguard Worker tst_module_load_(cleanup_fn, mod_name, argv);
76*49cdfc7eSAndroid Build Coastguard Worker }
77*49cdfc7eSAndroid Build Coastguard Worker
78*49cdfc7eSAndroid Build Coastguard Worker /*
79*49cdfc7eSAndroid Build Coastguard Worker * Unload a module using rmmod program. In case of failure, test will call
80*49cdfc7eSAndroid Build Coastguard Worker * cleanup_fn and exit with TBROK return value.
81*49cdfc7eSAndroid Build Coastguard Worker *
82*49cdfc7eSAndroid Build Coastguard Worker * @mod_name: can be module name or module's file name.
83*49cdfc7eSAndroid Build Coastguard Worker */
tst_module_unload(void (cleanup_fn)(void),const char * mod_name)84*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_module_unload(void (cleanup_fn)(void), const char *mod_name)
85*49cdfc7eSAndroid Build Coastguard Worker {
86*49cdfc7eSAndroid Build Coastguard Worker tst_module_unload_(cleanup_fn, mod_name);
87*49cdfc7eSAndroid Build Coastguard Worker }
88*49cdfc7eSAndroid Build Coastguard Worker
89*49cdfc7eSAndroid Build Coastguard Worker #endif /* TST_MODULE */
90