]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm: Suppress intentional warning backtraces in scaling unit tests
authorGuenter Roeck <linux@roeck-us.net>
Thu, 14 May 2026 11:06:39 +0000 (13:06 +0200)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 14 May 2026 16:50:00 +0000 (10:50 -0600)
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. Additionally, the
suppression API allows to actually ensure a warning was triggered,
without parsing any kernel logs and keeping them clean.
The suppression check requires CONFIG_BUG enabled.

Link: https://lore.kernel.org/r/20260514-kunit_add_support-v11-3-b36a530a6d8f@redhat.com
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Acked-by: Dan Carpenter <dan.carpenter@linaro.org>
Acked-by: MaĆ­ra Canal <mcanal@igalia.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Alessandro Carminati <acarmina@redhat.com>
Acked-by: David Gow <david@davidgow.net>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
drivers/gpu/drm/tests/drm_rect_test.c

index 17e1f34b761017ce6c9576bd04dde3e55a40af0c..3402f993d7d33e09a1b9ce45c74aae23b4ca3260 100644 (file)
@@ -10,6 +10,7 @@
 #include <drm/drm_rect.h>
 #include <drm/drm_mode.h>
 
+#include <linux/limits.h>
 #include <linux/string_helpers.h>
 #include <linux/errno.h>
 
@@ -407,10 +408,27 @@ KUNIT_ARRAY_PARAM(drm_rect_scale, drm_rect_scale_cases, drm_rect_scale_case_desc
 static void drm_test_rect_calc_hscale(struct kunit *test)
 {
        const struct drm_rect_scale_case *params = test->param_value;
-       int scaling_factor;
+       int expected_warnings = params->expected_scaling_factor == -EINVAL;
+       int scaling_factor = INT_MIN;
 
-       scaling_factor = drm_rect_calc_hscale(&params->src, &params->dst,
-                                             params->min_range, params->max_range);
+       /*
+        * Without CONFIG_BUG, WARN_ON() is a no-op and the suppressed warning
+        * count stays zero, failing the assertion.
+        */
+       if (expected_warnings && !IS_ENABLED(CONFIG_BUG))
+               kunit_skip(test, "requires CONFIG_BUG");
+
+       /*
+        * drm_rect_calc_hscale() generates a warning backtrace whenever bad
+        * parameters are passed to it. This affects unit tests with -EINVAL
+        * error code in expected_scaling_factor.
+        */
+       kunit_warning_suppress(test) {
+               scaling_factor = drm_rect_calc_hscale(&params->src, &params->dst,
+                                                     params->min_range,
+                                                     params->max_range);
+               KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, expected_warnings);
+       }
 
        KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor);
 }
@@ -418,10 +436,26 @@ static void drm_test_rect_calc_hscale(struct kunit *test)
 static void drm_test_rect_calc_vscale(struct kunit *test)
 {
        const struct drm_rect_scale_case *params = test->param_value;
-       int scaling_factor;
+       int expected_warnings = params->expected_scaling_factor == -EINVAL;
+       int scaling_factor = INT_MIN;
 
-       scaling_factor = drm_rect_calc_vscale(&params->src, &params->dst,
-                                             params->min_range, params->max_range);
+       /*
+        * Without CONFIG_BUG, WARN_ON() is a no-op and the suppressed warning
+        * count stays zero, failing the assertion.
+        */
+       if (expected_warnings && !IS_ENABLED(CONFIG_BUG))
+               kunit_skip(test, "requires CONFIG_BUG");
+
+       /*
+        * drm_rect_calc_vscale() generates a warning backtrace whenever bad
+        * parameters are passed to it. This affects unit tests with -EINVAL
+        * error code in expected_scaling_factor.
+        */
+       kunit_warning_suppress(test) {
+               scaling_factor = drm_rect_calc_vscale(&params->src, &params->dst,
+                                                     params->min_range, params->max_range);
+               KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, expected_warnings);
+       }
 
        KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor);
 }