firmware: cs_dsp: Add some sanity-checking to test harness

Add sanity checking to some test harness functions to help catch bugs
in the test code. This consists of checking the range of some arguments
and checking that reads from the dummy regmap succeed.

Most of the harness code already had sanity-checking but there were a
few places where it was missing or was assumed that the test could be
trusted to pass valid values.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20250416122422.783215-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Richard Fitzgerald 2025-04-16 13:24:22 +01:00 committed by Mark Brown
parent 9b62b7a657
commit 4308487b29
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
3 changed files with 16 additions and 6 deletions

View File

@ -176,6 +176,9 @@ struct cs_dsp_mock_bin_builder *cs_dsp_mock_bin_init(struct cs_dsp_test *priv,
struct cs_dsp_mock_bin_builder *builder;
struct wmfw_coeff_hdr *hdr;
KUNIT_ASSERT_LE(priv->test, format_version, 0xff);
KUNIT_ASSERT_LE(priv->test, fw_version, 0xffffff);
builder = kunit_kzalloc(priv->test, sizeof(*builder), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(priv->test, builder);
builder->test_priv = priv;

View File

@ -535,9 +535,11 @@ void cs_dsp_mock_xm_header_drop_from_regmap_cache(struct cs_dsp_test *priv)
* Could be one 32-bit register or two 16-bit registers.
* A raw read will read the requested number of bytes.
*/
regmap_raw_read(priv->dsp->regmap,
xm + (offsetof(struct wmfw_adsp2_id_hdr, n_algs) / 2),
&num_algs_be32, sizeof(num_algs_be32));
KUNIT_ASSERT_GE(priv->test, 0,
regmap_raw_read(priv->dsp->regmap,
xm +
(offsetof(struct wmfw_adsp2_id_hdr, n_algs) / 2),
&num_algs_be32, sizeof(num_algs_be32)));
num_algs = be32_to_cpu(num_algs_be32);
bytes = sizeof(struct wmfw_adsp2_id_hdr) +
(num_algs * sizeof(struct wmfw_adsp2_alg_hdr)) +
@ -546,9 +548,10 @@ void cs_dsp_mock_xm_header_drop_from_regmap_cache(struct cs_dsp_test *priv)
regcache_drop_region(priv->dsp->regmap, xm, xm + (bytes / 2) - 1);
break;
case WMFW_HALO:
regmap_read(priv->dsp->regmap,
xm + offsetof(struct wmfw_halo_id_hdr, n_algs),
&num_algs);
KUNIT_ASSERT_GE(priv->test, 0,
regmap_read(priv->dsp->regmap,
xm + offsetof(struct wmfw_halo_id_hdr, n_algs),
&num_algs));
bytes = sizeof(struct wmfw_halo_id_hdr) +
(num_algs * sizeof(struct wmfw_halo_alg_hdr)) +
4 /* terminator word */;

View File

@ -178,6 +178,8 @@ void cs_dsp_mock_wmfw_start_alg_info_block(struct cs_dsp_mock_wmfw_builder *buil
size_t bytes_needed, name_len, description_len;
int offset;
KUNIT_ASSERT_LE(builder->test_priv->test, alg_id, 0xffffff);
/* Bytes needed for region header */
bytes_needed = offsetof(struct wmfw_region, data);
@ -435,6 +437,8 @@ struct cs_dsp_mock_wmfw_builder *cs_dsp_mock_wmfw_init(struct cs_dsp_test *priv,
{
struct cs_dsp_mock_wmfw_builder *builder;
KUNIT_ASSERT_LE(priv->test, format_version, 0xff);
/* If format version isn't given use the default for the target core */
if (format_version < 0) {
switch (priv->dsp->type) {