ASoC: cs-amp-lib: Add KUnit test for calibration helpers
Subsystems (3)
Richard Fitzgerald
maintainerPATCH v3 1/1 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.
--- include/sound/cs-amp-lib.h | 14 + sound/soc/codecs/Kconfig | 13 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/cs-amp-lib-test.c | 709 +++++++++++++++++++++++++++++ sound/soc/codecs/cs-amp-lib.c | 18 +- 5 files changed, 754 insertions(+), 2 deletions(-) create mode 100644 sound/soc/codecs/cs-amp-lib-test.c
include/sound/cs-amp-lib.h +14 -0
@@ -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 */
sound/soc/codecs/Kconfig +13 -0
@@ -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
sound/soc/codecs/Makefile +2 -0
@@ -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
@@ -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
sound/soc/codecs/cs-amp-lib-test.c new file +709 -0
709 lines not on this page · raw message
sound/soc/codecs/cs-amp-lib.c +16 -2
@@ -6,6 +6,7 @@// Cirrus Logic International Semiconductor Ltd. #include <asm/byteorder.h> +#include <kunit/static_stub.h> #include <linux/dev_printk.h> #include <linux/efi.h> #include <linux/firmware/cirrus/cs_dsp.h>
@@ -27,6 +28,8 @@ static int cs_amp_write_cal_coeff(struct cs_dsp *dsp,__be32 beval =cpu_to_be32 (val);int ret; +KUNIT_STATIC_STUB_REDIRECT (cs_amp_write_cal_coeff, dsp, controls, ctl_name, val); +if (IS_REACHABLE (CONFIG_FW_CS_DSP )) {mutex_lock (&dsp->pwr_lock); cs_ctl =cs_dsp_get_ctl (dsp, ctl_name, controls->mem_region, controls->alg_id);
@@ -84,7 +87,7 @@ int cs_amp_write_cal_coeffs(struct cs_dsp *dsp,const struct cirrus_amp_cal_controls *controls, const struct cirrus_amp_cal_data *data) { - if (IS_REACHABLE(CONFIG_FW_CS_DSP)) + if (IS_REACHABLE(CONFIG_FW_CS_DSP) || IS_ENABLED(CONFIG_SND_SOC_CS_AMP_LIB_TEST)) return _cs_amp_write_cal_coeffs(dsp, controls, data); else return -ENODEV;
@@ -98,6 +101,8 @@ static efi_status_t cs_amp_get_efi_variable(efi_char16_t *name, {u32 attr; +KUNIT_STATIC_STUB_REDIRECT (cs_amp_get_efi_variable, name, guid, size, buf); +if (IS_ENABLED (CONFIG_EFI ))return efi.get_variable (name, guid, &attr, size, buf);
@@ -250,13 +255,22 @@ static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid,int cs_amp_get_efi_calibration_data (struct device *dev,u64 target_uid,int amp_index,struct cirrus_amp_cal_data *out_data) { -if (IS_ENABLED (CONFIG_EFI )) +if (IS_ENABLED (CONFIG_EFI ) ||IS_ENABLED (CONFIG_SND_SOC_CS_AMP_LIB_TEST ))return _cs_amp_get_efi_calibration_data (dev, target_uid, amp_index, out_data);else return -ENOENT ; }EXPORT_SYMBOL_NS_GPL (cs_amp_get_efi_calibration_data,SND_SOC_CS_AMP_LIB ); +static const struct cs_amp_test_hooks cs_amp_test_hook_ptrs = { + .get_efi_variable = cs_amp_get_efi_variable, + .write_cal_coeff = cs_amp_write_cal_coeff, +}; + +const struct cs_amp_test_hooks *const cs_amp_test_hooks = +PTR_IF (IS_ENABLED (CONFIG_SND_SOC_CS_AMP_LIB_TEST ), &cs_amp_test_hook_ptrs); +EXPORT_SYMBOL_NS_GPL (cs_amp_test_hooks,SND_SOC_CS_AMP_LIB ); +MODULE_DESCRIPTION ("Cirrus Logic amplifier library" );MODULE_AUTHOR ("Richard Fitzgerald <[email protected]>" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.39.2
Mark Brown
maintainerQuoted 8 lines · Richard Fitzgerald
Add a KUnit test for the cs-amp-lib library. This has test cases for
cs_amp_get_efi_calibration_data()andcs_amp_write_cal_coeffs().A
KUNIT_STATIC_STUB_REDIRECT()has been added tocs_amp_get_efi_variable()andcs_amp_write_cal_coeff()so that the KUnit test can redirect these to test harness functions.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] ASoC: cs-amp-lib: Add KUnit test for calibration helpers
commit: 177862317a98adde284233aee074fc6e6a51cf95
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark