Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: soc-utils-test: Add test for snd_soc_params_to_bclk()

snd_soc_params_to_bclk() calculates the BCLK from only the information in
snd_pcm_hw_params. It is therefore a subset of the functionality of
snd_soc_tdm_params_to_bclk() so can use a subset of the test case table.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20220817125508.1406651-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Richard Fitzgerald and committed by
Mark Brown
e32e23a2 aa16a3dc

+46
+46
sound/soc/soc-utils-test.c
··· 170 170 } 171 171 } 172 172 173 + static void test_snd_soc_params_to_bclk_one(struct kunit *test, 174 + unsigned int rate, snd_pcm_format_t fmt, 175 + unsigned int channels, 176 + unsigned int expected_bclk) 177 + { 178 + struct snd_pcm_hw_params params; 179 + int got_bclk; 180 + 181 + _snd_pcm_hw_params_any(&params); 182 + snd_mask_none(hw_param_mask(&params, SNDRV_PCM_HW_PARAM_FORMAT)); 183 + hw_param_interval(&params, SNDRV_PCM_HW_PARAM_RATE)->min = rate; 184 + hw_param_interval(&params, SNDRV_PCM_HW_PARAM_RATE)->max = rate; 185 + hw_param_interval(&params, SNDRV_PCM_HW_PARAM_CHANNELS)->min = channels; 186 + hw_param_interval(&params, SNDRV_PCM_HW_PARAM_CHANNELS)->max = channels; 187 + params_set_format(&params, fmt); 188 + 189 + got_bclk = snd_soc_params_to_bclk(&params); 190 + pr_debug("%s: r=%u sb=%u ch=%u expected=%u got=%d\n", 191 + __func__, 192 + rate, params_width(&params), channels, expected_bclk, got_bclk); 193 + KUNIT_ASSERT_EQ(test, expected_bclk, (unsigned int)got_bclk); 194 + } 195 + 196 + static void test_snd_soc_params_to_bclk(struct kunit *test) 197 + { 198 + int i; 199 + 200 + for (i = 0; i < ARRAY_SIZE(tdm_params_to_bclk_cases); ++i) { 201 + /* 202 + * snd_soc_params_to_bclk() is all the test cases where 203 + * snd_pcm_hw_params values are not overridden. 204 + */ 205 + if (tdm_params_to_bclk_cases[i].tdm_width | 206 + tdm_params_to_bclk_cases[i].tdm_slots | 207 + tdm_params_to_bclk_cases[i].slot_multiple) 208 + continue; 209 + 210 + test_snd_soc_params_to_bclk_one(test, 211 + tdm_params_to_bclk_cases[i].rate, 212 + tdm_params_to_bclk_cases[i].fmt, 213 + tdm_params_to_bclk_cases[i].channels, 214 + tdm_params_to_bclk_cases[i].bclk); 215 + } 216 + } 217 + 173 218 static struct kunit_case soc_utils_test_cases[] = { 174 219 KUNIT_CASE(test_tdm_params_to_bclk), 220 + KUNIT_CASE(test_snd_soc_params_to_bclk), 175 221 {} 176 222 }; 177 223