From mboxrd@z Thu Jan 1 00:00:00 1970 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 7868439FCA3 for ; Mon, 20 Apr 2026 12:29:14 +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=1776688155; cv=none; b=tedDEDE0SzXNLoeNC1Od+N9Ft89QxyseENfNyL3X5OUEYKzOYglReIE/zzZhaH7b4U5BHJNsFgthbhuCtC3xQ0JEc3cVj2oQPccGcC6ywvbK2iE1I813mAb+uuhH848gR9Nw34chqiDtfggRFp9A8BvXP5UFrZ4VwM4RzJ4LyE0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688155; c=relaxed/simple; bh=2ReGco5diB/JcWx1D3nTqkxNNlKZwwBtIlmygG3amqQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PDuztZw1XzVoLkPUvhrSFvlmzflCPjPzF5L8a6TEqT+f0ohwZrOR5Klt2A0T/Al/HKtip2e4BhXsUedtHcAsqDfnLNxMinLXgez9i04NQxAAShykDGdrGEvkKlC27rCmzbKGf956zHbQZa0J9fncG7Z4pwRPAQcOxkSSk899FEg= 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=OrxCt5Z+; 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="OrxCt5Z+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776688153; 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=hsLazpgDoZcx+ASK1eTTBe2uAy362phg74sYeHXc9dM=; b=OrxCt5Z+pqN5zDwoUvCkjOqfJijkCUpnFv+ZgWowrqsU1CAfmkBAKcjiVR7YAve/69ck5M gd6GBz/ScYmDfuG9kHl8Z3KM27uEzCkigFRs1ZqAHzr+M0Irj7H1KnNaLtXLlwpp7pRsSq hTInb3zj3Sj4NJr3n1rU6j8Mi369vJ0= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-uOLzcwM6PmSvNgLFUozmdw-1; Mon, 20 Apr 2026 08:29:10 -0400 X-MC-Unique: uOLzcwM6PmSvNgLFUozmdw-1 X-Mimecast-MFC-AGG-ID: uOLzcwM6PmSvNgLFUozmdw_1776688147 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9FFB61955DDB; Mon, 20 Apr 2026 12:29:06 +0000 (UTC) Received: from [192.168.1.153] (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C5F5A1956095; Mon, 20 Apr 2026 12:29:00 +0000 (UTC) From: Albert Esteve Date: Mon, 20 Apr 2026 14:28:05 +0200 Subject: [PATCH v7 3/5] kunit: Add backtrace suppression self-tests Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260420-kunit_add_support-v7-3-e8bc6e0f70de@redhat.com> References: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> In-Reply-To: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> To: Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet , Shuah Khan , Andrew Morton 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-doc@vger.kernel.org, peterz@infradead.org, Guenter Roeck , Linux Kernel Functional Testing , Dan Carpenter , Alessandro Carminati , Albert Esteve , Kees Cook X-Developer-Signature: v=1; a=ed25519-sha256; t=1776688120; l=4375; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=vuDHildPEPNlCHogR5KyfnFhxEoODOxMc2R3mM4Q7g4=; b=ELW2SvmwsG5uXtj+qpzqCxqtNwG1LIsm1McB6sCN5QK+FOTG5/pEpAapAxC1WOUnBhwSOfayA 78HEDz1TIaDBD8o0X3gylq2LDZbflDbkE2QUYCuGRtZtRisEva92Z/E X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 From: Guenter Roeck Add unit tests to verify that warning backtrace suppression works, covering WARN() and WARN_ON() with direct calls, indirect calls through helper functions, and multiple warnings in a single window. 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 Signed-off-by: Albert Esteve --- lib/kunit/Makefile | 3 ++ lib/kunit/backtrace-suppression-test.c | 90 ++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index fe177ff3ebdef..b2f2b8ada7b71 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -23,6 +23,9 @@ obj-$(if $(CONFIG_KUNIT),y) += hooks.o \ obj-$(CONFIG_KUNIT_TEST) += kunit-test.o obj-$(CONFIG_KUNIT_TEST) += platform-test.o +ifeq ($(CONFIG_KUNIT_SUPPRESS_BACKTRACE),y) +obj-$(CONFIG_KUNIT_TEST) += backtrace-suppression-test.o +endif # 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-suppression-test.c new file mode 100644 index 0000000000000..2ba5dcb5fef35 --- /dev/null +++ b/lib/kunit/backtrace-suppression-test.c @@ -0,0 +1,90 @@ +// 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_START_SUPPRESSED_WARNING(test); + WARN(1, "This backtrace should be suppressed"); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 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_START_SUPPRESSED_WARNING(test); + trigger_backtrace_warn(); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 1); +} + +static void backtrace_suppression_test_warn_multi(struct kunit *test) +{ + KUNIT_START_SUPPRESSED_WARNING(test); + WARN(1, "This backtrace should be suppressed"); + trigger_backtrace_warn(); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 2); +} + +static void backtrace_suppression_test_warn_on_direct(struct kunit *test) +{ + if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE) && !IS_ENABLED(CONFIG_KALLSYMS)) + kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE or CONFIG_KALLSYMS"); + + KUNIT_START_SUPPRESSED_WARNING(test); + WARN_ON(1); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 1); +} + +static void trigger_backtrace_warn_on(void) +{ + WARN_ON(1); +} + +static void backtrace_suppression_test_warn_on_indirect(struct kunit *test) +{ + if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) + kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE"); + + KUNIT_START_SUPPRESSED_WARNING(test); + trigger_backtrace_warn_on(); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 1); +} + +static struct kunit_case backtrace_suppression_test_cases[] = { + 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 = { + .name = "backtrace-suppression-test", + .test_cases = backtrace_suppression_test_cases, +}; +kunit_test_suites(&backtrace_suppression_test_suite); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("KUnit test to verify warning backtrace suppression"); -- 2.52.0