Commit e7f30460 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

kselftest: run tests by fixture

Now that all tests have a fixture object move from a global
list of tests to a list of tests per fixture.

Order of tests may change as we will now group and run test
fixture by fixture, rather than in declaration order.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 142aca6b
...@@ -659,9 +659,12 @@ ...@@ -659,9 +659,12 @@
} \ } \
} }
struct __test_metadata;
/* Contains all the information about a fixture. */ /* Contains all the information about a fixture. */
struct __fixture_metadata { struct __fixture_metadata {
const char *name; const char *name;
struct __test_metadata *tests;
struct __fixture_metadata *prev, *next; struct __fixture_metadata *prev, *next;
} _fixture_global __attribute__((unused)) = { } _fixture_global __attribute__((unused)) = {
.name = "global", .name = "global",
...@@ -698,7 +701,6 @@ struct __test_metadata { ...@@ -698,7 +701,6 @@ struct __test_metadata {
}; };
/* Storage for the (global) tests to be run. */ /* Storage for the (global) tests to be run. */
static struct __test_metadata *__test_list;
static unsigned int __test_count; static unsigned int __test_count;
/* /*
...@@ -713,7 +715,7 @@ static unsigned int __test_count; ...@@ -713,7 +715,7 @@ static unsigned int __test_count;
static inline void __register_test(struct __test_metadata *t) static inline void __register_test(struct __test_metadata *t)
{ {
__test_count++; __test_count++;
__LIST_APPEND(__test_list, t); __LIST_APPEND(t->fixture->tests, t);
} }
static inline int __bail(int for_realz, bool no_print, __u8 step) static inline int __bail(int for_realz, bool no_print, __u8 step)
...@@ -843,6 +845,7 @@ void __run_test(struct __fixture_metadata *f, ...@@ -843,6 +845,7 @@ void __run_test(struct __fixture_metadata *f,
static int test_harness_run(int __attribute__((unused)) argc, static int test_harness_run(int __attribute__((unused)) argc,
char __attribute__((unused)) **argv) char __attribute__((unused)) **argv)
{ {
struct __fixture_metadata *f;
struct __test_metadata *t; struct __test_metadata *t;
int ret = 0; int ret = 0;
unsigned int count = 0; unsigned int count = 0;
...@@ -851,13 +854,15 @@ static int test_harness_run(int __attribute__((unused)) argc, ...@@ -851,13 +854,15 @@ static int test_harness_run(int __attribute__((unused)) argc,
/* TODO(wad) add optional arguments similar to gtest. */ /* TODO(wad) add optional arguments similar to gtest. */
printf("[==========] Running %u tests from %u test cases.\n", printf("[==========] Running %u tests from %u test cases.\n",
__test_count, __fixture_count + 1); __test_count, __fixture_count + 1);
for (t = __test_list; t; t = t->next) { for (f = __fixture_list; f; f = f->next) {
count++; for (t = f->tests; t; t = t->next) {
__run_test(t->fixture, t); count++;
if (t->passed) __run_test(f, t);
pass_count++; if (t->passed)
else pass_count++;
ret = 1; else
ret = 1;
}
} }
printf("[==========] %u / %u tests passed.\n", pass_count, count); printf("[==========] %u / %u tests passed.\n", pass_count, count);
printf("[ %s ]\n", (ret ? "FAILED" : "PASSED")); printf("[ %s ]\n", (ret ? "FAILED" : "PASSED"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment