Skip to content

Commit a07bff4

Browse files
committed
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>
1 parent 1800330 commit a07bff4

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

drivers/base/regmap/regmap-kunit.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,37 @@ static void write_readonly(struct kunit *test)
231231
regmap_exit(map);
232232
}
233233

234+
static void read_writeonly(struct kunit *test)
235+
{
236+
struct regcache_types *t = (struct regcache_types *)test->param_value;
237+
struct regmap *map;
238+
struct regmap_config config;
239+
struct regmap_ram_data *data;
240+
unsigned int val;
241+
int i;
242+
243+
config = test_regmap_config;
244+
config.cache_type = t->type;
245+
config.readable_reg = reg_5_false;
246+
247+
map = gen_regmap(&config, &data);
248+
KUNIT_ASSERT_FALSE(test, IS_ERR(map));
249+
if (IS_ERR(map))
250+
return;
251+
252+
for (i = 0; i < BLOCK_TEST_SIZE; i++)
253+
data->read[i] = false;
254+
255+
/* Try to read all the registers, the writeonly one should fail */
256+
for (i = 0; i < BLOCK_TEST_SIZE; i++)
257+
KUNIT_EXPECT_EQ(test, i != 5, regmap_read(map, i, &val) == 0);
258+
259+
/* Did we trigger a hardware access? */
260+
KUNIT_EXPECT_FALSE(test, data->read[5]);
261+
262+
regmap_exit(map);
263+
}
264+
234265
static void reg_defaults(struct kunit *test)
235266
{
236267
struct regcache_types *t = (struct regcache_types *)test->param_value;
@@ -1078,6 +1109,7 @@ static struct kunit_case regmap_test_cases[] = {
10781109
KUNIT_CASE_PARAM(bulk_write, regcache_types_gen_params),
10791110
KUNIT_CASE_PARAM(bulk_read, regcache_types_gen_params),
10801111
KUNIT_CASE_PARAM(write_readonly, regcache_types_gen_params),
1112+
KUNIT_CASE_PARAM(read_writeonly, regcache_types_gen_params),
10811113
KUNIT_CASE_PARAM(reg_defaults, regcache_types_gen_params),
10821114
KUNIT_CASE_PARAM(reg_defaults_read_dev, regcache_types_gen_params),
10831115
KUNIT_CASE_PARAM(register_patch, regcache_types_gen_params),

0 commit comments

Comments
 (0)