linux/drivers/firmware/cirrus/test
Richard Fitzgerald 9be71d462c
firmware: cs_dsp: Simplify suppressing log messages during KUnit testing
Rework the way that kernel log messages are rate-limited or suppressed
while running the cs_dsp KUnit tests.

Under normal conditions cs_dsp doesn't produce an unreasonable number of
log messages, and state changes are relatively infrequent. But the KUnit
tests run through a very large number of test cases, especially error
cases, and this produces an unusually large amount of log output from
cs_dsp.

The original fix for this in commit 10db9f6899 ("firmware: cs_dsp:
rate-limit log messages in KUnit builds") was effective but not pretty.
It involved different definitions of the log macros for KUnit and
not-KUnit builds, and exported variables for the KUnit tests to disable
log messages. I would have preferred to turn the log macros into real
functions that can contain a KUNIT_STATIC_STUB_REDIRECT(), but the
dev_xxx() macros don't have a version that take va_args, so they can't
be wrapped by a function.

This patch enables the use of a KUNIT_STATIC_STUB_REDIRECT() instead
of exported variables, and avoids the need for different definitions of
the debug macros in KUnit and not-KUnit builds.

- A new function cs_dsp_can_emit_message() returns true if the
  messages can be emitted to the kernel log. In a normal not-KUnit build
  this function collapses to simply returning true. In KUnit builds it
  will rate-limit output, and this uses a single static rate limiter so
  it limits the overall rate across all cs_dsp log messages. The KUnit
  test can redirect it to change the suppression behavior.

- The cs_dsp debug message macros are changed to only call the dev_xxx()
  if cs_dsp_can_emit_message() returns true. These are still macros so
  there is no problem wrapping the dev_xxx(). For a normal not-KUnit
  build cs_dsp_can_emit_message() always returns true so these macros
  simplify down to being identical to calling dev_xxx() directly.

- The KUnit tests that cause a lot of cs_dsp messages now redirect
  cs_dsp_can_emit_message() to a local function. This returns false
  to suppress cs_dsp messages, unless DEBUG is defined for that test.

I have checked that for a x86_64 production (non-KUnit) build the
disassembled cs_dsp.o is identical to what was generated from the
original code. So the complier is correctly simplifying the
cs_dsp_can_emit_message() and macros down to only the call to dev_xxx().

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260310130343.1791951-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2026-03-10 14:53:05 +00:00
..
cs_dsp_mock_bin.c firmware: cs_dsp: mock_bin: Add function to create long-offset patches 2026-01-05 13:18:28 +00:00
cs_dsp_mock_mem_maps.c firmware: cs_dsp: test: Increase size of XM and YM on Halo Core 2026-01-05 13:18:29 +00:00
cs_dsp_mock_regmap.c firmware: cs_dsp: test: Increase size of XM and YM on Halo Core 2026-01-05 13:18:29 +00:00
cs_dsp_mock_utils.c
cs_dsp_mock_wmfw.c firmware: cs_dsp: Fix OOB memory read access in KUnit test (wmfw info) 2025-05-26 11:33:51 +01:00
cs_dsp_test_bin_error.c firmware: cs_dsp: Simplify suppressing log messages during KUnit testing 2026-03-10 14:53:05 +00:00
cs_dsp_test_bin.c firmware: cs_dsp: Simplify suppressing log messages during KUnit testing 2026-03-10 14:53:05 +00:00
cs_dsp_test_callbacks.c firmware: cs_dsp: Add test cases for client_ops == NULL 2025-11-28 11:47:56 +00:00
cs_dsp_test_control_cache.c firmware: cs_dsp: Mark KUnit test suites KUNIT_SPEED_SLOW 2026-02-25 18:33:17 +00:00
cs_dsp_test_control_parse.c firmware: cs_dsp: Mark KUnit test suites KUNIT_SPEED_SLOW 2026-02-25 18:33:17 +00:00
cs_dsp_test_control_rw.c firmware: cs_dsp: Mark KUnit test suites KUNIT_SPEED_SLOW 2026-02-25 18:33:17 +00:00
cs_dsp_test_wmfw_error.c firmware: cs_dsp: Simplify suppressing log messages during KUnit testing 2026-03-10 14:53:05 +00:00
cs_dsp_test_wmfw.c firmware: cs_dsp: Simplify suppressing log messages during KUnit testing 2026-03-10 14:53:05 +00:00
cs_dsp_tests.c firmware: cs_dsp: rate-limit log messages in KUnit builds 2026-02-02 12:09:28 +00:00
Makefile firmware: cs_dsp: Add KUnit testing of client callbacks 2024-12-13 13:14:48 +00:00