/* * snd_soc_component needs device to operate on (primarily for prints), create * fake one, as we don't register with PCI or anything else * device_driver name is used in some of the prints (fmt_single_name) so * we also mock up minimal one
*/ staticstruct device *test_dev;
/* * helper struct we use when registering component, as we load topology during * component probe, we need to pass struct kunit somehow to probe function, so * we can report test result
*/ struct kunit_soc_component { struct kunit *kunit; int expect; /* what result we expect when loading topology */ struct snd_soc_component comp; struct snd_soc_card card; struct firmware fw;
};
/* ===== TEST CASES ========================================================= */
// TEST CASE // Test passing NULL component as parameter to snd_soc_tplg_component_load
/* * need to override generic probe function with one using NULL when calling * topology load during component initialization, we don't need .remove * handler as load should fail
*/ staticint d_probe_null_comp(struct snd_soc_component *component)
{ struct kunit_soc_component *kunit_comp =
container_of(component, struct kunit_soc_component, comp); int ret;
/* instead of passing component pointer as first argument, pass NULL here */
ret = snd_soc_tplg_component_load(NULL, NULL, &kunit_comp->fw);
KUNIT_EXPECT_EQ_MSG(kunit_comp->kunit, kunit_comp->expect, ret, "Failed topology load");
// TEST CASE // Test passing NULL ops as parameter to snd_soc_tplg_component_load
/* * NULL ops is default case, we pass empty topology (fw), so we don't have * anything to parse and just do nothing, which results in return 0; from * calling soc_tplg_dapm_complete in soc_tplg_process_headers
*/ staticvoid snd_soc_tplg_test_load_with_null_ops(struct kunit *test)
{ struct kunit_soc_component *kunit_comp; int ret;
// TEST CASE // Test passing NULL fw as parameter to snd_soc_tplg_component_load
/* * need to override generic probe function with one using NULL pointer to fw * when calling topology load during component initialization, we don't need * .remove handler as load should fail
*/ staticint d_probe_null_fw(struct snd_soc_component *component)
{ struct kunit_soc_component *kunit_comp =
container_of(component, struct kunit_soc_component, comp); int ret;
/* instead of passing fw pointer as third argument, pass NULL here */
ret = snd_soc_tplg_component_load(component, NULL, NULL);
KUNIT_EXPECT_EQ_MSG(kunit_comp->kunit, kunit_comp->expect, ret, "Failed topology load");
// TEST CASE // Test passing "empty" topology file staticvoid snd_soc_tplg_test_load_empty_tplg(struct kunit *test)
{ struct kunit_soc_component *kunit_comp; struct tplg_tmpl_001 *data; int size; int ret;
// TEST CASE // Test "empty" topology file, but with bad "magic" // In theory we could loop through all possible bad values, but it takes too // long, so just use SND_SOC_TPLG_MAGIC + 1 staticvoid snd_soc_tplg_test_load_empty_tplg_bad_magic(struct kunit *test)
{ struct kunit_soc_component *kunit_comp; struct tplg_tmpl_001 *data; int size; int ret;
size = sizeof(tplg_tmpl_empty);
data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
memcpy(data, &tplg_tmpl_empty, sizeof(tplg_tmpl_empty)); /* * override abi * any value != magic number is wrong
*/
data->header.magic = cpu_to_le32(SND_SOC_TPLG_MAGIC + 1);
// TEST CASE // Test "empty" topology file, but with bad "abi" // In theory we could loop through all possible bad values, but it takes too // long, so just use SND_SOC_TPLG_ABI_VERSION + 1 staticvoid snd_soc_tplg_test_load_empty_tplg_bad_abi(struct kunit *test)
{ struct kunit_soc_component *kunit_comp; struct tplg_tmpl_001 *data; int size; int ret;
size = sizeof(tplg_tmpl_empty);
data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
memcpy(data, &tplg_tmpl_empty, sizeof(tplg_tmpl_empty)); /* * override abi * any value != accepted range is wrong
*/
data->header.abi = cpu_to_le32(SND_SOC_TPLG_ABI_VERSION + 1);
// TEST CASE // Test "empty" topology file, but with bad "size" // In theory we could loop through all possible bad values, but it takes too // long, so just use sizeof(struct snd_soc_tplg_hdr) + 1 staticvoid snd_soc_tplg_test_load_empty_tplg_bad_size(struct kunit *test)
{ struct kunit_soc_component *kunit_comp; struct tplg_tmpl_001 *data; int size; int ret;
// TEST CASE // Test "empty" topology file, but with bad "payload_size" // In theory we could loop through all possible bad values, but it takes too // long, so just use the known wrong one staticvoid snd_soc_tplg_test_load_empty_tplg_bad_payload_size(struct kunit *test)
{ struct kunit_soc_component *kunit_comp; struct tplg_tmpl_001 *data; int size; int ret;
size = sizeof(tplg_tmpl_empty);
data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
memcpy(data, &tplg_tmpl_empty, sizeof(tplg_tmpl_empty)); /* * override payload size * there is only explicit check for 0, so check with it, other values * are handled by just not reading behind EOF
*/
data->header.payload_size = 0;
// TEST CASE // Test passing topology file with PCM definition staticvoid snd_soc_tplg_test_load_pcm_tplg(struct kunit *test)
{ struct kunit_soc_component *kunit_comp;
u8 *data; int size; int ret;
// TEST CASE // Test passing topology file with PCM definition // with component reload staticvoid snd_soc_tplg_test_load_pcm_tplg_reload_comp(struct kunit *test)
{ struct kunit_soc_component *kunit_comp;
u8 *data; int size; int ret; int i;
// TEST CASE // Test passing topology file with PCM definition // with card reload staticvoid snd_soc_tplg_test_load_pcm_tplg_reload_card(struct kunit *test)
{ struct kunit_soc_component *kunit_comp;
u8 *data; int size; int ret; int i;
/* run test */
ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
KUNIT_EXPECT_EQ(test, 0, ret);
ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
for (i = 0; i < 100; i++) {
ret = snd_soc_register_card(&kunit_comp->card); if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
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.