~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/codecs/cs-amp-lib-test.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/soc/codecs/cs-amp-lib-test.c (Architecture i386) and /sound/soc/codecs/cs-amp-lib-test.c (Architecture sparc)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 //                                                  2 //
  3 // KUnit test for the Cirrus common amplifier       3 // KUnit test for the Cirrus common amplifier library.
  4 //                                                  4 //
  5 // Copyright (C) 2024 Cirrus Logic, Inc. and        5 // Copyright (C) 2024 Cirrus Logic, Inc. and
  6 //                    Cirrus Logic Internation      6 //                    Cirrus Logic International Semiconductor Ltd.
  7                                                     7 
  8 #include <kunit/test.h>                             8 #include <kunit/test.h>
  9 #include <kunit/static_stub.h>                      9 #include <kunit/static_stub.h>
 10 #include <linux/firmware/cirrus/cs_dsp.h>          10 #include <linux/firmware/cirrus/cs_dsp.h>
 11 #include <linux/firmware/cirrus/wmfw.h>            11 #include <linux/firmware/cirrus/wmfw.h>
 12 #include <linux/gpio/driver.h>                     12 #include <linux/gpio/driver.h>
 13 #include <linux/list.h>                            13 #include <linux/list.h>
 14 #include <linux/module.h>                          14 #include <linux/module.h>
 15 #include <linux/platform_device.h>                 15 #include <linux/platform_device.h>
 16 #include <linux/random.h>                          16 #include <linux/random.h>
 17 #include <sound/cs-amp-lib.h>                      17 #include <sound/cs-amp-lib.h>
 18                                                    18 
 19 struct cs_amp_lib_test_priv {                      19 struct cs_amp_lib_test_priv {
 20         struct platform_device amp_pdev;           20         struct platform_device amp_pdev;
 21                                                    21 
 22         struct cirrus_amp_efi_data *cal_blob;      22         struct cirrus_amp_efi_data *cal_blob;
 23         struct list_head ctl_write_list;           23         struct list_head ctl_write_list;
 24 };                                                 24 };
 25                                                    25 
 26 struct cs_amp_lib_test_ctl_write_entry {           26 struct cs_amp_lib_test_ctl_write_entry {
 27         struct list_head list;                     27         struct list_head list;
 28         unsigned int value;                        28         unsigned int value;
 29         char name[16];                             29         char name[16];
 30 };                                                 30 };
 31                                                    31 
 32 struct cs_amp_lib_test_param {                     32 struct cs_amp_lib_test_param {
 33         int num_amps;                              33         int num_amps;
 34         int amp_index;                             34         int amp_index;
 35 };                                                 35 };
 36                                                    36 
 37 static void cs_amp_lib_test_init_dummy_cal_blo     37 static void cs_amp_lib_test_init_dummy_cal_blob(struct kunit *test, int num_amps)
 38 {                                                  38 {
 39         struct cs_amp_lib_test_priv *priv = te     39         struct cs_amp_lib_test_priv *priv = test->priv;
 40         unsigned int blob_size;                    40         unsigned int blob_size;
 41         int i;                                     41         int i;
 42                                                    42 
 43         blob_size = offsetof(struct cirrus_amp     43         blob_size = offsetof(struct cirrus_amp_efi_data, data) +
 44                     sizeof(struct cirrus_amp_c     44                     sizeof(struct cirrus_amp_cal_data) * num_amps;
 45                                                    45 
 46         priv->cal_blob = kunit_kzalloc(test, b     46         priv->cal_blob = kunit_kzalloc(test, blob_size, GFP_KERNEL);
 47         KUNIT_ASSERT_NOT_NULL(test, priv->cal_     47         KUNIT_ASSERT_NOT_NULL(test, priv->cal_blob);
 48                                                    48 
 49         priv->cal_blob->size = blob_size;          49         priv->cal_blob->size = blob_size;
 50         priv->cal_blob->count = num_amps;          50         priv->cal_blob->count = num_amps;
 51                                                    51 
 52         get_random_bytes(priv->cal_blob->data,     52         get_random_bytes(priv->cal_blob->data, sizeof(struct cirrus_amp_cal_data) * num_amps);
 53                                                    53 
 54         /* Ensure all timestamps are non-zero      54         /* Ensure all timestamps are non-zero to mark the entry valid. */
 55         for (i = 0; i < num_amps; i++)             55         for (i = 0; i < num_amps; i++)
 56                 priv->cal_blob->data[i].calTim     56                 priv->cal_blob->data[i].calTime[0] |= 1;
 57                                                    57 
 58         /* Ensure that all UIDs are non-zero a     58         /* Ensure that all UIDs are non-zero and unique. */
 59         for (i = 0; i < num_amps; i++)             59         for (i = 0; i < num_amps; i++)
 60                 *(u8 *)&priv->cal_blob->data[i     60                 *(u8 *)&priv->cal_blob->data[i].calTarget[0] = i + 1;
 61 }                                                  61 }
 62                                                    62 
 63 static u64 cs_amp_lib_test_get_target_uid(stru     63 static u64 cs_amp_lib_test_get_target_uid(struct kunit *test)
 64 {                                                  64 {
 65         struct cs_amp_lib_test_priv *priv = te     65         struct cs_amp_lib_test_priv *priv = test->priv;
 66         const struct cs_amp_lib_test_param *pa     66         const struct cs_amp_lib_test_param *param = test->param_value;
 67         u64 uid;                                   67         u64 uid;
 68                                                    68 
 69         uid = priv->cal_blob->data[param->amp_     69         uid = priv->cal_blob->data[param->amp_index].calTarget[1];
 70         uid <<= 32;                                70         uid <<= 32;
 71         uid |= priv->cal_blob->data[param->amp     71         uid |= priv->cal_blob->data[param->amp_index].calTarget[0];
 72                                                    72 
 73         return uid;                                73         return uid;
 74 }                                                  74 }
 75                                                    75 
 76 /* Redirected get_efi_variable to simulate tha     76 /* Redirected get_efi_variable to simulate that the file is too short */
 77 static efi_status_t cs_amp_lib_test_get_efi_va     77 static efi_status_t cs_amp_lib_test_get_efi_variable_nohead(efi_char16_t *name,
 78                                                    78                                                             efi_guid_t *guid,
 79                                                    79                                                             unsigned long *size,
 80                                                    80                                                             void *buf)
 81 {                                                  81 {
 82         if (!buf) {                                82         if (!buf) {
 83                 *size = offsetof(struct cirrus     83                 *size = offsetof(struct cirrus_amp_efi_data, data) - 1;
 84                 return EFI_BUFFER_TOO_SMALL;       84                 return EFI_BUFFER_TOO_SMALL;
 85         }                                          85         }
 86                                                    86 
 87         return EFI_NOT_FOUND;                      87         return EFI_NOT_FOUND;
 88 }                                                  88 }
 89                                                    89 
 90 /* Should return -EOVERFLOW if the header is l     90 /* Should return -EOVERFLOW if the header is larger than the EFI data */
 91 static void cs_amp_lib_test_cal_data_too_short     91 static void cs_amp_lib_test_cal_data_too_short_test(struct kunit *test)
 92 {                                                  92 {
 93         struct cs_amp_lib_test_priv *priv = te     93         struct cs_amp_lib_test_priv *priv = test->priv;
 94         struct cirrus_amp_cal_data result_data     94         struct cirrus_amp_cal_data result_data;
 95         int ret;                                   95         int ret;
 96                                                    96 
 97         /* Redirect calls to get EFI data */       97         /* Redirect calls to get EFI data */
 98         kunit_activate_static_stub(test,           98         kunit_activate_static_stub(test,
 99                                    cs_amp_test     99                                    cs_amp_test_hooks->get_efi_variable,
100                                    cs_amp_lib_    100                                    cs_amp_lib_test_get_efi_variable_nohead);
101                                                   101 
102         ret = cs_amp_get_efi_calibration_data(    102         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 0, &result_data);
103         KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW)    103         KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW);
104                                                   104 
105         kunit_deactivate_static_stub(test, cs_    105         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
106 }                                                 106 }
107                                                   107 
108 /* Redirected get_efi_variable to simulate tha    108 /* Redirected get_efi_variable to simulate that the count is larger than the file */
109 static efi_status_t cs_amp_lib_test_get_efi_va    109 static efi_status_t cs_amp_lib_test_get_efi_variable_bad_count(efi_char16_t *name,
110                                                   110                                                                efi_guid_t *guid,
111                                                   111                                                                unsigned long *size,
112                                                   112                                                                void *buf)
113 {                                                 113 {
114         struct kunit *test = kunit_get_current    114         struct kunit *test = kunit_get_current_test();
115         struct cs_amp_lib_test_priv *priv = te    115         struct cs_amp_lib_test_priv *priv = test->priv;
116                                                   116 
117         if (!buf) {                               117         if (!buf) {
118                 /*                                118                 /*
119                  * Return a size that is short    119                  * Return a size that is shorter than required for the
120                  * declared number of entries.    120                  * declared number of entries.
121                  */                               121                  */
122                 *size = priv->cal_blob->size -    122                 *size = priv->cal_blob->size - 1;
123                 return EFI_BUFFER_TOO_SMALL;      123                 return EFI_BUFFER_TOO_SMALL;
124         }                                         124         }
125                                                   125 
126         memcpy(buf, priv->cal_blob, priv->cal_    126         memcpy(buf, priv->cal_blob, priv->cal_blob->size - 1);
127                                                   127 
128         return EFI_SUCCESS;                       128         return EFI_SUCCESS;
129 }                                                 129 }
130                                                   130 
131 /* Should return -EOVERFLOW if the entry count    131 /* Should return -EOVERFLOW if the entry count is larger than the EFI data */
132 static void cs_amp_lib_test_cal_count_too_big_    132 static void cs_amp_lib_test_cal_count_too_big_test(struct kunit *test)
133 {                                                 133 {
134         struct cs_amp_lib_test_priv *priv = te    134         struct cs_amp_lib_test_priv *priv = test->priv;
135         struct cirrus_amp_cal_data result_data    135         struct cirrus_amp_cal_data result_data;
136         int ret;                                  136         int ret;
137                                                   137 
138         cs_amp_lib_test_init_dummy_cal_blob(te    138         cs_amp_lib_test_init_dummy_cal_blob(test, 8);
139                                                   139 
140         /* Redirect calls to get EFI data */      140         /* Redirect calls to get EFI data */
141         kunit_activate_static_stub(test,          141         kunit_activate_static_stub(test,
142                                    cs_amp_test    142                                    cs_amp_test_hooks->get_efi_variable,
143                                    cs_amp_lib_    143                                    cs_amp_lib_test_get_efi_variable_bad_count);
144                                                   144 
145         ret = cs_amp_get_efi_calibration_data(    145         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 0, &result_data);
146         KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW)    146         KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW);
147                                                   147 
148         kunit_deactivate_static_stub(test, cs_    148         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
149 }                                                 149 }
150                                                   150 
151 /* Redirected get_efi_variable to simulate tha    151 /* Redirected get_efi_variable to simulate that the variable not found */
152 static efi_status_t cs_amp_lib_test_get_efi_va    152 static efi_status_t cs_amp_lib_test_get_efi_variable_none(efi_char16_t *name,
153                                                   153                                                           efi_guid_t *guid,
154                                                   154                                                           unsigned long *size,
155                                                   155                                                           void *buf)
156 {                                                 156 {
157         return EFI_NOT_FOUND;                     157         return EFI_NOT_FOUND;
158 }                                                 158 }
159                                                   159 
160 /* If EFI doesn't contain a cal data variable     160 /* If EFI doesn't contain a cal data variable the result should be -ENOENT */
161 static void cs_amp_lib_test_no_cal_data_test(s    161 static void cs_amp_lib_test_no_cal_data_test(struct kunit *test)
162 {                                                 162 {
163         struct cs_amp_lib_test_priv *priv = te    163         struct cs_amp_lib_test_priv *priv = test->priv;
164         struct cirrus_amp_cal_data result_data    164         struct cirrus_amp_cal_data result_data;
165         int ret;                                  165         int ret;
166                                                   166 
167         /* Redirect calls to get EFI data */      167         /* Redirect calls to get EFI data */
168         kunit_activate_static_stub(test,          168         kunit_activate_static_stub(test,
169                                    cs_amp_test    169                                    cs_amp_test_hooks->get_efi_variable,
170                                    cs_amp_lib_    170                                    cs_amp_lib_test_get_efi_variable_none);
171                                                   171 
172         ret = cs_amp_get_efi_calibration_data(    172         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 0, &result_data);
173         KUNIT_EXPECT_EQ(test, ret, -ENOENT);      173         KUNIT_EXPECT_EQ(test, ret, -ENOENT);
174                                                   174 
175         kunit_deactivate_static_stub(test, cs_    175         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
176 }                                                 176 }
177                                                   177 
178 /* Redirected get_efi_variable to simulate rea    178 /* Redirected get_efi_variable to simulate reading a cal data blob */
179 static efi_status_t cs_amp_lib_test_get_efi_va    179 static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name,
180                                                   180                                                      efi_guid_t *guid,
181                                                   181                                                      unsigned long *size,
182                                                   182                                                      void *buf)
183 {                                                 183 {
184         static const efi_char16_t expected_nam    184         static const efi_char16_t expected_name[] = L"CirrusSmartAmpCalibrationData";
185         static const efi_guid_t expected_guid     185         static const efi_guid_t expected_guid =
186                 EFI_GUID(0x02f9af02, 0x7734, 0    186                 EFI_GUID(0x02f9af02, 0x7734, 0x4233, 0xb4, 0x3d, 0x93, 0xfe, 0x5a, 0xa3, 0x5d, 0xb3);
187         struct kunit *test = kunit_get_current    187         struct kunit *test = kunit_get_current_test();
188         struct cs_amp_lib_test_priv *priv = te    188         struct cs_amp_lib_test_priv *priv = test->priv;
189                                                   189 
190         KUNIT_EXPECT_NOT_ERR_OR_NULL(test, nam    190         KUNIT_EXPECT_NOT_ERR_OR_NULL(test, name);
191         KUNIT_EXPECT_NOT_ERR_OR_NULL(test, gui    191         KUNIT_EXPECT_NOT_ERR_OR_NULL(test, guid);
192         KUNIT_EXPECT_NOT_ERR_OR_NULL(test, siz    192         KUNIT_EXPECT_NOT_ERR_OR_NULL(test, size);
193                                                   193 
194         KUNIT_EXPECT_MEMEQ(test, name, expecte    194         KUNIT_EXPECT_MEMEQ(test, name, expected_name, sizeof(expected_name));
195         KUNIT_EXPECT_MEMEQ(test, guid, &expect    195         KUNIT_EXPECT_MEMEQ(test, guid, &expected_guid, sizeof(expected_guid));
196                                                   196 
197         if (!buf) {                               197         if (!buf) {
198                 *size = priv->cal_blob->size;     198                 *size = priv->cal_blob->size;
199                 return EFI_BUFFER_TOO_SMALL;      199                 return EFI_BUFFER_TOO_SMALL;
200         }                                         200         }
201                                                   201 
202         KUNIT_ASSERT_GE_MSG(test, ksize(buf),     202         KUNIT_ASSERT_GE_MSG(test, ksize(buf), priv->cal_blob->size, "Buffer to small");
203                                                   203 
204         memcpy(buf, priv->cal_blob, priv->cal_    204         memcpy(buf, priv->cal_blob, priv->cal_blob->size);
205                                                   205 
206         return EFI_SUCCESS;                       206         return EFI_SUCCESS;
207 }                                                 207 }
208                                                   208 
209 /* Get cal data block for a given amp, matched    209 /* Get cal data block for a given amp, matched by target UID. */
210 static void cs_amp_lib_test_get_efi_cal_by_uid    210 static void cs_amp_lib_test_get_efi_cal_by_uid_test(struct kunit *test)
211 {                                                 211 {
212         struct cs_amp_lib_test_priv *priv = te    212         struct cs_amp_lib_test_priv *priv = test->priv;
213         const struct cs_amp_lib_test_param *pa    213         const struct cs_amp_lib_test_param *param = test->param_value;
214         struct cirrus_amp_cal_data result_data    214         struct cirrus_amp_cal_data result_data;
215         u64 target_uid;                           215         u64 target_uid;
216         int ret;                                  216         int ret;
217                                                   217 
218         cs_amp_lib_test_init_dummy_cal_blob(te    218         cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
219                                                   219 
220         /* Redirect calls to get EFI data */      220         /* Redirect calls to get EFI data */
221         kunit_activate_static_stub(test,          221         kunit_activate_static_stub(test,
222                                    cs_amp_test    222                                    cs_amp_test_hooks->get_efi_variable,
223                                    cs_amp_lib_    223                                    cs_amp_lib_test_get_efi_variable);
224                                                   224 
225         target_uid = cs_amp_lib_test_get_targe    225         target_uid = cs_amp_lib_test_get_target_uid(test);
226         ret = cs_amp_get_efi_calibration_data(    226         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, target_uid, -1, &result_data);
227         KUNIT_EXPECT_EQ(test, ret, 0);            227         KUNIT_EXPECT_EQ(test, ret, 0);
228                                                   228 
229         kunit_deactivate_static_stub(test, cs_    229         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
230                                                   230 
231         KUNIT_EXPECT_EQ(test, result_data.calT    231         KUNIT_EXPECT_EQ(test, result_data.calTarget[0], target_uid & 0xFFFFFFFFULL);
232         KUNIT_EXPECT_EQ(test, result_data.calT    232         KUNIT_EXPECT_EQ(test, result_data.calTarget[1], target_uid >> 32);
233         KUNIT_EXPECT_EQ(test, result_data.calT    233         KUNIT_EXPECT_EQ(test, result_data.calTime[0],
234                               priv->cal_blob->    234                               priv->cal_blob->data[param->amp_index].calTime[0]);
235         KUNIT_EXPECT_EQ(test, result_data.calT    235         KUNIT_EXPECT_EQ(test, result_data.calTime[1],
236                               priv->cal_blob->    236                               priv->cal_blob->data[param->amp_index].calTime[1]);
237         KUNIT_EXPECT_EQ(test, result_data.calA    237         KUNIT_EXPECT_EQ(test, result_data.calAmbient,
238                               priv->cal_blob->    238                               priv->cal_blob->data[param->amp_index].calAmbient);
239         KUNIT_EXPECT_EQ(test, result_data.calS    239         KUNIT_EXPECT_EQ(test, result_data.calStatus,
240                               priv->cal_blob->    240                               priv->cal_blob->data[param->amp_index].calStatus);
241         KUNIT_EXPECT_EQ(test, result_data.calR    241         KUNIT_EXPECT_EQ(test, result_data.calR,
242                               priv->cal_blob->    242                               priv->cal_blob->data[param->amp_index].calR);
243 }                                                 243 }
244                                                   244 
245 /* Get cal data block for a given amp index wi    245 /* Get cal data block for a given amp index without checking target UID. */
246 static void cs_amp_lib_test_get_efi_cal_by_ind    246 static void cs_amp_lib_test_get_efi_cal_by_index_unchecked_test(struct kunit *test)
247 {                                                 247 {
248         struct cs_amp_lib_test_priv *priv = te    248         struct cs_amp_lib_test_priv *priv = test->priv;
249         const struct cs_amp_lib_test_param *pa    249         const struct cs_amp_lib_test_param *param = test->param_value;
250         struct cirrus_amp_cal_data result_data    250         struct cirrus_amp_cal_data result_data;
251         int ret;                                  251         int ret;
252                                                   252 
253         cs_amp_lib_test_init_dummy_cal_blob(te    253         cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
254                                                   254 
255         /* Redirect calls to get EFI data */      255         /* Redirect calls to get EFI data */
256         kunit_activate_static_stub(test,          256         kunit_activate_static_stub(test,
257                                    cs_amp_test    257                                    cs_amp_test_hooks->get_efi_variable,
258                                    cs_amp_lib_    258                                    cs_amp_lib_test_get_efi_variable);
259                                                   259 
260         ret = cs_amp_get_efi_calibration_data(    260         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0,
261                                                   261                                               param->amp_index, &result_data);
262         KUNIT_EXPECT_EQ(test, ret, 0);            262         KUNIT_EXPECT_EQ(test, ret, 0);
263                                                   263 
264         kunit_deactivate_static_stub(test, cs_    264         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
265                                                   265 
266         KUNIT_EXPECT_EQ(test, result_data.calT    266         KUNIT_EXPECT_EQ(test, result_data.calTime[0],
267                               priv->cal_blob->    267                               priv->cal_blob->data[param->amp_index].calTime[0]);
268         KUNIT_EXPECT_EQ(test, result_data.calT    268         KUNIT_EXPECT_EQ(test, result_data.calTime[1],
269                               priv->cal_blob->    269                               priv->cal_blob->data[param->amp_index].calTime[1]);
270         KUNIT_EXPECT_EQ(test, result_data.calA    270         KUNIT_EXPECT_EQ(test, result_data.calAmbient,
271                               priv->cal_blob->    271                               priv->cal_blob->data[param->amp_index].calAmbient);
272         KUNIT_EXPECT_EQ(test, result_data.calS    272         KUNIT_EXPECT_EQ(test, result_data.calStatus,
273                               priv->cal_blob->    273                               priv->cal_blob->data[param->amp_index].calStatus);
274         KUNIT_EXPECT_EQ(test, result_data.calR    274         KUNIT_EXPECT_EQ(test, result_data.calR,
275                               priv->cal_blob->    275                               priv->cal_blob->data[param->amp_index].calR);
276 }                                                 276 }
277                                                   277 
278 /* Get cal data block for a given amp index wi    278 /* Get cal data block for a given amp index with checked target UID. */
279 static void cs_amp_lib_test_get_efi_cal_by_ind    279 static void cs_amp_lib_test_get_efi_cal_by_index_checked_test(struct kunit *test)
280 {                                                 280 {
281         struct cs_amp_lib_test_priv *priv = te    281         struct cs_amp_lib_test_priv *priv = test->priv;
282         const struct cs_amp_lib_test_param *pa    282         const struct cs_amp_lib_test_param *param = test->param_value;
283         struct cirrus_amp_cal_data result_data    283         struct cirrus_amp_cal_data result_data;
284         u64 target_uid;                           284         u64 target_uid;
285         int ret;                                  285         int ret;
286                                                   286 
287         cs_amp_lib_test_init_dummy_cal_blob(te    287         cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
288                                                   288 
289         /* Redirect calls to get EFI data */      289         /* Redirect calls to get EFI data */
290         kunit_activate_static_stub(test,          290         kunit_activate_static_stub(test,
291                                    cs_amp_test    291                                    cs_amp_test_hooks->get_efi_variable,
292                                    cs_amp_lib_    292                                    cs_amp_lib_test_get_efi_variable);
293                                                   293 
294         target_uid = cs_amp_lib_test_get_targe    294         target_uid = cs_amp_lib_test_get_target_uid(test);
295         ret = cs_amp_get_efi_calibration_data(    295         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, target_uid,
296                                                   296                                               param->amp_index, &result_data);
297         KUNIT_EXPECT_EQ(test, ret, 0);            297         KUNIT_EXPECT_EQ(test, ret, 0);
298                                                   298 
299         kunit_deactivate_static_stub(test, cs_    299         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
300                                                   300 
301         KUNIT_EXPECT_EQ(test, result_data.calT    301         KUNIT_EXPECT_EQ(test, result_data.calTime[0],
302                               priv->cal_blob->    302                               priv->cal_blob->data[param->amp_index].calTime[0]);
303         KUNIT_EXPECT_EQ(test, result_data.calT    303         KUNIT_EXPECT_EQ(test, result_data.calTime[1],
304                               priv->cal_blob->    304                               priv->cal_blob->data[param->amp_index].calTime[1]);
305         KUNIT_EXPECT_EQ(test, result_data.calA    305         KUNIT_EXPECT_EQ(test, result_data.calAmbient,
306                               priv->cal_blob->    306                               priv->cal_blob->data[param->amp_index].calAmbient);
307         KUNIT_EXPECT_EQ(test, result_data.calS    307         KUNIT_EXPECT_EQ(test, result_data.calStatus,
308                               priv->cal_blob->    308                               priv->cal_blob->data[param->amp_index].calStatus);
309         KUNIT_EXPECT_EQ(test, result_data.calR    309         KUNIT_EXPECT_EQ(test, result_data.calR,
310                               priv->cal_blob->    310                               priv->cal_blob->data[param->amp_index].calR);
311 }                                                 311 }
312                                                   312 
313 /*                                                313 /*
314  * Get cal data block for a given amp index wi    314  * Get cal data block for a given amp index with checked target UID.
315  * The UID does not match so the result should    315  * The UID does not match so the result should be -ENOENT.
316  */                                               316  */
317 static void cs_amp_lib_test_get_efi_cal_by_ind    317 static void cs_amp_lib_test_get_efi_cal_by_index_uid_mismatch_test(struct kunit *test)
318 {                                                 318 {
319         struct cs_amp_lib_test_priv *priv = te    319         struct cs_amp_lib_test_priv *priv = test->priv;
320         const struct cs_amp_lib_test_param *pa    320         const struct cs_amp_lib_test_param *param = test->param_value;
321         struct cirrus_amp_cal_data result_data    321         struct cirrus_amp_cal_data result_data;
322         u64 target_uid;                           322         u64 target_uid;
323         int ret;                                  323         int ret;
324                                                   324 
325         cs_amp_lib_test_init_dummy_cal_blob(te    325         cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
326                                                   326 
327         /* Redirect calls to get EFI data */      327         /* Redirect calls to get EFI data */
328         kunit_activate_static_stub(test,          328         kunit_activate_static_stub(test,
329                                    cs_amp_test    329                                    cs_amp_test_hooks->get_efi_variable,
330                                    cs_amp_lib_    330                                    cs_amp_lib_test_get_efi_variable);
331                                                   331 
332         /* Get a target UID that won't match t    332         /* Get a target UID that won't match the entry */
333         target_uid = ~cs_amp_lib_test_get_targ    333         target_uid = ~cs_amp_lib_test_get_target_uid(test);
334         ret = cs_amp_get_efi_calibration_data(    334         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, target_uid,
335                                                   335                                               param->amp_index, &result_data);
336         KUNIT_EXPECT_EQ(test, ret, -ENOENT);      336         KUNIT_EXPECT_EQ(test, ret, -ENOENT);
337                                                   337 
338         kunit_deactivate_static_stub(test, cs_    338         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
339 }                                                 339 }
340                                                   340 
341 /*                                                341 /*
342  * Get cal data block for a given amp, where t    342  * Get cal data block for a given amp, where the cal data does not
343  * specify calTarget so the lookup falls back     343  * specify calTarget so the lookup falls back to using the index
344  */                                               344  */
345 static void cs_amp_lib_test_get_efi_cal_by_ind    345 static void cs_amp_lib_test_get_efi_cal_by_index_fallback_test(struct kunit *test)
346 {                                                 346 {
347         struct cs_amp_lib_test_priv *priv = te    347         struct cs_amp_lib_test_priv *priv = test->priv;
348         const struct cs_amp_lib_test_param *pa    348         const struct cs_amp_lib_test_param *param = test->param_value;
349         struct cirrus_amp_cal_data result_data    349         struct cirrus_amp_cal_data result_data;
350         static const u64 bad_target_uid = 0xBA    350         static const u64 bad_target_uid = 0xBADCA100BABABABAULL;
351         int i, ret;                               351         int i, ret;
352                                                   352 
353         cs_amp_lib_test_init_dummy_cal_blob(te    353         cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps);
354                                                   354 
355         /* Make all the target values zero so     355         /* Make all the target values zero so they are ignored */
356         for (i = 0; i < priv->cal_blob->count;    356         for (i = 0; i < priv->cal_blob->count; ++i) {
357                 priv->cal_blob->data[i].calTar    357                 priv->cal_blob->data[i].calTarget[0] = 0;
358                 priv->cal_blob->data[i].calTar    358                 priv->cal_blob->data[i].calTarget[1] = 0;
359         }                                         359         }
360                                                   360 
361         /* Redirect calls to get EFI data */      361         /* Redirect calls to get EFI data */
362         kunit_activate_static_stub(test,          362         kunit_activate_static_stub(test,
363                                    cs_amp_test    363                                    cs_amp_test_hooks->get_efi_variable,
364                                    cs_amp_lib_    364                                    cs_amp_lib_test_get_efi_variable);
365                                                   365 
366         ret = cs_amp_get_efi_calibration_data(    366         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, bad_target_uid,
367                                                   367                                               param->amp_index, &result_data);
368         KUNIT_EXPECT_EQ(test, ret, 0);            368         KUNIT_EXPECT_EQ(test, ret, 0);
369                                                   369 
370         kunit_deactivate_static_stub(test, cs_    370         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
371                                                   371 
372         KUNIT_EXPECT_EQ(test, result_data.calT    372         KUNIT_EXPECT_EQ(test, result_data.calTime[0],
373                               priv->cal_blob->    373                               priv->cal_blob->data[param->amp_index].calTime[0]);
374         KUNIT_EXPECT_EQ(test, result_data.calT    374         KUNIT_EXPECT_EQ(test, result_data.calTime[1],
375                               priv->cal_blob->    375                               priv->cal_blob->data[param->amp_index].calTime[1]);
376         KUNIT_EXPECT_EQ(test, result_data.calA    376         KUNIT_EXPECT_EQ(test, result_data.calAmbient,
377                               priv->cal_blob->    377                               priv->cal_blob->data[param->amp_index].calAmbient);
378         KUNIT_EXPECT_EQ(test, result_data.calS    378         KUNIT_EXPECT_EQ(test, result_data.calStatus,
379                               priv->cal_blob->    379                               priv->cal_blob->data[param->amp_index].calStatus);
380         KUNIT_EXPECT_EQ(test, result_data.calR    380         KUNIT_EXPECT_EQ(test, result_data.calR,
381                               priv->cal_blob->    381                               priv->cal_blob->data[param->amp_index].calR);
382 }                                                 382 }
383                                                   383 
384 /*                                                384 /*
385  * If the target UID isn't present in the cal     385  * If the target UID isn't present in the cal data, and there isn't an
386  * index to fall back do, the result should be    386  * index to fall back do, the result should be -ENOENT.
387  */                                               387  */
388 static void cs_amp_lib_test_get_efi_cal_uid_no    388 static void cs_amp_lib_test_get_efi_cal_uid_not_found_noindex_test(struct kunit *test)
389 {                                                 389 {
390         struct cs_amp_lib_test_priv *priv = te    390         struct cs_amp_lib_test_priv *priv = test->priv;
391         struct cirrus_amp_cal_data result_data    391         struct cirrus_amp_cal_data result_data;
392         static const u64 bad_target_uid = 0xBA    392         static const u64 bad_target_uid = 0xBADCA100BABABABAULL;
393         int i, ret;                               393         int i, ret;
394                                                   394 
395         cs_amp_lib_test_init_dummy_cal_blob(te    395         cs_amp_lib_test_init_dummy_cal_blob(test, 8);
396                                                   396 
397         /* Make all the target values != bad_t    397         /* Make all the target values != bad_target_uid */
398         for (i = 0; i < priv->cal_blob->count;    398         for (i = 0; i < priv->cal_blob->count; ++i) {
399                 priv->cal_blob->data[i].calTar    399                 priv->cal_blob->data[i].calTarget[0] &= ~(bad_target_uid & 0xFFFFFFFFULL);
400                 priv->cal_blob->data[i].calTar    400                 priv->cal_blob->data[i].calTarget[1] &= ~(bad_target_uid >> 32);
401         }                                         401         }
402                                                   402 
403         /* Redirect calls to get EFI data */      403         /* Redirect calls to get EFI data */
404         kunit_activate_static_stub(test,          404         kunit_activate_static_stub(test,
405                                    cs_amp_test    405                                    cs_amp_test_hooks->get_efi_variable,
406                                    cs_amp_lib_    406                                    cs_amp_lib_test_get_efi_variable);
407                                                   407 
408         ret = cs_amp_get_efi_calibration_data(    408         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, bad_target_uid, -1,
409                                                   409                                               &result_data);
410         KUNIT_EXPECT_EQ(test, ret, -ENOENT);      410         KUNIT_EXPECT_EQ(test, ret, -ENOENT);
411                                                   411 
412         kunit_deactivate_static_stub(test, cs_    412         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
413 }                                                 413 }
414                                                   414 
415 /*                                                415 /*
416  * If the target UID isn't present in the cal     416  * If the target UID isn't present in the cal data, and the index is
417  * out of range, the result should be -ENOENT.    417  * out of range, the result should be -ENOENT.
418  */                                               418  */
419 static void cs_amp_lib_test_get_efi_cal_uid_no    419 static void cs_amp_lib_test_get_efi_cal_uid_not_found_index_not_found_test(struct kunit *test)
420 {                                                 420 {
421         struct cs_amp_lib_test_priv *priv = te    421         struct cs_amp_lib_test_priv *priv = test->priv;
422         struct cirrus_amp_cal_data result_data    422         struct cirrus_amp_cal_data result_data;
423         static const u64 bad_target_uid = 0xBA    423         static const u64 bad_target_uid = 0xBADCA100BABABABAULL;
424         int i, ret;                               424         int i, ret;
425                                                   425 
426         cs_amp_lib_test_init_dummy_cal_blob(te    426         cs_amp_lib_test_init_dummy_cal_blob(test, 8);
427                                                   427 
428         /* Make all the target values != bad_t    428         /* Make all the target values != bad_target_uid */
429         for (i = 0; i < priv->cal_blob->count;    429         for (i = 0; i < priv->cal_blob->count; ++i) {
430                 priv->cal_blob->data[i].calTar    430                 priv->cal_blob->data[i].calTarget[0] &= ~(bad_target_uid & 0xFFFFFFFFULL);
431                 priv->cal_blob->data[i].calTar    431                 priv->cal_blob->data[i].calTarget[1] &= ~(bad_target_uid >> 32);
432         }                                         432         }
433                                                   433 
434         /* Redirect calls to get EFI data */      434         /* Redirect calls to get EFI data */
435         kunit_activate_static_stub(test,          435         kunit_activate_static_stub(test,
436                                    cs_amp_test    436                                    cs_amp_test_hooks->get_efi_variable,
437                                    cs_amp_lib_    437                                    cs_amp_lib_test_get_efi_variable);
438                                                   438 
439         ret = cs_amp_get_efi_calibration_data(    439         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, bad_target_uid, 99,
440                                                   440                                               &result_data);
441         KUNIT_EXPECT_EQ(test, ret, -ENOENT);      441         KUNIT_EXPECT_EQ(test, ret, -ENOENT);
442                                                   442 
443         kunit_deactivate_static_stub(test, cs_    443         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
444 }                                                 444 }
445                                                   445 
446 /*                                                446 /*
447  * If the target UID isn't given, and the inde    447  * If the target UID isn't given, and the index is out of range, the
448  * result should be -ENOENT.                      448  * result should be -ENOENT.
449  */                                               449  */
450 static void cs_amp_lib_test_get_efi_cal_no_uid    450 static void cs_amp_lib_test_get_efi_cal_no_uid_index_not_found_test(struct kunit *test)
451 {                                                 451 {
452         struct cs_amp_lib_test_priv *priv = te    452         struct cs_amp_lib_test_priv *priv = test->priv;
453         struct cirrus_amp_cal_data result_data    453         struct cirrus_amp_cal_data result_data;
454         int ret;                                  454         int ret;
455                                                   455 
456         cs_amp_lib_test_init_dummy_cal_blob(te    456         cs_amp_lib_test_init_dummy_cal_blob(test, 8);
457                                                   457 
458         /* Redirect calls to get EFI data */      458         /* Redirect calls to get EFI data */
459         kunit_activate_static_stub(test,          459         kunit_activate_static_stub(test,
460                                    cs_amp_test    460                                    cs_amp_test_hooks->get_efi_variable,
461                                    cs_amp_lib_    461                                    cs_amp_lib_test_get_efi_variable);
462                                                   462 
463         ret = cs_amp_get_efi_calibration_data(    463         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 99, &result_data);
464         KUNIT_EXPECT_EQ(test, ret, -ENOENT);      464         KUNIT_EXPECT_EQ(test, ret, -ENOENT);
465                                                   465 
466         kunit_deactivate_static_stub(test, cs_    466         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
467 }                                                 467 }
468                                                   468 
469 /* If neither the target UID or the index is g    469 /* If neither the target UID or the index is given the result should be -ENOENT. */
470 static void cs_amp_lib_test_get_efi_cal_no_uid    470 static void cs_amp_lib_test_get_efi_cal_no_uid_no_index_test(struct kunit *test)
471 {                                                 471 {
472         struct cs_amp_lib_test_priv *priv = te    472         struct cs_amp_lib_test_priv *priv = test->priv;
473         struct cirrus_amp_cal_data result_data    473         struct cirrus_amp_cal_data result_data;
474         int ret;                                  474         int ret;
475                                                   475 
476         cs_amp_lib_test_init_dummy_cal_blob(te    476         cs_amp_lib_test_init_dummy_cal_blob(test, 8);
477                                                   477 
478         /* Redirect calls to get EFI data */      478         /* Redirect calls to get EFI data */
479         kunit_activate_static_stub(test,          479         kunit_activate_static_stub(test,
480                                    cs_amp_test    480                                    cs_amp_test_hooks->get_efi_variable,
481                                    cs_amp_lib_    481                                    cs_amp_lib_test_get_efi_variable);
482                                                   482 
483         ret = cs_amp_get_efi_calibration_data(    483         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, -1, &result_data);
484         KUNIT_EXPECT_EQ(test, ret, -ENOENT);      484         KUNIT_EXPECT_EQ(test, ret, -ENOENT);
485                                                   485 
486         kunit_deactivate_static_stub(test, cs_    486         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
487 }                                                 487 }
488                                                   488 
489 /*                                                489 /*
490  * If the UID is passed as 0 this must not mat    490  * If the UID is passed as 0 this must not match an entry with an
491  * unpopulated calTarget                          491  * unpopulated calTarget
492  */                                               492  */
493 static void cs_amp_lib_test_get_efi_cal_zero_n    493 static void cs_amp_lib_test_get_efi_cal_zero_not_matched_test(struct kunit *test)
494 {                                                 494 {
495         struct cs_amp_lib_test_priv *priv = te    495         struct cs_amp_lib_test_priv *priv = test->priv;
496         struct cirrus_amp_cal_data result_data    496         struct cirrus_amp_cal_data result_data;
497         int i, ret;                               497         int i, ret;
498                                                   498 
499         cs_amp_lib_test_init_dummy_cal_blob(te    499         cs_amp_lib_test_init_dummy_cal_blob(test, 8);
500                                                   500 
501         /* Make all the target values zero so     501         /* Make all the target values zero so they are ignored */
502         for (i = 0; i < priv->cal_blob->count;    502         for (i = 0; i < priv->cal_blob->count; ++i) {
503                 priv->cal_blob->data[i].calTar    503                 priv->cal_blob->data[i].calTarget[0] = 0;
504                 priv->cal_blob->data[i].calTar    504                 priv->cal_blob->data[i].calTarget[1] = 0;
505         }                                         505         }
506                                                   506 
507         /* Redirect calls to get EFI data */      507         /* Redirect calls to get EFI data */
508         kunit_activate_static_stub(test,          508         kunit_activate_static_stub(test,
509                                    cs_amp_test    509                                    cs_amp_test_hooks->get_efi_variable,
510                                    cs_amp_lib_    510                                    cs_amp_lib_test_get_efi_variable);
511                                                   511 
512         ret = cs_amp_get_efi_calibration_data(    512         ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, -1, &result_data);
513         KUNIT_EXPECT_EQ(test, ret, -ENOENT);      513         KUNIT_EXPECT_EQ(test, ret, -ENOENT);
514                                                   514 
515         kunit_deactivate_static_stub(test, cs_    515         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
516 }                                                 516 }
517                                                   517 
518 /*                                                518 /*
519  * If an entry has a timestamp of 0 it should     519  * If an entry has a timestamp of 0 it should be ignored even if it has
520  * a matching target UID.                         520  * a matching target UID.
521  */                                               521  */
522 static void cs_amp_lib_test_get_efi_cal_empty_    522 static void cs_amp_lib_test_get_efi_cal_empty_entry_test(struct kunit *test)
523 {                                                 523 {
524         struct cs_amp_lib_test_priv *priv = te    524         struct cs_amp_lib_test_priv *priv = test->priv;
525         struct cirrus_amp_cal_data result_data    525         struct cirrus_amp_cal_data result_data;
526         u64 uid;                                  526         u64 uid;
527                                                   527 
528         cs_amp_lib_test_init_dummy_cal_blob(te    528         cs_amp_lib_test_init_dummy_cal_blob(test, 8);
529                                                   529 
530         /* Mark the 3rd entry invalid by zeroi    530         /* Mark the 3rd entry invalid by zeroing calTime */
531         priv->cal_blob->data[2].calTime[0] = 0    531         priv->cal_blob->data[2].calTime[0] = 0;
532         priv->cal_blob->data[2].calTime[1] = 0    532         priv->cal_blob->data[2].calTime[1] = 0;
533                                                   533 
534         /* Get the UID value of the 3rd entry     534         /* Get the UID value of the 3rd entry */
535         uid = priv->cal_blob->data[2].calTarge    535         uid = priv->cal_blob->data[2].calTarget[1];
536         uid <<= 32;                               536         uid <<= 32;
537         uid |= priv->cal_blob->data[2].calTarg    537         uid |= priv->cal_blob->data[2].calTarget[0];
538                                                   538 
539         /* Redirect calls to get EFI data */      539         /* Redirect calls to get EFI data */
540         kunit_activate_static_stub(test,          540         kunit_activate_static_stub(test,
541                                    cs_amp_test    541                                    cs_amp_test_hooks->get_efi_variable,
542                                    cs_amp_lib_    542                                    cs_amp_lib_test_get_efi_variable);
543                                                   543 
544         /* Lookup by UID should not find it */    544         /* Lookup by UID should not find it */
545         KUNIT_EXPECT_EQ(test,                     545         KUNIT_EXPECT_EQ(test,
546                         cs_amp_get_efi_calibra    546                         cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev,
547                                                   547                                                         uid, -1,
548                                                   548                                                         &result_data),
549                         -ENOENT);                 549                         -ENOENT);
550                                                   550 
551         /* Get by index should ignore it */       551         /* Get by index should ignore it */
552         KUNIT_EXPECT_EQ(test,                     552         KUNIT_EXPECT_EQ(test,
553                         cs_amp_get_efi_calibra    553                         cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev,
554                                                   554                                                         0, 2,
555                                                   555                                                         &result_data),
556                         -ENOENT);                 556                         -ENOENT);
557                                                   557 
558         kunit_deactivate_static_stub(test, cs_    558         kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable);
559 }                                                 559 }
560                                                   560 
561 static const struct cirrus_amp_cal_controls cs    561 static const struct cirrus_amp_cal_controls cs_amp_lib_test_calibration_controls = {
562         .alg_id =       0x9f210,                  562         .alg_id =       0x9f210,
563         .mem_region =   WMFW_ADSP2_YM,            563         .mem_region =   WMFW_ADSP2_YM,
564         .ambient =      "CAL_AMBIENT",            564         .ambient =      "CAL_AMBIENT",
565         .calr =         "CAL_R",                  565         .calr =         "CAL_R",
566         .status =       "CAL_STATUS",             566         .status =       "CAL_STATUS",
567         .checksum =     "CAL_CHECKSUM",           567         .checksum =     "CAL_CHECKSUM",
568 };                                                568 };
569                                                   569 
570 static int cs_amp_lib_test_write_cal_coeff(str    570 static int cs_amp_lib_test_write_cal_coeff(struct cs_dsp *dsp,
571                                            con    571                                            const struct cirrus_amp_cal_controls *controls,
572                                            con    572                                            const char *ctl_name, u32 val)
573 {                                                 573 {
574         struct kunit *test = kunit_get_current    574         struct kunit *test = kunit_get_current_test();
575         struct cs_amp_lib_test_priv *priv = te    575         struct cs_amp_lib_test_priv *priv = test->priv;
576         struct cs_amp_lib_test_ctl_write_entry    576         struct cs_amp_lib_test_ctl_write_entry *entry;
577                                                   577 
578         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctl    578         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctl_name);
579         KUNIT_EXPECT_PTR_EQ(test, controls, &c    579         KUNIT_EXPECT_PTR_EQ(test, controls, &cs_amp_lib_test_calibration_controls);
580                                                   580 
581         entry = kunit_kzalloc(test, sizeof(*en    581         entry = kunit_kzalloc(test, sizeof(*entry), GFP_KERNEL);
582         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ent    582         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, entry);
583                                                   583 
584         INIT_LIST_HEAD(&entry->list);             584         INIT_LIST_HEAD(&entry->list);
585         strscpy(entry->name, ctl_name, sizeof(    585         strscpy(entry->name, ctl_name, sizeof(entry->name));
586         entry->value = val;                       586         entry->value = val;
587                                                   587 
588         list_add_tail(&entry->list, &priv->ctl    588         list_add_tail(&entry->list, &priv->ctl_write_list);
589                                                   589 
590         return 0;                                 590         return 0;
591 }                                                 591 }
592                                                   592 
593 static void cs_amp_lib_test_write_cal_data_tes    593 static void cs_amp_lib_test_write_cal_data_test(struct kunit *test)
594 {                                                 594 {
595         struct cs_amp_lib_test_priv *priv = te    595         struct cs_amp_lib_test_priv *priv = test->priv;
596         struct cs_amp_lib_test_ctl_write_entry    596         struct cs_amp_lib_test_ctl_write_entry *entry;
597         struct cirrus_amp_cal_data data;          597         struct cirrus_amp_cal_data data;
598         struct cs_dsp *dsp;                       598         struct cs_dsp *dsp;
599         int ret;                                  599         int ret;
600                                                   600 
601         dsp = kunit_kzalloc(test, sizeof(*dsp)    601         dsp = kunit_kzalloc(test, sizeof(*dsp), GFP_KERNEL);
602         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dsp    602         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dsp);
603         dsp->dev = &priv->amp_pdev.dev;           603         dsp->dev = &priv->amp_pdev.dev;
604                                                   604 
605         get_random_bytes(&data, sizeof(data));    605         get_random_bytes(&data, sizeof(data));
606                                                   606 
607         /* Redirect calls to write firmware co    607         /* Redirect calls to write firmware controls */
608         kunit_activate_static_stub(test,          608         kunit_activate_static_stub(test,
609                                    cs_amp_test    609                                    cs_amp_test_hooks->write_cal_coeff,
610                                    cs_amp_lib_    610                                    cs_amp_lib_test_write_cal_coeff);
611                                                   611 
612         ret = cs_amp_write_cal_coeffs(dsp, &cs    612         ret = cs_amp_write_cal_coeffs(dsp, &cs_amp_lib_test_calibration_controls, &data);
613         KUNIT_EXPECT_EQ(test, ret, 0);            613         KUNIT_EXPECT_EQ(test, ret, 0);
614                                                   614 
615         kunit_deactivate_static_stub(test, cs_    615         kunit_deactivate_static_stub(test, cs_amp_test_hooks->write_cal_coeff);
616                                                   616 
617         KUNIT_EXPECT_EQ(test, list_count_nodes    617         KUNIT_EXPECT_EQ(test, list_count_nodes(&priv->ctl_write_list), 4);
618                                                   618 
619         /* Checksum control must be written la    619         /* Checksum control must be written last */
620         entry = list_last_entry(&priv->ctl_wri    620         entry = list_last_entry(&priv->ctl_write_list, typeof(*entry), list);
621         KUNIT_EXPECT_STREQ(test, entry->name,     621         KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.checksum);
622         KUNIT_EXPECT_EQ(test, entry->value, da    622         KUNIT_EXPECT_EQ(test, entry->value, data.calR + 1);
623         list_del(&entry->list);                   623         list_del(&entry->list);
624                                                   624 
625         entry = list_first_entry(&priv->ctl_wr    625         entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list);
626         KUNIT_EXPECT_STREQ(test, entry->name,     626         KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.ambient);
627         KUNIT_EXPECT_EQ(test, entry->value, da    627         KUNIT_EXPECT_EQ(test, entry->value, data.calAmbient);
628         list_del(&entry->list);                   628         list_del(&entry->list);
629                                                   629 
630         entry = list_first_entry(&priv->ctl_wr    630         entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list);
631         KUNIT_EXPECT_STREQ(test, entry->name,     631         KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.calr);
632         KUNIT_EXPECT_EQ(test, entry->value, da    632         KUNIT_EXPECT_EQ(test, entry->value, data.calR);
633         list_del(&entry->list);                   633         list_del(&entry->list);
634                                                   634 
635         entry = list_first_entry(&priv->ctl_wr    635         entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list);
636         KUNIT_EXPECT_STREQ(test, entry->name,     636         KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.status);
637         KUNIT_EXPECT_EQ(test, entry->value, da    637         KUNIT_EXPECT_EQ(test, entry->value, data.calStatus);
638 }                                                 638 }
639                                                   639 
640 static void cs_amp_lib_test_dev_release(struct    640 static void cs_amp_lib_test_dev_release(struct device *dev)
641 {                                                 641 {
642 }                                                 642 }
643                                                   643 
644 static int cs_amp_lib_test_case_init(struct ku    644 static int cs_amp_lib_test_case_init(struct kunit *test)
645 {                                                 645 {
646         struct cs_amp_lib_test_priv *priv;        646         struct cs_amp_lib_test_priv *priv;
647         int ret;                                  647         int ret;
648                                                   648 
649         KUNIT_ASSERT_NOT_NULL(test, cs_amp_tes    649         KUNIT_ASSERT_NOT_NULL(test, cs_amp_test_hooks);
650                                                   650 
651         priv = kunit_kzalloc(test, sizeof(*pri    651         priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
652         if (!priv)                                652         if (!priv)
653                 return -ENOMEM;                   653                 return -ENOMEM;
654                                                   654 
655         test->priv = priv;                        655         test->priv = priv;
656         INIT_LIST_HEAD(&priv->ctl_write_list);    656         INIT_LIST_HEAD(&priv->ctl_write_list);
657                                                   657 
658         /* Create dummy amp driver dev */         658         /* Create dummy amp driver dev */
659         priv->amp_pdev.name = "cs_amp_lib_test    659         priv->amp_pdev.name = "cs_amp_lib_test_drv";
660         priv->amp_pdev.id = -1;                   660         priv->amp_pdev.id = -1;
661         priv->amp_pdev.dev.release = cs_amp_li    661         priv->amp_pdev.dev.release = cs_amp_lib_test_dev_release;
662         ret = platform_device_register(&priv->    662         ret = platform_device_register(&priv->amp_pdev);
663         KUNIT_ASSERT_GE_MSG(test, ret, 0, "Fai    663         KUNIT_ASSERT_GE_MSG(test, ret, 0, "Failed to register amp platform device\n");
664                                                   664 
665         return 0;                                 665         return 0;
666 }                                                 666 }
667                                                   667 
668 static void cs_amp_lib_test_case_exit(struct k    668 static void cs_amp_lib_test_case_exit(struct kunit *test)
669 {                                                 669 {
670         struct cs_amp_lib_test_priv *priv = te    670         struct cs_amp_lib_test_priv *priv = test->priv;
671                                                   671 
672         if (priv->amp_pdev.name)                  672         if (priv->amp_pdev.name)
673                 platform_device_unregister(&pr    673                 platform_device_unregister(&priv->amp_pdev);
674 }                                                 674 }
675                                                   675 
676 static const struct cs_amp_lib_test_param cs_a    676 static const struct cs_amp_lib_test_param cs_amp_lib_test_get_cal_param_cases[] = {
677         { .num_amps = 2, .amp_index = 0 },        677         { .num_amps = 2, .amp_index = 0 },
678         { .num_amps = 2, .amp_index = 1 },        678         { .num_amps = 2, .amp_index = 1 },
679                                                   679 
680         { .num_amps = 3, .amp_index = 0 },        680         { .num_amps = 3, .amp_index = 0 },
681         { .num_amps = 3, .amp_index = 1 },        681         { .num_amps = 3, .amp_index = 1 },
682         { .num_amps = 3, .amp_index = 2 },        682         { .num_amps = 3, .amp_index = 2 },
683                                                   683 
684         { .num_amps = 4, .amp_index = 0 },        684         { .num_amps = 4, .amp_index = 0 },
685         { .num_amps = 4, .amp_index = 1 },        685         { .num_amps = 4, .amp_index = 1 },
686         { .num_amps = 4, .amp_index = 2 },        686         { .num_amps = 4, .amp_index = 2 },
687         { .num_amps = 4, .amp_index = 3 },        687         { .num_amps = 4, .amp_index = 3 },
688                                                   688 
689         { .num_amps = 5, .amp_index = 0 },        689         { .num_amps = 5, .amp_index = 0 },
690         { .num_amps = 5, .amp_index = 1 },        690         { .num_amps = 5, .amp_index = 1 },
691         { .num_amps = 5, .amp_index = 2 },        691         { .num_amps = 5, .amp_index = 2 },
692         { .num_amps = 5, .amp_index = 3 },        692         { .num_amps = 5, .amp_index = 3 },
693         { .num_amps = 5, .amp_index = 4 },        693         { .num_amps = 5, .amp_index = 4 },
694                                                   694 
695         { .num_amps = 6, .amp_index = 0 },        695         { .num_amps = 6, .amp_index = 0 },
696         { .num_amps = 6, .amp_index = 1 },        696         { .num_amps = 6, .amp_index = 1 },
697         { .num_amps = 6, .amp_index = 2 },        697         { .num_amps = 6, .amp_index = 2 },
698         { .num_amps = 6, .amp_index = 3 },        698         { .num_amps = 6, .amp_index = 3 },
699         { .num_amps = 6, .amp_index = 4 },        699         { .num_amps = 6, .amp_index = 4 },
700         { .num_amps = 6, .amp_index = 5 },        700         { .num_amps = 6, .amp_index = 5 },
701                                                   701 
702         { .num_amps = 8, .amp_index = 0 },        702         { .num_amps = 8, .amp_index = 0 },
703         { .num_amps = 8, .amp_index = 1 },        703         { .num_amps = 8, .amp_index = 1 },
704         { .num_amps = 8, .amp_index = 2 },        704         { .num_amps = 8, .amp_index = 2 },
705         { .num_amps = 8, .amp_index = 3 },        705         { .num_amps = 8, .amp_index = 3 },
706         { .num_amps = 8, .amp_index = 4 },        706         { .num_amps = 8, .amp_index = 4 },
707         { .num_amps = 8, .amp_index = 5 },        707         { .num_amps = 8, .amp_index = 5 },
708         { .num_amps = 8, .amp_index = 6 },        708         { .num_amps = 8, .amp_index = 6 },
709         { .num_amps = 8, .amp_index = 7 },        709         { .num_amps = 8, .amp_index = 7 },
710 };                                                710 };
711                                                   711 
712 static void cs_amp_lib_test_get_cal_param_desc    712 static void cs_amp_lib_test_get_cal_param_desc(const struct cs_amp_lib_test_param *param,
713                                                   713                                                char *desc)
714 {                                                 714 {
715         snprintf(desc, KUNIT_PARAM_DESC_SIZE,     715         snprintf(desc, KUNIT_PARAM_DESC_SIZE, "num_amps:%d amp_index:%d",
716                  param->num_amps, param->amp_i    716                  param->num_amps, param->amp_index);
717 }                                                 717 }
718                                                   718 
719 KUNIT_ARRAY_PARAM(cs_amp_lib_test_get_cal, cs_    719 KUNIT_ARRAY_PARAM(cs_amp_lib_test_get_cal, cs_amp_lib_test_get_cal_param_cases,
720                   cs_amp_lib_test_get_cal_para    720                   cs_amp_lib_test_get_cal_param_desc);
721                                                   721 
722 static struct kunit_case cs_amp_lib_test_cases    722 static struct kunit_case cs_amp_lib_test_cases[] = {
723         /* Tests for getting calibration data     723         /* Tests for getting calibration data from EFI */
724         KUNIT_CASE(cs_amp_lib_test_cal_data_to    724         KUNIT_CASE(cs_amp_lib_test_cal_data_too_short_test),
725         KUNIT_CASE(cs_amp_lib_test_cal_count_t    725         KUNIT_CASE(cs_amp_lib_test_cal_count_too_big_test),
726         KUNIT_CASE(cs_amp_lib_test_no_cal_data    726         KUNIT_CASE(cs_amp_lib_test_no_cal_data_test),
727         KUNIT_CASE(cs_amp_lib_test_get_efi_cal    727         KUNIT_CASE(cs_amp_lib_test_get_efi_cal_uid_not_found_noindex_test),
728         KUNIT_CASE(cs_amp_lib_test_get_efi_cal    728         KUNIT_CASE(cs_amp_lib_test_get_efi_cal_uid_not_found_index_not_found_test),
729         KUNIT_CASE(cs_amp_lib_test_get_efi_cal    729         KUNIT_CASE(cs_amp_lib_test_get_efi_cal_no_uid_index_not_found_test),
730         KUNIT_CASE(cs_amp_lib_test_get_efi_cal    730         KUNIT_CASE(cs_amp_lib_test_get_efi_cal_no_uid_no_index_test),
731         KUNIT_CASE(cs_amp_lib_test_get_efi_cal    731         KUNIT_CASE(cs_amp_lib_test_get_efi_cal_zero_not_matched_test),
732         KUNIT_CASE_PARAM(cs_amp_lib_test_get_e    732         KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_uid_test,
733                          cs_amp_lib_test_get_c    733                          cs_amp_lib_test_get_cal_gen_params),
734         KUNIT_CASE_PARAM(cs_amp_lib_test_get_e    734         KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_unchecked_test,
735                          cs_amp_lib_test_get_c    735                          cs_amp_lib_test_get_cal_gen_params),
736         KUNIT_CASE_PARAM(cs_amp_lib_test_get_e    736         KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_checked_test,
737                          cs_amp_lib_test_get_c    737                          cs_amp_lib_test_get_cal_gen_params),
738         KUNIT_CASE_PARAM(cs_amp_lib_test_get_e    738         KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_uid_mismatch_test,
739                          cs_amp_lib_test_get_c    739                          cs_amp_lib_test_get_cal_gen_params),
740         KUNIT_CASE_PARAM(cs_amp_lib_test_get_e    740         KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_fallback_test,
741                          cs_amp_lib_test_get_c    741                          cs_amp_lib_test_get_cal_gen_params),
742         KUNIT_CASE(cs_amp_lib_test_get_efi_cal    742         KUNIT_CASE(cs_amp_lib_test_get_efi_cal_empty_entry_test),
743                                                   743 
744         /* Tests for writing calibration data     744         /* Tests for writing calibration data */
745         KUNIT_CASE(cs_amp_lib_test_write_cal_d    745         KUNIT_CASE(cs_amp_lib_test_write_cal_data_test),
746                                                   746 
747         { } /* terminator */                      747         { } /* terminator */
748 };                                                748 };
749                                                   749 
750 static struct kunit_suite cs_amp_lib_test_suit    750 static struct kunit_suite cs_amp_lib_test_suite = {
751         .name = "snd-soc-cs-amp-lib-test",        751         .name = "snd-soc-cs-amp-lib-test",
752         .init = cs_amp_lib_test_case_init,        752         .init = cs_amp_lib_test_case_init,
753         .exit = cs_amp_lib_test_case_exit,        753         .exit = cs_amp_lib_test_case_exit,
754         .test_cases = cs_amp_lib_test_cases,      754         .test_cases = cs_amp_lib_test_cases,
755 };                                                755 };
756                                                   756 
757 kunit_test_suite(cs_amp_lib_test_suite);          757 kunit_test_suite(cs_amp_lib_test_suite);
758                                                   758 
759 MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB);             759 MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB);
760 MODULE_DESCRIPTION("KUnit test for Cirrus Logi    760 MODULE_DESCRIPTION("KUnit test for Cirrus Logic amplifier library");
761 MODULE_AUTHOR("Richard Fitzgerald <rf@opensour    761 MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
762 MODULE_LICENSE("GPL");                            762 MODULE_LICENSE("GPL");
763                                                   763 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php