2 * Distributed under the terms of the GNU GPL version 2.
3 * Copyright (c) 2007 The Board of Trustees of The Leland Stanford Junior Univer
7 #include <linux/autoconf.h>
8 #include <linux/module.h>
9 #include <linux/string.h>
10 #include <linux/version.h>
11 #include <linux/errno.h>
15 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
16 static char run[1024];
17 module_param_string(run, run, sizeof run, 0);
18 MODULE_PARM_DESC(run_tests, "run=\"test1,[test2,...]\"\n");
21 MODULE_PARM(run, "s");
24 static int test_failed;
25 static const char *test_name;
27 void unit_fail_function(const char *function, const char *msg, ...)
31 printk("%s: FAIL: %s: ", test_name, function);
44 static int run_test(const char *name, size_t len)
46 static const struct test {
50 #define UNIT_TEST(NAME) {#NAME, run_##NAME},
57 for (p = tests; p < &tests[ARRAY_SIZE(tests)]; p++)
58 if (len == strlen(p->name)
59 && !memcmp(name, p->name, len)) {
63 printk("%s: %s\n", test_name,
64 test_failed ? "FAIL" : "PASS");
67 printk("unknown unit test %.*s\n", (int) len, name);
73 int n_pass = 0, n_fail = 0;
76 static const char white_space[] = " \t\r\n\v,";
79 p += strspn(p, white_space);
83 len = strcspn(p, white_space);
91 if (n_pass + n_fail == 0)
92 printk("no tests specified (use run=\"test1 [test2...]\")\n");
94 printk("%d tests passed, %d failed\n", n_pass, n_fail);
99 module_init(unit_init);
100 MODULE_LICENSE("GPL");