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