mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
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>
This commit is contained in:
1 parent
9e6f39535c
commit
177862317a
5 files changed
+754
-2
No files matched your search
@@ -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 */
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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 <rf@opensource.cirrus.com>");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
Reference in new issue
Block a user