1 // SPDX-License-Identifier: GPL-2.0-only
3 * soc-topology-test.c -- ALSA SoC Topology Kernel Unit Tests
5 * Copyright(c) 2021 Intel Corporation. All rights reserved.
8 #include <linux/firmware.h>
9 #include <sound/core.h>
10 #include <sound/soc.h>
11 #include <sound/soc-topology.h>
12 #include <kunit/test.h>
14 /* ===== HELPER FUNCTIONS =================================================== */
17 * snd_soc_component needs device to operate on (primarily for prints), create
18 * fake one, as we don't register with PCI or anything else
19 * device_driver name is used in some of the prints (fmt_single_name) so
20 * we also mock up minimal one
22 static struct device *test_dev;
24 static struct device_driver test_drv = {
25 .name = "sound-soc-topology-test-driver",
28 static int snd_soc_tplg_test_init(struct kunit *test)
30 test_dev = root_device_register("sound-soc-topology-test");
31 test_dev = get_device(test_dev);
35 test_dev->driver = &test_drv;
40 static void snd_soc_tplg_test_exit(struct kunit *test)
43 root_device_unregister(test_dev);
47 * helper struct we use when registering component, as we load topology during
48 * component probe, we need to pass struct kunit somehow to probe function, so
49 * we can report test result
51 struct kunit_soc_component {
53 int expect; /* what result we expect when loading topology */
54 struct snd_soc_component comp;
55 struct snd_soc_card card;
59 static int d_probe(struct snd_soc_component *component)
61 struct kunit_soc_component *kunit_comp =
62 container_of(component, struct kunit_soc_component, comp);
65 ret = snd_soc_tplg_component_load(component, NULL, &kunit_comp->fw);
66 KUNIT_EXPECT_EQ_MSG(kunit_comp->kunit, kunit_comp->expect, ret,
67 "Failed topology load");
72 static void d_remove(struct snd_soc_component *component)
74 struct kunit_soc_component *kunit_comp =
75 container_of(component, struct kunit_soc_component, comp);
78 ret = snd_soc_tplg_component_remove(component);
79 KUNIT_EXPECT_EQ(kunit_comp->kunit, 0, ret);
83 * ASoC minimal boiler plate
85 SND_SOC_DAILINK_DEF(dummy, DAILINK_COMP_ARRAY(COMP_DUMMY()));
87 SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("sound-soc-topology-test")));
89 static struct snd_soc_dai_link kunit_dai_links[] = {
91 .name = "KUNIT Audio Port",
93 .stream_name = "Audio Playback/Capture",
96 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
99 SND_SOC_DAILINK_REG(dummy, dummy, platform),
103 static const struct snd_soc_component_driver test_component = {
104 .name = "sound-soc-topology-test",
109 /* ===== TOPOLOGY TEMPLATES ================================================= */
111 // Structural representation of topology which can be generated with:
113 // $ alsatplg -c empty -o empty.tplg
114 // $ xxd -i empty.tplg
116 struct tplg_tmpl_001 {
117 struct snd_soc_tplg_hdr header;
118 struct snd_soc_tplg_manifest manifest;
121 static struct tplg_tmpl_001 tplg_tmpl_empty = {
123 .magic = cpu_to_le32(SND_SOC_TPLG_MAGIC),
124 .abi = cpu_to_le32(5),
126 .type = cpu_to_le32(SND_SOC_TPLG_TYPE_MANIFEST),
127 .size = cpu_to_le32(sizeof(struct snd_soc_tplg_hdr)),
129 .payload_size = cpu_to_le32(sizeof(struct snd_soc_tplg_manifest)),
131 .count = cpu_to_le32(1),
135 .size = cpu_to_le32(sizeof(struct snd_soc_tplg_manifest)),
136 /* rest of fields is 0 */
140 // Structural representation of topology containing SectionPCM
142 struct tplg_tmpl_002 {
143 struct snd_soc_tplg_hdr header;
144 struct snd_soc_tplg_manifest manifest;
145 struct snd_soc_tplg_hdr pcm_header;
146 struct snd_soc_tplg_pcm pcm;
149 static struct tplg_tmpl_002 tplg_tmpl_with_pcm = {
151 .magic = cpu_to_le32(SND_SOC_TPLG_MAGIC),
152 .abi = cpu_to_le32(5),
154 .type = cpu_to_le32(SND_SOC_TPLG_TYPE_MANIFEST),
155 .size = cpu_to_le32(sizeof(struct snd_soc_tplg_hdr)),
157 .payload_size = cpu_to_le32(sizeof(struct snd_soc_tplg_manifest)),
159 .count = cpu_to_le32(1),
162 .size = cpu_to_le32(sizeof(struct snd_soc_tplg_manifest)),
163 .pcm_elems = cpu_to_le32(1),
164 /* rest of fields is 0 */
167 .magic = cpu_to_le32(SND_SOC_TPLG_MAGIC),
168 .abi = cpu_to_le32(5),
170 .type = cpu_to_le32(SND_SOC_TPLG_TYPE_PCM),
171 .size = cpu_to_le32(sizeof(struct snd_soc_tplg_hdr)),
173 .payload_size = cpu_to_le32(sizeof(struct snd_soc_tplg_pcm)),
175 .count = cpu_to_le32(1),
178 .size = cpu_to_le32(sizeof(struct snd_soc_tplg_pcm)),
179 .pcm_name = "KUNIT Audio",
180 .dai_name = "kunit-audio-dai",
183 .playback = cpu_to_le32(1),
184 .capture = cpu_to_le32(1),
188 .channels = cpu_to_le32(2),
191 .channels = cpu_to_le32(2),
197 .name = "kunit-audio-playback",
198 .channels_min = cpu_to_le32(2),
199 .channels_max = cpu_to_le32(2),
202 .name = "kunit-audio-capture",
203 .channels_min = cpu_to_le32(2),
204 .channels_max = cpu_to_le32(2),
213 /* ===== TEST CASES ========================================================= */
216 // Test passing NULL component as parameter to snd_soc_tplg_component_load
219 * need to override generic probe function with one using NULL when calling
220 * topology load during component initialization, we don't need .remove
221 * handler as load should fail
223 static int d_probe_null_comp(struct snd_soc_component *component)
225 struct kunit_soc_component *kunit_comp =
226 container_of(component, struct kunit_soc_component, comp);
229 /* instead of passing component pointer as first argument, pass NULL here */
230 ret = snd_soc_tplg_component_load(NULL, NULL, &kunit_comp->fw);
231 KUNIT_EXPECT_EQ_MSG(kunit_comp->kunit, kunit_comp->expect, ret,
232 "Failed topology load");
237 static const struct snd_soc_component_driver test_component_null_comp = {
238 .name = "sound-soc-topology-test",
239 .probe = d_probe_null_comp,
242 static void snd_soc_tplg_test_load_with_null_comp(struct kunit *test)
244 struct kunit_soc_component *kunit_comp;
248 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
249 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
250 kunit_comp->kunit = test;
251 kunit_comp->expect = -EINVAL; /* expect failure */
253 kunit_comp->card.dev = test_dev,
254 kunit_comp->card.name = "kunit-card",
255 kunit_comp->card.owner = THIS_MODULE,
256 kunit_comp->card.dai_link = kunit_dai_links,
257 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
258 kunit_comp->card.fully_routed = true,
261 ret = snd_soc_register_card(&kunit_comp->card);
262 if (ret != 0 && ret != -EPROBE_DEFER)
263 KUNIT_FAIL(test, "Failed to register card");
265 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component_null_comp, test_dev);
266 KUNIT_EXPECT_EQ(test, 0, ret);
268 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
269 KUNIT_EXPECT_EQ(test, 0, ret);
272 snd_soc_unregister_card(&kunit_comp->card);
273 snd_soc_unregister_component(test_dev);
277 // Test passing NULL ops as parameter to snd_soc_tplg_component_load
280 * NULL ops is default case, we pass empty topology (fw), so we don't have
281 * anything to parse and just do nothing, which results in return 0; from
282 * calling soc_tplg_dapm_complete in soc_tplg_process_headers
284 static void snd_soc_tplg_test_load_with_null_ops(struct kunit *test)
286 struct kunit_soc_component *kunit_comp;
290 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
291 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
292 kunit_comp->kunit = test;
293 kunit_comp->expect = 0; /* expect success */
295 kunit_comp->card.dev = test_dev,
296 kunit_comp->card.name = "kunit-card",
297 kunit_comp->card.owner = THIS_MODULE,
298 kunit_comp->card.dai_link = kunit_dai_links,
299 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
300 kunit_comp->card.fully_routed = true,
303 ret = snd_soc_register_card(&kunit_comp->card);
304 if (ret != 0 && ret != -EPROBE_DEFER)
305 KUNIT_FAIL(test, "Failed to register card");
307 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
308 KUNIT_EXPECT_EQ(test, 0, ret);
310 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
311 KUNIT_EXPECT_EQ(test, 0, ret);
314 snd_soc_unregister_card(&kunit_comp->card);
316 snd_soc_unregister_component(test_dev);
320 // Test passing NULL fw as parameter to snd_soc_tplg_component_load
323 * need to override generic probe function with one using NULL pointer to fw
324 * when calling topology load during component initialization, we don't need
325 * .remove handler as load should fail
327 static int d_probe_null_fw(struct snd_soc_component *component)
329 struct kunit_soc_component *kunit_comp =
330 container_of(component, struct kunit_soc_component, comp);
333 /* instead of passing fw pointer as third argument, pass NULL here */
334 ret = snd_soc_tplg_component_load(component, NULL, NULL);
335 KUNIT_EXPECT_EQ_MSG(kunit_comp->kunit, kunit_comp->expect, ret,
336 "Failed topology load");
341 static const struct snd_soc_component_driver test_component_null_fw = {
342 .name = "sound-soc-topology-test",
343 .probe = d_probe_null_fw,
346 static void snd_soc_tplg_test_load_with_null_fw(struct kunit *test)
348 struct kunit_soc_component *kunit_comp;
352 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
353 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
354 kunit_comp->kunit = test;
355 kunit_comp->expect = -EINVAL; /* expect failure */
357 kunit_comp->card.dev = test_dev,
358 kunit_comp->card.name = "kunit-card",
359 kunit_comp->card.owner = THIS_MODULE,
360 kunit_comp->card.dai_link = kunit_dai_links,
361 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
362 kunit_comp->card.fully_routed = true,
365 ret = snd_soc_register_card(&kunit_comp->card);
366 if (ret != 0 && ret != -EPROBE_DEFER)
367 KUNIT_FAIL(test, "Failed to register card");
369 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component_null_fw, test_dev);
370 KUNIT_EXPECT_EQ(test, 0, ret);
372 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
373 KUNIT_EXPECT_EQ(test, 0, ret);
376 snd_soc_unregister_card(&kunit_comp->card);
378 snd_soc_unregister_component(test_dev);
382 // Test passing "empty" topology file
383 static void snd_soc_tplg_test_load_empty_tplg(struct kunit *test)
385 struct kunit_soc_component *kunit_comp;
386 struct tplg_tmpl_001 *data;
391 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
392 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
393 kunit_comp->kunit = test;
394 kunit_comp->expect = 0; /* expect success */
396 size = sizeof(tplg_tmpl_empty);
397 data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
398 KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
400 memcpy(data, &tplg_tmpl_empty, sizeof(tplg_tmpl_empty));
402 kunit_comp->fw.data = (u8 *)data;
403 kunit_comp->fw.size = size;
405 kunit_comp->card.dev = test_dev,
406 kunit_comp->card.name = "kunit-card",
407 kunit_comp->card.owner = THIS_MODULE,
408 kunit_comp->card.dai_link = kunit_dai_links,
409 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
410 kunit_comp->card.fully_routed = true,
413 ret = snd_soc_register_card(&kunit_comp->card);
414 if (ret != 0 && ret != -EPROBE_DEFER)
415 KUNIT_FAIL(test, "Failed to register card");
417 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
418 KUNIT_EXPECT_EQ(test, 0, ret);
420 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
421 KUNIT_EXPECT_EQ(test, 0, ret);
424 snd_soc_unregister_card(&kunit_comp->card);
426 snd_soc_unregister_component(test_dev);
430 // Test "empty" topology file, but with bad "magic"
431 // In theory we could loop through all possible bad values, but it takes too
432 // long, so just use SND_SOC_TPLG_MAGIC + 1
433 static void snd_soc_tplg_test_load_empty_tplg_bad_magic(struct kunit *test)
435 struct kunit_soc_component *kunit_comp;
436 struct tplg_tmpl_001 *data;
441 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
442 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
443 kunit_comp->kunit = test;
444 kunit_comp->expect = -EINVAL; /* expect failure */
446 size = sizeof(tplg_tmpl_empty);
447 data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
448 KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
450 memcpy(data, &tplg_tmpl_empty, sizeof(tplg_tmpl_empty));
453 * any value != magic number is wrong
455 data->header.magic = cpu_to_le32(SND_SOC_TPLG_MAGIC + 1);
457 kunit_comp->fw.data = (u8 *)data;
458 kunit_comp->fw.size = size;
460 kunit_comp->card.dev = test_dev,
461 kunit_comp->card.name = "kunit-card",
462 kunit_comp->card.owner = THIS_MODULE,
463 kunit_comp->card.dai_link = kunit_dai_links,
464 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
465 kunit_comp->card.fully_routed = true,
468 ret = snd_soc_register_card(&kunit_comp->card);
469 if (ret != 0 && ret != -EPROBE_DEFER)
470 KUNIT_FAIL(test, "Failed to register card");
472 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
473 KUNIT_EXPECT_EQ(test, 0, ret);
475 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
476 KUNIT_EXPECT_EQ(test, 0, ret);
479 snd_soc_unregister_card(&kunit_comp->card);
481 snd_soc_unregister_component(test_dev);
485 // Test "empty" topology file, but with bad "abi"
486 // In theory we could loop through all possible bad values, but it takes too
487 // long, so just use SND_SOC_TPLG_ABI_VERSION + 1
488 static void snd_soc_tplg_test_load_empty_tplg_bad_abi(struct kunit *test)
490 struct kunit_soc_component *kunit_comp;
491 struct tplg_tmpl_001 *data;
496 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
497 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
498 kunit_comp->kunit = test;
499 kunit_comp->expect = -EINVAL; /* expect failure */
501 size = sizeof(tplg_tmpl_empty);
502 data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
503 KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
505 memcpy(data, &tplg_tmpl_empty, sizeof(tplg_tmpl_empty));
508 * any value != accepted range is wrong
510 data->header.abi = cpu_to_le32(SND_SOC_TPLG_ABI_VERSION + 1);
512 kunit_comp->fw.data = (u8 *)data;
513 kunit_comp->fw.size = size;
515 kunit_comp->card.dev = test_dev,
516 kunit_comp->card.name = "kunit-card",
517 kunit_comp->card.owner = THIS_MODULE,
518 kunit_comp->card.dai_link = kunit_dai_links,
519 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
520 kunit_comp->card.fully_routed = true,
523 ret = snd_soc_register_card(&kunit_comp->card);
524 if (ret != 0 && ret != -EPROBE_DEFER)
525 KUNIT_FAIL(test, "Failed to register card");
527 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
528 KUNIT_EXPECT_EQ(test, 0, ret);
530 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
531 KUNIT_EXPECT_EQ(test, 0, ret);
534 snd_soc_unregister_card(&kunit_comp->card);
536 snd_soc_unregister_component(test_dev);
540 // Test "empty" topology file, but with bad "size"
541 // In theory we could loop through all possible bad values, but it takes too
542 // long, so just use sizeof(struct snd_soc_tplg_hdr) + 1
543 static void snd_soc_tplg_test_load_empty_tplg_bad_size(struct kunit *test)
545 struct kunit_soc_component *kunit_comp;
546 struct tplg_tmpl_001 *data;
551 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
552 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
553 kunit_comp->kunit = test;
554 kunit_comp->expect = -EINVAL; /* expect failure */
556 size = sizeof(tplg_tmpl_empty);
557 data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
558 KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
560 memcpy(data, &tplg_tmpl_empty, sizeof(tplg_tmpl_empty));
563 * any value != struct size is wrong
565 data->header.size = cpu_to_le32(sizeof(struct snd_soc_tplg_hdr) + 1);
567 kunit_comp->fw.data = (u8 *)data;
568 kunit_comp->fw.size = size;
570 kunit_comp->card.dev = test_dev,
571 kunit_comp->card.name = "kunit-card",
572 kunit_comp->card.owner = THIS_MODULE,
573 kunit_comp->card.dai_link = kunit_dai_links,
574 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
575 kunit_comp->card.fully_routed = true,
578 ret = snd_soc_register_card(&kunit_comp->card);
579 if (ret != 0 && ret != -EPROBE_DEFER)
580 KUNIT_FAIL(test, "Failed to register card");
582 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
583 KUNIT_EXPECT_EQ(test, 0, ret);
585 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
586 KUNIT_EXPECT_EQ(test, 0, ret);
589 snd_soc_unregister_card(&kunit_comp->card);
591 snd_soc_unregister_component(test_dev);
595 // Test "empty" topology file, but with bad "payload_size"
596 // In theory we could loop through all possible bad values, but it takes too
597 // long, so just use the known wrong one
598 static void snd_soc_tplg_test_load_empty_tplg_bad_payload_size(struct kunit *test)
600 struct kunit_soc_component *kunit_comp;
601 struct tplg_tmpl_001 *data;
606 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
607 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
608 kunit_comp->kunit = test;
609 kunit_comp->expect = -EINVAL; /* expect failure */
611 size = sizeof(tplg_tmpl_empty);
612 data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
613 KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
615 memcpy(data, &tplg_tmpl_empty, sizeof(tplg_tmpl_empty));
617 * override payload size
618 * there is only explicit check for 0, so check with it, other values
619 * are handled by just not reading behind EOF
621 data->header.payload_size = 0;
623 kunit_comp->fw.data = (u8 *)data;
624 kunit_comp->fw.size = size;
626 kunit_comp->card.dev = test_dev,
627 kunit_comp->card.name = "kunit-card",
628 kunit_comp->card.owner = THIS_MODULE,
629 kunit_comp->card.dai_link = kunit_dai_links,
630 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
631 kunit_comp->card.fully_routed = true,
634 ret = snd_soc_register_card(&kunit_comp->card);
635 if (ret != 0 && ret != -EPROBE_DEFER)
636 KUNIT_FAIL(test, "Failed to register card");
638 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
639 KUNIT_EXPECT_EQ(test, 0, ret);
641 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
642 KUNIT_EXPECT_EQ(test, 0, ret);
645 snd_soc_unregister_component(test_dev);
647 snd_soc_unregister_card(&kunit_comp->card);
651 // Test passing topology file with PCM definition
652 static void snd_soc_tplg_test_load_pcm_tplg(struct kunit *test)
654 struct kunit_soc_component *kunit_comp;
660 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
661 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
662 kunit_comp->kunit = test;
663 kunit_comp->expect = 0; /* expect success */
665 size = sizeof(tplg_tmpl_with_pcm);
666 data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
667 KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
669 memcpy(data, &tplg_tmpl_with_pcm, sizeof(tplg_tmpl_with_pcm));
671 kunit_comp->fw.data = data;
672 kunit_comp->fw.size = size;
674 kunit_comp->card.dev = test_dev,
675 kunit_comp->card.name = "kunit-card",
676 kunit_comp->card.owner = THIS_MODULE,
677 kunit_comp->card.dai_link = kunit_dai_links,
678 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
679 kunit_comp->card.fully_routed = true,
682 ret = snd_soc_register_card(&kunit_comp->card);
683 if (ret != 0 && ret != -EPROBE_DEFER)
684 KUNIT_FAIL(test, "Failed to register card");
686 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
687 KUNIT_EXPECT_EQ(test, 0, ret);
689 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
690 KUNIT_EXPECT_EQ(test, 0, ret);
692 snd_soc_unregister_component(test_dev);
695 snd_soc_unregister_card(&kunit_comp->card);
699 // Test passing topology file with PCM definition
700 // with component reload
701 static void snd_soc_tplg_test_load_pcm_tplg_reload_comp(struct kunit *test)
703 struct kunit_soc_component *kunit_comp;
710 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
711 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
712 kunit_comp->kunit = test;
713 kunit_comp->expect = 0; /* expect success */
715 size = sizeof(tplg_tmpl_with_pcm);
716 data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
717 KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
719 memcpy(data, &tplg_tmpl_with_pcm, sizeof(tplg_tmpl_with_pcm));
721 kunit_comp->fw.data = data;
722 kunit_comp->fw.size = size;
724 kunit_comp->card.dev = test_dev,
725 kunit_comp->card.name = "kunit-card",
726 kunit_comp->card.owner = THIS_MODULE,
727 kunit_comp->card.dai_link = kunit_dai_links,
728 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
729 kunit_comp->card.fully_routed = true,
732 ret = snd_soc_register_card(&kunit_comp->card);
733 if (ret != 0 && ret != -EPROBE_DEFER)
734 KUNIT_FAIL(test, "Failed to register card");
736 for (i = 0; i < 100; i++) {
737 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
738 KUNIT_EXPECT_EQ(test, 0, ret);
740 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
741 KUNIT_EXPECT_EQ(test, 0, ret);
743 snd_soc_unregister_component(test_dev);
747 snd_soc_unregister_card(&kunit_comp->card);
751 // Test passing topology file with PCM definition
753 static void snd_soc_tplg_test_load_pcm_tplg_reload_card(struct kunit *test)
755 struct kunit_soc_component *kunit_comp;
762 kunit_comp = kunit_kzalloc(test, sizeof(*kunit_comp), GFP_KERNEL);
763 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, kunit_comp);
764 kunit_comp->kunit = test;
765 kunit_comp->expect = 0; /* expect success */
767 size = sizeof(tplg_tmpl_with_pcm);
768 data = kunit_kzalloc(kunit_comp->kunit, size, GFP_KERNEL);
769 KUNIT_EXPECT_NOT_ERR_OR_NULL(kunit_comp->kunit, data);
771 memcpy(data, &tplg_tmpl_with_pcm, sizeof(tplg_tmpl_with_pcm));
773 kunit_comp->fw.data = data;
774 kunit_comp->fw.size = size;
776 kunit_comp->card.dev = test_dev,
777 kunit_comp->card.name = "kunit-card",
778 kunit_comp->card.owner = THIS_MODULE,
779 kunit_comp->card.dai_link = kunit_dai_links,
780 kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links),
781 kunit_comp->card.fully_routed = true,
784 ret = snd_soc_component_initialize(&kunit_comp->comp, &test_component, test_dev);
785 KUNIT_EXPECT_EQ(test, 0, ret);
787 ret = snd_soc_add_component(&kunit_comp->comp, NULL, 0);
788 KUNIT_EXPECT_EQ(test, 0, ret);
790 for (i = 0; i < 100; i++) {
791 ret = snd_soc_register_card(&kunit_comp->card);
792 if (ret != 0 && ret != -EPROBE_DEFER)
793 KUNIT_FAIL(test, "Failed to register card");
795 snd_soc_unregister_card(&kunit_comp->card);
799 snd_soc_unregister_component(test_dev);
802 /* ===== KUNIT MODULE DEFINITIONS =========================================== */
804 static struct kunit_case snd_soc_tplg_test_cases[] = {
805 KUNIT_CASE(snd_soc_tplg_test_load_with_null_comp),
806 KUNIT_CASE(snd_soc_tplg_test_load_with_null_ops),
807 KUNIT_CASE(snd_soc_tplg_test_load_with_null_fw),
808 KUNIT_CASE(snd_soc_tplg_test_load_empty_tplg),
809 KUNIT_CASE(snd_soc_tplg_test_load_empty_tplg_bad_magic),
810 KUNIT_CASE(snd_soc_tplg_test_load_empty_tplg_bad_abi),
811 KUNIT_CASE(snd_soc_tplg_test_load_empty_tplg_bad_size),
812 KUNIT_CASE(snd_soc_tplg_test_load_empty_tplg_bad_payload_size),
813 KUNIT_CASE(snd_soc_tplg_test_load_pcm_tplg),
814 KUNIT_CASE(snd_soc_tplg_test_load_pcm_tplg_reload_comp),
815 KUNIT_CASE(snd_soc_tplg_test_load_pcm_tplg_reload_card),
819 static struct kunit_suite snd_soc_tplg_test_suite = {
820 .name = "snd_soc_tplg_test",
821 .init = snd_soc_tplg_test_init,
822 .exit = snd_soc_tplg_test_exit,
823 .test_cases = snd_soc_tplg_test_cases,
826 kunit_test_suites(&snd_soc_tplg_test_suite);
828 MODULE_LICENSE("GPL");