]> git.ipfire.org Git - thirdparty/linux.git/commit
kunit: Reset suite counter right before running tests
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Wed, 4 Oct 2023 20:57:00 +0000 (22:57 +0200)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 14 Nov 2023 20:01:47 +0000 (13:01 -0700)
commit2e3c94aed51eabbe9c1c0ee515371ea5441c2fa7
tree6cc1de286f47a81cf7af773a121bbe73085550e2
parentf8f2847f739dc899d0e563eac01299dadefa64ff
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 <michal.wajdeczko@intel.com>
Cc: David Gow <davidgow@google.com>
Cc: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/kunit/test.c