Skip to content

Commit 2e3c94a

Browse files
mwajdeczshuahkh
authored andcommitted
kunit: Reset suite counter right before running tests
Today we reset the suite counter as part of the suite cleanup, called from the module exit callback, but it might not work that well as one can try to collect results without unloading a previous test (either unintentionally or due to dependencies). For easy reproduction try to load the kunit-test.ko and then collect and parse results from the kunit-example-test.ko load. Parser will complain about mismatch of expected test number: [ ] KTAP version 1 [ ] 1..1 [ ] # example: initializing suite [ ] KTAP version 1 [ ] # Subtest: example .. [ ] # example: pass:5 fail:0 skip:4 total:9 [ ] # Totals: pass:6 fail:0 skip:6 total:12 [ ] ok 7 example [ ] [ERROR] Test: example: Expected test number 1 but found 7 [ ] ===================== [PASSED] example ===================== [ ] ============================================================ [ ] Testing complete. Ran 12 tests: passed: 6, skipped: 6, errors: 1 Since we are now printing suite test plan on every module load, right before running suite tests, we should make sure that suite counter will also start from 1. Easiest solution seems to be move counter reset to the __kunit_test_suites_init() function. Signed-off-by: Michal Wajdeczko <[email protected]> Cc: David Gow <[email protected]> Cc: Rae Moar <[email protected]> Reviewed-by: David Gow <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent f8f2847 commit 2e3c94a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/kunit/test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_
708708
return 0;
709709
}
710710

711+
kunit_suite_counter = 1;
712+
711713
static_branch_inc(&kunit_running);
712714

713715
for (i = 0; i < num_suites; i++) {
@@ -734,8 +736,6 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites)
734736

735737
for (i = 0; i < num_suites; i++)
736738
kunit_exit_suite(suites[i]);
737-
738-
kunit_suite_counter = 1;
739739
}
740740
EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);
741741

0 commit comments

Comments
 (0)