Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Jakub Kicinski <kuba@kernel.org>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
e7f30460 142aca6b

+14 -9
+14 -9
tools/testing/selftests/kselftest_harness.h
··· 659 659 } \ 660 660 } 661 661 662 + struct __test_metadata; 663 + 662 664 /* Contains all the information about a fixture. */ 663 665 struct __fixture_metadata { 664 666 const char *name; 667 + struct __test_metadata *tests; 665 668 struct __fixture_metadata *prev, *next; 666 669 } _fixture_global __attribute__((unused)) = { 667 670 .name = "global", ··· 701 698 }; 702 699 703 700 /* Storage for the (global) tests to be run. */ 704 - static struct __test_metadata *__test_list; 705 701 static unsigned int __test_count; 706 702 707 703 /* ··· 715 713 static inline void __register_test(struct __test_metadata *t) 716 714 { 717 715 __test_count++; 718 - __LIST_APPEND(__test_list, t); 716 + __LIST_APPEND(t->fixture->tests, t); 719 717 } 720 718 721 719 static inline int __bail(int for_realz, bool no_print, __u8 step) ··· 845 843 static int test_harness_run(int __attribute__((unused)) argc, 846 844 char __attribute__((unused)) **argv) 847 845 { 846 + struct __fixture_metadata *f; 848 847 struct __test_metadata *t; 849 848 int ret = 0; 850 849 unsigned int count = 0; ··· 854 851 /* TODO(wad) add optional arguments similar to gtest. */ 855 852 printf("[==========] Running %u tests from %u test cases.\n", 856 853 __test_count, __fixture_count + 1); 857 - for (t = __test_list; t; t = t->next) { 858 - count++; 859 - __run_test(t->fixture, t); 860 - if (t->passed) 861 - pass_count++; 862 - else 863 - ret = 1; 854 + for (f = __fixture_list; f; f = f->next) { 855 + for (t = f->tests; t; t = t->next) { 856 + count++; 857 + __run_test(f, t); 858 + if (t->passed) 859 + pass_count++; 860 + else 861 + ret = 1; 862 + } 864 863 } 865 864 printf("[==========] %u / %u tests passed.\n", pass_count, count); 866 865 printf("[ %s ]\n", (ret ? "FAILED" : "PASSED"));