1 // SPDX-License-Identifier: GPL-2.0-only
3 // KUnit test for the Cirrus common amplifier library.
5 // Copyright (C) 2024 Cirrus Logic, Inc. and
6 // Cirrus Logic International Semiconductor Ltd.
8 #include <kunit/test.h>
9 #include <kunit/static_stub.h>
10 #include <linux/firmware/cirrus/cs_dsp.h>
11 #include <linux/firmware/cirrus/wmfw.h>
12 #include <linux/gpio/driver.h>
13 #include <linux/list.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/random.h>
17 #include <sound/cs-amp-lib.h>
19 struct cs_amp_lib_test_priv {
20 struct platform_device amp_pdev;
22 struct cirrus_amp_efi_data *cal_blob;
23 struct list_head ctl_write_list;
26 struct cs_amp_lib_test_ctl_write_entry {
27 struct list_head list;
32 struct cs_amp_lib_test_param {
37 static void cs_amp_lib_test_init_dummy_cal_blob(struct kunit *test, int num_amps)
39 struct cs_amp_lib_test_priv *priv = test->priv;
40 unsigned int blob_size;
42 blob_size = offsetof(struct cirrus_amp_efi_data, data) +
43 sizeof(struct cirrus_amp_cal_data) * num_amps;
45 priv->cal_blob = kunit_kzalloc(test, blob_size, GFP_KERNEL);
46 KUNIT_ASSERT_NOT_NULL(test, priv->cal_blob);
48 priv->cal_blob->size = blob_size;
49 priv->cal_blob->count = num_amps;
51 get_random_bytes(priv->cal_blob->data, sizeof(struct cirrus_amp_cal_data) * num_amps);
54 static u64 cs_amp_lib_test_get_target_uid(struct kunit *test)
56 struct cs_amp_lib_test_priv *priv = test->priv;
57 const struct cs_amp_lib_test_param *param = test->param_value;
60 uid = priv->cal_blob->data[param->amp_index].calTarget[1];
62 uid |= priv->cal_blob->data[param->amp_index].calTarget[0];
67 /* Redirected get_efi_variable to simulate that the file is too short */
68 static efi_status_t cs_amp_lib_test_get_efi_variable_nohead(efi_char16_t *name,
74 *size = offsetof(struct cirrus_amp_efi_data, data) - 1;
75 return EFI_BUFFER_TOO_SMALL;
81 /* Should return -EOVERFLOW if the header is larger than the EFI data */
82 static void cs_amp_lib_test_cal_data_too_short_test(struct kunit *test)
84 struct cs_amp_lib_test_priv *priv = test->priv;
85 struct cirrus_amp_cal_data result_data;
88 /* Redirect calls to get EFI data */
89 kunit_activate_static_stub(test,
90 cs_amp_test_hooks->get_efi_variable,
91 cs_amp_lib_test_get_efi_variable_nohead);
93 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 0, &result_data);
94 KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW);
96 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
99 /* Redirected get_efi_variable to simulate that the count is larger than the file */
100 static efi_status_t cs_amp_lib_test_get_efi_variable_bad_count(efi_char16_t *name,
105 struct kunit *test = kunit_get_current_test();
106 struct cs_amp_lib_test_priv *priv = test->priv;
110 * Return a size that is shorter than required for the
111 * declared number of entries.
113 *size = priv->cal_blob->size - 1;
114 return EFI_BUFFER_TOO_SMALL;
117 memcpy(buf, priv->cal_blob, priv->cal_blob->size - 1);
122 /* Should return -EOVERFLOW if the entry count is larger than the EFI data */
123 static void cs_amp_lib_test_cal_count_too_big_test(struct kunit *test)
125 struct cs_amp_lib_test_priv *priv = test->priv;
126 struct cirrus_amp_cal_data result_data;
129 cs_amp_lib_test_init_dummy_cal_blob(test, 8);
131 /* Redirect calls to get EFI data */
132 kunit_activate_static_stub(test,
133 cs_amp_test_hooks->get_efi_variable,
134 cs_amp_lib_test_get_efi_variable_bad_count);
136 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 0, &result_data);
137 KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW);
139 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
142 /* Redirected get_efi_variable to simulate that the variable not found */
143 static efi_status_t cs_amp_lib_test_get_efi_variable_none(efi_char16_t *name,
148 return EFI_NOT_FOUND;
151 /* If EFI doesn't contain a cal data variable the result should be -ENOENT */
152 static void cs_amp_lib_test_no_cal_data_test(struct kunit *test)
154 struct cs_amp_lib_test_priv *priv = test->priv;
155 struct cirrus_amp_cal_data result_data;
158 /* Redirect calls to get EFI data */
159 kunit_activate_static_stub(test,
160 cs_amp_test_hooks->get_efi_variable,
161 cs_amp_lib_test_get_efi_variable_none);
163 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 0, &result_data);
164 KUNIT_EXPECT_EQ(test, ret, -ENOENT);
166 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
169 /* Redirected get_efi_variable to simulate reading a cal data blob */
170 static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name,
175 static const efi_char16_t expected_name[] = L"CirrusSmartAmpCalibrationData";
176 static const efi_guid_t expected_guid =
177 EFI_GUID(0x02f9af02, 0x7734, 0x4233, 0xb4, 0x3d, 0x93, 0xfe, 0x5a, 0xa3, 0x5d, 0xb3);
178 struct kunit *test = kunit_get_current_test();
179 struct cs_amp_lib_test_priv *priv = test->priv;
181 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, name);
182 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, guid);
183 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, size);
185 KUNIT_EXPECT_MEMEQ(test, name, expected_name, sizeof(expected_name));
186 KUNIT_EXPECT_MEMEQ(test, guid, &expected_guid, sizeof(expected_guid));
189 *size = priv->cal_blob->size;
190 return EFI_BUFFER_TOO_SMALL;
193 KUNIT_ASSERT_GE_MSG(test, ksize(buf), priv->cal_blob->size, "Buffer to small");
195 memcpy(buf, priv->cal_blob, priv->cal_blob->size);
200 /* Get cal data block for a given amp, matched by target UID. */
201 static void cs_amp_lib_test_get_efi_cal_by_uid_test(struct kunit *test)
203 struct cs_amp_lib_test_priv *priv = test->priv;
204 const struct cs_amp_lib_test_param *param = test->param_value;
205 struct cirrus_amp_cal_data result_data;
209 cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
211 /* Redirect calls to get EFI data */
212 kunit_activate_static_stub(test,
213 cs_amp_test_hooks->get_efi_variable,
214 cs_amp_lib_test_get_efi_variable);
216 target_uid = cs_amp_lib_test_get_target_uid(test);
217 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, target_uid, -1, &result_data);
218 KUNIT_EXPECT_EQ(test, ret, 0);
220 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
222 KUNIT_EXPECT_EQ(test, result_data.calTarget[0], target_uid & 0xFFFFFFFFULL);
223 KUNIT_EXPECT_EQ(test, result_data.calTarget[1], target_uid >> 32);
224 KUNIT_EXPECT_EQ(test, result_data.calTime[0],
225 priv->cal_blob->data[param->amp_index].calTime[0]);
226 KUNIT_EXPECT_EQ(test, result_data.calTime[1],
227 priv->cal_blob->data[param->amp_index].calTime[1]);
228 KUNIT_EXPECT_EQ(test, result_data.calAmbient,
229 priv->cal_blob->data[param->amp_index].calAmbient);
230 KUNIT_EXPECT_EQ(test, result_data.calStatus,
231 priv->cal_blob->data[param->amp_index].calStatus);
232 KUNIT_EXPECT_EQ(test, result_data.calR,
233 priv->cal_blob->data[param->amp_index].calR);
236 /* Get cal data block for a given amp index without checking target UID. */
237 static void cs_amp_lib_test_get_efi_cal_by_index_unchecked_test(struct kunit *test)
239 struct cs_amp_lib_test_priv *priv = test->priv;
240 const struct cs_amp_lib_test_param *param = test->param_value;
241 struct cirrus_amp_cal_data result_data;
244 cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
246 /* Redirect calls to get EFI data */
247 kunit_activate_static_stub(test,
248 cs_amp_test_hooks->get_efi_variable,
249 cs_amp_lib_test_get_efi_variable);
251 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0,
252 param->amp_index, &result_data);
253 KUNIT_EXPECT_EQ(test, ret, 0);
255 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
257 KUNIT_EXPECT_EQ(test, result_data.calTime[0],
258 priv->cal_blob->data[param->amp_index].calTime[0]);
259 KUNIT_EXPECT_EQ(test, result_data.calTime[1],
260 priv->cal_blob->data[param->amp_index].calTime[1]);
261 KUNIT_EXPECT_EQ(test, result_data.calAmbient,
262 priv->cal_blob->data[param->amp_index].calAmbient);
263 KUNIT_EXPECT_EQ(test, result_data.calStatus,
264 priv->cal_blob->data[param->amp_index].calStatus);
265 KUNIT_EXPECT_EQ(test, result_data.calR,
266 priv->cal_blob->data[param->amp_index].calR);
269 /* Get cal data block for a given amp index with checked target UID. */
270 static void cs_amp_lib_test_get_efi_cal_by_index_checked_test(struct kunit *test)
272 struct cs_amp_lib_test_priv *priv = test->priv;
273 const struct cs_amp_lib_test_param *param = test->param_value;
274 struct cirrus_amp_cal_data result_data;
278 cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
280 /* Redirect calls to get EFI data */
281 kunit_activate_static_stub(test,
282 cs_amp_test_hooks->get_efi_variable,
283 cs_amp_lib_test_get_efi_variable);
285 target_uid = cs_amp_lib_test_get_target_uid(test);
286 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, target_uid,
287 param->amp_index, &result_data);
288 KUNIT_EXPECT_EQ(test, ret, 0);
290 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
292 KUNIT_EXPECT_EQ(test, result_data.calTime[0],
293 priv->cal_blob->data[param->amp_index].calTime[0]);
294 KUNIT_EXPECT_EQ(test, result_data.calTime[1],
295 priv->cal_blob->data[param->amp_index].calTime[1]);
296 KUNIT_EXPECT_EQ(test, result_data.calAmbient,
297 priv->cal_blob->data[param->amp_index].calAmbient);
298 KUNIT_EXPECT_EQ(test, result_data.calStatus,
299 priv->cal_blob->data[param->amp_index].calStatus);
300 KUNIT_EXPECT_EQ(test, result_data.calR,
301 priv->cal_blob->data[param->amp_index].calR);
305 * Get cal data block for a given amp index with checked target UID.
306 * The UID does not match so the result should be -ENOENT.
308 static void cs_amp_lib_test_get_efi_cal_by_index_uid_mismatch_test(struct kunit *test)
310 struct cs_amp_lib_test_priv *priv = test->priv;
311 const struct cs_amp_lib_test_param *param = test->param_value;
312 struct cirrus_amp_cal_data result_data;
316 cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
318 /* Redirect calls to get EFI data */
319 kunit_activate_static_stub(test,
320 cs_amp_test_hooks->get_efi_variable,
321 cs_amp_lib_test_get_efi_variable);
323 /* Get a target UID that won't match the entry */
324 target_uid = ~cs_amp_lib_test_get_target_uid(test);
325 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, target_uid,
326 param->amp_index, &result_data);
327 KUNIT_EXPECT_EQ(test, ret, -ENOENT);
329 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
333 * Get cal data block for a given amp, where the cal data does not
334 * specify calTarget so the lookup falls back to using the index
336 static void cs_amp_lib_test_get_efi_cal_by_index_fallback_test(struct kunit *test)
338 struct cs_amp_lib_test_priv *priv = test->priv;
339 const struct cs_amp_lib_test_param *param = test->param_value;
340 struct cirrus_amp_cal_data result_data;
341 static const u64 bad_target_uid = 0xBADCA100BABABABAULL;
344 cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
346 /* Make all the target values zero so they are ignored */
347 for (i = 0; i < priv->cal_blob->count; ++i) {
348 priv->cal_blob->data[i].calTarget[0] = 0;
349 priv->cal_blob->data[i].calTarget[1] = 0;
352 /* Redirect calls to get EFI data */
353 kunit_activate_static_stub(test,
354 cs_amp_test_hooks->get_efi_variable,
355 cs_amp_lib_test_get_efi_variable);
357 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, bad_target_uid,
358 param->amp_index, &result_data);
359 KUNIT_EXPECT_EQ(test, ret, 0);
361 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
363 KUNIT_EXPECT_EQ(test, result_data.calTime[0],
364 priv->cal_blob->data[param->amp_index].calTime[0]);
365 KUNIT_EXPECT_EQ(test, result_data.calTime[1],
366 priv->cal_blob->data[param->amp_index].calTime[1]);
367 KUNIT_EXPECT_EQ(test, result_data.calAmbient,
368 priv->cal_blob->data[param->amp_index].calAmbient);
369 KUNIT_EXPECT_EQ(test, result_data.calStatus,
370 priv->cal_blob->data[param->amp_index].calStatus);
371 KUNIT_EXPECT_EQ(test, result_data.calR,
372 priv->cal_blob->data[param->amp_index].calR);
376 * If the target UID isn't present in the cal data, and there isn't an
377 * index to fall back do, the result should be -ENOENT.
379 static void cs_amp_lib_test_get_efi_cal_uid_not_found_noindex_test(struct kunit *test)
381 struct cs_amp_lib_test_priv *priv = test->priv;
382 struct cirrus_amp_cal_data result_data;
383 static const u64 bad_target_uid = 0xBADCA100BABABABAULL;
386 cs_amp_lib_test_init_dummy_cal_blob(test, 8);
388 /* Make all the target values != bad_target_uid */
389 for (i = 0; i < priv->cal_blob->count; ++i) {
390 priv->cal_blob->data[i].calTarget[0] &= ~(bad_target_uid & 0xFFFFFFFFULL);
391 priv->cal_blob->data[i].calTarget[1] &= ~(bad_target_uid >> 32);
394 /* Redirect calls to get EFI data */
395 kunit_activate_static_stub(test,
396 cs_amp_test_hooks->get_efi_variable,
397 cs_amp_lib_test_get_efi_variable);
399 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, bad_target_uid, -1,
401 KUNIT_EXPECT_EQ(test, ret, -ENOENT);
403 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
407 * If the target UID isn't present in the cal data, and the index is
408 * out of range, the result should be -ENOENT.
410 static void cs_amp_lib_test_get_efi_cal_uid_not_found_index_not_found_test(struct kunit *test)
412 struct cs_amp_lib_test_priv *priv = test->priv;
413 struct cirrus_amp_cal_data result_data;
414 static const u64 bad_target_uid = 0xBADCA100BABABABAULL;
417 cs_amp_lib_test_init_dummy_cal_blob(test, 8);
419 /* Make all the target values != bad_target_uid */
420 for (i = 0; i < priv->cal_blob->count; ++i) {
421 priv->cal_blob->data[i].calTarget[0] &= ~(bad_target_uid & 0xFFFFFFFFULL);
422 priv->cal_blob->data[i].calTarget[1] &= ~(bad_target_uid >> 32);
425 /* Redirect calls to get EFI data */
426 kunit_activate_static_stub(test,
427 cs_amp_test_hooks->get_efi_variable,
428 cs_amp_lib_test_get_efi_variable);
430 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, bad_target_uid, 99,
432 KUNIT_EXPECT_EQ(test, ret, -ENOENT);
434 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
438 * If the target UID isn't given, and the index is out of range, the
439 * result should be -ENOENT.
441 static void cs_amp_lib_test_get_efi_cal_no_uid_index_not_found_test(struct kunit *test)
443 struct cs_amp_lib_test_priv *priv = test->priv;
444 struct cirrus_amp_cal_data result_data;
447 cs_amp_lib_test_init_dummy_cal_blob(test, 8);
449 /* Redirect calls to get EFI data */
450 kunit_activate_static_stub(test,
451 cs_amp_test_hooks->get_efi_variable,
452 cs_amp_lib_test_get_efi_variable);
454 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 99, &result_data);
455 KUNIT_EXPECT_EQ(test, ret, -ENOENT);
457 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
460 /* If neither the target UID or the index is given the result should be -ENOENT. */
461 static void cs_amp_lib_test_get_efi_cal_no_uid_no_index_test(struct kunit *test)
463 struct cs_amp_lib_test_priv *priv = test->priv;
464 struct cirrus_amp_cal_data result_data;
467 cs_amp_lib_test_init_dummy_cal_blob(test, 8);
469 /* Redirect calls to get EFI data */
470 kunit_activate_static_stub(test,
471 cs_amp_test_hooks->get_efi_variable,
472 cs_amp_lib_test_get_efi_variable);
474 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, -1, &result_data);
475 KUNIT_EXPECT_EQ(test, ret, -ENOENT);
477 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
481 * If the UID is passed as 0 this must not match an entry with an
482 * unpopulated calTarget
484 static void cs_amp_lib_test_get_efi_cal_zero_not_matched_test(struct kunit *test)
486 struct cs_amp_lib_test_priv *priv = test->priv;
487 struct cirrus_amp_cal_data result_data;
490 cs_amp_lib_test_init_dummy_cal_blob(test, 8);
492 /* Make all the target values zero so they are ignored */
493 for (i = 0; i < priv->cal_blob->count; ++i) {
494 priv->cal_blob->data[i].calTarget[0] = 0;
495 priv->cal_blob->data[i].calTarget[1] = 0;
498 /* Redirect calls to get EFI data */
499 kunit_activate_static_stub(test,
500 cs_amp_test_hooks->get_efi_variable,
501 cs_amp_lib_test_get_efi_variable);
503 ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, -1, &result_data);
504 KUNIT_EXPECT_EQ(test, ret, -ENOENT);
506 kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
509 static const struct cirrus_amp_cal_controls cs_amp_lib_test_calibration_controls = {
511 .mem_region = WMFW_ADSP2_YM,
512 .ambient = "CAL_AMBIENT",
514 .status = "CAL_STATUS",
515 .checksum = "CAL_CHECKSUM",
518 static int cs_amp_lib_test_write_cal_coeff(struct cs_dsp *dsp,
519 const struct cirrus_amp_cal_controls *controls,
520 const char *ctl_name, u32 val)
522 struct kunit *test = kunit_get_current_test();
523 struct cs_amp_lib_test_priv *priv = test->priv;
524 struct cs_amp_lib_test_ctl_write_entry *entry;
526 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctl_name);
527 KUNIT_EXPECT_PTR_EQ(test, controls, &cs_amp_lib_test_calibration_controls);
529 entry = kunit_kzalloc(test, sizeof(*entry), GFP_KERNEL);
530 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, entry);
532 INIT_LIST_HEAD(&entry->list);
533 strscpy(entry->name, ctl_name, sizeof(entry->name));
536 list_add_tail(&entry->list, &priv->ctl_write_list);
541 static void cs_amp_lib_test_write_cal_data_test(struct kunit *test)
543 struct cs_amp_lib_test_priv *priv = test->priv;
544 struct cs_amp_lib_test_ctl_write_entry *entry;
545 struct cirrus_amp_cal_data data;
549 dsp = kunit_kzalloc(test, sizeof(*dsp), GFP_KERNEL);
550 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dsp);
551 dsp->dev = &priv->amp_pdev.dev;
553 get_random_bytes(&data, sizeof(data));
555 /* Redirect calls to write firmware controls */
556 kunit_activate_static_stub(test,
557 cs_amp_test_hooks->write_cal_coeff,
558 cs_amp_lib_test_write_cal_coeff);
560 ret = cs_amp_write_cal_coeffs(dsp, &cs_amp_lib_test_calibration_controls, &data);
561 KUNIT_EXPECT_EQ(test, ret, 0);
563 kunit_deactivate_static_stub(test, cs_amp_test_hooks->write_cal_coeff);
565 KUNIT_EXPECT_EQ(test, list_count_nodes(&priv->ctl_write_list), 4);
567 /* Checksum control must be written last */
568 entry = list_last_entry(&priv->ctl_write_list, typeof(*entry), list);
569 KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.checksum);
570 KUNIT_EXPECT_EQ(test, entry->value, data.calR + 1);
571 list_del(&entry->list);
573 entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list);
574 KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.ambient);
575 KUNIT_EXPECT_EQ(test, entry->value, data.calAmbient);
576 list_del(&entry->list);
578 entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list);
579 KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.calr);
580 KUNIT_EXPECT_EQ(test, entry->value, data.calR);
581 list_del(&entry->list);
583 entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list);
584 KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.status);
585 KUNIT_EXPECT_EQ(test, entry->value, data.calStatus);
588 static void cs_amp_lib_test_dev_release(struct device *dev)
592 static int cs_amp_lib_test_case_init(struct kunit *test)
594 struct cs_amp_lib_test_priv *priv;
597 KUNIT_ASSERT_NOT_NULL(test, cs_amp_test_hooks);
599 priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
604 INIT_LIST_HEAD(&priv->ctl_write_list);
606 /* Create dummy amp driver dev */
607 priv->amp_pdev.name = "cs_amp_lib_test_drv";
608 priv->amp_pdev.id = -1;
609 priv->amp_pdev.dev.release = cs_amp_lib_test_dev_release;
610 ret = platform_device_register(&priv->amp_pdev);
611 KUNIT_ASSERT_GE_MSG(test, ret, 0, "Failed to register amp platform device\n");
616 static void cs_amp_lib_test_case_exit(struct kunit *test)
618 struct cs_amp_lib_test_priv *priv = test->priv;
620 if (priv->amp_pdev.name)
621 platform_device_unregister(&priv->amp_pdev);
624 static const struct cs_amp_lib_test_param cs_amp_lib_test_get_cal_param_cases[] = {
625 { .num_amps = 2, .amp_index = 0 },
626 { .num_amps = 2, .amp_index = 1 },
628 { .num_amps = 3, .amp_index = 0 },
629 { .num_amps = 3, .amp_index = 1 },
630 { .num_amps = 3, .amp_index = 2 },
632 { .num_amps = 4, .amp_index = 0 },
633 { .num_amps = 4, .amp_index = 1 },
634 { .num_amps = 4, .amp_index = 2 },
635 { .num_amps = 4, .amp_index = 3 },
637 { .num_amps = 5, .amp_index = 0 },
638 { .num_amps = 5, .amp_index = 1 },
639 { .num_amps = 5, .amp_index = 2 },
640 { .num_amps = 5, .amp_index = 3 },
641 { .num_amps = 5, .amp_index = 4 },
643 { .num_amps = 6, .amp_index = 0 },
644 { .num_amps = 6, .amp_index = 1 },
645 { .num_amps = 6, .amp_index = 2 },
646 { .num_amps = 6, .amp_index = 3 },
647 { .num_amps = 6, .amp_index = 4 },
648 { .num_amps = 6, .amp_index = 5 },
650 { .num_amps = 8, .amp_index = 0 },
651 { .num_amps = 8, .amp_index = 1 },
652 { .num_amps = 8, .amp_index = 2 },
653 { .num_amps = 8, .amp_index = 3 },
654 { .num_amps = 8, .amp_index = 4 },
655 { .num_amps = 8, .amp_index = 5 },
656 { .num_amps = 8, .amp_index = 6 },
657 { .num_amps = 8, .amp_index = 7 },
660 static void cs_amp_lib_test_get_cal_param_desc(const struct cs_amp_lib_test_param *param,
663 snprintf(desc, KUNIT_PARAM_DESC_SIZE, "num_amps:%d amp_index:%d",
664 param->num_amps, param->amp_index);
667 KUNIT_ARRAY_PARAM(cs_amp_lib_test_get_cal, cs_amp_lib_test_get_cal_param_cases,
668 cs_amp_lib_test_get_cal_param_desc);
670 static struct kunit_case cs_amp_lib_test_cases[] = {
671 /* Tests for getting calibration data from EFI */
672 KUNIT_CASE(cs_amp_lib_test_cal_data_too_short_test),
673 KUNIT_CASE(cs_amp_lib_test_cal_count_too_big_test),
674 KUNIT_CASE(cs_amp_lib_test_no_cal_data_test),
675 KUNIT_CASE(cs_amp_lib_test_get_efi_cal_uid_not_found_noindex_test),
676 KUNIT_CASE(cs_amp_lib_test_get_efi_cal_uid_not_found_index_not_found_test),
677 KUNIT_CASE(cs_amp_lib_test_get_efi_cal_no_uid_index_not_found_test),
678 KUNIT_CASE(cs_amp_lib_test_get_efi_cal_no_uid_no_index_test),
679 KUNIT_CASE(cs_amp_lib_test_get_efi_cal_zero_not_matched_test),
680 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_uid_test,
681 cs_amp_lib_test_get_cal_gen_params),
682 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_unchecked_test,
683 cs_amp_lib_test_get_cal_gen_params),
684 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_checked_test,
685 cs_amp_lib_test_get_cal_gen_params),
686 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_uid_mismatch_test,
687 cs_amp_lib_test_get_cal_gen_params),
688 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_fallback_test,
689 cs_amp_lib_test_get_cal_gen_params),
691 /* Tests for writing calibration data */
692 KUNIT_CASE(cs_amp_lib_test_write_cal_data_test),
697 static struct kunit_suite cs_amp_lib_test_suite = {
698 .name = "snd-soc-cs-amp-lib-test",
699 .init = cs_amp_lib_test_case_init,
700 .exit = cs_amp_lib_test_case_exit,
701 .test_cases = cs_amp_lib_test_cases,
704 kunit_test_suite(cs_amp_lib_test_suite);
706 MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB);
707 MODULE_DESCRIPTION("KUnit test for Cirrus Logic amplifier library");
709 MODULE_LICENSE("GPL");