Skip to content

Commit

Permalink
ASoC: cs-amp-lib: Add KUnit test for calibration helpers
Browse files Browse the repository at this point in the history
Add a KUnit test for the cs-amp-lib library. This has test cases
for cs_amp_get_efi_calibration_data() and cs_amp_write_cal_coeffs().

A KUNIT_STATIC_STUB_REDIRECT() has been added to
cs_amp_get_efi_variable() and cs_amp_write_cal_coeff() so that the
KUnit test can redirect these to test harness functions.

Much of the testing involves invoking the same function with different
parameters, i.e. the number of amps and the amp index within the array.
This uses parameterization rather than looping. The idea is to avoid
looping over configurations within one test case as that has a higher
chance of having a bug that doesn't actually test all the expected cases.
Having the test run exactly one configuration, and then tear-down, is less
prone to accidentally skipped configurations.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://msgid.link/r/20240304143705.26362-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Richard Fitzgerald authored and Mark Brown committed Mar 4, 2024
1 parent 9e6f395 commit 1778623
Show file tree
Hide file tree
Showing 5 changed files with 754 additions and 2 deletions.
14 changes: 14 additions & 0 deletions include/sound/cs-amp-lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,18 @@ int cs_amp_write_cal_coeffs(struct cs_dsp *dsp,
const struct cirrus_amp_cal_data *data);
int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index,
struct cirrus_amp_cal_data *out_data);

struct cs_amp_test_hooks {
efi_status_t (*get_efi_variable)(efi_char16_t *name,
efi_guid_t *guid,
unsigned long *size,
void *buf);

int (*write_cal_coeff)(struct cs_dsp *dsp,
const struct cirrus_amp_cal_controls *controls,
const char *ctl_name, u32 val);
};

extern const struct cs_amp_test_hooks * const cs_amp_test_hooks;

#endif /* CS_AMP_LIB_H */
13 changes: 13 additions & 0 deletions sound/soc/codecs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,19 @@ config SND_SOC_CROS_EC_CODEC
config SND_SOC_CS_AMP_LIB
tristate

config SND_SOC_CS_AMP_LIB_TEST
tristate "KUnit test for Cirrus Logic cs-amp-lib"
depends on KUNIT
default KUNIT_ALL_TESTS
select SND_SOC_CS_AMP_LIB
help
This builds KUnit tests for the Cirrus Logic common
amplifier 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_CS35L32
tristate "Cirrus Logic CS35L32 CODEC"
depends on I2C
Expand Down
2 changes: 2 additions & 0 deletions sound/soc/codecs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ snd-soc-cpcap-objs := cpcap.o
snd-soc-cq93vc-objs := cq93vc.o
snd-soc-cros-ec-codec-objs := cros_ec_codec.o
snd-soc-cs-amp-lib-objs := cs-amp-lib.o
snd-soc-cs-amp-lib-test-objs := cs-amp-lib-test.o
snd-soc-cs35l32-objs := cs35l32.o
snd-soc-cs35l33-objs := cs35l33.o
snd-soc-cs35l34-objs := cs35l34.o
Expand Down Expand Up @@ -454,6 +455,7 @@ obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
obj-$(CONFIG_SND_SOC_CPCAP) += snd-soc-cpcap.o
obj-$(CONFIG_SND_SOC_CROS_EC_CODEC) += snd-soc-cros-ec-codec.o
obj-$(CONFIG_SND_SOC_CS_AMP_LIB) += snd-soc-cs-amp-lib.o
obj-$(CONFIG_SND_SOC_CS_AMP_LIB_TEST) += snd-soc-cs-amp-lib-test.o
obj-$(CONFIG_SND_SOC_CS35L32) += snd-soc-cs35l32.o
obj-$(CONFIG_SND_SOC_CS35L33) += snd-soc-cs35l33.o
obj-$(CONFIG_SND_SOC_CS35L34) += snd-soc-cs35l34.o
Expand Down
Loading

0 comments on commit 1778623

Please sign in to comment.