2012-01-25 05:59:54 +07:00
|
|
|
#ifndef _LIBKMOD_TESTSUITE_
|
|
|
|
#define _LIBKMOD_TESTSUITE_
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
struct test;
|
|
|
|
typedef int (*testfunc)(const struct test *t);
|
|
|
|
|
|
|
|
enum test_config {
|
|
|
|
TC_ROOTFS = 0,
|
|
|
|
TC_UNAME_R,
|
2012-01-26 11:09:28 +07:00
|
|
|
TC_INIT_MODULE_RETCODES,
|
2012-01-27 01:10:41 +07:00
|
|
|
TC_DELETE_MODULE_RETCODES,
|
2012-01-25 05:59:54 +07:00
|
|
|
_TC_LAST,
|
|
|
|
};
|
|
|
|
|
2012-01-25 11:44:45 +07:00
|
|
|
#define S_TC_ROOTFS "TESTSUITE_ROOTFS"
|
2012-01-25 07:04:46 +07:00
|
|
|
#define S_TC_UNAME_R "TESTSUITE_UNAME_R"
|
2012-01-26 11:09:28 +07:00
|
|
|
#define S_TC_INIT_MODULE_RETCODES "TESTSUITE_INIT_MODULE_RETCODES"
|
2012-01-27 01:10:41 +07:00
|
|
|
#define S_TC_DELETE_MODULE_RETCODES "TESTSUITE_DELETE_MODULE_RETCODES"
|
2012-01-25 07:04:46 +07:00
|
|
|
|
|
|
|
|
2012-01-25 05:59:54 +07:00
|
|
|
struct test {
|
|
|
|
const char *name;
|
|
|
|
const char *description;
|
2012-01-26 02:46:52 +07:00
|
|
|
struct {
|
|
|
|
const char *stdout;
|
|
|
|
const char *stderr;
|
|
|
|
} output;
|
2012-01-25 05:59:54 +07:00
|
|
|
testfunc func;
|
|
|
|
const char *config[_TC_LAST];
|
2012-01-25 08:28:39 +07:00
|
|
|
bool need_spawn;
|
2012-01-25 05:59:54 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const struct test *test_find(const struct test *tests[], const char *name);
|
|
|
|
int test_init(int argc, char *const argv[], const struct test *tests[]);
|
2012-01-26 05:32:48 +07:00
|
|
|
int test_spawn_prog(const char *prog, const char *const args[]);
|
2012-01-25 05:59:54 +07:00
|
|
|
|
|
|
|
int test_run(const struct test *t);
|
|
|
|
|
|
|
|
#define TS_EXPORT __attribute__ ((visibility("default")))
|
|
|
|
|
|
|
|
#define _LOG(prefix, fmt, ...) printf("TESTSUITE: " prefix fmt, ## __VA_ARGS__)
|
|
|
|
#define LOG(fmt, ...) _LOG("", fmt, ## __VA_ARGS__)
|
|
|
|
#define WARN(fmt, ...) _LOG("WARN: ", fmt, ## __VA_ARGS__)
|
|
|
|
#define ERR(fmt, ...) _LOG("ERR: ", fmt, ## __VA_ARGS__)
|
|
|
|
|
|
|
|
/* Test definitions */
|
|
|
|
#define DEFINE_TEST(_name) \
|
|
|
|
struct test s_name = { \
|
|
|
|
.name = #_name, \
|
|
|
|
.func = _name, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|