Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1207747lql; Tue, 12 Mar 2024 10:07:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX6i5GQCRpCtHOnUYkOkHoPoZHvzj++cWf0SMCzmfju/2OnzOtzQXxXAg7kCUtezOP1jK7PQai3231g4a2p649FB6nUb3IayDnlrDbYfg== X-Google-Smtp-Source: AGHT+IG8youstmoYOKczTXonQaLXQTAbW8r9oUacKJyJTDlUZ3OnOyxQKkWMu6sFpq2pOQOg2Wmf X-Received: by 2002:a17:902:e750:b0:1dd:9cb3:8f96 with SMTP id p16-20020a170902e75000b001dd9cb38f96mr7311957plf.42.1710263238910; Tue, 12 Mar 2024 10:07:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710263238; cv=pass; d=google.com; s=arc-20160816; b=Tc9HPCMqtHzP4pC6nC+PXSgiinGAOhhnlF1ZrNRgMUj2kukLlhsNFmoisNwSwdwqGa Qv1pca9MbEiAes4xMp97IiFr0Vqz70D07yPaEEGTSZBC/VTbF+DmCcmdRe2KIgTKmlpJ QZC2usGkaoXdgNGVUZ3k1Umq+IF82/bzHjRHPp+6YyUmZQDggL3Q7Z9WCIJMNgEtyO1o Pus2U+u08ljBw0KbSK26I0RNsyVw5WyYfV+2eLOEYjctfCN6cpqn2obz+O9sD1XMai9a 5N4yjZUlbNPPgvAMkDU21v4aPyX7GiG73CSh8Fez28c16LUH2Hm5HIntbX8feGgBHMDW N8vg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:sender:dkim-signature; bh=0g4hKhLnYWz4PyvpNTr/SgCP1vJlAe2ABRcfc3yqje8=; fh=OuNAd3ugC+AbbEEhnmoI0DGz0IV5xk2oh6EpqW9Yr/M=; b=I+2cqVDpxaU0LDprKPQWlaMWOjjWVom6ur9pE+I1QLKjY2eu2U4UPNwPTwhgZRLR8A BkhdFEnRDKXB2jq3bt/5mmaF99Rmq3fy6w3vahZLADVsKJHoGs/7bcG1OFjVjGwlSZHF iZ+/V8QR3As/PrgnHMs4HvgyXToebwE3hVsHN+Du4HXfeers3GOdGThu31j+1x85YGow FuP/XS2NNrAziP4TBo9QvPYeNhsjCMmZPrTVp92yzqlssnS10JO3frU58mht6bHgpPV6 tMSjwSDmS47Az6GhAw2HfP3reGjADToKIlkHuYl4v+oGqbxiE6GYQEHE7iuWNgItBF/p XptQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hIxEPtvV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-100559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100559-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u14-20020a170902e5ce00b001dcf977f18csi7316474plf.321.2024.03.12.10.07.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 10:07:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hIxEPtvV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-100559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100559-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id BFAB3B2436F for ; Tue, 12 Mar 2024 17:04:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7D2B139594; Tue, 12 Mar 2024 17:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hIxEPtvV" Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09D4B137C28; Tue, 12 Mar 2024 17:03:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710263003; cv=none; b=ndDSQFW3dxmDN5FRmM2tGRN2gOD0Ki2BT4iTnsgeiFuMGh7BcDbEPY9GUPEjzv714AaWGtYGiFE5jH32Cy+uIfaqy5rYZF2lsIZpODx7EJt2JfwU1oXurTyGMiFi/U+xQpx/RDFDDIj/+Sp3LfNbWodvKvwyLlkva9tWLL7sJY8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710263003; c=relaxed/simple; bh=6sNYSIeWjeJasEWjPkKmJrJOPHHuw7n+sDWqcd32API=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VoPnidiaUPmkT0BE2zFYpx2wrX6UOITT4/vEgOv8HhsFf0fyrZmkdq4JFB2im9LYVej5koHKjQQ6+S+lGVP8IEfF4OE/l4cOJKwsqFHrxoIaRfMjZIIMpDSQKXFpV4Xcl3W7aXmiZ+gP+t48IWidWdBr/17UJ8n6SEnNZsH7QSQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hIxEPtvV; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6e622b46f45so3449441b3a.1; Tue, 12 Mar 2024 10:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710263000; x=1710867800; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=0g4hKhLnYWz4PyvpNTr/SgCP1vJlAe2ABRcfc3yqje8=; b=hIxEPtvVCrxqUlyuA3CHzu8qlTZn1/iRuh+92+0gCYs2kwxBXc3ojGWjbmYql6QM2+ Yzt2zsIVE1pn4z3XxfdDTaSVju75fniSexX/65FAeqJul/CHhyRMTFACezGmsytY5zju H5lK3tDXwwOacy3w4nIX1GZMK234mVeONb41UCo6D4GyqA6tilLYeSr2g8eFgwFIu0cm 5RD9GvMYercy2Z2iuF/8b0veGXd0XqV2FqivCv9yze1jpX3Vw5Ih3jDbvTVyyEMfroxW wIXjzncNg6srpBbhUBFY/JV7ALcbkdbF91gCcRLhH8WfmcpoqHD+8vn0zsJyRHSYLL8w MjCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710263000; x=1710867800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0g4hKhLnYWz4PyvpNTr/SgCP1vJlAe2ABRcfc3yqje8=; b=LFR/3SaShVlVQwrxv44DZ5GXEiLyHwIezA0irO1RVzf3UhDOMfHE99nJQb2WPcdoKS cboSgKh5DiLhaTECsHpuaejQkVCrU2lof0mSEjJcKHoVfKcVHqVOiQTYPjPObvxskSZU qTDL4EgNWYIk20+/DygKte5KhNAbH+akIq6Aw1hGpZn7lW7N9+bHEdi6r9g1NG3dCYbW p764biW6tuyyAvTqzEC7/egc2EN0SWplM/rGRKpU+96S5M2ZRHgreFlqZG3OEAWeR2/8 jsyxr2/TvzAMkUZ7Lg/6ttYCKlQRZWJ3P/TFBa8zQvl9EeoZBqe4kUbkpa7Ar1KbIPJY UQ6A== X-Forwarded-Encrypted: i=1; AJvYcCXuV8XUyqSwTY/7nboMA5kXR5IZXieWuQLYDFqjTtuFREIpfIoAStiWPoBARwQKXD/G002aD3mssrOxBJIz1XuC1iLeIQ14C+ZK/b9VamlFnh9zCaNljkETLxNNjOf6vNpF+OUzlPsnDteY6qoi3HMMuk/raOd8h/9obTiJ3+1ZzAlX6cey62GedgztK3qqMZpSZIyt8X8mG1Riyu0XAMcxdwt6sTVRcTpdT8f4pLT4t5gmCrTD1Ia5tFVr1+iHCyWJk1e1ysyoWzyJ7KE0veCZK0FLRgK4Mg== X-Gm-Message-State: AOJu0YwrmI7R5JFAVLf6UP/ktgIcP5qOSFn102u4iauyf3e4UbqP5wkn 5GfGC46AIYPqi+41RgtzxDm+Hxx+KY/4kgGb8WAlIdLuH3DBDCp57gVvOGW7 X-Received: by 2002:a05:6a00:10d2:b0:6e5:ad7d:d031 with SMTP id d18-20020a056a0010d200b006e5ad7dd031mr32842pfu.32.1710263000113; Tue, 12 Mar 2024 10:03:20 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id r2-20020aa79ec2000000b006e31f615af6sm6552880pfq.17.2024.03.12.10.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 10:03:19 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-kselftest@vger.kernel.org Cc: David Airlie , Arnd Bergmann , =?UTF-8?q?Ma=C3=ADra=20Canal?= , Dan Carpenter , Kees Cook , Daniel Diaz , David Gow , Arthur Grillo , Brendan Higgins , Naresh Kamboju , Maarten Lankhorst , Andrew Morton , Maxime Ripard , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Daniel Vetter , Thomas Zimmermann , dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, loongarch@lists.linux.dev, netdev@lists.linux.dev, Guenter Roeck Subject: [PATCH 03/14] kunit: Add test cases for backtrace warning suppression Date: Tue, 12 Mar 2024 10:02:58 -0700 Message-Id: <20240312170309.2546362-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240312170309.2546362-1-linux@roeck-us.net> References: <20240312170309.2546362-1-linux@roeck-us.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Guenter Roeck --- lib/kunit/Makefile | 3 +- lib/kunit/backtrace-suppression-test.c | 104 +++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 lib/kunit/backtrace-suppression-test.c diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 545b57c3be48..6a44d2b54ea9 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -19,7 +19,8 @@ endif obj-y += hooks.o \ bug.o -obj-$(CONFIG_KUNIT_TEST) += kunit-test.o +obj-$(CONFIG_KUNIT_TEST) += kunit-test.o \ + backtrace-suppression-test.o # 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 000000000000..47c619283802 --- /dev/null +++ b/lib/kunit/backtrace-suppression-test.c @@ -0,0 +1,104 @@ +// 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) +{ + DEFINE_SUPPRESSED_WARNING(backtrace_suppression_test_warn_direct); + + START_SUPPRESSED_WARNING(backtrace_suppression_test_warn_direct); + WARN(1, "This backtrace should be suppressed"); + END_SUPPRESSED_WARNING(backtrace_suppression_test_warn_direct); + + KUNIT_EXPECT_EQ(test, SUPPRESSED_WARNING_COUNT(backtrace_suppression_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) +{ + DEFINE_SUPPRESSED_WARNING(trigger_backtrace_warn); + + START_SUPPRESSED_WARNING(trigger_backtrace_warn); + trigger_backtrace_warn(); + END_SUPPRESSED_WARNING(trigger_backtrace_warn); + + KUNIT_EXPECT_EQ(test, SUPPRESSED_WARNING_COUNT(trigger_backtrace_warn), 1); +} + +static void backtrace_suppression_test_warn_multi(struct kunit *test) +{ + DEFINE_SUPPRESSED_WARNING(trigger_backtrace_warn); + DEFINE_SUPPRESSED_WARNING(backtrace_suppression_test_warn_multi); + + START_SUPPRESSED_WARNING(backtrace_suppression_test_warn_multi); + START_SUPPRESSED_WARNING(trigger_backtrace_warn); + WARN(1, "This backtrace should be suppressed"); + trigger_backtrace_warn(); + END_SUPPRESSED_WARNING(trigger_backtrace_warn); + END_SUPPRESSED_WARNING(backtrace_suppression_test_warn_multi); + + KUNIT_EXPECT_EQ(test, SUPPRESSED_WARNING_COUNT(backtrace_suppression_test_warn_multi), 1); + KUNIT_EXPECT_EQ(test, SUPPRESSED_WARNING_COUNT(trigger_backtrace_warn), 1); +} + +static void backtrace_suppression_test_warn_on_direct(struct kunit *test) +{ + 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"); + + START_SUPPRESSED_WARNING(backtrace_suppression_test_warn_on_direct); + WARN_ON(1); + END_SUPPRESSED_WARNING(backtrace_suppression_test_warn_on_direct); + + KUNIT_EXPECT_EQ(test, + SUPPRESSED_WARNING_COUNT(backtrace_suppression_test_warn_on_direct), 1); +} + +static void trigger_backtrace_warn_on(void) +{ + WARN_ON(1); +} + +static void backtrace_suppression_test_warn_on_indirect(struct kunit *test) +{ + DEFINE_SUPPRESSED_WARNING(trigger_backtrace_warn_on); + + if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) + kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE"); + + START_SUPPRESSED_WARNING(trigger_backtrace_warn_on); + trigger_backtrace_warn_on(); + END_SUPPRESSED_WARNING(trigger_backtrace_warn_on); + + KUNIT_EXPECT_EQ(test, SUPPRESSED_WARNING_COUNT(trigger_backtrace_warn_on), 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"); -- 2.39.2