From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: broonie@kernel.org, brendan.higgins@linux.dev,
davidgow@google.com, raemoar63@gmail.com
Cc: linux-sound@vger.kernel.org, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
patches@opensource.cirrus.com
Subject: [PATCH 2/4] ASoC: cs35l56: Some KUnit testing of cs35l56_get_speaker_id()
Date: Wed, 4 Mar 2026 16:24:00 +0000 [thread overview]
Message-ID: <20260304162402.1714759-3-rf@opensource.cirrus.com> (raw)
In-Reply-To: <20260304162402.1714759-1-rf@opensource.cirrus.com>
Add some KUnit tests for cs35l56_get_speaker_id().
These only test the simpler cases of reading the speaker ID from
cs_amp_get_vendor_spkid() or the "cirrus,speaker-id" property.
The untested case is reading it from GPIOs, which would require
a dummy implementation of a GPIO driver.
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
sound/soc/codecs/cs-amp-lib.c | 2 ++
sound/soc/codecs/cs35l56-shared-test.c | 43 ++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/sound/soc/codecs/cs-amp-lib.c b/sound/soc/codecs/cs-amp-lib.c
index 8b131975143d..b34b1f5f121f 100644
--- a/sound/soc/codecs/cs-amp-lib.c
+++ b/sound/soc/codecs/cs-amp-lib.c
@@ -716,6 +716,8 @@ int cs_amp_get_vendor_spkid(struct device *dev)
{
int i, ret;
+ KUNIT_STATIC_STUB_REDIRECT(cs_amp_get_vendor_spkid, dev);
+
if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE) &&
!IS_ENABLED(CONFIG_SND_SOC_CS_AMP_LIB_TEST_HOOKS))
return -ENOENT;
diff --git a/sound/soc/codecs/cs35l56-shared-test.c b/sound/soc/codecs/cs35l56-shared-test.c
index 94db02aef7dc..d510893dcd44 100644
--- a/sound/soc/codecs/cs35l56-shared-test.c
+++ b/sound/soc/codecs/cs35l56-shared-test.c
@@ -37,6 +37,10 @@ KUNIT_DEFINE_ACTION_WRAPPER(faux_device_destroy_wrapper, faux_device_destroy,
KUNIT_DEFINE_ACTION_WRAPPER(regmap_exit_wrapper, regmap_exit, struct regmap *)
+KUNIT_DEFINE_ACTION_WRAPPER(device_remove_software_node_wrapper,
+ device_remove_software_node,
+ struct device *)
+
static const struct regmap_config cs35l56_shared_test_mock_registers_regmap = {
.reg_bits = 32,
.val_bits = 32,
@@ -410,6 +414,41 @@ static void cs35l56_shared_test_onchip_speaker_id_not_defined(struct kunit *test
KUNIT_EXPECT_EQ(test, cs35l56_read_onchip_spkid(cs35l56_base), -ENOENT);
}
+/* simulate cs_amp_get_vendor_spkid() reading a vendor-specific ID of 1 */
+static int cs35l56_shared_test_get_vendor_spkid_1(struct device *dev)
+{
+ return 1;
+}
+
+static void cs35l56_shared_test_get_speaker_id_vendor(struct kunit *test)
+{
+ struct cs35l56_shared_test_priv *priv = test->priv;
+
+ /* Hook cs_amp_get_vendor_spkid() to return an ID of 1 */
+ kunit_activate_static_stub(test, cs_amp_get_vendor_spkid,
+ cs35l56_shared_test_get_vendor_spkid_1);
+
+ KUNIT_EXPECT_EQ(test, cs35l56_get_speaker_id(priv->cs35l56_base), 1);
+}
+
+static void cs35l56_shared_test_get_speaker_id_property(struct kunit *test)
+{
+ struct cs35l56_shared_test_priv *priv = test->priv;
+ const struct property_entry dev_props[] = {
+ PROPERTY_ENTRY_U32("cirrus,speaker-id", 2),
+ { }
+ };
+ const struct software_node dev_node = SOFTWARE_NODE("SPK1", dev_props, NULL);
+
+ KUNIT_ASSERT_EQ(test, device_add_software_node(priv->cs35l56_base->dev, &dev_node), 0);
+ KUNIT_ASSERT_EQ(test, 0,
+ kunit_add_action_or_reset(test,
+ device_remove_software_node_wrapper,
+ priv->cs35l56_base->dev));
+
+ KUNIT_EXPECT_EQ(test, cs35l56_get_speaker_id(priv->cs35l56_base), 2);
+}
+
static int cs35l56_shared_test_case_regmap_init(struct kunit *test,
const struct regmap_config *regmap_config)
{
@@ -616,6 +655,10 @@ static struct kunit_case cs35l56_shared_test_cases[] = {
cs35l56_shared_test_onchip_spkid_pull_gen_params),
KUNIT_CASE(cs35l56_shared_test_stash_onchip_spkid_pins_reject_invalid),
KUNIT_CASE(cs35l56_shared_test_onchip_speaker_id_not_defined),
+
+ KUNIT_CASE(cs35l56_shared_test_get_speaker_id_vendor),
+ KUNIT_CASE(cs35l56_shared_test_get_speaker_id_property),
+
{ }
};
--
2.47.3
next prev parent reply other threads:[~2026-03-04 16:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 16:23 [PATCH 0/4] ASoC: cs35l56: More KUnit tests for speaker ID Richard Fitzgerald
2026-03-04 16:23 ` [PATCH 1/4] ASoC: cs35l56: KUnit tests for setting dsp.system_name Richard Fitzgerald
2026-03-04 16:24 ` Richard Fitzgerald [this message]
2026-03-04 16:24 ` [PATCH 3/4] ASoC: cs35l56: KUnit tests for reading speaker ID from host GPIOs Richard Fitzgerald
2026-03-04 16:24 ` [PATCH 4/4] kunit: config: all_tests: Select CONFIG_GPIOLIB Richard Fitzgerald
2026-03-05 22:49 ` (subset) [PATCH 0/4] ASoC: cs35l56: More KUnit tests for speaker ID Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260304162402.1714759-3-rf@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=brendan.higgins@linux.dev \
--cc=broonie@kernel.org \
--cc=davidgow@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=raemoar63@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox