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 /* << 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 518 static const struct cirrus_amp_cal_controls cs_amp_lib_test_calibration_controls = { 562 .alg_id = 0x9f210, 519 .alg_id = 0x9f210, 563 .mem_region = WMFW_ADSP2_YM, 520 .mem_region = WMFW_ADSP2_YM, 564 .ambient = "CAL_AMBIENT", 521 .ambient = "CAL_AMBIENT", 565 .calr = "CAL_R", 522 .calr = "CAL_R", 566 .status = "CAL_STATUS", 523 .status = "CAL_STATUS", 567 .checksum = "CAL_CHECKSUM", 524 .checksum = "CAL_CHECKSUM", 568 }; 525 }; 569 526 570 static int cs_amp_lib_test_write_cal_coeff(str 527 static int cs_amp_lib_test_write_cal_coeff(struct cs_dsp *dsp, 571 con 528 const struct cirrus_amp_cal_controls *controls, 572 con 529 const char *ctl_name, u32 val) 573 { 530 { 574 struct kunit *test = kunit_get_current 531 struct kunit *test = kunit_get_current_test(); 575 struct cs_amp_lib_test_priv *priv = te 532 struct cs_amp_lib_test_priv *priv = test->priv; 576 struct cs_amp_lib_test_ctl_write_entry 533 struct cs_amp_lib_test_ctl_write_entry *entry; 577 534 578 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctl 535 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctl_name); 579 KUNIT_EXPECT_PTR_EQ(test, controls, &c 536 KUNIT_EXPECT_PTR_EQ(test, controls, &cs_amp_lib_test_calibration_controls); 580 537 581 entry = kunit_kzalloc(test, sizeof(*en 538 entry = kunit_kzalloc(test, sizeof(*entry), GFP_KERNEL); 582 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ent 539 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, entry); 583 540 584 INIT_LIST_HEAD(&entry->list); 541 INIT_LIST_HEAD(&entry->list); 585 strscpy(entry->name, ctl_name, sizeof( 542 strscpy(entry->name, ctl_name, sizeof(entry->name)); 586 entry->value = val; 543 entry->value = val; 587 544 588 list_add_tail(&entry->list, &priv->ctl 545 list_add_tail(&entry->list, &priv->ctl_write_list); 589 546 590 return 0; 547 return 0; 591 } 548 } 592 549 593 static void cs_amp_lib_test_write_cal_data_tes 550 static void cs_amp_lib_test_write_cal_data_test(struct kunit *test) 594 { 551 { 595 struct cs_amp_lib_test_priv *priv = te 552 struct cs_amp_lib_test_priv *priv = test->priv; 596 struct cs_amp_lib_test_ctl_write_entry 553 struct cs_amp_lib_test_ctl_write_entry *entry; 597 struct cirrus_amp_cal_data data; 554 struct cirrus_amp_cal_data data; 598 struct cs_dsp *dsp; 555 struct cs_dsp *dsp; 599 int ret; 556 int ret; 600 557 601 dsp = kunit_kzalloc(test, sizeof(*dsp) 558 dsp = kunit_kzalloc(test, sizeof(*dsp), GFP_KERNEL); 602 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dsp 559 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dsp); 603 dsp->dev = &priv->amp_pdev.dev; 560 dsp->dev = &priv->amp_pdev.dev; 604 561 605 get_random_bytes(&data, sizeof(data)); 562 get_random_bytes(&data, sizeof(data)); 606 563 607 /* Redirect calls to write firmware co 564 /* Redirect calls to write firmware controls */ 608 kunit_activate_static_stub(test, 565 kunit_activate_static_stub(test, 609 cs_amp_test 566 cs_amp_test_hooks->write_cal_coeff, 610 cs_amp_lib_ 567 cs_amp_lib_test_write_cal_coeff); 611 568 612 ret = cs_amp_write_cal_coeffs(dsp, &cs 569 ret = cs_amp_write_cal_coeffs(dsp, &cs_amp_lib_test_calibration_controls, &data); 613 KUNIT_EXPECT_EQ(test, ret, 0); 570 KUNIT_EXPECT_EQ(test, ret, 0); 614 571 615 kunit_deactivate_static_stub(test, cs_ 572 kunit_deactivate_static_stub(test, cs_amp_test_hooks->write_cal_coeff); 616 573 617 KUNIT_EXPECT_EQ(test, list_count_nodes 574 KUNIT_EXPECT_EQ(test, list_count_nodes(&priv->ctl_write_list), 4); 618 575 619 /* Checksum control must be written la 576 /* Checksum control must be written last */ 620 entry = list_last_entry(&priv->ctl_wri 577 entry = list_last_entry(&priv->ctl_write_list, typeof(*entry), list); 621 KUNIT_EXPECT_STREQ(test, entry->name, 578 KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.checksum); 622 KUNIT_EXPECT_EQ(test, entry->value, da 579 KUNIT_EXPECT_EQ(test, entry->value, data.calR + 1); 623 list_del(&entry->list); 580 list_del(&entry->list); 624 581 625 entry = list_first_entry(&priv->ctl_wr 582 entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list); 626 KUNIT_EXPECT_STREQ(test, entry->name, 583 KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.ambient); 627 KUNIT_EXPECT_EQ(test, entry->value, da 584 KUNIT_EXPECT_EQ(test, entry->value, data.calAmbient); 628 list_del(&entry->list); 585 list_del(&entry->list); 629 586 630 entry = list_first_entry(&priv->ctl_wr 587 entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list); 631 KUNIT_EXPECT_STREQ(test, entry->name, 588 KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.calr); 632 KUNIT_EXPECT_EQ(test, entry->value, da 589 KUNIT_EXPECT_EQ(test, entry->value, data.calR); 633 list_del(&entry->list); 590 list_del(&entry->list); 634 591 635 entry = list_first_entry(&priv->ctl_wr 592 entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list); 636 KUNIT_EXPECT_STREQ(test, entry->name, 593 KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.status); 637 KUNIT_EXPECT_EQ(test, entry->value, da 594 KUNIT_EXPECT_EQ(test, entry->value, data.calStatus); 638 } 595 } 639 596 640 static void cs_amp_lib_test_dev_release(struct 597 static void cs_amp_lib_test_dev_release(struct device *dev) 641 { 598 { 642 } 599 } 643 600 644 static int cs_amp_lib_test_case_init(struct ku 601 static int cs_amp_lib_test_case_init(struct kunit *test) 645 { 602 { 646 struct cs_amp_lib_test_priv *priv; 603 struct cs_amp_lib_test_priv *priv; 647 int ret; 604 int ret; 648 605 649 KUNIT_ASSERT_NOT_NULL(test, cs_amp_tes 606 KUNIT_ASSERT_NOT_NULL(test, cs_amp_test_hooks); 650 607 651 priv = kunit_kzalloc(test, sizeof(*pri 608 priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); 652 if (!priv) 609 if (!priv) 653 return -ENOMEM; 610 return -ENOMEM; 654 611 655 test->priv = priv; 612 test->priv = priv; 656 INIT_LIST_HEAD(&priv->ctl_write_list); 613 INIT_LIST_HEAD(&priv->ctl_write_list); 657 614 658 /* Create dummy amp driver dev */ 615 /* Create dummy amp driver dev */ 659 priv->amp_pdev.name = "cs_amp_lib_test 616 priv->amp_pdev.name = "cs_amp_lib_test_drv"; 660 priv->amp_pdev.id = -1; 617 priv->amp_pdev.id = -1; 661 priv->amp_pdev.dev.release = cs_amp_li 618 priv->amp_pdev.dev.release = cs_amp_lib_test_dev_release; 662 ret = platform_device_register(&priv-> 619 ret = platform_device_register(&priv->amp_pdev); 663 KUNIT_ASSERT_GE_MSG(test, ret, 0, "Fai 620 KUNIT_ASSERT_GE_MSG(test, ret, 0, "Failed to register amp platform device\n"); 664 621 665 return 0; 622 return 0; 666 } 623 } 667 624 668 static void cs_amp_lib_test_case_exit(struct k 625 static void cs_amp_lib_test_case_exit(struct kunit *test) 669 { 626 { 670 struct cs_amp_lib_test_priv *priv = te 627 struct cs_amp_lib_test_priv *priv = test->priv; 671 628 672 if (priv->amp_pdev.name) 629 if (priv->amp_pdev.name) 673 platform_device_unregister(&pr 630 platform_device_unregister(&priv->amp_pdev); 674 } 631 } 675 632 676 static const struct cs_amp_lib_test_param cs_a 633 static const struct cs_amp_lib_test_param cs_amp_lib_test_get_cal_param_cases[] = { 677 { .num_amps = 2, .amp_index = 0 }, 634 { .num_amps = 2, .amp_index = 0 }, 678 { .num_amps = 2, .amp_index = 1 }, 635 { .num_amps = 2, .amp_index = 1 }, 679 636 680 { .num_amps = 3, .amp_index = 0 }, 637 { .num_amps = 3, .amp_index = 0 }, 681 { .num_amps = 3, .amp_index = 1 }, 638 { .num_amps = 3, .amp_index = 1 }, 682 { .num_amps = 3, .amp_index = 2 }, 639 { .num_amps = 3, .amp_index = 2 }, 683 640 684 { .num_amps = 4, .amp_index = 0 }, 641 { .num_amps = 4, .amp_index = 0 }, 685 { .num_amps = 4, .amp_index = 1 }, 642 { .num_amps = 4, .amp_index = 1 }, 686 { .num_amps = 4, .amp_index = 2 }, 643 { .num_amps = 4, .amp_index = 2 }, 687 { .num_amps = 4, .amp_index = 3 }, 644 { .num_amps = 4, .amp_index = 3 }, 688 645 689 { .num_amps = 5, .amp_index = 0 }, 646 { .num_amps = 5, .amp_index = 0 }, 690 { .num_amps = 5, .amp_index = 1 }, 647 { .num_amps = 5, .amp_index = 1 }, 691 { .num_amps = 5, .amp_index = 2 }, 648 { .num_amps = 5, .amp_index = 2 }, 692 { .num_amps = 5, .amp_index = 3 }, 649 { .num_amps = 5, .amp_index = 3 }, 693 { .num_amps = 5, .amp_index = 4 }, 650 { .num_amps = 5, .amp_index = 4 }, 694 651 695 { .num_amps = 6, .amp_index = 0 }, 652 { .num_amps = 6, .amp_index = 0 }, 696 { .num_amps = 6, .amp_index = 1 }, 653 { .num_amps = 6, .amp_index = 1 }, 697 { .num_amps = 6, .amp_index = 2 }, 654 { .num_amps = 6, .amp_index = 2 }, 698 { .num_amps = 6, .amp_index = 3 }, 655 { .num_amps = 6, .amp_index = 3 }, 699 { .num_amps = 6, .amp_index = 4 }, 656 { .num_amps = 6, .amp_index = 4 }, 700 { .num_amps = 6, .amp_index = 5 }, 657 { .num_amps = 6, .amp_index = 5 }, 701 658 702 { .num_amps = 8, .amp_index = 0 }, 659 { .num_amps = 8, .amp_index = 0 }, 703 { .num_amps = 8, .amp_index = 1 }, 660 { .num_amps = 8, .amp_index = 1 }, 704 { .num_amps = 8, .amp_index = 2 }, 661 { .num_amps = 8, .amp_index = 2 }, 705 { .num_amps = 8, .amp_index = 3 }, 662 { .num_amps = 8, .amp_index = 3 }, 706 { .num_amps = 8, .amp_index = 4 }, 663 { .num_amps = 8, .amp_index = 4 }, 707 { .num_amps = 8, .amp_index = 5 }, 664 { .num_amps = 8, .amp_index = 5 }, 708 { .num_amps = 8, .amp_index = 6 }, 665 { .num_amps = 8, .amp_index = 6 }, 709 { .num_amps = 8, .amp_index = 7 }, 666 { .num_amps = 8, .amp_index = 7 }, 710 }; 667 }; 711 668 712 static void cs_amp_lib_test_get_cal_param_desc 669 static void cs_amp_lib_test_get_cal_param_desc(const struct cs_amp_lib_test_param *param, 713 670 char *desc) 714 { 671 { 715 snprintf(desc, KUNIT_PARAM_DESC_SIZE, 672 snprintf(desc, KUNIT_PARAM_DESC_SIZE, "num_amps:%d amp_index:%d", 716 param->num_amps, param->amp_i 673 param->num_amps, param->amp_index); 717 } 674 } 718 675 719 KUNIT_ARRAY_PARAM(cs_amp_lib_test_get_cal, cs_ 676 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 677 cs_amp_lib_test_get_cal_param_desc); 721 678 722 static struct kunit_case cs_amp_lib_test_cases 679 static struct kunit_case cs_amp_lib_test_cases[] = { 723 /* Tests for getting calibration data 680 /* Tests for getting calibration data from EFI */ 724 KUNIT_CASE(cs_amp_lib_test_cal_data_to 681 KUNIT_CASE(cs_amp_lib_test_cal_data_too_short_test), 725 KUNIT_CASE(cs_amp_lib_test_cal_count_t 682 KUNIT_CASE(cs_amp_lib_test_cal_count_too_big_test), 726 KUNIT_CASE(cs_amp_lib_test_no_cal_data 683 KUNIT_CASE(cs_amp_lib_test_no_cal_data_test), 727 KUNIT_CASE(cs_amp_lib_test_get_efi_cal 684 KUNIT_CASE(cs_amp_lib_test_get_efi_cal_uid_not_found_noindex_test), 728 KUNIT_CASE(cs_amp_lib_test_get_efi_cal 685 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 686 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 687 KUNIT_CASE(cs_amp_lib_test_get_efi_cal_no_uid_no_index_test), 731 KUNIT_CASE(cs_amp_lib_test_get_efi_cal 688 KUNIT_CASE(cs_amp_lib_test_get_efi_cal_zero_not_matched_test), 732 KUNIT_CASE_PARAM(cs_amp_lib_test_get_e 689 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_uid_test, 733 cs_amp_lib_test_get_c 690 cs_amp_lib_test_get_cal_gen_params), 734 KUNIT_CASE_PARAM(cs_amp_lib_test_get_e 691 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_unchecked_test, 735 cs_amp_lib_test_get_c 692 cs_amp_lib_test_get_cal_gen_params), 736 KUNIT_CASE_PARAM(cs_amp_lib_test_get_e 693 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_checked_test, 737 cs_amp_lib_test_get_c 694 cs_amp_lib_test_get_cal_gen_params), 738 KUNIT_CASE_PARAM(cs_amp_lib_test_get_e 695 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_uid_mismatch_test, 739 cs_amp_lib_test_get_c 696 cs_amp_lib_test_get_cal_gen_params), 740 KUNIT_CASE_PARAM(cs_amp_lib_test_get_e 697 KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_fallback_test, 741 cs_amp_lib_test_get_c 698 cs_amp_lib_test_get_cal_gen_params), 742 KUNIT_CASE(cs_amp_lib_test_get_efi_cal << 743 699 744 /* Tests for writing calibration data 700 /* Tests for writing calibration data */ 745 KUNIT_CASE(cs_amp_lib_test_write_cal_d 701 KUNIT_CASE(cs_amp_lib_test_write_cal_data_test), 746 702 747 { } /* terminator */ 703 { } /* terminator */ 748 }; 704 }; 749 705 750 static struct kunit_suite cs_amp_lib_test_suit 706 static struct kunit_suite cs_amp_lib_test_suite = { 751 .name = "snd-soc-cs-amp-lib-test", 707 .name = "snd-soc-cs-amp-lib-test", 752 .init = cs_amp_lib_test_case_init, 708 .init = cs_amp_lib_test_case_init, 753 .exit = cs_amp_lib_test_case_exit, 709 .exit = cs_amp_lib_test_case_exit, 754 .test_cases = cs_amp_lib_test_cases, 710 .test_cases = cs_amp_lib_test_cases, 755 }; 711 }; 756 712 757 kunit_test_suite(cs_amp_lib_test_suite); 713 kunit_test_suite(cs_amp_lib_test_suite); 758 714 759 MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB); 715 MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB); 760 MODULE_DESCRIPTION("KUnit test for Cirrus Logi 716 MODULE_DESCRIPTION("KUnit test for Cirrus Logic amplifier library"); 761 MODULE_AUTHOR("Richard Fitzgerald <rf@opensour 717 MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>"); 762 MODULE_LICENSE("GPL"); 718 MODULE_LICENSE("GPL"); 763 719
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.