Skip to content

Commit

Permalink
firmware: cs_dsp: Add KUnit testing of bin file download
Browse files Browse the repository at this point in the history
This adds a KUnit test suite to test downloading bin files.

The general technique is
1. Create mock bin file content
2. Tell cs_dsp to download the bin file
3. Check in the emulated regmap registers that the correct values have
   been written to DSP memory
4. Drop the regmap cache for the expected written registers and then do a
   regcache_sync() to check for unexpected writes to other registers.

The test covers ADSP2 v1 and v2, and HALO Core DSPs. (ADSP1 is very
obsolete so isn't tested).

There is a large number of test cases and parameterized variants of tests
because of the many different addressing schemes supported by the Cirrus
devices. The DSP has 2 or 3 memory spaces: XM, YM and ZM. The DSP sees
these using its native addressing, which is word-addressed (not
byte-addressed). The host sees these through one of several register
mappings (depending on the DSP type and parent codec family). The
registers have three different addressing schemes: 16-bit registers
addressed by register number, 32-bit registers addressed by register
number, or 32-bit registers addressed by byte (with a stride of 4). In
addition to these multiple addressing schemes, the Halo Core DSPs have a
"packed" register mapping that maps 4 DSP words into 3 registers. The bin
file addresses the data blob relative to the base address of an algorithm,
which has to be calculated in both DSP words (for the DSP to access) and
register addresses (for the host).

This results in many different addressing schemes used in parallel, hence
the complexity of the address and size manipulation in the test cases:
word addresses in DSP memory, byte offsets, word offsets, register
addresses (either byte-addressed 32-bit or index-addressed 16-bit), and
packed register addresses.

The test cases intentionally have relatively little factoring-out of
similar code. This makes it much easier to visually verify that a test
case is testing correctly, and what exactly it is testing. Factoring out
large amounts of code into helper functions tends to obscure what the
actual test procedure is, so increasing the chance of hidden errors where
test cases don't actually test as intended.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20241212143725.1381013-6-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
rfvirgil authored and broonie committed Dec 13, 2024
1 parent 7c052c6 commit dd0b6b1
Show file tree
Hide file tree
Showing 4 changed files with 2,590 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/firmware/cirrus/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@ config FW_CS_DSP_KUNIT_TEST_UTILS
depends on KUNIT
select REGMAP
select FW_CS_DSP

config FW_CS_DSP_KUNIT_TEST
tristate "KUnit tests for Cirrus Logic cs_dsp" if !KUNIT_ALL_TESTS
depends on KUNIT
default KUNIT_ALL_TESTS
select REGMAP
select FW_CS_DSP
select FW_CS_DSP_KUNIT_TEST_UTILS
help
This builds KUnit tests for cs_dsp.
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".
5 changes: 5 additions & 0 deletions drivers/firmware/cirrus/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ cs_dsp_test_utils-objs := \
cs_dsp_mock_utils.o \
cs_dsp_mock_wmfw.o

cs_dsp_test-objs := \
cs_dsp_test_bin.o \
cs_dsp_tests.o

obj-$(CONFIG_FW_CS_DSP_KUNIT_TEST_UTILS) += cs_dsp_test_utils.o
obj-$(CONFIG_FW_CS_DSP_KUNIT_TEST) += cs_dsp_test.o
Loading

0 comments on commit dd0b6b1

Please sign in to comment.