]> git.ipfire.org Git - thirdparty/kmod.git/blame - testsuite/testsuite.h
testsuite: add GPL license
[thirdparty/kmod.git] / testsuite / testsuite.h
CommitLineData
e701e381
LDM
1/*
2 * Copyright (C) 2012 ProFUSION embedded systems
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
80f9e023
LDM
18#ifndef _LIBKMOD_TESTSUITE_
19#define _LIBKMOD_TESTSUITE_
20
21#include <stdbool.h>
22#include <stdarg.h>
23
24struct test;
25typedef int (*testfunc)(const struct test *t);
26
27enum test_config {
28 TC_ROOTFS = 0,
29 TC_UNAME_R,
53646fc5 30 TC_INIT_MODULE_RETCODES,
f6ef5d6b 31 TC_DELETE_MODULE_RETCODES,
80f9e023
LDM
32 _TC_LAST,
33};
34
6afc9cd6 35#define S_TC_ROOTFS "TESTSUITE_ROOTFS"
68cc4493 36#define S_TC_UNAME_R "TESTSUITE_UNAME_R"
53646fc5 37#define S_TC_INIT_MODULE_RETCODES "TESTSUITE_INIT_MODULE_RETCODES"
f6ef5d6b 38#define S_TC_DELETE_MODULE_RETCODES "TESTSUITE_DELETE_MODULE_RETCODES"
68cc4493
LDM
39
40
80f9e023
LDM
41struct test {
42 const char *name;
43 const char *description;
3dbb8dea
LDM
44 struct {
45 const char *stdout;
46 const char *stderr;
47 } output;
80f9e023
LDM
48 testfunc func;
49 const char *config[_TC_LAST];
ed2df4e9 50 bool need_spawn;
80f9e023
LDM
51};
52
53
54const struct test *test_find(const struct test *tests[], const char *name);
55int test_init(int argc, char *const argv[], const struct test *tests[]);
95daea07 56int test_spawn_prog(const char *prog, const char *const args[]);
80f9e023
LDM
57
58int test_run(const struct test *t);
80f9e023
LDM
59
60#define TS_EXPORT __attribute__ ((visibility("default")))
61
62#define _LOG(prefix, fmt, ...) printf("TESTSUITE: " prefix fmt, ## __VA_ARGS__)
63#define LOG(fmt, ...) _LOG("", fmt, ## __VA_ARGS__)
64#define WARN(fmt, ...) _LOG("WARN: ", fmt, ## __VA_ARGS__)
65#define ERR(fmt, ...) _LOG("ERR: ", fmt, ## __VA_ARGS__)
66
67/* Test definitions */
68#define DEFINE_TEST(_name) \
69 struct test s_name = { \
70 .name = #_name, \
71 .func = _name, \
72 }
73
74#endif