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