2 * Distributed under the terms of the GNU GPL version 2.
3 * Copyright (c) 2007, 2008 The Board of Trustees of The Leland
4 * Stanford Junior University
7 #include <linux/autoconf.h>
8 #include <linux/init.h>
9 #include <linux/module.h>
10 #include <linux/string.h>
11 #include <linux/version.h>
12 #include <linux/errno.h>
16 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
17 static char run[1024];
18 module_param_string(run, run, sizeof run, 0);
19 MODULE_PARM_DESC(run_tests, "run=\"test1,[test2,...]\"\n");
22 MODULE_PARM(run, "s");
25 static int test_failed;
26 static const char *test_name;
28 void unit_fail_function(const char *function, const char *msg, ...)
32 printk("%s: FAIL: %s: ", test_name, function);
45 static int run_test(const char *name, size_t len)
47 static const struct test {
51 #define UNIT_TEST(NAME) {#NAME, run_##NAME},
58 for (p = tests; p < &tests[ARRAY_SIZE(tests)]; p++)
59 if (len == strlen(p->name)
60 && !memcmp(name, p->name, len)) {
64 printk("%s: %s\n", test_name,
65 test_failed ? "FAIL" : "PASS");
68 printk("unknown unit test %.*s\n", (int) len, name);
74 int n_pass = 0, n_fail = 0;
81 static const char white_space[] = " \t\r\n\v,";
84 p += strspn(p, white_space);
88 len = strcspn(p, white_space);
96 if (n_pass + n_fail == 0)
97 printk("no tests specified (use run=\"test1 [test2...]\")\n");
99 printk("%d tests passed, %d failed\n", n_pass, n_fail);
104 module_init(unit_init);
105 MODULE_LICENSE("GPL");