~ [ 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 (Version linux-6.12-rc7) and /sound/soc/codecs/cs-amp-lib-test.c (Version linux-4.14.336)


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