ASoC: wm_adsp: Add kunit test for firmware file search

Add KUnit testing of the wm_adsp code that searches for firmware files.
Also make the SND_SOC_WM_ADSP Kconfig symbol visible if KUNIT is enabled
so that wm_adsp can be manually included for KUnit testing.

The firmware filename is composed of several fields, some of which are
optional, and there is a search algorithm to fallback from specific to
generic versions of firmware for a device. This KUnit test verifies that
wm_adsp is searching for the correct sequence of filenames.

The are two ways of testing this, and both are used in this KUnit test.

1. Trap the calls to firmware_request_nowarn() and test that the sequence
   of filenames request is correct.

   This is the most thorough test because it proves that exactly the
   expected filenames are requested, in the correct order.

   But it doesn't fully cover regression testing. If a change to the search
   algorithm changes the expected sequence of requested files, the test
   must also be changed to expect that new sequence. If the expectation is
   wrong, the tests can pass (because the search order is as expected)
   while picking a different file in some cases from what it did before the
   change.

2. Test which file is picked from a simulated directory of files.

   This is better for regression testing because it is independent of the
   search algorithm. It does not need to change if the search algorithm
   changes. It is not testing exactly which files the algorithm searches
   for, only which file it eventually picks from a given set of available
   files.

   In other words, the regression test is: does it still pick the same file
   from the same directory of files?

   But it is impractical for thorough testing. It doesn't prove that
   exactly the correct files were searched for, unless it was to test with
   every possible combination of file names and directory content that
   could ever exist. Clearly this is impossible to implement, since the
   number of combations of possible valid filenames in a directory and
   number of files in a directory is astronomically large.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260310141817.1871794-5-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Richard Fitzgerald 2026-03-10 14:18:11 +00:00 committed by Mark Brown
parent b4e6b01191
commit bf2d44d07d
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
3 changed files with 1238 additions and 1 deletions

View File

@ -398,7 +398,7 @@ config SND_SOC_WM_HUBS
default m if SND_SOC_WM8993=m || SND_SOC_WM8994=m
config SND_SOC_WM_ADSP
tristate
tristate "Cirrus Logic wm_adsp driver" if KUNIT
select FW_CS_DSP
select SND_SOC_COMPRESS
default y if SND_SOC_MADERA=y
@ -424,6 +424,18 @@ config SND_SOC_WM_ADSP
default m if SND_SOC_CS35L56=m
default m if SND_SOC_CS48L32=m
config SND_SOC_WM_ADSP_TEST
tristate "KUnit tests for Cirrus Logic wm_adsp" if !KUNIT_ALL_TESTS
depends on KUNIT
depends on SND_SOC_WM_ADSP
default KUNIT_ALL_TESTS
help
This builds KUnit tests for the Cirrus Logic wm_adsp library.
For more information on KUnit and unit tests in general,
please refer to the KUnit documentation in
Documentation/dev-tools/kunit/.
If in doubt, say "N".
config SND_SOC_AB8500_CODEC
tristate
depends on ABX500_CORE

View File

@ -361,6 +361,7 @@ snd-soc-wcd938x-sdw-y := wcd938x-sdw.o
snd-soc-wcd939x-y := wcd939x.o
snd-soc-wcd939x-sdw-y := wcd939x-sdw.o
snd-soc-wm-adsp-y := wm_adsp.o
snd-soc-wm-adsp-test-y := wm_adsp_fw_find_test.o
snd-soc-wm0010-y := wm0010.o
snd-soc-wm1250-ev1-y := wm1250-ev1.o
snd-soc-wm2000-y := wm2000.o
@ -862,6 +863,7 @@ obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o
obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
obj-$(CONFIG_SND_SOC_WM_ADSP) += snd-soc-wm-adsp.o
obj-$(CONFIG_SND_SOC_WM_ADSP_TEST) += snd-soc-wm-adsp-test.o
obj-$(CONFIG_SND_SOC_WM_HUBS) += snd-soc-wm-hubs.o
obj-$(CONFIG_SND_SOC_WSA881X) += snd-soc-wsa881x.o
obj-$(CONFIG_SND_SOC_WSA883X) += snd-soc-wsa883x.o

File diff suppressed because it is too large Load Diff