Commit 410f0749 authored by David Gow's avatar David Gow Committed by Shuah Khan

Documentation: kunit: Note that assertions should not be used in cleanup

As assertions abort the test cleanup process, they should be avoided
from within a suite's exit function, or from within resource 'free'
functions. Unlike with initialisation or main test execution, no further
cleanup will be performed after a failed assertion, potentially causing
a leak of resources.
Reviewed-by: default avatarSadiya Kazi <sadiyakazi@google.com>
Signed-off-by: default avatarDavid Gow <davidgow@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 55e8c1b4
...@@ -121,6 +121,12 @@ there's an allocation error. ...@@ -121,6 +121,12 @@ there's an allocation error.
``return`` so they only work from the test function. In KUnit, we stop the ``return`` so they only work from the test function. In KUnit, we stop the
current kthread on failure, so you can call them from anywhere. current kthread on failure, so you can call them from anywhere.
.. note::
Warning: There is an exception to the above rule. You shouldn't use assertions
in the suite's exit() function, or in the free function for a resource. These
run when a test is shutting down, and an assertion here prevents further
cleanup code from running, potentially leading to a memory leak.
Customizing error messages Customizing error messages
-------------------------- --------------------------
......
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