2 * Copyright (C) 2012 ProFUSION embedded systems
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will 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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef _LIBKMOD_TESTSUITE_
19 #define _LIBKMOD_TESTSUITE_
25 typedef int (*testfunc
)(const struct test
*t
);
29 * Where's the roots dir for this test. It will LD_PRELOAD path.so in
30 * order to trap calls to functions using paths.
35 * What's the desired string to be returned by `uname -r`. It will
36 * trap calls to uname(3P) by LD_PRELOAD'ing uname.so and then filling
37 * in the information in u.release.
42 * Fake calls to init_module(2), returning return-code and setting
43 * errno to err-code. Set this variable with the following format:
45 * modname:return-code:err-code
47 * When this variable is used, all calls to init_module() are trapped
48 * and by default the return code is 0. In other words, they fake
49 * "success" for all modules, except the ones in the list above, for
50 * which the return codes are used.
52 TC_INIT_MODULE_RETCODES
,
55 * Fake calls to delete_module(2), returning return-code and setting
56 * errno to err-code. Set this variable with the following format:
58 * modname:return-code:err-code
60 * When this variable is used, all calls to init_module() are trapped
61 * and by default the return code is 0. In other words, they fake
62 * "success" for all modules, except the ones in the list above, for
63 * which the return codes are used.
65 TC_DELETE_MODULE_RETCODES
,
70 #define S_TC_ROOTFS "TESTSUITE_ROOTFS"
71 #define S_TC_UNAME_R "TESTSUITE_UNAME_R"
72 #define S_TC_INIT_MODULE_RETCODES "TESTSUITE_INIT_MODULE_RETCODES"
73 #define S_TC_DELETE_MODULE_RETCODES "TESTSUITE_DELETE_MODULE_RETCODES"
78 const char *description
;
84 const char *config
[_TC_LAST
];
90 const struct test
*test_find(const struct test
*tests
[], const char *name
);
91 int test_init(int argc
, char *const argv
[], const struct test
*tests
[]);
92 int test_spawn_prog(const char *prog
, const char *const args
[]);
94 int test_run(const struct test
*t
);
96 #define TS_EXPORT __attribute__ ((visibility("default")))
98 #define _LOG(prefix, fmt, ...) printf("TESTSUITE: " prefix fmt, ## __VA_ARGS__)
99 #define LOG(fmt, ...) _LOG("", fmt, ## __VA_ARGS__)
100 #define WARN(fmt, ...) _LOG("WARN: ", fmt, ## __VA_ARGS__)
101 #define ERR(fmt, ...) _LOG("ERR: ", fmt, ## __VA_ARGS__)
103 /* Test definitions */
104 #define DEFINE_TEST(_name) \
105 struct test s_name = { \