// SPDX-License-Identifier: GPL-2.0-only // // KUnit test for the Cirrus common amplifier library. // // Copyright (C) 2024 Cirrus Logic, Inc. and // Cirrus Logic International Semiconductor Ltd.
/* Redirected get_efi_variable to simulate that the file is too short */ static efi_status_t cs_amp_lib_test_get_efi_variable_nohead(efi_char16_t *name,
efi_guid_t *guid, unsignedlong *size, void *buf)
{ if (!buf) {
*size = offsetof(struct cirrus_amp_efi_data, data) - 1; return EFI_BUFFER_TOO_SMALL;
}
return EFI_NOT_FOUND;
}
/* Should return -EOVERFLOW if the header is larger than the EFI data */ staticvoid cs_amp_lib_test_cal_data_too_short_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; struct cirrus_amp_cal_data result_data; int ret;
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable_nohead);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, 0, 0, &result_data);
KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW);
/* Redirected get_efi_variable to simulate that the count is larger than the file */ static efi_status_t cs_amp_lib_test_get_efi_variable_bad_count(efi_char16_t *name,
efi_guid_t *guid, unsignedlong *size, void *buf)
{ struct kunit *test = kunit_get_current_test(); struct cs_amp_lib_test_priv *priv = test->priv;
if (!buf) { /* * Return a size that is shorter than required for the * declared number of entries.
*/
*size = priv->cal_blob->size - 1; return EFI_BUFFER_TOO_SMALL;
}
/* Should return -EOVERFLOW if the entry count is larger than the EFI data */ staticvoid cs_amp_lib_test_cal_count_too_big_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; struct cirrus_amp_cal_data result_data; int ret;
cs_amp_lib_test_init_dummy_cal_blob(test, 8);
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable_bad_count);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, 0, 0, &result_data);
KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW);
/* Redirected get_efi_variable to simulate that the variable not found */ static efi_status_t cs_amp_lib_test_get_efi_variable_none(efi_char16_t *name,
efi_guid_t *guid, unsignedlong *size, void *buf)
{ return EFI_NOT_FOUND;
}
/* If EFI doesn't contain a cal data variable the result should be -ENOENT */ staticvoid cs_amp_lib_test_no_cal_data_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; struct cirrus_amp_cal_data result_data; int ret;
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable_none);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, 0, 0, &result_data);
KUNIT_EXPECT_EQ(test, ret, -ENOENT);
/* Get cal data block for a given amp, matched by target UID. */ staticvoid cs_amp_lib_test_get_efi_cal_by_uid_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; conststruct cs_amp_lib_test_param *param = test->param_value; struct cirrus_amp_cal_data result_data;
u64 target_uid; int ret;
/* Get cal data block for a given amp index without checking target UID. */ staticvoid cs_amp_lib_test_get_efi_cal_by_index_unchecked_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; conststruct cs_amp_lib_test_param *param = test->param_value; struct cirrus_amp_cal_data result_data; int ret;
/* Get cal data block for a given amp index with checked target UID. */ staticvoid cs_amp_lib_test_get_efi_cal_by_index_checked_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; conststruct cs_amp_lib_test_param *param = test->param_value; struct cirrus_amp_cal_data result_data;
u64 target_uid; int ret;
/* * Get cal data block for a given amp index with checked target UID. * The UID does not match so the result should be -ENOENT.
*/ staticvoid cs_amp_lib_test_get_efi_cal_by_index_uid_mismatch_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; conststruct cs_amp_lib_test_param *param = test->param_value; struct cirrus_amp_cal_data result_data;
u64 target_uid; int ret;
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable);
/* Get a target UID that won't match the entry */
target_uid = ~cs_amp_lib_test_get_target_uid(test);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, target_uid,
param->amp_index, &result_data);
KUNIT_EXPECT_EQ(test, ret, -ENOENT);
/* * Get cal data block for a given amp, where the cal data does not * specify calTarget so the lookup falls back to using the index
*/ staticvoid cs_amp_lib_test_get_efi_cal_by_index_fallback_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; conststruct cs_amp_lib_test_param *param = test->param_value; struct cirrus_amp_cal_data result_data; staticconst u64 bad_target_uid = 0xBADCA100BABABABAULL; int i, ret;
/* Make all the target values zero so they are ignored */ for (i = 0; i < priv->cal_blob->count; ++i) {
priv->cal_blob->data[i].calTarget[0] = 0;
priv->cal_blob->data[i].calTarget[1] = 0;
}
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, bad_target_uid,
param->amp_index, &result_data);
KUNIT_EXPECT_EQ(test, ret, 0);
/* * If the target UID isn't present in the cal data, and there isn't an * index to fall back do, the result should be -ENOENT.
*/ staticvoid cs_amp_lib_test_get_efi_cal_uid_not_found_noindex_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; struct cirrus_amp_cal_data result_data; staticconst u64 bad_target_uid = 0xBADCA100BABABABAULL; int i, ret;
cs_amp_lib_test_init_dummy_cal_blob(test, 8);
/* Make all the target values != bad_target_uid */ for (i = 0; i < priv->cal_blob->count; ++i) {
priv->cal_blob->data[i].calTarget[0] &= ~(bad_target_uid & 0xFFFFFFFFULL);
priv->cal_blob->data[i].calTarget[1] &= ~(bad_target_uid >> 32);
}
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, bad_target_uid, -1,
&result_data);
KUNIT_EXPECT_EQ(test, ret, -ENOENT);
/* * If the target UID isn't present in the cal data, and the index is * out of range, the result should be -ENOENT.
*/ staticvoid cs_amp_lib_test_get_efi_cal_uid_not_found_index_not_found_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; struct cirrus_amp_cal_data result_data; staticconst u64 bad_target_uid = 0xBADCA100BABABABAULL; int i, ret;
cs_amp_lib_test_init_dummy_cal_blob(test, 8);
/* Make all the target values != bad_target_uid */ for (i = 0; i < priv->cal_blob->count; ++i) {
priv->cal_blob->data[i].calTarget[0] &= ~(bad_target_uid & 0xFFFFFFFFULL);
priv->cal_blob->data[i].calTarget[1] &= ~(bad_target_uid >> 32);
}
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, bad_target_uid, 99,
&result_data);
KUNIT_EXPECT_EQ(test, ret, -ENOENT);
/* * If the target UID isn't given, and the index is out of range, the * result should be -ENOENT.
*/ staticvoid cs_amp_lib_test_get_efi_cal_no_uid_index_not_found_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; struct cirrus_amp_cal_data result_data; int ret;
cs_amp_lib_test_init_dummy_cal_blob(test, 8);
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, 0, 99, &result_data);
KUNIT_EXPECT_EQ(test, ret, -ENOENT);
/* If neither the target UID or the index is given the result should be -ENOENT. */ staticvoid cs_amp_lib_test_get_efi_cal_no_uid_no_index_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; struct cirrus_amp_cal_data result_data; int ret;
cs_amp_lib_test_init_dummy_cal_blob(test, 8);
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, 0, -1, &result_data);
KUNIT_EXPECT_EQ(test, ret, -ENOENT);
/* * If the UID is passed as 0 this must not match an entry with an * unpopulated calTarget
*/ staticvoid cs_amp_lib_test_get_efi_cal_zero_not_matched_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; struct cirrus_amp_cal_data result_data; int i, ret;
cs_amp_lib_test_init_dummy_cal_blob(test, 8);
/* Make all the target values zero so they are ignored */ for (i = 0; i < priv->cal_blob->count; ++i) {
priv->cal_blob->data[i].calTarget[0] = 0;
priv->cal_blob->data[i].calTarget[1] = 0;
}
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable);
ret = cs_amp_get_efi_calibration_data(&priv->amp_dev->dev, 0, -1, &result_data);
KUNIT_EXPECT_EQ(test, ret, -ENOENT);
/* * If an entry has a timestamp of 0 it should be ignored even if it has * a matching target UID.
*/ staticvoid cs_amp_lib_test_get_efi_cal_empty_entry_test(struct kunit *test)
{ struct cs_amp_lib_test_priv *priv = test->priv; struct cirrus_amp_cal_data result_data;
u64 uid;
cs_amp_lib_test_init_dummy_cal_blob(test, 8);
/* Mark the 3rd entry invalid by zeroing calTime */
priv->cal_blob->data[2].calTime[0] = 0;
priv->cal_blob->data[2].calTime[1] = 0;
/* Get the UID value of the 3rd entry */
uid = priv->cal_blob->data[2].calTarget[1];
uid <<= 32;
uid |= priv->cal_blob->data[2].calTarget[0];
/* Redirect calls to get EFI data */
kunit_activate_static_stub(test,
cs_amp_test_hooks->get_efi_variable,
cs_amp_lib_test_get_efi_variable);
/* Lookup by UID should not find it */
KUNIT_EXPECT_EQ(test,
cs_amp_get_efi_calibration_data(&priv->amp_dev->dev,
uid, -1,
&result_data),
-ENOENT);
/* Get by index should ignore it */
KUNIT_EXPECT_EQ(test,
cs_amp_get_efi_calibration_data(&priv->amp_dev->dev,
0, 2,
&result_data),
-ENOENT);
/* Checksum control must be written last */
entry = list_last_entry(&priv->ctl_write_list, typeof(*entry), list);
KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.checksum);
KUNIT_EXPECT_EQ(test, entry->value, data.calR + 1);
list_del(&entry->list);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.