Skip to content

Commit c2bb819

Browse files
groeckbroonie
authored andcommitted
regmap: kunit: Add test cases for regmap_multi_reg_(read,write}()
Add test cases for regmap_multi_reg_read() and regmap_multi_reg_write(). Signed-off-by: Guenter Roeck <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 450a60e commit c2bb819

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

drivers/base/regmap/regmap-kunit.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,77 @@ static void bulk_read(struct kunit *test)
304304
KUNIT_EXPECT_EQ(test, config.cache_type == REGCACHE_NONE, data->read[i]);
305305
}
306306

307+
static void multi_write(struct kunit *test)
308+
{
309+
struct regmap *map;
310+
struct regmap_config config;
311+
struct regmap_ram_data *data;
312+
struct reg_sequence sequence[BLOCK_TEST_SIZE];
313+
unsigned int val[BLOCK_TEST_SIZE], rval[BLOCK_TEST_SIZE];
314+
int i;
315+
316+
config = test_regmap_config;
317+
318+
map = gen_regmap(test, &config, &data);
319+
KUNIT_ASSERT_FALSE(test, IS_ERR(map));
320+
if (IS_ERR(map))
321+
return;
322+
323+
get_random_bytes(&val, sizeof(val));
324+
325+
/*
326+
* Data written via the multi API can be read back with single
327+
* reads.
328+
*/
329+
for (i = 0; i < BLOCK_TEST_SIZE; i++) {
330+
sequence[i].reg = i;
331+
sequence[i].def = val[i];
332+
sequence[i].delay_us = 0;
333+
}
334+
KUNIT_EXPECT_EQ(test, 0,
335+
regmap_multi_reg_write(map, sequence, BLOCK_TEST_SIZE));
336+
for (i = 0; i < BLOCK_TEST_SIZE; i++)
337+
KUNIT_EXPECT_EQ(test, 0, regmap_read(map, i, &rval[i]));
338+
339+
KUNIT_EXPECT_MEMEQ(test, val, rval, sizeof(val));
340+
341+
/* If using a cache the cache satisfied the read */
342+
for (i = 0; i < BLOCK_TEST_SIZE; i++)
343+
KUNIT_EXPECT_EQ(test, config.cache_type == REGCACHE_NONE, data->read[i]);
344+
}
345+
346+
static void multi_read(struct kunit *test)
347+
{
348+
struct regmap *map;
349+
struct regmap_config config;
350+
struct regmap_ram_data *data;
351+
unsigned int regs[BLOCK_TEST_SIZE];
352+
unsigned int val[BLOCK_TEST_SIZE], rval[BLOCK_TEST_SIZE];
353+
int i;
354+
355+
config = test_regmap_config;
356+
357+
map = gen_regmap(test, &config, &data);
358+
KUNIT_ASSERT_FALSE(test, IS_ERR(map));
359+
if (IS_ERR(map))
360+
return;
361+
362+
get_random_bytes(&val, sizeof(val));
363+
364+
/* Data written as single writes can be read via the multi API */
365+
for (i = 0; i < BLOCK_TEST_SIZE; i++) {
366+
regs[i] = i;
367+
KUNIT_EXPECT_EQ(test, 0, regmap_write(map, i, val[i]));
368+
}
369+
KUNIT_EXPECT_EQ(test, 0,
370+
regmap_multi_reg_read(map, regs, rval, BLOCK_TEST_SIZE));
371+
KUNIT_EXPECT_MEMEQ(test, val, rval, sizeof(val));
372+
373+
/* If using a cache the cache satisfied the read */
374+
for (i = 0; i < BLOCK_TEST_SIZE; i++)
375+
KUNIT_EXPECT_EQ(test, config.cache_type == REGCACHE_NONE, data->read[i]);
376+
}
377+
307378
static void read_bypassed(struct kunit *test)
308379
{
309380
const struct regmap_test_param *param = test->param_value;
@@ -1905,6 +1976,8 @@ static struct kunit_case regmap_test_cases[] = {
19051976
KUNIT_CASE_PARAM(read_bypassed_volatile, real_cache_types_gen_params),
19061977
KUNIT_CASE_PARAM(bulk_write, regcache_types_gen_params),
19071978
KUNIT_CASE_PARAM(bulk_read, regcache_types_gen_params),
1979+
KUNIT_CASE_PARAM(multi_write, regcache_types_gen_params),
1980+
KUNIT_CASE_PARAM(multi_read, regcache_types_gen_params),
19081981
KUNIT_CASE_PARAM(write_readonly, regcache_types_gen_params),
19091982
KUNIT_CASE_PARAM(read_writeonly, regcache_types_gen_params),
19101983
KUNIT_CASE_PARAM(reg_defaults, regcache_types_gen_params),

0 commit comments

Comments
 (0)