From nobody Fri Dec 19 20:42:17 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BECA202C30 for ; Mon, 26 May 2025 13:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266105; cv=none; b=OA5o39mZUDyPjOr4NQucCYHJZEJNqVT8PKwYQ/MuDxv0OdCWr9DN7rz2X/Xl+mHtYDVSlScbwtFlkrtpJUCmTuoZjxyC++roz8iXxyAwhlrF4M5IH0dKfUxAisKO4D2jX4Gq2R8CavvhueZ/aUDLRkGPsKdMgjsN3tesiuezolY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266105; c=relaxed/simple; bh=n5d4OGoYqctd2xiuPMjzJfNMCDRu7K0X6TIZ9vKgqEE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-type; b=sikcP0//xXGMAkCL7+BCv2EZ6M/NUP2vxIJuh41daXdNLhM3pwEbgXYWZBQq+RI+jKhpAszUsOLw7gOO7nQwhR6JE6VoT2jGQQk3+w1z11+yi0jY2UTq04Sg+Em0/4NJNfUFYbadNCjM56uruJvzdh47u3XMWrK4bibHIOt6bic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=avwsqcbA; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="avwsqcbA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748266102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t9vjEnV/6++7H0UqvKE3E1Ij3XuBUAM7NnKxdzBpzS8=; b=avwsqcbAmO970Tf9nLpXcCeYCGspHo+MJvp5rNoZxLy0G+Ty/tP3HpR3eUGCxS5dpXVJf/ D1Z5Sb/NYot3zQcuf8I0HXPfzNJsLV/CsEPFSvw03voxbSrwWBC2qZ22l/msVrqH45BP0h u3mP7sJNZi7PLFrNb4bZS1FGhc+TUjw= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-6Dm4EgpnO1GxsKjcVoZyMQ-1; Mon, 26 May 2025 09:28:18 -0400 X-MC-Unique: 6Dm4EgpnO1GxsKjcVoZyMQ-1 X-Mimecast-MFC-AGG-ID: 6Dm4EgpnO1GxsKjcVoZyMQ_1748266097 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a4dcfc375aso438224f8f.2 for ; Mon, 26 May 2025 06:28:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748266097; x=1748870897; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t9vjEnV/6++7H0UqvKE3E1Ij3XuBUAM7NnKxdzBpzS8=; b=wrk/02Jl2pe59/29BcZmJmVpbqS2mMRAcK+nDeJOz2+zq6kGJXj+VqUGOtB60MvLD/ FKeCxyiH7lM6J0GrMeRlUWhmVJdIdBo7iUIA/XInSvSxIiqCZdLPD4z+9M1UvPX8Q8uf CS6+DaG/efedXqZ2wSBUmJ/PqvvMJbK2fjpkhgesomVdUcU1oRpSpzxTwdMPvb7xSLnm DYx5joYTci62uyLVSgorii76qh1bWNjWPRGiF5QH5h4y9PTSQSzAlyjlWmP2RCIsZpcG ismDOcvm27OgLLDezTEw7bQuUNaKqWakSB2whpfj0IzcxnjAjV2/WOgOPCy0uwWImnFg cyUw== X-Forwarded-Encrypted: i=1; AJvYcCVVvb862nztthiAWn6CiFIpXUcnsmC4iNDi6kmeRe6TkY6uu2wmC4FLZP1idOVJ1skQkXVGnAu1HaE8gG0=@vger.kernel.org X-Gm-Message-State: AOJu0YzcYofx9IfhzkP2c7dHZfegJJEsjryOJMqp9L6ZvG3gh92Zq3q1 asfRg4dWTnQPL9RmZHEVLfKA2dI55PTv1vl2csOXCdY8AyVMdbzvLkWTQKnUwVT4xo3+fvhvVbK mj6wO1AuxGbuzh3Sqp9eF62eyD5dRWWtG2RW5LCQo5xlD91Po5z54EcOL3ISGJKLMbg== X-Gm-Gg: ASbGncvYhFQljX/Gq2JXwAekEwCXuTVyzJrIxRvrIqKOVZ//JGtpxgcRu2/s2kNvCJ7 kTljW/un8iNcnESbeAuJfB/xsYaS/nZF+pHcu/pW0fl/s3EumrzzYj4TYD1xMqx133WJIUBhB2N EMuKAbJworEWBc5FzBZIg2OuWqwaA4s5h7punS/dEyA3RFkJxnFiDD/ZFXxVoKj6brFaL5euo2H NWs+45cbMCsHzggF89kcTkzZd5ckodr6Xuf6VtATkwf5JEeg7WBTaFgcMSlPEfobtnvjo4nrWnc q7zoMipty6UliGJd X-Received: by 2002:a05:6000:2389:b0:3a4:d238:682c with SMTP id ffacd0b85a97d-3a4d2386cfbmr4387683f8f.53.1748266096753; Mon, 26 May 2025 06:28:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+TzELYirrzRn6GPl7VyqI1Bh67rUmwdFP6IvCc7nKkcDX0YZ4TFGDqi0wpDkJs21TebdnUg== X-Received: by 2002:a05:6000:2389:b0:3a4:d238:682c with SMTP id ffacd0b85a97d-3a4d2386cfbmr4387648f8f.53.1748266096286; Mon, 26 May 2025 06:28:16 -0700 (PDT) Received: from lab.hqhome163.com ([81.57.75.210]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4c8455e7dsm8836663f8f.9.2025.05.26.06.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 06:28:15 -0700 (PDT) From: Alessandro Carminati To: linux-kselftest@vger.kernel.org Cc: Dan Carpenter , Kees Cook , Daniel Diaz , David Gow , Arthur Grillo , Brendan Higgins , Naresh Kamboju , Andrew Morton , Maxime Ripard , Ville Syrjala , Daniel Vetter , Guenter Roeck , Alessandro Carminati , Jani Nikula , Jeff Johnson , Peter Zijlstra , Josh Poimboeuf , Shuah Khan , Linux Kernel Functional Testing , dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Alessandro Carminati Subject: [PATCH v5 1/5] bug/kunit: Core support for suppressing warning backtraces Date: Mon, 26 May 2025 13:27:51 +0000 Message-Id: <20250526132755.166150-2-acarmina@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250526132755.166150-1-acarmina@redhat.com> References: <20250526132755.166150-1-acarmina@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some unit tests intentionally trigger warning backtraces by passing bad parameters to kernel API functions. Such unit tests typically check the return value from such calls, not the existence of the warning backtrace. Such intentionally generated warning backtraces are neither desirable nor useful for a number of reasons: - They can result in overlooked real problems. - A warning that suddenly starts to show up in unit tests needs to be investigated and has to be marked to be ignored, for example by adjusting filter scripts. Such filters are ad hoc because there is no real standard format for warnings. On top of that, such filter scripts would require constant maintenance. Solve the problem by providing a means to identify and suppress specific warning backtraces while executing test code. Support suppressing multiple backtraces while at the same time limiting changes to generic code to the absolute minimum. Implementation details: Check suppression directly in the `WARN()` Macros. This avoids the need for function symbol resolution or ELF section modification. Suppression is implemented directly in the `WARN*()` macros. A helper function, `__kunit_is_suppressed_warning()`, is used to determine whether suppression applies. It is marked as `noinstr`, since some `WARN*()` sites reside in non-instrumentable sections. As it uses `strcmp`, a `noinstr` version of `strcmp` was introduced. The implementation is deliberately simple and avoids architecture-specific optimizations to preserve portability. Since this mechanism compares function names and is intended for test usage only, performance is not a primary concern. Signed-off-by: Guenter Roeck Signed-off-by: Alessandro Carminati Reviewed-by: Kees Cook --- include/asm-generic/bug.h | 41 ++++++++++++++++---------- include/kunit/bug.h | 61 +++++++++++++++++++++++++++++++++++++++ include/kunit/test.h | 1 + lib/kunit/Kconfig | 9 ++++++ lib/kunit/Makefile | 6 ++-- lib/kunit/bug.c | 50 ++++++++++++++++++++++++++++++++ 6 files changed, 151 insertions(+), 17 deletions(-) create mode 100644 include/kunit/bug.h create mode 100644 lib/kunit/bug.c diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index 387720933973..3cc8cb100ccd 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -18,6 +18,7 @@ #endif =20 #ifndef __ASSEMBLY__ +#include #include #include =20 @@ -61,9 +62,12 @@ struct bug_entry { */ #ifndef HAVE_ARCH_BUG #define BUG() do { \ - printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ - barrier_before_unreachable(); \ - panic("BUG!"); \ + if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ + printk("BUG: failure at %s:%d/%s()!\n", __FILE__, \ + __LINE__, __func__); \ + barrier_before_unreachable(); \ + panic("BUG!"); \ + } } while (0) #endif =20 @@ -95,21 +99,26 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); #ifndef __WARN_FLAGS #define __WARN() __WARN_printf(TAINT_WARN, NULL) #define __WARN_printf(taint, arg...) do { \ - instrumentation_begin(); \ - warn_slowpath_fmt(__FILE__, __LINE__, taint, arg); \ - instrumentation_end(); \ + if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ + instrumentation_begin(); \ + warn_slowpath_fmt(__FILE__, __LINE__, taint, arg);\ + instrumentation_end(); \ + } } while (0) #else #define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN)) #define __WARN_printf(taint, arg...) do { \ - instrumentation_begin(); \ - __warn_printk(arg); \ - __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\ - instrumentation_end(); \ + if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ + instrumentation_begin(); \ + __warn_printk(arg); \ + __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | \ + BUGFLAG_TAINT(taint)); \ + instrumentation_end(); \ + } \ } while (0) #define WARN_ON_ONCE(condition) ({ \ int __ret_warn_on =3D !!(condition); \ - if (unlikely(__ret_warn_on)) \ + if (unlikely(__ret_warn_on) && !KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ __WARN_FLAGS(BUGFLAG_ONCE | \ BUGFLAG_TAINT(TAINT_WARN)); \ unlikely(__ret_warn_on); \ @@ -121,7 +130,7 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); #ifndef WARN_ON #define WARN_ON(condition) ({ \ int __ret_warn_on =3D !!(condition); \ - if (unlikely(__ret_warn_on)) \ + if (unlikely(__ret_warn_on) && !KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ __WARN(); \ unlikely(__ret_warn_on); \ }) @@ -138,7 +147,7 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); =20 #define WARN_TAINT(condition, taint, format...) ({ \ int __ret_warn_on =3D !!(condition); \ - if (unlikely(__ret_warn_on)) \ + if (unlikely(__ret_warn_on) && !KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ __WARN_printf(taint, format); \ unlikely(__ret_warn_on); \ }) @@ -157,8 +166,10 @@ extern __printf(1, 2) void __warn_printk(const char *f= mt, ...); #else /* !CONFIG_BUG */ #ifndef HAVE_ARCH_BUG #define BUG() do { \ - do {} while (1); \ - unreachable(); \ + if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ + do {} while (1); \ + unreachable(); \ + } \ } while (0) #endif =20 diff --git a/include/kunit/bug.h b/include/kunit/bug.h new file mode 100644 index 000000000000..9a4eff2897e9 --- /dev/null +++ b/include/kunit/bug.h @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit helpers for backtrace suppression + * + * Copyright (C) 2025 Alessandro Carminati + * Copyright (C) 2024 Guenter Roeck + */ + +#ifndef _KUNIT_BUG_H +#define _KUNIT_BUG_H + +#ifndef __ASSEMBLY__ + +#include + +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE + +#include +#include + +struct __suppressed_warning { + struct list_head node; + const char *function; + int counter; +}; + +void __kunit_start_suppress_warning(struct __suppressed_warning *warning); +void __kunit_end_suppress_warning(struct __suppressed_warning *warning); +bool __kunit_is_suppressed_warning(const char *function); + +#define KUNIT_DEFINE_SUPPRESSED_WARNING(func) \ + struct __suppressed_warning __kunit_suppress_##func =3D \ + { .function =3D __stringify(func), .counter =3D 0 } + +#define KUNIT_START_SUPPRESSED_WARNING(func) \ + __kunit_start_suppress_warning(&__kunit_suppress_##func) + +#define KUNIT_END_SUPPRESSED_WARNING(func) \ + __kunit_end_suppress_warning(&__kunit_suppress_##func) + +#define KUNIT_IS_SUPPRESSED_WARNING(func) \ + __kunit_is_suppressed_warning(func) + +#define KUNIT_SUPPRESSED_WARNING_COUNT(func) \ + (__kunit_suppress_##func.counter) + +#define KUNIT_SUPPRESSED_WARNING_COUNT_RESET(func) \ + __kunit_suppress_##func.counter =3D 0 + +#else /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ + +#define KUNIT_DEFINE_SUPPRESSED_WARNING(func) +#define KUNIT_START_SUPPRESSED_WARNING(func) +#define KUNIT_END_SUPPRESSED_WARNING(func) +#define KUNIT_IS_SUPPRESSED_WARNING(func) (false) +#define KUNIT_SUPPRESSED_WARNING_COUNT(func) (0) +#define KUNIT_SUPPRESSED_WARNING_COUNT_RESET(func) + +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#endif /* __ASSEMBLY__ */ +#endif /* _KUNIT_BUG_H */ diff --git a/include/kunit/test.h b/include/kunit/test.h index 39c768f87dc9..bd810ea2f869 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -10,6 +10,7 @@ #define _KUNIT_TEST_H =20 #include +#include #include =20 #include diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index a97897edd964..201402f0ab49 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -15,6 +15,15 @@ menuconfig KUNIT =20 if KUNIT =20 +config KUNIT_SUPPRESS_BACKTRACE + bool "KUnit - Enable backtrace suppression" + default y + help + Enable backtrace suppression for KUnit. If enabled, backtraces + generated intentionally by KUnit tests are suppressed. Disable + to reduce kernel image size if image size is more important than + suppression of backtraces generated by KUnit tests. + config KUNIT_DEBUGFS bool "KUnit - Enable /sys/kernel/debug/kunit debugfs representation" if != KUNIT_ALL_TESTS default KUNIT_ALL_TESTS diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 5aa51978e456..3195e861d63c 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -16,8 +16,10 @@ ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o endif =20 -# KUnit 'hooks' are built-in even when KUnit is built as a module. -obj-y +=3D hooks.o +# KUnit 'hooks' and bug handling are built-in even when KUnit is built +# as a module. +obj-y +=3D hooks.o \ + bug.o =20 obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o diff --git a/lib/kunit/bug.c b/lib/kunit/bug.c new file mode 100644 index 000000000000..4da9ae478f25 --- /dev/null +++ b/lib/kunit/bug.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit helpers for backtrace suppression + * + * Copyright (C) 2025 Alessandro Carminati + * Copyright (C) 2024 Guenter Roeck + */ + +#include +#include +#include + +static LIST_HEAD(suppressed_warnings); + +void __kunit_start_suppress_warning(struct __suppressed_warning *warning) +{ + list_add(&warning->node, &suppressed_warnings); +} +EXPORT_SYMBOL_GPL(__kunit_start_suppress_warning); + +void __kunit_end_suppress_warning(struct __suppressed_warning *warning) +{ + list_del(&warning->node); +} +EXPORT_SYMBOL_GPL(__kunit_end_suppress_warning); + +static noinstr int kunit_strcmp(const char *s1, const char *s2) { + while (*s1 !=3D '\0' && *s1 =3D=3D *s2) { + s1++; + s2++; + } + return *(const unsigned char*)s1 - *(const unsigned char*)s2; +} + +noinstr bool __kunit_is_suppressed_warning(const char *function) +{ + struct __suppressed_warning *warning; + + if (!function) + return false; + + list_for_each_entry(warning, &suppressed_warnings, node) { + if (!kunit_strcmp(function, warning->function)) { + warning->counter++; + return true; + } + } + return false; +} +EXPORT_SYMBOL_GPL(__kunit_is_suppressed_warning); --=20 2.34.1 From nobody Fri Dec 19 20:42:17 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CB11202F67 for ; Mon, 26 May 2025 13:28:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266103; cv=none; b=o30ZfKreIBnbfQJPnTuEA9H9k7U853cZrV7+PNguh3EsjaNiGHrK0bcBCyB77aiyGYMcGCVYUeNZ9MSGqx2TYC1+xgSJdVdZ8oBxpa+QGvgyeSYE52B8b+jUnKyihup9BeFEJHms3CdRrpKoXPuJcJkBuQv09iueEQ+IS2yY+AM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266103; c=relaxed/simple; bh=+87yx7PFE+dmNd8ZWYDr1ls094OuOxH6ApcNFb2s70I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-type; b=mgO+zCsc/qSO5iourAWJjKxc2wW9+BXnE7SOgTMd0H/iIUlVV2fohPTO+ftpvD+qBjqAgnEF1lfCTryggj3wjZYAUlpaMAGoATk1m5ftz4kolOnNokYj+RBWHxw0NAH1wEMJ8/L3xhGQR+ZZXEjSuKug/O47nWHwqzDTpZRmI3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MGM2s/zs; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MGM2s/zs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748266101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oPlt4ytZ6F2hvn0V4PkuFNl5i8ajyUihcCaYhF+iFpQ=; b=MGM2s/zsTevNq8B8sZZ3VvKz82NEU6wxR72R98BbGILdveJGHj/JDHLrtWgvmT5WKlX9fe 0j6CycVonIilZSOlblfJ28TOUsfvvJviU0C7gMPMF300AtRN72EyPpGpBLl40zik2M4Lxl 3fOqZySjlnLayf9GBLuBnOm4y1SP+24= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-pQQ1tvU0NpqjZFOWcvbg7g-1; Mon, 26 May 2025 09:28:20 -0400 X-MC-Unique: pQQ1tvU0NpqjZFOWcvbg7g-1 X-Mimecast-MFC-AGG-ID: pQQ1tvU0NpqjZFOWcvbg7g_1748266099 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a375938404so1493694f8f.0 for ; Mon, 26 May 2025 06:28:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748266099; x=1748870899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oPlt4ytZ6F2hvn0V4PkuFNl5i8ajyUihcCaYhF+iFpQ=; b=QazP3E0hHrb/4rpM9Jr42iKjrjRqO6F8BjlWQ7MxdfQ0uGQG4an4+7PVc42M6KCOct c0jqB5Ig2MXilFkU2H6T4vlCSAyaJS5S+ogo/dOuHy8T5F434DIjVoBnHanGohQNi3GC dA6Gt7zMDVi4E1R/ICKvYmNgSnrCHgd1UiovpFoW5pc6Wj/5e3afYcyreKSs6ZxeFige xBecCSUdaSXuGMDSMyWC5ypewvlR9UJIqBr00Dodec2AF6/kWxh0KycdLfP5oelxgJZ2 r5fQPkj/0qi/VO33Ny9CFVTeqepxIR1D2PmetJgD+xLPxMKY1MhKutODYrLVS2B33CsO z3tQ== X-Forwarded-Encrypted: i=1; AJvYcCXbFx87HGe0+jE1HTLxM403nV7WiMRFOr9/NIRAhJZsogmJNHIwhZaw/4NLniGPgfyuMc7KIll2xNKZluU=@vger.kernel.org X-Gm-Message-State: AOJu0YzfIZyUH/fJODGLORaJ628K8cigj8FLAWCNQza7FvsgG3O8T3iz JAyx7+ajATlQRfzyGV3L8yuufNViskbE7P7DzfOvZMJphE4G9Q1DJkWW34o/BHAtY0yfsJdrmb5 Tv9dbldvOt4L83GJjR8ONtaxfjnBq7ewvjfJlsxvYxcf79t55mvwc2lMzzHxUFSarHw== X-Gm-Gg: ASbGncvKXWtypgLXSaVDKF/F7EAPxkKTn0Ex1c3WhGL/CPoqF2RRI/h+d3ysOkJ/sLE UQtVxPeHSzeQow3rOinXvd50LTos0EUKp9N3eyclI3XCm1X6KWET4SETJJk4lbo2Lm3AY8GIIoI jhmVETzdVkBRsVJdtkV4buMOoBSlKqaxFSmz1iUfg4+mVe29VfbfblDT0yw4HYmIgL+Y99GHiO3 wf0/bw2WK3d0qJTbxhLVB+wK+5nXJjJxKRQisSXfOfK3A2981qflh+/GqmSSR9vBTGEK+eJ8hl2 BLbdA7OMGO4sT8uw X-Received: by 2002:a05:6000:430c:b0:3a4:dd63:4aec with SMTP id ffacd0b85a97d-3a4dd634cfcmr1564326f8f.48.1748266098639; Mon, 26 May 2025 06:28:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfQ14aemGGVrnyyULM4fmrilLUTKS/3ULR87fBB6DJGO5nAXb+suetmJzZdWhNA46LzsMX5w== X-Received: by 2002:a05:6000:430c:b0:3a4:dd63:4aec with SMTP id ffacd0b85a97d-3a4dd634cfcmr1564292f8f.48.1748266098242; Mon, 26 May 2025 06:28:18 -0700 (PDT) Received: from lab.hqhome163.com ([81.57.75.210]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4c8455e7dsm8836663f8f.9.2025.05.26.06.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 06:28:17 -0700 (PDT) From: Alessandro Carminati To: linux-kselftest@vger.kernel.org Cc: Dan Carpenter , Kees Cook , Daniel Diaz , David Gow , Arthur Grillo , Brendan Higgins , Naresh Kamboju , Andrew Morton , Maxime Ripard , Ville Syrjala , Daniel Vetter , Guenter Roeck , Alessandro Carminati , Jani Nikula , Jeff Johnson , Peter Zijlstra , Josh Poimboeuf , Shuah Khan , Linux Kernel Functional Testing , dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Alessandro Carminati Subject: [PATCH v5 2/5] bug/kunit: Suppressing warning backtraces reduced impact on WARN*() sites Date: Mon, 26 May 2025 13:27:52 +0000 Message-Id: <20250526132755.166150-3-acarmina@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250526132755.166150-1-acarmina@redhat.com> References: <20250526132755.166150-1-acarmina@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" KUnit support is not consistently present across distributions, some include it in their stock kernels, while others do not. While both KUNIT and KUNIT_SUPPRESS_BACKTRACE can be considered debug features, the fact that some distros ship with KUnit enabled means it's important to minimize the runtime impact of this patch. To that end, this patch introduces a counter for the number of suppressed symbols and skips execution of __kunit_is_suppressed_warning() entirely when no symbols are currently being suppressed. Signed-off-by: Alessandro Carminati --- include/asm-generic/bug.h | 21 ++++++++++++++------- include/kunit/bug.h | 1 + lib/kunit/bug.c | 4 ++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index 3cc8cb100ccd..c5587820bd8c 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -62,7 +62,8 @@ struct bug_entry { */ #ifndef HAVE_ARCH_BUG #define BUG() do { \ - if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ + if (suppressed_symbols_cnt && \ + !KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ printk("BUG: failure at %s:%d/%s()!\n", __FILE__, \ __LINE__, __func__); \ barrier_before_unreachable(); \ @@ -99,7 +100,8 @@ extern __printf(1, 2) void __warn_printk(const char *fmt= , ...); #ifndef __WARN_FLAGS #define __WARN() __WARN_printf(TAINT_WARN, NULL) #define __WARN_printf(taint, arg...) do { \ - if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ + if (suppressed_symbols_cnt && \ + !KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ instrumentation_begin(); \ warn_slowpath_fmt(__FILE__, __LINE__, taint, arg);\ instrumentation_end(); \ @@ -108,7 +110,8 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); #else #define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN)) #define __WARN_printf(taint, arg...) do { \ - if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ + if (suppressed_symbols_cnt && \ + !KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ instrumentation_begin(); \ __warn_printk(arg); \ __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | \ @@ -118,7 +121,8 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); } while (0) #define WARN_ON_ONCE(condition) ({ \ int __ret_warn_on =3D !!(condition); \ - if (unlikely(__ret_warn_on) && !KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ + if (unlikely(__ret_warn_on) && suppressed_symbols_cnt &&\ + !KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ __WARN_FLAGS(BUGFLAG_ONCE | \ BUGFLAG_TAINT(TAINT_WARN)); \ unlikely(__ret_warn_on); \ @@ -130,7 +134,8 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); #ifndef WARN_ON #define WARN_ON(condition) ({ \ int __ret_warn_on =3D !!(condition); \ - if (unlikely(__ret_warn_on) && !KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ + if (unlikely(__ret_warn_on) && suppressed_symbols_cnt && \ + !KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ __WARN(); \ unlikely(__ret_warn_on); \ }) @@ -147,7 +152,8 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); =20 #define WARN_TAINT(condition, taint, format...) ({ \ int __ret_warn_on =3D !!(condition); \ - if (unlikely(__ret_warn_on) && !KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ + if (unlikely(__ret_warn_on) && suppressed_symbols_cnt && \ + !KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ __WARN_printf(taint, format); \ unlikely(__ret_warn_on); \ }) @@ -166,7 +172,8 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); #else /* !CONFIG_BUG */ #ifndef HAVE_ARCH_BUG #define BUG() do { \ - if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ + if (suppressed_symbols_cnt && \ + !KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ do {} while (1); \ unreachable(); \ } \ diff --git a/include/kunit/bug.h b/include/kunit/bug.h index 9a4eff2897e9..3256e3f2c165 100644 --- a/include/kunit/bug.h +++ b/include/kunit/bug.h @@ -23,6 +23,7 @@ struct __suppressed_warning { const char *function; int counter; }; +extern int suppressed_symbols_cnt; =20 void __kunit_start_suppress_warning(struct __suppressed_warning *warning); void __kunit_end_suppress_warning(struct __suppressed_warning *warning); diff --git a/lib/kunit/bug.c b/lib/kunit/bug.c index 4da9ae478f25..5beaee1049eb 100644 --- a/lib/kunit/bug.c +++ b/lib/kunit/bug.c @@ -11,15 +11,19 @@ #include =20 static LIST_HEAD(suppressed_warnings); +int suppressed_symbols_cnt =3D 0; +EXPORT_SYMBOL_GPL(suppressed_symbols_cnt); =20 void __kunit_start_suppress_warning(struct __suppressed_warning *warning) { + suppressed_symbols_cnt++; list_add(&warning->node, &suppressed_warnings); } EXPORT_SYMBOL_GPL(__kunit_start_suppress_warning); =20 void __kunit_end_suppress_warning(struct __suppressed_warning *warning) { + suppressed_symbols_cnt--; list_del(&warning->node); } EXPORT_SYMBOL_GPL(__kunit_end_suppress_warning); --=20 2.34.1 From nobody Fri Dec 19 20:42:17 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 188A8207A25 for ; Mon, 26 May 2025 13:28:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266106; cv=none; b=dKCIFvmtOEReIz8hFjhdlbiekFn4oQQsoFw06y0Tw72HqQ/krHyO5IZA3jWx7nYkDd1Oq0+F5dJXbKIE5HmNhJty3UPxvTNYhrxQ2PgerfyMFG8kZGUX6/MuqvOQ2ywKEXt0YzIYP2iyYLFIhNQuAfwARdKxSjA/i+wNp1CIYgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266106; c=relaxed/simple; bh=7yRg+dfR8t8qM7YDN3CmiOT2bOidYPimlJooWf0iZlk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-type; b=CsoxnxyRDzji4uUHLEr1xrV77wj6LulvN26VFze81sHdVskA7cY/98z2j+v9ymJxyZH8SsOFspggq8lQPUTdBnv2cJOOi0tqHHung02NLs47x4iCeWQBv1tl/ae5CxeGVV4NZcRB6xToO+lSf+ORlh/6A8MyUvHyiXFKDyS9kM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IcyDshW5; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IcyDshW5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748266104; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i0YRJWOlICqCgS45Er6beMSN4o1Be1F4DIB5uq3fyIU=; b=IcyDshW5ZsjTmRzuOqRajmZIJwoXekddLuLWs2yQcQZk2WKkT43gTNX4I66FZ6bObhPORH NQVGJ7TPs3m8azfyuso8OWgfkKOYZ9b3s36K2ke7SamfWVoB4WRd6OGF6Gj0Gs7ALT4DoU Mzg39RU2VtS/Xgvao1kBq1jdAeGWD3Q= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-rRdZDhPnOG2RIm4XzXZ6_Q-1; Mon, 26 May 2025 09:28:22 -0400 X-MC-Unique: rRdZDhPnOG2RIm4XzXZ6_Q-1 X-Mimecast-MFC-AGG-ID: rRdZDhPnOG2RIm4XzXZ6_Q_1748266101 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a4d95375c6so398364f8f.0 for ; Mon, 26 May 2025 06:28:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748266100; x=1748870900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i0YRJWOlICqCgS45Er6beMSN4o1Be1F4DIB5uq3fyIU=; b=OerURAc9XsSXz2SFmRWbgQR5CkpDeeBDjB72//F1Ut/QqhKbn4h8zwbWku4FRvjBEI mPxcrxwgZ/R+ayDPrehaAknMZcIJiEzSJ9T1Om+BwhE4Od6rcMM+Vp3zUO7k2Nzteo9i 5uTevsTrUC3bAJaJ/8WcdgThBeEUm6556Gq4xPBS2g4xTjqr3BxxxCFf3KwL9mgQVO5k H3fkuvVsggWjoBGB0riaDJ4dej4Qgg+f3Odtwt7T1vjoZqXwGXUZ7PlzQ3QI5SykJL+7 2cwwoz67idgh3H628YXNEo0y3+w8ECqx7bq/LK2LAC29nJJSGsjqyTb5OPjCux9L+hzL yx7g== X-Forwarded-Encrypted: i=1; AJvYcCWwJqvqYlAX3FVfGe/Zh0JqALxNlITZIroT7IACTN50heReCV5niLFgZmggjFz6uPFElI/lH4Lbh7so5Nw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx16XQwMuCQd3K1Q+BHq69yGZzBAXW3zXQRiBKWeWM02vjXdSAY a3YDb80IZoBBIthz1n5r8KasOAsyB6IlRLI3bp7CmT8pVm8IgTSama5Vdp9K7ZM5L/yo81hkWN0 Qsh3OaU1MksTCMTmQ0kHkDB9gROTRJnojGrS8MT4o+XZWOCyk/wrT6s53y4/xCjoUlQ== X-Gm-Gg: ASbGncuhr/L1ktraDfuWpwiPuPwq5CFkRs2fjEc3eP6bcJymCUZtq9Iemo0fWMbbc0j IufayebCrIMoFXI1tH17ZtGe89EcC+rUWgR/ThzwVjvKGDMAxmR9hgnZ1WBpvi6YjWiVKrZT4oI aI9pOUWJz/DsVLa7ahZnDSaYT62u2wb6icxTjouPE7k5BIfL5WP63kRm3hg69lk8bNOok/aBDi+ aXs6mHlemS9cBJa0f2quG5yesqLqok0C57Wjoh+H2EmhcJxBAF1ahQJ9r/DYTvDM3KoRfhL1KUL XjR3B5LHSXfLQkV6 X-Received: by 2002:a05:6000:4022:b0:3a3:7638:d754 with SMTP id ffacd0b85a97d-3a4cb454b98mr7833517f8f.21.1748266100568; Mon, 26 May 2025 06:28:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6pOAvbuHyLjhUOMwzoRe4s1Do1fW/hrkf0UqrCoecUCHTClHzHJUHZb8Hgf3W8Hzp8xWVNA== X-Received: by 2002:a05:6000:4022:b0:3a3:7638:d754 with SMTP id ffacd0b85a97d-3a4cb454b98mr7833471f8f.21.1748266100089; Mon, 26 May 2025 06:28:20 -0700 (PDT) Received: from lab.hqhome163.com ([81.57.75.210]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4c8455e7dsm8836663f8f.9.2025.05.26.06.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 06:28:19 -0700 (PDT) From: Alessandro Carminati To: linux-kselftest@vger.kernel.org Cc: Dan Carpenter , Kees Cook , Daniel Diaz , David Gow , Arthur Grillo , Brendan Higgins , Naresh Kamboju , Andrew Morton , Maxime Ripard , Ville Syrjala , Daniel Vetter , Guenter Roeck , Alessandro Carminati , Jani Nikula , Jeff Johnson , Peter Zijlstra , Josh Poimboeuf , Shuah Khan , Linux Kernel Functional Testing , dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Alessandro Carminati Subject: [PATCH v5 3/5] Add unit tests to verify that warning backtrace suppression works. Date: Mon, 26 May 2025 13:27:53 +0000 Message-Id: <20250526132755.166150-4-acarmina@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250526132755.166150-1-acarmina@redhat.com> References: <20250526132755.166150-1-acarmina@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Guenter Roeck Add unit tests to verify that warning backtrace suppression works. If backtrace suppression does _not_ work, the unit tests will likely trigger unsuppressed backtraces, which should actually help to get the affected architectures / platforms fixed. Tested-by: Linux Kernel Functional Testing Acked-by: Dan Carpenter Reviewed-by: Kees Cook Signed-off-by: Guenter Roeck Signed-off-by: Alessandro Carminati --- lib/kunit/Makefile | 3 + lib/kunit/backtrace-suppression-test.c | 105 +++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 lib/kunit/backtrace-suppression-test.c diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 3195e861d63c..05fb19d69709 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -23,6 +23,9 @@ obj-y +=3D hooks.o \ =20 obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o +ifeq ($(CONFIG_KUNIT_SUPPRESS_BACKTRACE),y) +obj-$(CONFIG_KUNIT_TEST) +=3D backtrace-suppression-test.o +endif =20 # string-stream-test compiles built-in only. ifeq ($(CONFIG_KUNIT_TEST),y) diff --git a/lib/kunit/backtrace-suppression-test.c b/lib/kunit/backtrace-s= uppression-test.c new file mode 100644 index 000000000000..a3d5991b9b15 --- /dev/null +++ b/lib/kunit/backtrace-suppression-test.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit test for suppressing warning tracebacks + * + * Copyright (C) 2024, Guenter Roeck + * Author: Guenter Roeck + */ + +#include +#include + +static void backtrace_suppression_test_warn_direct(struct kunit *test) +{ + KUNIT_DEFINE_SUPPRESSED_WARNING(backtrace_suppression_test_warn_direct); + + KUNIT_START_SUPPRESSED_WARNING(backtrace_suppression_test_warn_direct); + WARN(1, "This backtrace should be suppressed"); + KUNIT_END_SUPPRESSED_WARNING(backtrace_suppression_test_warn_direct); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(backtrace_suppressio= n_test_warn_direct), 1); +} + +static void trigger_backtrace_warn(void) +{ + WARN(1, "This backtrace should be suppressed"); +} + +static void backtrace_suppression_test_warn_indirect(struct kunit *test) +{ + KUNIT_DEFINE_SUPPRESSED_WARNING(trigger_backtrace_warn); + + KUNIT_START_SUPPRESSED_WARNING(trigger_backtrace_warn); + trigger_backtrace_warn(); + KUNIT_END_SUPPRESSED_WARNING(trigger_backtrace_warn); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(trigger_backtrace_wa= rn), 1); +} + +static void backtrace_suppression_test_warn_multi(struct kunit *test) +{ + KUNIT_DEFINE_SUPPRESSED_WARNING(trigger_backtrace_warn); + KUNIT_DEFINE_SUPPRESSED_WARNING(backtrace_suppression_test_warn_multi); + + KUNIT_START_SUPPRESSED_WARNING(backtrace_suppression_test_warn_multi); + KUNIT_START_SUPPRESSED_WARNING(trigger_backtrace_warn); + WARN(1, "This backtrace should be suppressed"); + trigger_backtrace_warn(); + KUNIT_END_SUPPRESSED_WARNING(trigger_backtrace_warn); + KUNIT_END_SUPPRESSED_WARNING(backtrace_suppression_test_warn_multi); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(backtrace_suppressio= n_test_warn_multi), 1); + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(trigger_backtrace_wa= rn), 1); +} + +static void backtrace_suppression_test_warn_on_direct(struct kunit *test) +{ + KUNIT_DEFINE_SUPPRESSED_WARNING(backtrace_suppression_test_warn_on_direct= ); + + if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE) && !IS_ENABLED(CONFIG_KALLSYMS)) + kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE or CONFIG_KALLSYMS"); + + KUNIT_START_SUPPRESSED_WARNING(backtrace_suppression_test_warn_on_direct); + WARN_ON(1); + KUNIT_END_SUPPRESSED_WARNING(backtrace_suppression_test_warn_on_direct); + + KUNIT_EXPECT_EQ(test, + KUNIT_SUPPRESSED_WARNING_COUNT(backtrace_suppression_test_warn_on_direc= t), 1); +} + +static void trigger_backtrace_warn_on(void) +{ + WARN_ON(1); +} + +static void backtrace_suppression_test_warn_on_indirect(struct kunit *test) +{ + KUNIT_DEFINE_SUPPRESSED_WARNING(trigger_backtrace_warn_on); + + if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) + kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE"); + + KUNIT_START_SUPPRESSED_WARNING(trigger_backtrace_warn_on); + trigger_backtrace_warn_on(); + KUNIT_END_SUPPRESSED_WARNING(trigger_backtrace_warn_on); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(trigger_backtrace_wa= rn_on), 1); +} + +static struct kunit_case backtrace_suppression_test_cases[] =3D { + KUNIT_CASE(backtrace_suppression_test_warn_direct), + KUNIT_CASE(backtrace_suppression_test_warn_indirect), + KUNIT_CASE(backtrace_suppression_test_warn_multi), + KUNIT_CASE(backtrace_suppression_test_warn_on_direct), + KUNIT_CASE(backtrace_suppression_test_warn_on_indirect), + {} +}; + +static struct kunit_suite backtrace_suppression_test_suite =3D { + .name =3D "backtrace-suppression-test", + .test_cases =3D backtrace_suppression_test_cases, +}; +kunit_test_suites(&backtrace_suppression_test_suite); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("KUnit test to verify warning backtrace suppression"); --=20 2.34.1 From nobody Fri Dec 19 20:42:17 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AAF520AF98 for ; Mon, 26 May 2025 13:28:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266107; cv=none; b=JozItrA+G8oX8plkVJ03+mR/Bx7V2nUhKRovDjEClaRjdxpbm3yKJTsB0m7b9ajGGVL8YU85YqeL3/FFpVBHQa5bVuGsMxllHqbfIlLe+FqJky3trIfHF0FuxRX14Nuzi8kllfyCyU1W6z9lUQml4yPPZwOzxVumzeg2eJ3YZy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266107; c=relaxed/simple; bh=6t3eRY7hkJvKtTZGuaky3RihvRWdFfWK3lVmchxIyG0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type:Content-type; b=d5rEKjyMD5ZFZ6xKzLelxuwOox0BdUYb1Ym0/aSjaUf1n9g985XVHxVsFsBiLOousMMVHXXe0A4NPaJ+vY/TJ0ZogW6bjKYoE0hX7QgUt6i3zUnhP8ydVCy6lT3ZHv3hynQNDoaWUvI7ZUStMt89681uadqgPQBccPk2x/9DAm8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Osw74WHx; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Osw74WHx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748266105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tIJNc4z+prl6uqE8TJXFoIi+LuDA64zLV+jmBQfkFuc=; b=Osw74WHxGh/qyWekgIRDKb77Wplwqoib/oD7fhpgC8ToTZZh2eQNGwAJC0XkUW6Pes4r8L CigAd4KDg0I8KyzR5lhngwNfvGef+Z4kbdji6xcgwiUb6khz3orIXN0CliZds/WSTdRnk7 vBgWFplTeqA9L5HfBFKLy2PU5iSsV7g= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-292-IBO5KhujOXKUSnlK_IsTtg-1; Mon, 26 May 2025 09:28:23 -0400 X-MC-Unique: IBO5KhujOXKUSnlK_IsTtg-1 X-Mimecast-MFC-AGG-ID: IBO5KhujOXKUSnlK_IsTtg_1748266103 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43eea5a5d80so14412975e9.1 for ; Mon, 26 May 2025 06:28:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748266102; x=1748870902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tIJNc4z+prl6uqE8TJXFoIi+LuDA64zLV+jmBQfkFuc=; b=lwVvLhBUZU23YR4taXlkrlQKcBByoWdDk9nEpiEDAAbowamTfu69+cwEnBAIr31G10 wnfO9iRpDRD0AK/wyekmamSDJFnDB07pJ2s67PjBJ7MHVmL+Mpr6Be+yHH2VHWPEVB4z Ys12WznG94myh75JeDo8vN8Ljsbl7uAv3Ut2j8oZT8l+oDf4xP6wHjQUobe7QUuzOuP7 tSecMyRcYF2ytN/2D3eCqrdwyjMXekmlu0M2uCdqEfbvEuqtv84Rl4PAf30vJiTiFd+/ 2KYDiVw568tIucGNzo0D064wnD+goahIUjXw543nuHqHM/ltamnQ+lCbfwLVX1qWbHLt OsjA== X-Forwarded-Encrypted: i=1; AJvYcCUTXmV4ULgQaE8dw5BJGVZ3sjM7dOjQyXbS+TAQeYiSuLzZV78jjhMpxO6lHrtVAgph8Lmz9pqjsYFD+Xs=@vger.kernel.org X-Gm-Message-State: AOJu0YyYeNJAXNe/DmQM5wezLgH/1kHOBI3137ke5DyoSHNuH2lxDFFT BBFIlYeelglByy/SM13yr3fdQrqSv+hT0ii5wUcmyOQ6v46pN7BKXY9Q27v5SJgLYy+17CMyMI/ bl2Cs3HfVoFtwPbGQwHbJjCqCnTna/zxYl6IRCIaz2O26dilWM17fiOd9Re0pUbMNDA== X-Gm-Gg: ASbGncsx8oAMF6cwNRBNh/c5SNs00yBYmBHciiZFY9/JT+09uer+0a4oe3f+Ihe9P3n ZLn/gE+XWWib4sBZdSD7VZ8korsMMuvrOEEsZvlx1YnNhwoTO4z0+8HwharR9fhJdglAZDREydr 4e1VicqmWZoVapnI043JqHfnzdxvm6Nh5aSC6inDCQyWE5GiwL+p+vs3KZsSk4SVq+0znSu6QZI paO4UKeiKPfJCyQexNi+uTLC6/ILDqz5k7RZ3QhdiSw7M+skaO3C4TB9tO39zK4Gk59/Go0NahE 5zGbT0rk/FCdmE7d X-Received: by 2002:a7b:cb0e:0:b0:43d:8ea:8d80 with SMTP id 5b1f17b1804b1-44cf6d81628mr43597775e9.5.1748266102530; Mon, 26 May 2025 06:28:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFr19bNHeLuqPTA70dJ3loiMHnX3Wbi8DckD7ViZVw9xearBz01pBMAJtm6RFOqVblZmf8Afw== X-Received: by 2002:a7b:cb0e:0:b0:43d:8ea:8d80 with SMTP id 5b1f17b1804b1-44cf6d81628mr43597425e9.5.1748266102096; Mon, 26 May 2025 06:28:22 -0700 (PDT) Received: from lab.hqhome163.com ([81.57.75.210]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4c8455e7dsm8836663f8f.9.2025.05.26.06.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 06:28:21 -0700 (PDT) From: Alessandro Carminati To: linux-kselftest@vger.kernel.org Cc: Dan Carpenter , Kees Cook , Daniel Diaz , David Gow , Arthur Grillo , Brendan Higgins , Naresh Kamboju , Andrew Morton , Maxime Ripard , Ville Syrjala , Daniel Vetter , Guenter Roeck , Alessandro Carminati , Jani Nikula , Jeff Johnson , Peter Zijlstra , Josh Poimboeuf , Shuah Khan , Linux Kernel Functional Testing , dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, =?UTF-8?q?Ma=C3=ADra=20Canal?= , Maarten Lankhorst , David Airlie , Alessandro Carminati Subject: [PATCH v5 4/5] drm: Suppress intentional warning backtraces in scaling unit tests Date: Mon, 26 May 2025 13:27:54 +0000 Message-Id: <20250526132755.166150-5-acarmina@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250526132755.166150-1-acarmina@redhat.com> References: <20250526132755.166150-1-acarmina@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable From: Guenter Roeck The drm_test_rect_calc_hscale and drm_test_rect_calc_vscale unit tests intentionally trigger warning backtraces by providing bad parameters to the tested functions. What is tested is the return value, not the existence of a warning backtrace. Suppress the backtraces to avoid clogging the kernel log and distraction from real problems. Tested-by: Linux Kernel Functional Testing Acked-by: Dan Carpenter Acked-by: Ma=C3=ADra Canal Cc: Maarten Lankhorst Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Guenter Roeck Signed-off-by: Alessandro Carminati --- drivers/gpu/drm/tests/drm_rect_test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/= drm_rect_test.c index 17e1f34b7610..867845e7d5ab 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -406,22 +406,38 @@ KUNIT_ARRAY_PARAM(drm_rect_scale, drm_rect_scale_case= s, drm_rect_scale_case_desc =20 static void drm_test_rect_calc_hscale(struct kunit *test) { + KUNIT_DEFINE_SUPPRESSED_WARNING(drm_calc_scale); const struct drm_rect_scale_case *params =3D test->param_value; int scaling_factor; =20 + /* + * drm_rect_calc_hscale() generates a warning backtrace whenever bad + * parameters are passed to it. This affects all unit tests with an + * error code in expected_scaling_factor. + */ + KUNIT_START_SUPPRESSED_WARNING(drm_calc_scale); scaling_factor =3D drm_rect_calc_hscale(¶ms->src, ¶ms->dst, params->min_range, params->max_range); + KUNIT_END_SUPPRESSED_WARNING(drm_calc_scale); =20 KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); } =20 static void drm_test_rect_calc_vscale(struct kunit *test) { + KUNIT_DEFINE_SUPPRESSED_WARNING(drm_calc_scale); const struct drm_rect_scale_case *params =3D test->param_value; int scaling_factor; =20 + /* + * drm_rect_calc_vscale() generates a warning backtrace whenever bad + * parameters are passed to it. This affects all unit tests with an + * error code in expected_scaling_factor. + */ + KUNIT_START_SUPPRESSED_WARNING(drm_calc_scale); scaling_factor =3D drm_rect_calc_vscale(¶ms->src, ¶ms->dst, params->min_range, params->max_range); + KUNIT_END_SUPPRESSED_WARNING(drm_calc_scale); =20 KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); } --=20 2.34.1 From nobody Fri Dec 19 20:42:17 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B565B20C004 for ; Mon, 26 May 2025 13:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266109; cv=none; b=advPlFk6y1APA7qd9yGarmw9H2Ddih0zX6msOz7QvURZS6DqRdZB1al4J0Z75ue1HtFp/tLA6CM/MoV79uI/AxcbrDSdhLGTXOc90vac/7mXMaT3o85TVhoGHkLo6TuksmocgVMKkIkuW5CFxqG9RBhrBPcg4Q1gRsYP/gOiWvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748266109; c=relaxed/simple; bh=k/QW8yyThWQYD06PZzn8avBbFa43Ro0Rb4YCVVYWNuQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-type; b=nsn9D7KgsZkF9ZBgDRT5NyCy0H/ohT46Mdr3URSDeLqjg6CPGCCVRQ0+fwHDQiePJE5LFMuas3upFffZ4VzI6/l5zbRleVYsCtlVtyepNvLfsNi8FtyJBdCu7uWxwUemBrPW6kiQKfa9SjzXNw84col/CxoqxgmP8csU7Exr6eM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=A8ubggNr; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A8ubggNr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748266106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=piebsVU5QZFL/FeYXj8vMs1AI4HP2ZYK+Wi3o0pUrOA=; b=A8ubggNrNkDX1RKJqF1qPqkz0ydjr5LpCOonG7x5bJ603FJplLcE1tVS89qofimyVSSsUE zzIYc1Xw3HSXQSmvzlOqq8rXkdePLo+BNgRFXYPwiFo94jCwS+sQ4vu57C/wjvZpCXEQBi AB/xQo/txrNxx+FEs3vaDyGpWET5MM4= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-135-l-JvISr5M9uHzKBZ7xfqoQ-1; Mon, 26 May 2025 09:28:25 -0400 X-MC-Unique: l-JvISr5M9uHzKBZ7xfqoQ-1 X-Mimecast-MFC-AGG-ID: l-JvISr5M9uHzKBZ7xfqoQ_1748266104 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-442f90418b0so12243915e9.2 for ; Mon, 26 May 2025 06:28:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748266104; x=1748870904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=piebsVU5QZFL/FeYXj8vMs1AI4HP2ZYK+Wi3o0pUrOA=; b=RnEkpuXQQSjLzPMHbVp0svr0+uvsadW08R0RD5d2WnAIvxkRlXLDsZvw4n3rk0iQRD 0sobNNYwSdXTxDzCX6psHlZMLMUxEXhXuPbxMOVUokmcPsQsF4Nz7KhZj0a1tzRqDM23 T0QiHKxrYux/gSvSJFihKPOEmynHKvEYmceZDhTmvk1I+8KaXdd/0hKWHWUi2Jq4UZw6 kXMQ3ce+or9uHk2S8vevFxFRXeUAB5+6iF4JszPbK1F45BmBgINOM6fuIHSgxIeQyopo h/+EpMYidczrB0/PsdFT+xbGOTwew6mmgCb9a8EcLxObQGNj8R+VQ2Ti26JgGH20T4zV vysg== X-Forwarded-Encrypted: i=1; AJvYcCWQYkfQuLuHrS473R+vCyW6jWcor/7dNkOkjY7OWrcUxmpkZgUQ5p2XZBJ0KUMo5HrqmaVEjEHcH/nQtKA=@vger.kernel.org X-Gm-Message-State: AOJu0YwujAGfPRmWnKOE6I6Vl3R7qzGt4Qoa3XBsfQEO0GS9zZVEgY6a 53DdDztMhoeJjPVl+DZfE9HYNcdDpL3c+UPQUfpFoje6XTX4AEN4MZ/WLZBDPtfhB+nFcxmzuT2 7Qz/RP3i6ou6chl98l3/6Ise9ZIehLAHTl9Q1ewteIUuZAB+/2teSE8lmadVvFtiN0Q== X-Gm-Gg: ASbGnctAQnmK6fPLaHGFFPHU1OBAtup3Ko1nDUfaLwkF4+ypHceUzmf16Fcdz20BHwH IW0PRkxI5VRnQhvtUo6rpmp4ej9nEXoi+uhzQcMr/dBo9cl3H+DUxmw8+WtcSa/dl3TEey/uGZ/ h+RiC/Y62bEQhKcj7sr4yJL2r3VSnDgpGgRq3sPXwFdTZG0K6mEbxo64ud+jPErHuld9JYM6JM5 2yyXbCsOZCGOMAZGQ4kbV0DA0tfVUdPUgxXe2zxNnkdUtgqYrMFjUzbkKMaS3mkiMoQ6Ih7/SJO khWUE7q2IV8C4CYH X-Received: by 2002:a05:600c:511f:b0:442:f482:c429 with SMTP id 5b1f17b1804b1-44c919e1212mr72338685e9.8.1748266104406; Mon, 26 May 2025 06:28:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaaobnHeigG/eBkWZXd1t3qpSgOSBx99XMBgFVTdHMNgY3fiyKRZ23Lqf2VAX1TTWLq2keaQ== X-Received: by 2002:a05:600c:511f:b0:442:f482:c429 with SMTP id 5b1f17b1804b1-44c919e1212mr72338525e9.8.1748266103966; Mon, 26 May 2025 06:28:23 -0700 (PDT) Received: from lab.hqhome163.com ([81.57.75.210]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4c8455e7dsm8836663f8f.9.2025.05.26.06.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 06:28:23 -0700 (PDT) From: Alessandro Carminati To: linux-kselftest@vger.kernel.org Cc: Dan Carpenter , Kees Cook , Daniel Diaz , David Gow , Arthur Grillo , Brendan Higgins , Naresh Kamboju , Andrew Morton , Maxime Ripard , Ville Syrjala , Daniel Vetter , Guenter Roeck , Alessandro Carminati , Jani Nikula , Jeff Johnson , Peter Zijlstra , Josh Poimboeuf , Shuah Khan , Linux Kernel Functional Testing , dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Alessandro Carminati Subject: [PATCH v5 5/5] kunit: Add documentation for warning backtrace suppression API Date: Mon, 26 May 2025 13:27:55 +0000 Message-Id: <20250526132755.166150-6-acarmina@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250526132755.166150-1-acarmina@redhat.com> References: <20250526132755.166150-1-acarmina@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Guenter Roeck Document API functions for suppressing warning backtraces. Tested-by: Linux Kernel Functional Testing Acked-by: Dan Carpenter Reviewed-by: Kees Cook Signed-off-by: Guenter Roeck Reviewed-by: David Gow Signed-off-by: Alessandro Carminati --- Documentation/dev-tools/kunit/usage.rst | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-to= ols/kunit/usage.rst index 22955d56b379..b2f1e56d53b4 100644 --- a/Documentation/dev-tools/kunit/usage.rst +++ b/Documentation/dev-tools/kunit/usage.rst @@ -157,6 +157,34 @@ Alternatively, one can take full control over the erro= r message by using if (some_setup_function()) KUNIT_FAIL(test, "Failed to setup thing for testing"); =20 +Suppressing warning backtraces +------------------------------ + +Some unit tests trigger warning backtraces either intentionally or as 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. + +Such backtraces can be suppressed. To suppress a backtrace in some_functio= n(), +use the following code. + +.. code-block:: c + + static void some_test(struct kunit *test) + { + DEFINE_SUPPRESSED_WARNING(some_function); + + KUNIT_START_SUPPRESSED_WARNING(some_function); + trigger_backtrace(); + KUNIT_END_SUPPRESSED_WARNING(some_function); + } + +SUPPRESSED_WARNING_COUNT() returns the number of suppressed backtraces. If= the +suppressed backtrace was triggered on purpose, this can be used to check if +the backtrace was actually triggered. + +.. code-block:: c + + KUNIT_EXPECT_EQ(test, SUPPRESSED_WARNING_COUNT(some_function), 1); =20 Test Suites ~~~~~~~~~~~ @@ -857,4 +885,4 @@ For example: dev_managed_string =3D devm_kstrdup(fake_device, "Hello, World!"); =20 // Everything is cleaned up automatically when the test ends. - } \ No newline at end of file + } --=20 2.34.1