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