Re: [PATCH v3 2/4] Documentation: kunit: Note that assertions should not be used in cleanup

From: Sadiya Kazi
Date: Tue Apr 25 2023 - 01:56:45 EST


On Fri, Apr 21, 2023 at 9:32 AM David Gow <davidgow@xxxxxxxxxx> wrote:
>
> 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.
>
> Signed-off-by: David Gow <davidgow@xxxxxxxxxx>
> ---

Thank you, David. The note looks fine to me.
Reviewed-by: Sadiya Kazi <sadiyakazi@xxxxxxxxxx>

Regards,
Sadiya
>
> No changes since v2:
> https://lore.kernel.org/linux-kselftest/20230419085426.1671703-2-davidgow@xxxxxxxxxx/
>
> This patch was introduced in v2.
>
> ---
> Documentation/dev-tools/kunit/usage.rst | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
> index 9faf2b4153fc..9f720f1317d3 100644
> --- a/Documentation/dev-tools/kunit/usage.rst
> +++ b/Documentation/dev-tools/kunit/usage.rst
> @@ -121,6 +121,12 @@ there's an allocation error.
> ``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.
>
> +.. 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
> --------------------------
>
> --
> 2.40.0.634.g4ca3ef3211-goog
>