From: Guenter Roeck <[email protected]> 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.
Tested-by: Linux Kernel Functional Testing <[email protected]> Acked-by: Dan Carpenter <[email protected]> Acked-by: MaĆra Canal <[email protected]> Cc: Maarten Lankhorst <[email protected]> Cc: David Airlie <[email protected]> Cc: Daniel Vetter <[email protected]> Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Alessandro Carminati <[email protected]> Acked-by: David Gow <[email protected]> Signed-off-by: Albert Esteve <[email protected]> --- drivers/gpu/drm/tests/drm_rect_test.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c index 17e1f34b76101..809e73cb74498 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -407,10 +407,20 @@ 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 expected_warnings = params->expected_scaling_factor == -EINVAL; int scaling_factor; - scaling_factor = drm_rect_calc_hscale(¶ms->src, ¶ms->dst, - params->min_range, params->max_range); + /* + * 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(¶ms->src, ¶ms->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 +428,19 @@ 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 expected_warnings = params->expected_scaling_factor == -EINVAL; int scaling_factor; - scaling_factor = drm_rect_calc_vscale(¶ms->src, ¶ms->dst, - params->min_range, params->max_range); + /* + * 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(¶ms->src, ¶ms->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); } -- 2.53.0

