public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: David Gow <david@davidgow.net>
To: Albert Esteve <aesteve@redhat.com>, Arnd Bergmann <arnd@arndb.de>,
	Brendan Higgins <brendan.higgins@linux.dev>,
	Rae Moar <raemoar63@gmail.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	dri-devel@lists.freedesktop.org, workflows@vger.kernel.org,
	linux-riscv@lists.infradead.org, linux-doc@vger.kernel.org,
	peterz@infradead.org, Guenter Roeck <linux@roeck-us.net>,
	Linux Kernel Functional Testing <lkft@linaro.org>,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Alessandro Carminati <acarmina@redhat.com>,
	Kees Cook <kees@kernel.org>
Subject: Re: [PATCH v8 4/4] kunit: Add documentation for warning backtrace suppression API
Date: Wed, 6 May 2026 17:38:52 +0800	[thread overview]
Message-ID: <428e61d7-bd94-4264-bf7b-950f1dea2da0@davidgow.net> (raw)
In-Reply-To: <20260504-kunit_add_support-v8-4-3e5957cdd235@redhat.com>

Le 04/05/2026 à 3:41 PM, Albert Esteve a écrit :
> From: Guenter Roeck <linux@roeck-us.net>
> 
> Document API functions for suppressing warning backtraces.
> 
> Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
> Acked-by: Dan Carpenter <dan.carpenter@linaro.org>
> Reviewed-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> Reviewed-by: David Gow <davidgow@google.com>
> Signed-off-by: Alessandro Carminati <acarmina@redhat.com>
> Reviewed-by: David Gow <david@davidgow.net>
> Signed-off-by: Albert Esteve <aesteve@redhat.com>
> ---

This is great, thanks!

Reviewed-by: David Gow <david@davidgow.net>

Cheers,
-- David

>   Documentation/dev-tools/kunit/usage.rst | 63 ++++++++++++++++++++++++++++++++-
>   1 file changed, 62 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
> index ebd06f5ea4550..25724f7e72969 100644
> --- a/Documentation/dev-tools/kunit/usage.rst
> +++ b/Documentation/dev-tools/kunit/usage.rst
> @@ -157,6 +157,67 @@ Alternatively, one can take full control over the error message by using
>   	if (some_setup_function())
>   		KUNIT_FAIL(test, "Failed to setup thing for testing");
>   
> +Suppressing warning backtraces
> +------------------------------
> +
> +Some unit tests trigger warning backtraces either intentionally or as a side
> +effect. Such backtraces are normally undesirable since they distract from
> +the actual test and may result in the impression that there is a problem.
> +
> +Backtraces can be suppressed with **task-scoped suppression**: while
> +suppression is active on the current task, the backtrace and stack dump from
> +``WARN*()``, ``WARN_ON*()``, and related macros on that task are suppressed.
> +Three API forms are available, in order of convenience.
> +
> +- Scoped suppression is the simplest form. Wrap the code that triggers
> +  warnings in a ``kunit_warning_suppress()`` block:
> +
> +.. code-block:: c
> +
> +	static void some_test(struct kunit *test)
> +	{
> +		kunit_warning_suppress(test) {
> +			trigger_backtrace();
> +			KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
> +		}
> +	}
> +
> +.. note::
> +   The warning count must be checked inside the block; the suppression handle
> +   is not accessible after the block exits.
> +
> +- Manual macros are useful when the suppressed region is large enough that
> +  extra indentation is undesirable, or when the warning count needs to be
> +  checked after suppression ends. ``KUNIT_START_SUPPRESSED_WARNING()`` must
> +  appear before ``KUNIT_END_SUPPRESSED_WARNING()`` in the same scope.
> +  Limited to one pair per scope.
> +
> +.. code-block:: c
> +
> +	static void some_test(struct kunit *test)
> +	{
> +		KUNIT_START_SUPPRESSED_WARNING(test);
> +		trigger_backtrace();
> +		KUNIT_END_SUPPRESSED_WARNING(test);
> +
> +		KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
> +	}
> +
> +- Direct functions return an explicit handle pointer. Use them when the handle
> +  needs to be retained or passed across helper functions:
> +
> +.. code-block:: c
> +
> +	static void some_test(struct kunit *test)
> +	{
> +		struct kunit_suppressed_warning *w;
> +
> +		w = kunit_start_suppress_warning(test);
> +		trigger_backtrace();
> +		kunit_end_suppress_warning(test, w);
> +
> +		KUNIT_EXPECT_EQ(test, kunit_suppressed_warning_count(w), 1);
> +	}
>   
>   Test Suites
>   ~~~~~~~~~~~
> @@ -1211,4 +1272,4 @@ For example:
>   		dev_managed_string = devm_kstrdup(fake_device, "Hello, World!");
>   
>   		// Everything is cleaned up automatically when the test ends.
> -	}
> \ No newline at end of file
> +	}
> 


      reply	other threads:[~2026-05-06  9:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-04  7:41 [PATCH v8 0/4] kunit: Add support for suppressing warning backtraces Albert Esteve
2026-05-04  7:41 ` [PATCH v8 1/4] bug/kunit: Core " Albert Esteve
2026-05-06  9:38   ` David Gow
2026-05-06 10:11     ` Albert Esteve
2026-05-04  7:41 ` [PATCH v8 2/4] kunit: Add backtrace suppression self-tests Albert Esteve
2026-05-06  9:38   ` David Gow
2026-05-04  7:41 ` [PATCH v8 3/4] drm: Suppress intentional warning backtraces in scaling unit tests Albert Esteve
2026-05-04 10:03   ` Maxime Ripard
2026-05-06  8:37     ` Albert Esteve
2026-05-06  9:38   ` David Gow
2026-05-06  9:48     ` Maxime Ripard
2026-05-04  7:41 ` [PATCH v8 4/4] kunit: Add documentation for warning backtrace suppression API Albert Esteve
2026-05-06  9:38   ` David Gow [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=428e61d7-bd94-4264-bf7b-950f1dea2da0@davidgow.net \
    --to=david@davidgow.net \
    --cc=acarmina@redhat.com \
    --cc=aesteve@redhat.com \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=arnd@arndb.de \
    --cc=brendan.higgins@linux.dev \
    --cc=corbet@lwn.net \
    --cc=dan.carpenter@linaro.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kees@kernel.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux@roeck-us.net \
    --cc=lkft@linaro.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=peterz@infradead.org \
    --cc=pjw@kernel.org \
    --cc=raemoar63@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.org \
    --cc=tzimmermann@suse.de \
    --cc=workflows@vger.kernel.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