Skip to content

Commit 1778623

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: cs-amp-lib: Add KUnit test for calibration helpers
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>
1 parent 9e6f395 commit 1778623

File tree

5 files changed

+754
-2
lines changed

5 files changed

+754
-2
lines changed

include/sound/cs-amp-lib.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,18 @@ int cs_amp_write_cal_coeffs(struct cs_dsp *dsp,
4949
const struct cirrus_amp_cal_data *data);
5050
int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index,
5151
struct cirrus_amp_cal_data *out_data);
52+
53+
struct cs_amp_test_hooks {
54+
efi_status_t (*get_efi_variable)(efi_char16_t *name,
55+
efi_guid_t *guid,
56+
unsigned long *size,
57+
void *buf);
58+
59+
int (*write_cal_coeff)(struct cs_dsp *dsp,
60+
const struct cirrus_amp_cal_controls *controls,
61+
const char *ctl_name, u32 val);
62+
};
63+
64+
extern const struct cs_amp_test_hooks * const cs_amp_test_hooks;
65+
5266
#endif /* CS_AMP_LIB_H */

sound/soc/codecs/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,19 @@ config SND_SOC_CROS_EC_CODEC
732732
config SND_SOC_CS_AMP_LIB
733733
tristate
734734

735+
config SND_SOC_CS_AMP_LIB_TEST
736+
tristate "KUnit test for Cirrus Logic cs-amp-lib"
737+
depends on KUNIT
738+
default KUNIT_ALL_TESTS
739+
select SND_SOC_CS_AMP_LIB
740+
help
741+
This builds KUnit tests for the Cirrus Logic common
742+
amplifier library.
743+
For more information on KUnit and unit tests in general,
744+
please refer to the KUnit documentation in
745+
Documentation/dev-tools/kunit/.
746+
If in doubt, say "N".
747+
735748
config SND_SOC_CS35L32
736749
tristate "Cirrus Logic CS35L32 CODEC"
737750
depends on I2C

sound/soc/codecs/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ snd-soc-cpcap-objs := cpcap.o
6060
snd-soc-cq93vc-objs := cq93vc.o
6161
snd-soc-cros-ec-codec-objs := cros_ec_codec.o
6262
snd-soc-cs-amp-lib-objs := cs-amp-lib.o
63+
snd-soc-cs-amp-lib-test-objs := cs-amp-lib-test.o
6364
snd-soc-cs35l32-objs := cs35l32.o
6465
snd-soc-cs35l33-objs := cs35l33.o
6566
snd-soc-cs35l34-objs := cs35l34.o
@@ -454,6 +455,7 @@ obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
454455
obj-$(CONFIG_SND_SOC_CPCAP) += snd-soc-cpcap.o
455456
obj-$(CONFIG_SND_SOC_CROS_EC_CODEC) += snd-soc-cros-ec-codec.o
456457
obj-$(CONFIG_SND_SOC_CS_AMP_LIB) += snd-soc-cs-amp-lib.o
458+
obj-$(CONFIG_SND_SOC_CS_AMP_LIB_TEST) += snd-soc-cs-amp-lib-test.o
457459
obj-$(CONFIG_SND_SOC_CS35L32) += snd-soc-cs35l32.o
458460
obj-$(CONFIG_SND_SOC_CS35L33) += snd-soc-cs35l33.o
459461
obj-$(CONFIG_SND_SOC_CS35L34) += snd-soc-cs35l34.o

0 commit comments

Comments
 (0)