]> git.baikalelectronics.ru Git - kernel.git/commit
kunit: add ability to specify suite-level init and exit functions
authorDaniel Latypov <dlatypov@google.com>
Fri, 29 Apr 2022 18:12:57 +0000 (11:12 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 2 May 2022 18:35:51 +0000 (12:35 -0600)
commitd9ce8861ab3178ebde35f541d3e9f4d5eadebf48
tree20686c23382bfc795dbec9e530508e75e208a312
parente373e2e668995f7d02a236f29cfd2ad6a6a20410
kunit: add ability to specify suite-level init and exit functions

KUnit has support for setup/cleanup logic for each test case in a suite.
But it lacks the ability to specify setup/cleanup for the entire suite
itself.

This can be used to do setup that is too expensive or cumbersome to do
for each test.
Or it can be used to do simpler things like log debug information after
the suite completes.
It's a fairly common feature, so the lack of it is noticeable.

Some examples in other frameworks and languages:
* https://docs.python.org/3/library/unittest.html#setupclass-and-teardownclass
* https://google.github.io/googletest/reference/testing.html#Test::SetUpTestSuite

Meta:
This is very similar to this patch here: https://lore.kernel.org/linux-kselftest/20210805043503.20252-3-bvanassche@acm.org/
The changes from that patch:
* pass in `struct kunit *` so users can do stuff like
  `kunit_info(suite, "debug message")`
* makes sure the init failure is bubbled up as a failure
* updates kunit-example-test.c to use a suite init
* Updates kunit/usage.rst to mention the new support
* some minor cosmetic things
  * use `suite_{init,exit}` instead of `{init/exit}_suite`
  * make suite init error message more consistent w/ test init
  * etc.

Signed-off-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Documentation/dev-tools/kunit/usage.rst
include/kunit/test.h
lib/kunit/kunit-example-test.c
lib/kunit/test.c