linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: David Gow <davidgow@google.com>,
	Brendan Higgins <brendan.higgins@linux.dev>,
	Daniel Latypov <dlatypov@google.com>,
	Shuah Khan <skhan@linuxfoundation.org>
Cc: kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH 2/2] kunit: Use the static key in kunit_fail_current_test()
Date: Fri, 21 Oct 2022 07:16:46 -0700	[thread overview]
Message-ID: <C8A2E3D7-E62D-43B3-AECC-3B6117E1DD0E@kernel.org> (raw)
In-Reply-To: <20221021072854.333010-2-davidgow@google.com>

On October 21, 2022 12:28:55 AM PDT, David Gow <davidgow@google.com> wrote:
>Speed up the case where kunit_fail_current_test() is called when no test
>is running. This should make it convenient for code to call this
>unconditionally in some error paths, without fear of causing a
>performance problem.

A third patch showing these cases may help in understanding the utility. I get it, but I lack imagination on where/why they would be added. :)

>
>If CONFIG_KUNIT=n, this compiles away to nothing. If CONFIG_KUNIT=y, it
>will compile down to a NOP (on most architectures) if no KUnit test is
>currently running. kunit_fail_current_test() does not work if KUnit
>itself is built as a module, though this is a pre-existing limitation.
>
>Note that the definition of kunit_fail_current_test() still wraps an
>empty, inline function if KUnit is not built-in. This is to ensure that
>the printf format string __attribute__ will still work.
>
>Signed-off-by: David Gow <davidgow@google.com>
>---
> include/kunit/test-bug.h | 19 ++++++++++++++++---
> 1 file changed, 16 insertions(+), 3 deletions(-)
>
>diff --git a/include/kunit/test-bug.h b/include/kunit/test-bug.h
>index 5fc58081d511..ba9558a9f9c0 100644
>--- a/include/kunit/test-bug.h
>+++ b/include/kunit/test-bug.h
>@@ -9,16 +9,29 @@
> #ifndef _KUNIT_TEST_BUG_H
> #define _KUNIT_TEST_BUG_H
> 
>-#define kunit_fail_current_test(fmt, ...) \
>-	__kunit_fail_current_test(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
>-
> #if IS_BUILTIN(CONFIG_KUNIT)
> 
>+#include <linux/jump_label.h> /* For static branch */
>+
>+/* Static key if KUnit is running any tests. */
>+extern struct static_key_false kunit_running;
>+
>+#define kunit_fail_current_test(fmt, ...) do {					\
>+	if (static_branch_unlikely(&kunit_running)) {				\

This trailing { should be dropped.

>+		__kunit_fail_current_test(__FILE__, __LINE__,			\
>+					  fmt, ##__VA_ARGS__);			\

Or a closing one added here. (The {}s are unbalanced, as 0day complained about.)

>+	} while (0)
>+
>+
> extern __printf(3, 4) void __kunit_fail_current_test(const char *file, int line,
> 						    const char *fmt, ...);
> 
> #else
> 
>+/* We define this with an empty helper function so format string warnings work */
>+#define kunit_fail_current_test(fmt, ...) \
>+		__kunit_fail_current_test(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
>+
> static inline __printf(3, 4) void __kunit_fail_current_test(const char *file, int line,
> 							    const char *fmt, ...)
> {


-- 
Kees Cook

      reply	other threads:[~2022-10-21 14:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21  7:28 [PATCH 1/2] kunit: Provide a static key to check if KUnit is actively running tests David Gow
2022-10-21  7:28 ` [PATCH 2/2] kunit: Use the static key in kunit_fail_current_test() David Gow
2022-10-21 14:16   ` Kees Cook [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C8A2E3D7-E62D-43B3-AECC-3B6117E1DD0E@kernel.org \
    --to=kees@kernel.org \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=keescook@chromium.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).