2 * Copyright (C) 2012-2013 ProFUSION embedded systems
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 #include <shared/macro.h>
26 typedef int (*testfunc
)(const struct test
*t
);
30 * Where's the roots dir for this test. It will LD_PRELOAD path.so in
31 * order to trap calls to functions using paths.
36 * What's the desired string to be returned by `uname -r`. It will
37 * trap calls to uname(3P) by LD_PRELOAD'ing uname.so and then filling
38 * in the information in u.release.
43 * Fake calls to init_module(2), returning return-code and setting
44 * errno to err-code. Set this variable with the following format:
46 * modname:return-code:err-code
48 * When this variable is used, all calls to init_module() are trapped
49 * and by default the return code is 0. In other words, they fake
50 * "success" for all modules, except the ones in the list above, for
51 * which the return codes are used.
53 TC_INIT_MODULE_RETCODES
,
56 * Fake calls to delete_module(2), returning return-code and setting
57 * errno to err-code. Set this variable with the following format:
59 * modname:return-code:err-code
61 * When this variable is used, all calls to init_module() are trapped
62 * and by default the return code is 0. In other words, they fake
63 * "success" for all modules, except the ones in the list above, for
64 * which the return codes are used.
66 TC_DELETE_MODULE_RETCODES
,
71 #define S_TC_ROOTFS "TESTSUITE_ROOTFS"
72 #define S_TC_UNAME_R "TESTSUITE_UNAME_R"
73 #define S_TC_INIT_MODULE_RETCODES "TESTSUITE_INIT_MODULE_RETCODES"
74 #define S_TC_DELETE_MODULE_RETCODES "TESTSUITE_DELETE_MODULE_RETCODES"
83 const char *description
;
85 /* File with correct stdout */
87 /* File with correct stderr */
91 * Vector with pair of files
95 const struct keyval
*files
;
97 /* comma-separated list of loaded modules at the end of the test */
98 const char *modules_loaded
;
100 const char *config
[_TC_LAST
];
102 const struct keyval
*env_vars
;
105 } __attribute__((aligned(8)));
108 int test_init(const struct test
*start
, const struct test
*stop
,
109 int argc
, char *const argv
[]);
110 const struct test
*test_find(const struct test
*start
, const struct test
*stop
,
112 int test_spawn_prog(const char *prog
, const char *const args
[]);
113 int test_run(const struct test
*t
);
115 #define TS_EXPORT __attribute__ ((visibility("default")))
117 #define _LOG(prefix, fmt, ...) printf("TESTSUITE: " prefix fmt, ## __VA_ARGS__)
118 #define LOG(fmt, ...) _LOG("", fmt, ## __VA_ARGS__)
119 #define WARN(fmt, ...) _LOG("WARN: ", fmt, ## __VA_ARGS__)
120 #define ERR(fmt, ...) _LOG("ERR: ", fmt, ## __VA_ARGS__)
122 #define assert_return(expr, r) \
125 ERR("Failed assertion: " #expr " %s:%d %s\n", \
126 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
132 /* Test definitions */
133 #define DEFINE_TEST(_name, ...) \
134 static const struct test s##_name##UNIQ \
135 __attribute__((used, section("kmod_tests"), aligned(8))) = { \
141 #define TESTSUITE_MAIN() \
142 extern struct test __start_kmod_tests[] __attribute__((weak, visibility("hidden"))); \
143 extern struct test __stop_kmod_tests[] __attribute__((weak, visibility("hidden"))); \
144 int main(int argc, char *argv[]) \
146 const struct test *t; \
149 arg = test_init(__start_kmod_tests, __stop_kmod_tests, argc, argv); \
154 t = test_find(__start_kmod_tests, __stop_kmod_tests, argv[arg]); \
156 fprintf(stderr, "could not find test %s\n", argv[arg]); \
157 exit(EXIT_FAILURE); \
160 return test_run(t); \
163 for (t = __start_kmod_tests; t < __stop_kmod_tests; t++) { \
164 if (test_run(t) != 0) \
165 exit(EXIT_FAILURE); \
168 exit(EXIT_SUCCESS); \
172 # define __noreturn noreturn
173 #elif __STDC_VERSION__ >= 201112L
174 # define __noreturn _Noreturn
176 # define __noreturn __attribute__((noreturn))