Skip to content

Commit e5b4ad2

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: cs-amp-lib-test: Add test for getting cal data from HP EFI
Add a test case that cs_amp_get_efi_calibration_data() returns data when it is in the HP-specific EFI variable. This uses redirected implementation of cs_amp_get_efi_variable() that only returns data if the passes name and GUID match the HP EFI variable. A simple test case installs this function hook and then checks that calibration data is returned. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Message-ID: <20250909113039.922065-7-rf@opensource.cirrus.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent b78dd64 commit e5b4ad2

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

sound/soc/codecs/cs-amp-lib-test.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,56 @@ static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name,
220220
return EFI_SUCCESS;
221221
}
222222

223+
static efi_status_t cs_amp_lib_test_get_hp_cal_efi_variable(efi_char16_t *name,
224+
efi_guid_t *guid,
225+
unsigned long *size,
226+
void *buf)
227+
{
228+
static const efi_char16_t expected_name[] = L"SmartAmpCalibrationData";
229+
static const efi_guid_t expected_guid =
230+
EFI_GUID(0x53559579, 0x8753, 0x4f5c, 0x91, 0x30, 0xe8, 0x2a, 0xcf, 0xb8, 0xd8, 0x93);
231+
struct kunit *test = kunit_get_current_test();
232+
struct cs_amp_lib_test_priv *priv = test->priv;
233+
234+
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, name);
235+
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, guid);
236+
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, size);
237+
238+
if (memcmp(name, expected_name, sizeof(expected_name)) ||
239+
efi_guidcmp(*guid, expected_guid))
240+
return -EFI_NOT_FOUND;
241+
242+
if (!buf) {
243+
*size = priv->cal_blob->size;
244+
return EFI_BUFFER_TOO_SMALL;
245+
}
246+
247+
KUNIT_ASSERT_GE_MSG(test, ksize(buf), priv->cal_blob->size, "Buffer to small");
248+
249+
memcpy(buf, priv->cal_blob, priv->cal_blob->size);
250+
251+
return EFI_SUCCESS;
252+
}
253+
254+
/* Get cal data block from HP variable. */
255+
static void cs_amp_lib_test_get_hp_efi_cal(struct kunit *test)
256+
{
257+
struct cs_amp_lib_test_priv *priv = test->priv;
258+
struct cirrus_amp_cal_data result_data;
259+
int ret;
260+
261+
cs_amp_lib_test_init_dummy_cal_blob(test, 2);
262+
263+
kunit_activate_static_stub(test,
264+
cs_amp_test_hooks->get_efi_variable,
265+
cs_amp_lib_test_get_hp_cal_efi_variable);
266+
267+
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, 0, 0, &result_data);
268+
KUNIT_EXPECT_EQ(test, ret, 0);
269+
270+
KUNIT_EXPECT_MEMEQ(test, &result_data, &priv->cal_blob->data[0], sizeof(result_data));
271+
}
272+
223273
/* Get cal data block for a given amp, matched by target UID. */
224274
static void cs_amp_lib_test_get_efi_cal_by_uid_test(struct kunit *test)
225275
{
@@ -910,6 +960,7 @@ static struct kunit_case cs_amp_lib_test_cases[] = {
910960
KUNIT_CASE(cs_amp_lib_test_get_efi_cal_no_uid_index_not_found_test),
911961
KUNIT_CASE(cs_amp_lib_test_get_efi_cal_no_uid_no_index_test),
912962
KUNIT_CASE(cs_amp_lib_test_get_efi_cal_zero_not_matched_test),
963+
KUNIT_CASE(cs_amp_lib_test_get_hp_efi_cal),
913964
KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_uid_test,
914965
cs_amp_lib_test_get_cal_gen_params),
915966
KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_unchecked_test,

0 commit comments

Comments
 (0)