[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CABVgOSmGV=Aj94zX1wkaknhJFAeZ-ew_YmLdEB+g=wXvk-ki3A@mail.gmail.com>
Date: Sat, 19 Nov 2022 16:19:02 +0800
From: David Gow <davidgow@...gle.com>
To: Daniel Latypov <dlatypov@...gle.com>
Cc: brendanhiggins@...gle.com, rmoar@...gle.com,
linux-kernel@...r.kernel.org, kunit-dev@...glegroups.com,
linux-kselftest@...r.kernel.org, linux-doc@...r.kernel.org,
skhan@...uxfoundation.org, Sadiya Kazi <sadiyakazi@...gle.com>
Subject: Re: [PATCH v3 2/3] Documentation: KUnit: reword description of assertions
On Sat, Nov 12, 2022 at 2:29 AM Daniel Latypov <dlatypov@...gle.com> wrote:
>
> The existing wording implies that kunit_kmalloc_array() is "the method
> under test". We're actually testing the sort() function in that example.
> This is because the example was changed in commit 953574390634
> ("Documentation: KUnit: Rework writing page to focus on writing tests"),
> but the wording was not.
>
> Also add a `note` telling people they can use the KUNIT_ASSERT_EQ()
> macros from any function. Some users might be coming from a framework
> like gUnit where that'll compile but silently do the wrong thing.
>
> Signed-off-by: Daniel Latypov <dlatypov@...gle.com>
> Reviewed-by: Sadiya Kazi <sadiyakazi@...gle.com>
> ---
Looking good!
Reviewed-by: David Gow <davidgow@...gle.com>
Cheers,
-- David
> Documentation/dev-tools/kunit/usage.rst | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
> index b0a6c3bc0eeb..22416ebb94ab 100644
> --- a/Documentation/dev-tools/kunit/usage.rst
> +++ b/Documentation/dev-tools/kunit/usage.rst
> @@ -112,11 +112,14 @@ terminates the test case if the condition is not satisfied. For example:
> KUNIT_EXPECT_LE(test, a[i], a[i + 1]);
> }
>
> -In this example, the method under test should return pointer to a value. If the
> -pointer returns null or an errno, we want to stop the test since the following
> -expectation could crash the test case. `ASSERT_NOT_ERR_OR_NULL(...)` allows us
> -to bail out of the test case if the appropriate conditions are not satisfied to
> -complete the test.
> +In this example, we need to be able to allocate an array to test the ``sort()``
> +function. So we use ``KUNIT_ASSERT_NOT_ERR_OR_NULL()`` to abort the test if
> +there's an allocation error.
> +
> +.. note::
> + In other test frameworks, ``ASSERT`` macros are often implemented by calling
> + ``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.
>
> Customizing error messages
> --------------------------
> --
> 2.38.1.431.g37b22c650d-goog
>
Download attachment "smime.p7s" of type "application/pkcs7-signature" (4003 bytes)
Powered by blists - more mailing lists