diff options
author | Mark Brown <broonie@kernel.org> | 2023-06-13 21:17:43 +0100 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2023-06-14 12:27:07 +0100 |
commit | a07bff4054c9e2b3a5c5790312a4a45aaeca7afe (patch) | |
tree | d04096f03751494236606521b141eb4075b69f25 /drivers/base | |
parent | 180033061e203a7c5510e7c38bccd885657de517 (diff) | |
download | linux-a07bff4054c9e2b3a5c5790312a4a45aaeca7afe.tar.gz linux-a07bff4054c9e2b3a5c5790312a4a45aaeca7afe.tar.bz2 linux-a07bff4054c9e2b3a5c5790312a4a45aaeca7afe.zip |
regmap: Add a test case for write only registers
Validate that attempts to read from write only registers fail and don't
somehow trigger spurious hardware accesses.
Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20230613-regmap-kunit-read-write-v1-2-2db337c52827@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/regmap/regmap-kunit.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap-kunit.c b/drivers/base/regmap/regmap-kunit.c index f5c175022a47..a1a1a9ce2e13 100644 --- a/drivers/base/regmap/regmap-kunit.c +++ b/drivers/base/regmap/regmap-kunit.c @@ -231,6 +231,37 @@ static void write_readonly(struct kunit *test) regmap_exit(map); } +static void read_writeonly(struct kunit *test) +{ + struct regcache_types *t = (struct regcache_types *)test->param_value; + struct regmap *map; + struct regmap_config config; + struct regmap_ram_data *data; + unsigned int val; + int i; + + config = test_regmap_config; + config.cache_type = t->type; + config.readable_reg = reg_5_false; + + map = gen_regmap(&config, &data); + KUNIT_ASSERT_FALSE(test, IS_ERR(map)); + if (IS_ERR(map)) + return; + + for (i = 0; i < BLOCK_TEST_SIZE; i++) + data->read[i] = false; + + /* Try to read all the registers, the writeonly one should fail */ + for (i = 0; i < BLOCK_TEST_SIZE; i++) + KUNIT_EXPECT_EQ(test, i != 5, regmap_read(map, i, &val) == 0); + + /* Did we trigger a hardware access? */ + KUNIT_EXPECT_FALSE(test, data->read[5]); + + regmap_exit(map); +} + static void reg_defaults(struct kunit *test) { struct regcache_types *t = (struct regcache_types *)test->param_value; @@ -1078,6 +1109,7 @@ static struct kunit_case regmap_test_cases[] = { KUNIT_CASE_PARAM(bulk_write, regcache_types_gen_params), KUNIT_CASE_PARAM(bulk_read, regcache_types_gen_params), KUNIT_CASE_PARAM(write_readonly, regcache_types_gen_params), + KUNIT_CASE_PARAM(read_writeonly, regcache_types_gen_params), KUNIT_CASE_PARAM(reg_defaults, regcache_types_gen_params), KUNIT_CASE_PARAM(reg_defaults_read_dev, regcache_types_gen_params), KUNIT_CASE_PARAM(register_patch, regcache_types_gen_params), |