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.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 58505269894 for ; Thu, 13 Mar 2025 11:44:40 +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=1741866285; cv=none; b=ABSR+GkKgrs2URy5YNQxR8OKXQL81+LEqIwAp1ixBvSmtR+lxKBCE5rPdFJ4ShKn7uEjBaUk3QTXANB5+VmUItwL4Ae20g9XNEMBCwKYdfMiZcF58up5SiO9Py0wdSORVxFKkPaqbC77ekPquo5m7ep9dp3RoVVOu9DnosMlKiU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741866285; c=relaxed/simple; bh=k/QW8yyThWQYD06PZzn8avBbFa43Ro0Rb4YCVVYWNuQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-type; b=IK7S1fBSR4d6evKDYnD728ZOTVWyiajIDZO/iQQhbY/mD2WGiuU//Ms5/W0k0bw5b158PTt/uN6vg47G72U60ikbiYTeja5py6w4ClUsWmExPTv72lapqf9AXIVujBK//TgK9Gb7v/xA6dfAH94G+6G+5fe1nepjuD9eIqPVUFA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=dDT8Ld3i; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="dDT8Ld3i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741866280; 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=dDT8Ld3iMDbNLuPtKnwtwxnk1TH7HtnkGAXjEqLyEFPK4LmprwWoFs2HMl3iFWS/OzYfZy 1KoI4jEU/cc6j4SlnWN7bldVylm68N2CsIW9kLnt+jVvPKmxLdv1Opp/oBmmeU9nRj5h2/ yv4gscgc9EPIoUYRBU0w/db5+FyLpMw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-QEbmLBSPM-auyFn1g7HtYQ-1; Thu, 13 Mar 2025 07:44:39 -0400 X-MC-Unique: QEbmLBSPM-auyFn1g7HtYQ-1 X-Mimecast-MFC-AGG-ID: QEbmLBSPM-auyFn1g7HtYQ_1741866278 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43cfd9b833bso8852795e9.1 for ; Thu, 13 Mar 2025 04:44:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741866278; x=1742471078; 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=PPYeYeCS0c134OuZ2rfNZ9gXGimBpz9Pp/6wtydUFr0GiD062uvoTETY70gUEqXuAz 7bujp+BJU/efSxaSFZaf+BcHEjOb22j2yz8P3eWnn8WwI0p2hAjPDhEcmQJfnSjNoMiQ +IUmG9EJ/37J4Dm7jlHNuSeUaXMIFQG7L1XbsDb2b7SjqxjdUsMTdQ8tglcY8HcnIR3D JLj3aPbiMS4eptN34sml7zPEVUE/3MsUaF+RP85SvXQ6SL0dTNLSMg/E9Nc8NaDcdLX0 2zQzjsm9Uey99MS6BzfI2p4sCynE++a/SrukHOrNLxE/Y6dFsLjTEAtYzKhtKC9RJvqd 6edw== X-Forwarded-Encrypted: i=1; AJvYcCUh+AGGz9qx7VOtMp9GLXdDUB+EobhkJo4LWsJgZkVAjriafNBrH+lKAhAC0nCXgjP+2w173a6Q9HM=@vger.kernel.org X-Gm-Message-State: AOJu0YyrejCVQRx5gbdKzb0uw5I0rY13tpjzIKyV5/kysGQHva8wDqaE trFsqnhn/0OEhGccoUB3nV7JnRhCiHKPvCADJZ7UCVivpBLuIZ/D38yDZtWou5bsv63NpfOPM7D 10Kmz+nrlEMFYZp5V8ogvQgwCjAvRHkI1qIE1aO2i00sYOJU1/MmPUzWtNQ== X-Gm-Gg: ASbGncugcJxmBsImxHrUW9A5ji+a3mDZCBy3awOSz0eifUXvuVI+udxGF1/SXKcmoda H7Mxjpl5L/l/iVHb5c0Nxz2ci4rB+sRbj/7Bi58RjDiuSdRkPgDhIfx1Ns9ssCT5B8gSnMW2avI Q1vBsDpYnMk3/186XN3ObnHkzvYdyJhHtYJprgtMndKYjntPYFy1wZLX0MY8BFO8QGBWXyXVUwN P2JkHUxlonPauWj/xQjrXItSQRA/YZKg5ZZs0pK4oNJSiuVxfqBTMUfe5+traW/VUdKPkhtqi5M lwDT5h6TNzGqMQLEptnk X-Received: by 2002:a05:6000:1fa9:b0:390:f025:9e85 with SMTP id ffacd0b85a97d-395b954eeeamr1447628f8f.21.1741866277750; Thu, 13 Mar 2025 04:44:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPsIsJrLJpu/wcDWacnMw+4SNJEtb8GetI5Mzi5kv4VuMQGkXurfVfuA8bqNlB7JY189Yj3A== X-Received: by 2002:a05:6000:1fa9:b0:390:f025:9e85 with SMTP id ffacd0b85a97d-395b954eeeamr1447604f8f.21.1741866277398; Thu, 13 Mar 2025 04:44:37 -0700 (PDT) Received: from lab.hqhome163.com ([81.57.75.210]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43d188b754asm17844115e9.14.2025.03.13.04.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 04:44:36 -0700 (PDT) From: Alessandro Carminati 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 , Guenter Roeck , Alessandro Carminati , Jani Nikula , 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, x86@kernel.org, Linux Kernel Functional Testing , Alessandro Carminati Subject: [PATCH v4 04/14] kunit: Add documentation for warning backtrace suppression API Date: Thu, 13 Mar 2025 11:43:19 +0000 Message-Id: <20250313114329.284104-5-acarmina@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250313114329.284104-1-acarmina@redhat.com> References: <20250313114329.284104-1-acarmina@redhat.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit 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-tools/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 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 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_function(), +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); Test Suites ~~~~~~~~~~~ @@ -857,4 +885,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 + } -- 2.34.1