regmap: kunit: Add some test cases and a few small improvements
Subsystems (2)
cover regmap: kunit: Add some test cases and a few small improvements
This series adds some more test cases, mainly for testing:
commit eaa03486d932 ("regmap: maple: Fix uninitialized symbol 'ret' warnings") commit 00bb549d7d63 ("regmap: maple: Fix cache corruption in regcache_maple_drop()")
And the pending patch ("regmap: Add regmap_read_bypassed()")
https://lore.kernel.org/linux-sound/[email protected]/T/#m2b99b1e01872bfc3597e89dee57dcdd5dbaf1b55
There are also a few small improvements to the KUnit implementation.
Richard Fitzgerald (11):
regmap: kunit: Fix warnings of implicit casts to __le16 and __be16
regmap: kunit: Create a struct device for the regmap
regmap: kunit: Introduce struct for test case parameters
regmap: kunit: Run sparse cache tests at non-zero register addresses
regmap: kunit: Run non-sparse cache tests at non-zero register
addresses
regmap: kunit: Add more cache-drop tests
regmap: kunit: Add more cache-sync tests
regmap: kunit: Use a KUnit action to call regmap_exit()
regmap: kunit: Replace a kmalloc/kfree() pair with KUnit-managed alloc
regmap: kunit: Add cache-drop test with multiple cache blocks
regmap: kunit: Add test cases for regmap_read_bypassed()
drivers/base/regmap/internal.h | 14 +- drivers/base/regmap/regmap-kunit.c | 994 ++++++++++++++++++++------- drivers/base/regmap/regmap-ram.c | 5 +- drivers/base/regmap/regmap-raw-ram.c | 5 +- 4 files changed, 765 insertions(+), 253 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/11 regmap: kunit: Fix warnings of implicit casts to __le16 and __be16
Fix warnings about implicit casts to __le16 and __be16 types reported by smatch:
drivers/base/regmap/regmap-kunit.c:1118:25:
warning: cast to restricted __be16drivers/base/regmap/regmap-kunit.c:1120:25:
warning: cast to restricted __le16drivers/base/regmap/regmap-kunit.c:1187:33:
warning: cast to restricted __be16drivers/base/regmap/regmap-kunit.c:1190:33:
warning: cast to restricted __le16drivers/base/regmap/regmap-kunit.c:1302:33:
warning: cast to restricted __be16drivers/base/regmap/regmap-kunit.c:1305:33:
warning: cast to restricted __le16
Perform a __force cast for all these.
--- drivers/base/regmap/regmap-kunit.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/base/regmap/regmap-kunit.c +7 -7
@@ -1115,12 +1115,12 @@ static void raw_read_defaults(struct kunit *test)for (i =0 ; i < config.max_register +1 ; i++) { def = config.reg_defaults[i].def;if (config.val_format_endian ==REGMAP_ENDIAN_BIG ) { -KUNIT_EXPECT_EQ (test, def,be16_to_cpu (rval[i])); +KUNIT_EXPECT_EQ (test, def,be16_to_cpu ((__force __be16 )rval[i])); }else { -KUNIT_EXPECT_EQ (test, def,le16_to_cpu (rval[i])); +KUNIT_EXPECT_EQ (test, def,le16_to_cpu ((__force __le16 )rval[i])); } } - +kfree (rval);regmap_exit (map); }
@@ -1185,10 +1185,10 @@ static void raw_write(struct kunit *test)case 3 :if (config.val_format_endian ==REGMAP_ENDIAN_BIG ) {KUNIT_EXPECT_EQ (test, rval, -be16_to_cpu (val[i %2 ])); +be16_to_cpu ((__force __be16 )val[i %2 ])); }else {KUNIT_EXPECT_EQ (test, rval, -le16_to_cpu (val[i %2 ])); +le16_to_cpu ((__force __le16 )val[i %2 ])); }break ;default :
@@ -1300,10 +1300,10 @@ static void raw_sync(struct kunit *test)case 3 :if (config.val_format_endian ==REGMAP_ENDIAN_BIG ) {KUNIT_EXPECT_EQ (test, rval, -be16_to_cpu (val[i -2 ])); +be16_to_cpu ((__force __be16 )val[i -2 ])); }else {KUNIT_EXPECT_EQ (test, rval, -le16_to_cpu (val[i -2 ])); +le16_to_cpu ((__force __le16 )val[i -2 ])); }break ;case 4 :
Signature · 1 line
2.39.2
PATCH 2/11 regmap: kunit: Create a struct device for the regmap
In reply to Richard FitzgeraldUse kunit_device_register() to create a real struct device for the regmap instead of leaving it at NULL.
The main reason for this is that it allows context data to be passed into the readable_reg/writable_reg/volatile_reg functions by attaching it to the struct device with dev_set_drvdata().
The gen_regmap() and gen_raw_regmap() functions are updated to take a struct kunit * argument.
A new struct regmap_test_priv has been created to hold the struct device created by kunit_device_register(). This allows the struct to be extended in the future to hold more private data for the test suite.
--- drivers/base/regmap/internal.h | 14 ++-- drivers/base/regmap/regmap-kunit.c | 105 +++++++++++++++++++-------- drivers/base/regmap/regmap-ram.c | 5 +- drivers/base/regmap/regmap-raw-ram.c | 5 +- 4 files changed, 87 insertions(+), 42 deletions(-)
drivers/base/regmap/internal.h +8 -6
@@ -326,20 +326,22 @@ struct regmap_ram_data {* Create a test register map with data stored in RAM, not intended * for practical use. */ -struct regmap *__regmap_init_ram (const struct regmap_config *config, +struct regmap *__regmap_init_ram (struct device *dev, +const struct regmap_config *config,struct regmap_ram_data *data,struct lock_class_key *lock_key,const char *lock_name); -#define regmap_init_ram (config, data) \ - __regmap_lockdep_wrapper(__regmap_init_ram, #config, config, data) +#define regmap_init_ram (dev, config, data) \ + __regmap_lockdep_wrapper(__regmap_init_ram, #dev, dev, config, data) -struct regmap *__regmap_init_raw_ram (const struct regmap_config *config, +struct regmap *__regmap_init_raw_ram (struct device *dev, +const struct regmap_config *config,struct regmap_ram_data *data,struct lock_class_key *lock_key,const char *lock_name); -#define regmap_init_raw_ram (config, data) \ - __regmap_lockdep_wrapper(__regmap_init_raw_ram, #config, config, data) +#define regmap_init_raw_ram (dev, config, data) \ + __regmap_lockdep_wrapper(__regmap_init_raw_ram, #dev, dev, config, data)#endif
drivers/base/regmap/regmap-kunit.c +73 -32
321 lines not on this page · raw message
drivers/base/regmap/regmap-ram.c +3 -2
@@ -53,7 +53,8 @@ static const struct regmap_bus regmap_ram = { .free_context = regmap_ram_free_context, }; -struct regmap *__regmap_init_ram (const struct regmap_config *config, +struct regmap *__regmap_init_ram (struct device *dev, +const struct regmap_config *config,struct regmap_ram_data *data,struct lock_class_key *lock_key,const char *lock_name)
@@ -75,7 +76,7 @@ struct regmap *__regmap_init_ram(const struct regmap_config *config,if (!data->written)return ERR_PTR (-ENOMEM ); - map =__regmap_init (NULL , ®map_ram, data, config, + map =__regmap_init (dev, ®map_ram, data, config, lock_key, lock_name);return map;
drivers/base/regmap/regmap-raw-ram.c +3 -2
@@ -107,7 +107,8 @@ static const struct regmap_bus regmap_raw_ram = { .free_context = regmap_raw_ram_free_context, }; -struct regmap *__regmap_init_raw_ram (const struct regmap_config *config, +struct regmap *__regmap_init_raw_ram (struct device *dev, +const struct regmap_config *config,struct regmap_ram_data *data,struct lock_class_key *lock_key,const char *lock_name)
@@ -134,7 +135,7 @@ struct regmap *__regmap_init_raw_ram(const struct regmap_config *config, data->reg_endian = config->reg_format_endian; - map =__regmap_init (NULL , ®map_raw_ram, data, config, + map =__regmap_init (dev, ®map_raw_ram, data, config, lock_key, lock_name);return map;
Signature · 1 line
2.39.2
PATCH 3/11 regmap: kunit: Introduce struct for test case parameters
In reply to Richard FitzgeraldAdd a struct regmap_test_param and use it for all test cases instead of passing various different types of param object depending on the test case.
This makes it much easier and cleaner to expand what can be parameterized.
--- drivers/base/regmap/regmap-kunit.c | 213 +++++++++++++---------------- 1 file changed, 96 insertions(+), 117 deletions(-)
drivers/base/regmap/regmap-kunit.c +96 -117
@@ -14,6 +14,11 @@ struct regmap_test_priv {struct device *dev; }; +struct regmap_test_param { +enum regcache_type cache; +enum regmap_endian val_endian; +}; +static void get_changed_bytes (void *orig,void *new,size_t size) {char *o = orig;
@@ -37,44 +42,74 @@ static const struct regmap_config test_regmap_config = { .val_bits = sizeof(unsigned int) * 8, }; -struct regcache_types { -enum regcache_type type; -const char *name; -}; - -static void case_to_desc (const struct regcache_types *t,char *desc) +static const char *regcache_type_name (enum regcache_type type) { -strcpy (desc, t->name); +switch (type) { +case REGCACHE_NONE : +return "none" ; +case REGCACHE_FLAT : +return "flat" ; +case REGCACHE_RBTREE : +return "rbtree" ; +case REGCACHE_MAPLE : +return "maple" ; +default : +return NULL ; + } } -static const struct regcache_types regcache_types_list[] = { - {REGCACHE_NONE ,"none" }, - {REGCACHE_FLAT ,"flat" }, - {REGCACHE_RBTREE ,"rbtree" }, - {REGCACHE_MAPLE ,"maple" }, +static const char *regmap_endian_name (enum regmap_endian endian) +{ +switch (endian) { +case REGMAP_ENDIAN_BIG : +return "big" ; +case REGMAP_ENDIAN_LITTLE : +return "little" ; +case REGMAP_ENDIAN_DEFAULT : +return "default" ; +case REGMAP_ENDIAN_NATIVE : +return "native" ; +default : +return NULL ; + } +} + +static void param_to_desc (const struct regmap_test_param *param,char *desc) +{ +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s-%s" , +regcache_type_name (param->cache), +regmap_endian_name (param->val_endian)); +} + +static const struct regmap_test_param regcache_types_list[] = { + { .cache =REGCACHE_NONE }, + { .cache =REGCACHE_FLAT }, + { .cache =REGCACHE_RBTREE }, + { .cache =REGCACHE_MAPLE }, }; -KUNIT_ARRAY_PARAM (regcache_types, regcache_types_list, case_to_desc); +KUNIT_ARRAY_PARAM (regcache_types, regcache_types_list, param_to_desc); -static const struct regcache_types real_cache_types_list[] = { - {REGCACHE_FLAT ,"flat" }, - {REGCACHE_RBTREE ,"rbtree" }, - {REGCACHE_MAPLE ,"maple" }, +static const struct regmap_test_param real_cache_types_list[] = { + { .cache =REGCACHE_FLAT }, + { .cache =REGCACHE_RBTREE }, + { .cache =REGCACHE_MAPLE }, }; -KUNIT_ARRAY_PARAM (real_cache_types, real_cache_types_list, case_to_desc); +KUNIT_ARRAY_PARAM (real_cache_types, real_cache_types_list, param_to_desc); -static const struct regcache_types sparse_cache_types_list[] = { - {REGCACHE_RBTREE ,"rbtree" }, - {REGCACHE_MAPLE ,"maple" }, +static const struct regmap_test_param sparse_cache_types_list[] = { + { .cache =REGCACHE_RBTREE }, + { .cache =REGCACHE_MAPLE }, }; -KUNIT_ARRAY_PARAM (sparse_cache_types, sparse_cache_types_list, case_to_desc); +KUNIT_ARRAY_PARAM (sparse_cache_types, sparse_cache_types_list, param_to_desc);static struct regmap *gen_regmap (struct kunit *test,struct regmap_config *config,struct regmap_ram_data **data) { +const struct regmap_test_param *param = test->param_value;struct regmap_test_priv *priv = test->priv;unsigned int *buf;struct regmap *ret;
@@ -82,6 +117,7 @@ static struct regmap *gen_regmap(struct kunit *test,int i;struct reg_default *defaults; + config->cache_type = param->cache; config->disable_locking = config->cache_type ==REGCACHE_RBTREE || config->cache_type ==REGCACHE_MAPLE ;
@@ -126,14 +162,12 @@ static bool reg_5_false(struct device *context, unsigned int reg)static void basic_read_write (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, rval; config = test_regmap_config; - config.cache_type = t->type; map =gen_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));
@@ -148,14 +182,13 @@ static void basic_read_write(struct kunit *test)KUNIT_EXPECT_EQ (test, val, rval);/* If using a cache the cache satisfied the read */ -KUNIT_EXPECT_EQ (test, t->type ==REGCACHE_NONE , data->read[0 ]); +KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[0 ]);regmap_exit (map); }static void bulk_write (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;
@@ -163,7 +196,6 @@ static void bulk_write(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; map =gen_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));
@@ -185,14 +217,13 @@ static void bulk_write(struct kunit *test)/* If using a cache the cache satisfied the read */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test, t->type ==REGCACHE_NONE , data->read[i]); +KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]);regmap_exit (map); }static void bulk_read (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;
@@ -200,7 +231,6 @@ static void bulk_read(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; map =gen_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));
@@ -218,14 +248,13 @@ static void bulk_read(struct kunit *test)/* If using a cache the cache satisfied the read */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test, t->type ==REGCACHE_NONE , data->read[i]); +KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]);regmap_exit (map); }static void write_readonly (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;
@@ -233,7 +262,6 @@ static void write_readonly(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.num_reg_defaults =BLOCK_TEST_SIZE ; config.writeable_reg = reg_5_false;
@@ -260,7 +288,6 @@ static void write_readonly(struct kunit *test)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;
@@ -268,7 +295,6 @@ static void read_writeonly(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.readable_reg = reg_5_false; map =gen_regmap (test, &config, &data);
@@ -284,7 +310,7 @@ static void read_writeonly(struct kunit *test)* fail if we aren't using the flat cache. */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) { -if (t->type !=REGCACHE_FLAT ) { +if (config.cache_type !=REGCACHE_FLAT ) {KUNIT_EXPECT_EQ (test, i !=5 ,regmap_read (map, i, &val) ==0 ); }else {
@@ -300,7 +326,6 @@ static void read_writeonly(struct kunit *test)static void reg_defaults (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;
@@ -308,7 +333,6 @@ static void reg_defaults(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.num_reg_defaults =BLOCK_TEST_SIZE ; map =gen_regmap (test, &config, &data);
@@ -323,12 +347,11 @@ static void reg_defaults(struct kunit *test)/* The data should have been read from cache if there was one */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test, t->type ==REGCACHE_NONE , data->read[i]); +KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]); }static void reg_defaults_read_dev (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;
@@ -336,7 +359,6 @@ static void reg_defaults_read_dev(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.num_reg_defaults_raw =BLOCK_TEST_SIZE ; map =gen_regmap (test, &config, &data);
@@ -346,7 +368,7 @@ static void reg_defaults_read_dev(struct kunit *test)/* We should have read the cache defaults back from the map */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) { -KUNIT_EXPECT_EQ (test, t->type !=REGCACHE_NONE , data->read[i]); +KUNIT_EXPECT_EQ (test, config.cache_type !=REGCACHE_NONE , data->read[i]); data->read[i] = false; }
@@ -357,12 +379,11 @@ static void reg_defaults_read_dev(struct kunit *test)/* The data should have been read from cache if there was one */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test, t->type ==REGCACHE_NONE , data->read[i]); +KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]); }static void register_patch (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;
@@ -372,7 +393,6 @@ static void register_patch(struct kunit *test)/* We need defaults so readback works */ config = test_regmap_config; - config.cache_type = t->type; config.num_reg_defaults =BLOCK_TEST_SIZE ; map =gen_regmap (test, &config, &data);
@@ -414,7 +434,6 @@ static void register_patch(struct kunit *test)static void stride (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;
@@ -422,7 +441,6 @@ static void stride(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.reg_stride =2 ; config.num_reg_defaults =BLOCK_TEST_SIZE /2 ;
@@ -444,7 +462,7 @@ static void stride(struct kunit *test) }else {KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, i, &rval));KUNIT_EXPECT_EQ (test, data->vals[i], rval); -KUNIT_EXPECT_EQ (test, t->type ==REGCACHE_NONE , +KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]);KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, i, rval));
@@ -488,7 +506,6 @@ static bool test_range_all_volatile(struct device *dev, unsigned int reg)static void basic_ranges (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;
@@ -496,7 +513,6 @@ static void basic_ranges(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.volatile_reg = test_range_all_volatile; config.ranges = &test_range; config.num_ranges =1 ;
@@ -560,7 +576,6 @@ static void basic_ranges(struct kunit *test)/* Try to stress dynamic creation of cache data structures */ static void stress_insert (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;
@@ -569,7 +584,6 @@ static void stress_insert(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.max_register =300 ; map =gen_regmap (test, &config, &data);
@@ -606,7 +620,7 @@ static void stress_insert(struct kunit *test)for (i =0 ; i < config.max_register; i ++) {KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, i, &rval));KUNIT_EXPECT_EQ (test, rval, vals[i]); -KUNIT_EXPECT_EQ (test, t->type ==REGCACHE_NONE , data->read[i]); +KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]); }regmap_exit (map);
@@ -614,14 +628,12 @@ static void stress_insert(struct kunit *test)static void cache_bypass (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, rval; config = test_regmap_config; - config.cache_type = t->type; map =gen_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));
@@ -652,7 +664,6 @@ static void cache_bypass(struct kunit *test)static void cache_sync (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;
@@ -660,7 +671,6 @@ static void cache_sync(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; map =gen_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));
@@ -690,7 +700,6 @@ static void cache_sync(struct kunit *test)static void cache_sync_defaults (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;
@@ -698,7 +707,6 @@ static void cache_sync_defaults(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.num_reg_defaults =BLOCK_TEST_SIZE ; map =gen_regmap (test, &config, &data);
@@ -726,7 +734,6 @@ static void cache_sync_defaults(struct kunit *test)static void cache_sync_readonly (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;
@@ -734,7 +741,6 @@ static void cache_sync_readonly(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.writeable_reg = reg_5_false; map =gen_regmap (test, &config, &data);
@@ -767,7 +773,6 @@ static void cache_sync_readonly(struct kunit *test)static void cache_sync_patch (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;
@@ -777,7 +782,6 @@ static void cache_sync_patch(struct kunit *test)/* We need defaults so readback works */ config = test_regmap_config; - config.cache_type = t->type; config.num_reg_defaults =BLOCK_TEST_SIZE ; map =gen_regmap (test, &config, &data);
@@ -828,7 +832,6 @@ static void cache_sync_patch(struct kunit *test)static void cache_drop (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;
@@ -836,7 +839,6 @@ static void cache_drop(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.num_reg_defaults =BLOCK_TEST_SIZE ; map =gen_regmap (test, &config, &data);
@@ -870,7 +872,6 @@ static void cache_drop(struct kunit *test)static void cache_present (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;
@@ -878,7 +879,6 @@ static void cache_present(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; map =gen_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));
@@ -910,7 +910,6 @@ static void cache_present(struct kunit *test)/* Check that caching the window register works with sync */ static void cache_range_window_reg (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;
@@ -918,7 +917,6 @@ static void cache_range_window_reg(struct kunit *test)int i; config = test_regmap_config; - config.cache_type = t->type; config.volatile_reg = test_range_window_volatile; config.ranges = &test_range; config.num_ranges =1 ;
@@ -960,41 +958,29 @@ static void cache_range_window_reg(struct kunit *test)KUNIT_ASSERT_EQ (test, val,2 ); } -struct raw_test_types { -const char *name; - -enum regcache_type cache_type; -enum regmap_endian val_endian; +static const struct regmap_test_param raw_types_list[] = { + { .cache =REGCACHE_NONE , .val_endian =REGMAP_ENDIAN_LITTLE }, + { .cache =REGCACHE_NONE , .val_endian =REGMAP_ENDIAN_BIG }, + { .cache =REGCACHE_FLAT , .val_endian =REGMAP_ENDIAN_LITTLE }, + { .cache =REGCACHE_FLAT , .val_endian =REGMAP_ENDIAN_BIG }, + { .cache =REGCACHE_RBTREE , .val_endian =REGMAP_ENDIAN_LITTLE }, + { .cache =REGCACHE_RBTREE , .val_endian =REGMAP_ENDIAN_BIG }, + { .cache =REGCACHE_MAPLE , .val_endian =REGMAP_ENDIAN_LITTLE }, + { .cache =REGCACHE_MAPLE , .val_endian =REGMAP_ENDIAN_BIG }, }; -static void raw_to_desc (const struct raw_test_types *t,char *desc) -{ -strcpy (desc, t->name); -} +KUNIT_ARRAY_PARAM (raw_test_types, raw_types_list, param_to_desc); -static const struct raw_test_types raw_types_list[] = { - {"none-little" ,REGCACHE_NONE ,REGMAP_ENDIAN_LITTLE }, - {"none-big" ,REGCACHE_NONE ,REGMAP_ENDIAN_BIG }, - {"flat-little" ,REGCACHE_FLAT ,REGMAP_ENDIAN_LITTLE }, - {"flat-big" ,REGCACHE_FLAT ,REGMAP_ENDIAN_BIG }, - {"rbtree-little" ,REGCACHE_RBTREE ,REGMAP_ENDIAN_LITTLE }, - {"rbtree-big" ,REGCACHE_RBTREE ,REGMAP_ENDIAN_BIG }, - {"maple-little" ,REGCACHE_MAPLE ,REGMAP_ENDIAN_LITTLE }, - {"maple-big" ,REGCACHE_MAPLE ,REGMAP_ENDIAN_BIG }, +static const struct regmap_test_param raw_cache_types_list[] = { + { .cache =REGCACHE_FLAT , .val_endian =REGMAP_ENDIAN_LITTLE }, + { .cache =REGCACHE_FLAT , .val_endian =REGMAP_ENDIAN_BIG }, + { .cache =REGCACHE_RBTREE , .val_endian =REGMAP_ENDIAN_LITTLE }, + { .cache =REGCACHE_RBTREE , .val_endian =REGMAP_ENDIAN_BIG }, + { .cache =REGCACHE_MAPLE , .val_endian =REGMAP_ENDIAN_LITTLE }, + { .cache =REGCACHE_MAPLE , .val_endian =REGMAP_ENDIAN_BIG }, }; -KUNIT_ARRAY_PARAM (raw_test_types, raw_types_list, raw_to_desc); - -static const struct raw_test_types raw_cache_types_list[] = { - {"flat-little" ,REGCACHE_FLAT ,REGMAP_ENDIAN_LITTLE }, - {"flat-big" ,REGCACHE_FLAT ,REGMAP_ENDIAN_BIG }, - {"rbtree-little" ,REGCACHE_RBTREE ,REGMAP_ENDIAN_LITTLE }, - {"rbtree-big" ,REGCACHE_RBTREE ,REGMAP_ENDIAN_BIG }, - {"maple-little" ,REGCACHE_MAPLE ,REGMAP_ENDIAN_LITTLE }, - {"maple-big" ,REGCACHE_MAPLE ,REGMAP_ENDIAN_BIG }, -}; - -KUNIT_ARRAY_PARAM (raw_test_cache_types, raw_cache_types_list, raw_to_desc); +KUNIT_ARRAY_PARAM (raw_test_cache_types, raw_cache_types_list, param_to_desc);static const struct regmap_config raw_regmap_config = { .max_register =BLOCK_TEST_SIZE ,
@@ -1006,18 +992,18 @@ static const struct regmap_config raw_regmap_config = {static struct regmap *gen_raw_regmap (struct kunit *test,struct regmap_config *config, -struct raw_test_types *test_type,struct regmap_ram_data **data) {struct regmap_test_priv *priv = test->priv; +const struct regmap_test_param *param = test->param_value;u16 *buf;struct regmap *ret;size_t size = (config->max_register +1 ) * config->reg_bits /8 ;int i;struct reg_default *defaults; - config->cache_type = test_type->cache_type; - config->val_format_endian = test_type->val_endian; + config->cache_type = param->cache; + config->val_format_endian = param->val_endian; config->disable_locking = config->cache_type ==REGCACHE_RBTREE || config->cache_type ==REGCACHE_MAPLE ;
@@ -1042,7 +1028,7 @@ static struct regmap *gen_raw_regmap(struct kunit *test,for (i =0 ; i < config->num_reg_defaults; i++) { defaults[i].reg = i; -switch (test_type->val_endian) { +switch (param->val_endian) {case REGMAP_ENDIAN_LITTLE : defaults[i].def =le16_to_cpu (buf[i]);break ;
@@ -1072,7 +1058,6 @@ static struct regmap *gen_raw_regmap(struct kunit *test,static void raw_read_defaults_single (struct kunit *test) { -struct raw_test_types *t = (struct raw_test_types *)test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -1081,7 +1066,7 @@ static void raw_read_defaults_single(struct kunit *test) config = raw_regmap_config; - map =gen_raw_regmap (test, &config, t, &data); + map =gen_raw_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));if (IS_ERR (map))return ;
@@ -1097,7 +1082,6 @@ static void raw_read_defaults_single(struct kunit *test)static void raw_read_defaults (struct kunit *test) { -struct raw_test_types *t = (struct raw_test_types *)test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -1108,7 +1092,7 @@ static void raw_read_defaults(struct kunit *test) config = raw_regmap_config; - map =gen_raw_regmap (test, &config, t, &data); + map =gen_raw_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));if (IS_ERR (map))return ;
@@ -1136,7 +1120,6 @@ static void raw_read_defaults(struct kunit *test)static void raw_write_read_single (struct kunit *test) { -struct raw_test_types *t = (struct raw_test_types *)test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -1145,7 +1128,7 @@ static void raw_write_read_single(struct kunit *test) config = raw_regmap_config; - map =gen_raw_regmap (test, &config, t, &data); + map =gen_raw_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));if (IS_ERR (map))return ;
@@ -1162,7 +1145,6 @@ static void raw_write_read_single(struct kunit *test)static void raw_write (struct kunit *test) { -struct raw_test_types *t = (struct raw_test_types *)test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -1173,7 +1155,7 @@ static void raw_write(struct kunit *test) config = raw_regmap_config; - map =gen_raw_regmap (test, &config, t, &data); + map =gen_raw_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));if (IS_ERR (map))return ;
@@ -1224,7 +1206,6 @@ static bool ram_reg_zero(struct regmap_ram_data *data, unsigned int reg)static void raw_noinc_write (struct kunit *test) { -struct raw_test_types *t = (struct raw_test_types *)test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -1237,7 +1218,7 @@ static void raw_noinc_write(struct kunit *test) config.writeable_noinc_reg = reg_zero; config.readable_noinc_reg = reg_zero; - map =gen_raw_regmap (test, &config, t, &data); + map =gen_raw_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));if (IS_ERR (map))return ;
@@ -1274,7 +1255,6 @@ static void raw_noinc_write(struct kunit *test)static void raw_sync (struct kunit *test) { -struct raw_test_types *t = (struct raw_test_types *)test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -1285,7 +1265,7 @@ static void raw_sync(struct kunit *test) config = raw_regmap_config; - map =gen_raw_regmap (test, &config, t, &data); + map =gen_raw_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));if (IS_ERR (map))return ;
@@ -1352,7 +1332,6 @@ static void raw_sync(struct kunit *test)static void raw_ranges (struct kunit *test) { -struct raw_test_types *t = (struct raw_test_types *)test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -1365,7 +1344,7 @@ static void raw_ranges(struct kunit *test) config.num_ranges =1 ; config.max_register = test_range.range_max; - map =gen_raw_regmap (test, &config, t, &data); + map =gen_raw_regmap (test, &config, &data);KUNIT_ASSERT_FALSE (test,IS_ERR (map));if (IS_ERR (map))return ;
Signature · 1 line
2.39.2
PATCH 4/11 regmap: kunit: Run sparse cache tests at non-zero register addresses
In reply to Richard FitzgeraldRun the cache_drop() and cache_present() tests at blocks of addresses that don't start at zero.
This adds a from_reg parameter to struct regmap_test_param. This is used to set the base address of the register defaults created by gen_regmap().
Extra entries are added to sparse_cache_types_list[] to test at non-zero from_reg values. The cache_drop() and cache_present() tests are updated to test at the given offset.
The aim here is to add test cases to cache_drop() for the bug fixed by commit 00bb549d7d63 ("regmap: maple: Fix cache corruption in regcache_maple_drop()")
But the same parameter table is used by the cache_present() test so let's also update that to use from_reg.
--- drivers/base/regmap/regmap-kunit.c | 67 ++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 22 deletions(-)
drivers/base/regmap/regmap-kunit.c +45 -22
@@ -17,6 +17,8 @@ struct regmap_test_priv {struct regmap_test_param {enum regcache_type cache;enum regmap_endian val_endian; + +unsigned int from_reg; };static void get_changed_bytes (void *orig,void *new,size_t size)
@@ -37,7 +39,6 @@ static void get_changed_bytes(void *orig, void *new, size_t size) }static const struct regmap_config test_regmap_config = { - .max_register =BLOCK_TEST_SIZE , .reg_stride =1 , .val_bits =sizeof (unsigned int ) *8 , };
@@ -76,9 +77,10 @@ static const char *regmap_endian_name(enum regmap_endian endian)static void param_to_desc (const struct regmap_test_param *param,char *desc) { -snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s-%s" , +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s-%s @%#x" ,regcache_type_name (param->cache), -regmap_endian_name (param->val_endian)); +regmap_endian_name (param->val_endian), + param->from_reg); }static const struct regmap_test_param regcache_types_list[] = {
@@ -99,8 +101,16 @@ static const struct regmap_test_param real_cache_types_list[] = {KUNIT_ARRAY_PARAM (real_cache_types, real_cache_types_list, param_to_desc);static const struct regmap_test_param sparse_cache_types_list[] = { - { .cache =REGCACHE_RBTREE }, - { .cache =REGCACHE_MAPLE }, + { .cache =REGCACHE_RBTREE , .from_reg =0 }, + { .cache =REGCACHE_RBTREE , .from_reg =0x2001 }, + { .cache =REGCACHE_RBTREE , .from_reg =0x2002 }, + { .cache =REGCACHE_RBTREE , .from_reg =0x2003 }, + { .cache =REGCACHE_RBTREE , .from_reg =0x2004 }, + { .cache =REGCACHE_MAPLE , .from_reg =0 }, + { .cache =REGCACHE_MAPLE , .from_reg =0x2001 }, + { .cache =REGCACHE_MAPLE , .from_reg =0x2002 }, + { .cache =REGCACHE_MAPLE , .from_reg =0x2003 }, + { .cache =REGCACHE_MAPLE , .from_reg =0x2004 }, };KUNIT_ARRAY_PARAM (sparse_cache_types, sparse_cache_types_list, param_to_desc);
@@ -113,7 +123,7 @@ static struct regmap *gen_regmap(struct kunit *test,struct regmap_test_priv *priv = test->priv;unsigned int *buf;struct regmap *ret; -size_t size = (config->max_register +1 ) *sizeof (unsigned int ); +size_t size;int i;struct reg_default *defaults;
@@ -121,6 +131,16 @@ static struct regmap *gen_regmap(struct kunit *test, config->disable_locking = config->cache_type ==REGCACHE_RBTREE || config->cache_type ==REGCACHE_MAPLE ; +if (config->max_register ==0 ) { + config->max_register = param->from_reg; +if (config->num_reg_defaults) + config->max_register += (config->num_reg_defaults -1 ) * + config->reg_stride; +else + config->max_register += (BLOCK_TEST_SIZE * config->reg_stride); + } + + size = (config->max_register +1 ) *sizeof (unsigned int ); buf =kmalloc (size,GFP_KERNEL );if (!buf)return ERR_PTR (-ENOMEM );
@@ -141,8 +161,8 @@ static struct regmap *gen_regmap(struct kunit *test, config->reg_defaults = defaults;for (i =0 ; i < config->num_reg_defaults; i++) { - defaults[i].reg = i * config->reg_stride; - defaults[i].def = buf[i * config->reg_stride]; + defaults[i].reg = param->from_reg + (i * config->reg_stride); + defaults[i].def = buf[param->from_reg + (i * config->reg_stride)]; } }
@@ -832,6 +852,7 @@ static void cache_sync_patch(struct kunit *test)static void cache_drop (struct kunit *test) { +const struct regmap_test_param *param = test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -848,30 +869,32 @@ static void cache_drop(struct kunit *test)/* Ensure the data is read from the cache */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) - data->read[i] = false; -KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_read (map,0 , rval, + data->read[param->from_reg + i] = false; +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_read (map, param->from_reg, rval,BLOCK_TEST_SIZE ));for (i =0 ; i <BLOCK_TEST_SIZE ; i++) { -KUNIT_EXPECT_FALSE (test, data->read[i]); - data->read[i] = false; +KUNIT_EXPECT_FALSE (test, data->read[param->from_reg + i]); + data->read[param->from_reg + i] = false; } -KUNIT_EXPECT_MEMEQ (test, data->vals, rval,sizeof (rval)); +KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], rval,sizeof (rval));/* Drop some registers */ -KUNIT_EXPECT_EQ (test,0 ,regcache_drop_region (map,3 ,5 )); +KUNIT_EXPECT_EQ (test,0 ,regcache_drop_region (map, param->from_reg +3 , + param->from_reg +5 ));/* Reread and check only the dropped registers hit the device. */ -KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_read (map,0 , rval, +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_read (map, param->from_reg, rval,BLOCK_TEST_SIZE ));for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test, data->read[i], i >=3 && i <=5 ); -KUNIT_EXPECT_MEMEQ (test, data->vals, rval,sizeof (rval)); +KUNIT_EXPECT_EQ (test, data->read[param->from_reg + i], i >=3 && i <=5 ); +KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], rval,sizeof (rval));regmap_exit (map); }static void cache_present (struct kunit *test) { +const struct regmap_test_param *param = test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -886,23 +909,23 @@ static void cache_present(struct kunit *test)return ;for (i =0 ; i <BLOCK_TEST_SIZE ; i++) - data->read[i] = false; + data->read[param->from_reg + i] = false;/* No defaults so no registers cached. */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_ASSERT_FALSE (test,regcache_reg_cached (map, i)); +KUNIT_ASSERT_FALSE (test,regcache_reg_cached (map, param->from_reg + i));/* We didn't trigger any reads */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_ASSERT_FALSE (test, data->read[i]); +KUNIT_ASSERT_FALSE (test, data->read[param->from_reg + i]);/* Fill the cache */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, i, &val)); +KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, param->from_reg + i, &val));/* Now everything should be cached */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_ASSERT_TRUE (test,regcache_reg_cached (map, i)); +KUNIT_ASSERT_TRUE (test,regcache_reg_cached (map, param->from_reg + i));regmap_exit (map); }
Signature · 1 line
2.39.2
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Hi,
Quoted 11 lines · Richard Fitzgerald
Run the
cache_drop()andcache_present()tests at blocks of addresses that don't start at zero.This adds a
from_regparameter to structregmap_test_param. This is used to set the base address of the register defaults created bygen_regmap().Extra entries are added to sparse_cache_types_list[] to test at non-zero
from_regvalues. Thecache_drop()andcache_present()tests are updated to test at the given offset.
Quoted 8 lines
The aim here is to add test cases to
cache_drop()for the bug fixed by commit00bb549d7d63("regmap: maple: Fix cache corruption inregcache_maple_drop()")But the same parameter table is used by the
cache_present()test so let's also update that to usefrom_reg.Signed-off-by Richard Fitzgerald <[email protected]>
With this patch in mainline, I get lots of errors such as
[ 23.494308] ============================================================================= [ 23.496391] BUG kmalloc-64 (Tainted: G N): kmalloc Redzone overwritten
Bisect log and first of many backtraces attached for reference.
Guenter
---
# bad: [1b294a1f35616977caddaddf3e9d28e576a1adbc] Merge tag 'net-next-6.10' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next
# good: [a5131c3fdf2608f1c15f3809e201cf540eb28489] Merge tag 'x86-shstk-2024-05-13' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
git bisect start '1b294a1f3561' 'a5131c3fdf26'
# good: [f8beae078c82abde57fed4a5be0bbc3579b59ad0] Merge tag 'gtp-24-05-07' of git://git.kernel.org/pub/scm/linux/kernel/git/pablo/gtp Pablo neira Ayuso says:
git bisect good f8beae078c82abde57fed4a5be0bbc3579b59ad0
# bad: [ce952d8f0e9b58dc6a2bde7e47ca7fa7925583cc] Merge tag 'gpio-updates-for-v6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
git bisect bad ce952d8f0e9b58dc6a2bde7e47ca7fa7925583cc
# good: [f952b6c863090464c148066df9f46cb3edd603da] Merge tag 'thermal-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
git bisect good f952b6c863090464c148066df9f46cb3edd603da
# bad: [07bbfc6aba1efe332d9994b2995c9bea0cd3b25f] Merge tag 'regulator-v6.10' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
git bisect bad 07bbfc6aba1efe332d9994b2995c9bea0cd3b25f
# good: [e573d27e18f8289454b6abb378de531374bd3cde] Merge branches 'acpi-tools', 'acpi-docs' and 'pnp'
git bisect good e573d27e18f8289454b6abb378de531374bd3cde
# good: [440f9d47dfac065a8da663adbc4b28703fdf550e] Merge branches 'pm-cpuidle', 'pm-sleep' and 'pm-powercap'
git bisect good 440f9d47dfac065a8da663adbc4b28703fdf550e
# good: [41b94bc6d96b9b046ef08114f057dcc6c52e28b6] iio: addac: ad74115: Use devm_regulator_get_enable_read_voltage()
git bisect good 41b94bc6d96b9b046ef08114f057dcc6c52e28b6
# bad: [991b5e2aad870828669ca105f424ef1b2534f820] regmap: kunit: Fix an NULL vs IS_ERR() check
git bisect bad 991b5e2aad870828669ca105f424ef1b2534f820
# bad: [ce75e06eea9cfdddaa0082cef663cf2d4aa5ed1d] regmap: kunit: Use a KUnit action to call regmap_exit()
git bisect bad ce75e06eea9cfdddaa0082cef663cf2d4aa5ed1d
# bad: [710915743d53d19a1baf0326302aa1f743ab018e] regmap: kunit: Run sparse cache tests at non-zero register addresses
git bisect bad 710915743d53d19a1baf0326302aa1f743ab018e
# good: [7b7982f14315e0f6910e13b22ed38a47144a83ec] regmap: kunit: Create a struct device for the regmap
git bisect good 7b7982f14315e0f6910e13b22ed38a47144a83ec
# good: [48bccea96fead1b212e19e38e50bf8e69287c45d] regmap: kunit: Introduce struct for test case parameters
git bisect good 48bccea96fead1b212e19e38e50bf8e69287c45d
# first bad commit: [710915743d53d19a1baf0326302aa1f743ab018e] regmap: kunit: Run sparse cache tests at non-zero register addresses
---
[ 23.494308] ============================================================================= [ 23.496391] BUG kmalloc-64 (Tainted: G N): kmalloc Redzone overwritten [ 23.496900] ----------------------------------------------------------------------------- [ 23.496900] [ 23.497510] 0xc69ee28b-0xc69ee28b @offset=651. First byte 0x0 instead of 0xcc [ 23.498079] Allocated in __regmap_init_ram+0x30/0xa0 age=2 cpu=0 pid=1064 [ 23.499422] __kmalloc+0x270/0x378 [ 23.499783] __regmap_init_ram+0x30/0xa0 [ 23.500109] gen_regmap.constprop.0+0x144/0x198 [ 23.500440] stride+0x58/0x4e4 [ 23.500715] kunit_try_run_case+0x5c/0x1a4 [ 23.501016] kunit_generic_run_threadfn_adapter+0x1c/0x34 [ 23.501396] kthread+0xfc/0x120 [ 23.501682] ret_from_fork+0x14/0x24 [ 23.502030] Freed in pinctrl_free+0x9c/0x184 age=4 cpu=0 pid=10 [ 23.502450] pinctrl_free+0x9c/0x184 [ 23.502711] release_nodes+0x50/0x7c [ 23.502985] devres_release_all+0x80/0xf0 [ 23.503265] device_unbind_cleanup+0xc/0x60 [ 23.503587] really_probe+0x188/0x2d0 [ 23.503890] __driver_probe_device+0x84/0x1a0 [ 23.504175] driver_probe_device+0x2c/0xc4 [ 23.504454] __device_attach_driver+0x94/0xc4 [ 23.504738] bus_for_each_drv+0x84/0xdc [ 23.505003] __device_attach+0xac/0x1d8 [ 23.505268] bus_probe_device+0x8c/0x90 [ 23.505541] deferred_probe_work_func+0x8c/0xc0 [ 23.505822] process_one_work+0x260/0x6f8 [ 23.506100] worker_thread+0x178/0x3b0 [ 23.506373] kthread+0xfc/0x120 [ 23.506605] ret_from_fork+0x14/0x24 [ 23.506906] Slab 0xcbeacdc0 objects=21 used=19 fp=0xc69eec40 flags=0xa00(workingset|slab|zone=0) [ 23.507770] Object 0xc69ee280 @offset=640 fp=0xc69ee100 [ 23.507770] [ 23.508668] Redzone c69ee240: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ................ [ 23.509138] Redzone c69ee250: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ................ [ 23.509538] Redzone c69ee260: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ................ [ 23.509935] Redzone c69ee270: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ................ [ 23.510453] Object c69ee280: 01 00 01 00 01 00 01 00 01 00 01 00 cc cc cc cc ................ [ 23.510984] Object c69ee290: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ................ [ 23.511488] Object c69ee2a0: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ................ [ 23.511857] Object c69ee2b0: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ................ [ 23.512268] Redzone c69ee2c0: cc cc cc cc .... [ 23.512738] Padding c69ee2f4: 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZ [ 23.513444] CPU: 0 PID: 1065 Comm: kunit_try_catch Tainted: G N 6.9.0-05151-g1b294a1f3561 #1 [ 23.514023] Hardware name: Freescale i.MX6 Ultralite (Device Tree) [ 23.514542] Call trace: [ 23.514722] unwind_backtrace from show_stack+0x10/0x14 [ 23.515298] show_stack from dump_stack_lvl+0x78/0xa8 [ 23.515621] dump_stack_lvl from check_bytes_and_report+0x110/0x12c [ 23.515972] check_bytes_and_report from check_object+0x36c/0x3a8 [ 23.516310] check_object from free_to_partial_list+0x15c/0x5ec [ 23.516647] free_to_partial_list from kfree+0x218/0x2cc [ 23.516967] kfree from regmap_ram_free_context+0x18/0x2c [ 23.517298] regmap_ram_free_context from regmap_exit+0x7c/0x148 [ 23.517650] regmap_exit from kunit_remove_resource+0xac/0xc4 [ 23.518001] kunit_remove_resource from kunit_cleanup+0x2c/0x5c [ 23.518435] kunit_cleanup from kunit_generic_run_threadfn_adapter+0x1c/0x34 [ 23.518876] kunit_generic_run_threadfn_adapter from kthread+0xfc/0x120 [ 23.519305] kthread from ret_from_fork+0x14/0x24 [ 23.519764] Exception stack(0xd2541fb0 to 0xd2541ff8) [ 23.520248] 1fa0: 00000000 00000000 00000000 00000000 [ 23.520717] 1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 23.521161] 1fe0: 00000000 00000000 00000000 00000000 00000013 00000000 [ 23.521753] Disabling lock debugging due to kernel taint [ 23.522060] FIX kmalloc-64: Restoring kmalloc Redzone 0xc69ee28b-0xc69ee28b=0xcc [ 23.522403] FIX kmalloc-64: Object at 0xc69ee280 not freed
Mark Brown
maintainerRe: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Quoted 7 lines · Guenter Roeck
With this patch in mainline, I get lots of errors such as
[ 23.494308] ============================================================================= [ 23.496391] BUG kmalloc-64 (Tainted: G N): kmalloc Redzone overwrittenBisect log and first of many backtraces attached for reference.
What's your kernel architecture and config for this - it looks like there's some sanitiser enabled?
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Quoted 5 lines · Mark Brown
Quoted 3 lines · Guenter Roeck
With this patch in mainline, I get lots of errors such as
Quoted 7 lines
Quoted 4 lines
[ 23.494308] ============================================================================= [ 23.496391] BUG kmalloc-64 (Tainted: G N): kmalloc Redzone overwrittenBisect log and first of many backtraces attached for reference.
What's your kernel architecture and config for this - it looks like there's some sanitiser enabled?
I have CONFIG_SLUB_DEBUG and CONFIG_SLUB_DEBUG_ON enabled. I also have various other debug options enabled, but slub debugging should be the relevant one. I see the problem with several architectures.
- arm (all variants)
- arm64 (little and big endian)
- loongarch
- mips (all variants)
- nios2
- ppc (all variants)
- riscv (32 and 64 bit)
- x86 (32 and 64 bit)
Guenter
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
In reply to Guenter RoeckQuoted 21 lines · Guenter Roeck
Hi,
Quoted 18 lines · Richard Fitzgerald
Run the
cache_drop()andcache_present()tests at blocks of addresses that don't start at zero.This adds a
from_regparameter to structregmap_test_param. This is used to set the base address of the register defaults created bygen_regmap().Extra entries are added to sparse_cache_types_list[] to test at non-zero
from_regvalues. Thecache_drop()andcache_present()tests are updated to test at the given offset.The aim here is to add test cases to
cache_drop()for the bug fixed by commit00bb549d7d63("regmap: maple: Fix cache corruption inregcache_maple_drop()")But the same parameter table is used by the
cache_present()test so let's also update that to usefrom_reg.
Quoted 7 lines
Quoted 1 line
Signed-off-by Richard Fitzgerald <[email protected]>With this patch in mainline, I get lots of errors such as
[ 23.494308] ============================================================================= [ 23.496391] BUG kmalloc-64 (Tainted: G N): kmalloc Redzone overwritten
Just a random thought, I wonder whether in gen_regmap() this:
if (config->num_reg_defaults)
config->max_register += (config->num_reg_defaults - 1) * config->reg_stride; else config->max_register += (BLOCK_TEST_SIZE * config->reg_stride);
should be:
config->max_register += max(config->num_reg_defaults - 1,
BLOCK_TEST_SIZE) * config->reg_stride;
I've only had a quick scan through the code without seeing any other obvious problem.
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
In reply to Guenter RoeckQuoted 21 lines · Guenter Roeck
Hi,
Quoted 18 lines · Richard Fitzgerald
Run the
cache_drop()andcache_present()tests at blocks of addresses that don't start at zero.This adds a
from_regparameter to structregmap_test_param. This is used to set the base address of the register defaults created bygen_regmap().Extra entries are added to sparse_cache_types_list[] to test at non-zero
from_regvalues. Thecache_drop()andcache_present()tests are updated to test at the given offset.The aim here is to add test cases to
cache_drop()for the bug fixed by commit00bb549d7d63("regmap: maple: Fix cache corruption inregcache_maple_drop()")But the same parameter table is used by the
cache_present()test so let's also update that to usefrom_reg.
Quoted 7 lines
Quoted 1 line
Signed-off-by Richard Fitzgerald <[email protected]>With this patch in mainline, I get lots of errors such as
[ 23.494308] ============================================================================= [ 23.496391] BUG kmalloc-64 (Tainted: G N): kmalloc Redzone overwritten
I've managed to reproduce redzone errors in a x86_64 build with some of the SLUB debugging enabled. I will investigate.
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
In reply to Guenter RoeckQuoted 21 lines · Guenter Roeck
Hi,
Quoted 18 lines · Richard Fitzgerald
Run the
cache_drop()andcache_present()tests at blocks of addresses that don't start at zero.This adds a
from_regparameter to structregmap_test_param. This is used to set the base address of the register defaults created bygen_regmap().Extra entries are added to sparse_cache_types_list[] to test at non-zero
from_regvalues. Thecache_drop()andcache_present()tests are updated to test at the given offset.The aim here is to add test cases to
cache_drop()for the bug fixed by commit00bb549d7d63("regmap: maple: Fix cache corruption inregcache_maple_drop()")But the same parameter table is used by the
cache_present()test so let's also update that to usefrom_reg.
Quoted 7 lines
Quoted 1 line
Signed-off-by Richard Fitzgerald <[email protected]>With this patch in mainline, I get lots of errors such as
[ 23.494308] ============================================================================= [ 23.496391] BUG kmalloc-64 (Tainted: G N): kmalloc Redzone overwritten
Fix sent:
https://lore.kernel.org/lkml/[email protected]/T/#u
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Quoted 24 lines · Richard Fitzgerald
Quoted 23 lines · Guenter Roeck
Hi,
Quoted 19 lines · Richard Fitzgerald
Run the
cache_drop()andcache_present()tests at blocks of addresses that don't start at zero.This adds a
from_regparameter to structregmap_test_param. This is used to set the base address of the register defaults created bygen_regmap().Extra entries are added to sparse_cache_types_list[] to test at non-zero
from_regvalues. Thecache_drop()andcache_present()tests are updated to test at the given offset.The aim here is to add test cases to
cache_drop()for the bug fixed by commit00bb549d7d63("regmap: maple: Fix cache corruption inregcache_maple_drop()")But the same parameter table is used by the
cache_present()test so let's also update that to usefrom_reg.Signed-off-by Richard Fitzgerald <[email protected]>
Quoted 9 lines
Quoted 5 lines
With this patch in mainline, I get lots of errors such as
[ 23.494308] ============================================================================= [ 23.496391] BUG kmalloc-64 (Tainted: G N): kmalloc Redzone overwritten
Fix sent:
https://lore.kernel.org/lkml/[email protected]/T/#u
I noticed. Thanks a lot for the quick turnaround. Currently testing.
Thanks,
Guenter
PATCH 5/11 regmap: kunit: Run non-sparse cache tests at non-zero register addresses
In reply to Richard FitzgeraldChange the tests parameterized by real_cache_types_list[] to test at some register addresses that are not 0.
The cache_range_window_reg() test has hardcoded address assumptions that are not present in any other tests using real_cache_types_list[] table. So it has been given a separate parameter table, real_cache_types_only_list[], that preserves the original parameterization.
--- drivers/base/regmap/regmap-kunit.c | 86 ++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 29 deletions(-)
drivers/base/regmap/regmap-kunit.c +57 -29
@@ -92,12 +92,32 @@ static const struct regmap_test_param regcache_types_list[] = {KUNIT_ARRAY_PARAM (regcache_types, regcache_types_list, param_to_desc); -static const struct regmap_test_param real_cache_types_list[] = { +static const struct regmap_test_param real_cache_types_only_list[] = { { .cache =REGCACHE_FLAT }, { .cache =REGCACHE_RBTREE }, { .cache =REGCACHE_MAPLE }, }; +KUNIT_ARRAY_PARAM (real_cache_types_only, real_cache_types_only_list, param_to_desc); + +static const struct regmap_test_param real_cache_types_list[] = { + { .cache =REGCACHE_FLAT , .from_reg =0 }, + { .cache =REGCACHE_FLAT , .from_reg =0x2001 }, + { .cache =REGCACHE_FLAT , .from_reg =0x2002 }, + { .cache =REGCACHE_FLAT , .from_reg =0x2003 }, + { .cache =REGCACHE_FLAT , .from_reg =0x2004 }, + { .cache =REGCACHE_RBTREE , .from_reg =0 }, + { .cache =REGCACHE_RBTREE , .from_reg =0x2001 }, + { .cache =REGCACHE_RBTREE , .from_reg =0x2002 }, + { .cache =REGCACHE_RBTREE , .from_reg =0x2003 }, + { .cache =REGCACHE_RBTREE , .from_reg =0x2004 }, + { .cache =REGCACHE_MAPLE , .from_reg =0 }, + { .cache =REGCACHE_MAPLE , .from_reg =0x2001 }, + { .cache =REGCACHE_MAPLE , .from_reg =0x2002 }, + { .cache =REGCACHE_MAPLE , .from_reg =0x2003 }, + { .cache =REGCACHE_MAPLE , .from_reg =0x2004 }, +}; +KUNIT_ARRAY_PARAM (real_cache_types, real_cache_types_list, param_to_desc);static const struct regmap_test_param sparse_cache_types_list[] = {
@@ -175,9 +195,12 @@ static struct regmap *gen_regmap(struct kunit *test,return ret; } -static bool reg_5_false (struct device *context,unsigned int reg) +static bool reg_5_false (struct device *dev,unsigned int reg) { -return reg !=5 ; +struct kunit *test =dev_get_drvdata (dev); +const struct regmap_test_param *param = test->param_value; + +return reg != (param->from_reg +5 ); }static void basic_read_write (struct kunit *test)
@@ -648,6 +671,7 @@ static void stress_insert(struct kunit *test)static void cache_bypass (struct kunit *test) { +const struct regmap_test_param *param = test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -663,20 +687,20 @@ static void cache_bypass(struct kunit *test)get_random_bytes (&val,sizeof (val));/* Ensure the cache has a value in it */ -KUNIT_EXPECT_EQ (test,0 ,regmap_write (map,0 , val)); +KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, param->from_reg, val));/* Bypass then write a different value */ regcache_cache_bypass (map, true); -KUNIT_EXPECT_EQ (test,0 ,regmap_write (map,0 , val +1 )); +KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, param->from_reg, val +1 ));/* Read the bypassed value */ -KUNIT_EXPECT_EQ (test,0 ,regmap_read (map,0 , &rval)); +KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, param->from_reg, &rval));KUNIT_EXPECT_EQ (test, val +1 , rval); -KUNIT_EXPECT_EQ (test, data->vals[0 ], rval); +KUNIT_EXPECT_EQ (test, data->vals[param->from_reg], rval);/* Disable bypass, the cache should still return the original value */ regcache_cache_bypass (map, false); -KUNIT_EXPECT_EQ (test,0 ,regmap_read (map,0 , &rval)); +KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, param->from_reg, &rval));KUNIT_EXPECT_EQ (test, val, rval);regmap_exit (map);
@@ -684,6 +708,7 @@ static void cache_bypass(struct kunit *test)static void cache_sync (struct kunit *test) { +const struct regmap_test_param *param = test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -700,10 +725,10 @@ static void cache_sync(struct kunit *test)get_random_bytes (&val,sizeof (val));/* Put some data into the cache */ -KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_write (map,0 , val, +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_write (map, param->from_reg, val,BLOCK_TEST_SIZE ));for (i =0 ; i <BLOCK_TEST_SIZE ; i++) - data->written[i] = false; + data->written[param->from_reg + i] = false;/* Trash the data on the device itself then resync */ regcache_mark_dirty (map);
@@ -711,15 +736,16 @@ static void cache_sync(struct kunit *test)KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map));/* Did we just write the correct data out? */ -KUNIT_EXPECT_MEMEQ (test, data->vals, val,sizeof (val)); +KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], val,sizeof (val));for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test, true, data->written[i]); +KUNIT_EXPECT_EQ (test, true, data->written[param->from_reg + i]);regmap_exit (map); }static void cache_sync_defaults (struct kunit *test) { +const struct regmap_test_param *param = test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -737,23 +763,24 @@ static void cache_sync_defaults(struct kunit *test)get_random_bytes (&val,sizeof (val));/* Change the value of one register */ -KUNIT_EXPECT_EQ (test,0 ,regmap_write (map,2 , val)); +KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, param->from_reg +2 , val));/* Resync */ regcache_mark_dirty (map);for (i =0 ; i <BLOCK_TEST_SIZE ; i++) - data->written[i] = false; + data->written[param->from_reg + i] = false;KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map));/* Did we just sync the one register we touched? */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test, i ==2 , data->written[i]); +KUNIT_EXPECT_EQ (test, i ==2 , data->written[param->from_reg + i]);regmap_exit (map); }static void cache_sync_readonly (struct kunit *test) { +const struct regmap_test_param *param = test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -770,29 +797,30 @@ static void cache_sync_readonly(struct kunit *test)/* Read all registers to fill the cache */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, i, &val)); +KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, param->from_reg + i, &val));/* Change the value of all registers, readonly should fail */ get_random_bytes (&val,sizeof (val));regcache_cache_only (map, true);for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test, i !=5 ,regmap_write (map, i, val) ==0 ); +KUNIT_EXPECT_EQ (test, i !=5 ,regmap_write (map, param->from_reg + i, val) ==0 );regcache_cache_only (map, false);/* Resync */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) - data->written[i] = false; + data->written[param->from_reg + i] = false;KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map));/* Did that match what we see on the device? */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) -KUNIT_EXPECT_EQ (test, i !=5 , data->written[i]); +KUNIT_EXPECT_EQ (test, i !=5 , data->written[param->from_reg + i]);regmap_exit (map); }static void cache_sync_patch (struct kunit *test) { +const struct regmap_test_param *param = test->param_value;struct regmap *map;struct regmap_config config;struct regmap_ram_data *data;
@@ -810,14 +838,14 @@ static void cache_sync_patch(struct kunit *test)return ;/* Stash the original values */ -KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_read (map,0 , rval, +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_read (map, param->from_reg, rval,BLOCK_TEST_SIZE ));/* Patch a couple of values */ - patch[0 ].reg =2 ; + patch[0 ].reg = param->from_reg +2 ; patch[0 ].def = rval[2 ] +1 ; patch[0 ].delay_us =0 ; - patch[1 ].reg =5 ; + patch[1 ].reg = param->from_reg +5 ; patch[1 ].def = rval[5 ] +1 ; patch[1 ].delay_us =0 ; KUNIT_EXPECT_EQ(test, 0, regmap_register_patch(map, patch,
@@ -826,23 +854,23 @@ static void cache_sync_patch(struct kunit *test)/* Sync the cache */ regcache_mark_dirty (map);for (i =0 ; i <BLOCK_TEST_SIZE ; i++) - data->written[i] = false; + data->written[param->from_reg + i] = false;KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map));/* The patch should be on the device but not in the cache */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++) { -KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, i, &val)); +KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, param->from_reg + i, &val));KUNIT_EXPECT_EQ (test, val, rval[i]);switch (i) {case 2 :case 5 : -KUNIT_EXPECT_EQ (test, true, data->written[i]); -KUNIT_EXPECT_EQ (test, data->vals[i], rval[i] +1 ); +KUNIT_EXPECT_EQ (test, true, data->written[param->from_reg + i]); +KUNIT_EXPECT_EQ (test, data->vals[param->from_reg + i], rval[i] +1 );break ;default : -KUNIT_EXPECT_EQ (test, false, data->written[i]); -KUNIT_EXPECT_EQ (test, data->vals[i], rval[i]); +KUNIT_EXPECT_EQ (test, false, data->written[param->from_reg + i]); +KUNIT_EXPECT_EQ (test, data->vals[param->from_reg + i], rval[i]);break ; } }
@@ -1436,7 +1464,7 @@ static struct kunit_case regmap_test_cases[] = {KUNIT_CASE_PARAM (cache_sync_patch, real_cache_types_gen_params),KUNIT_CASE_PARAM (cache_drop, sparse_cache_types_gen_params),KUNIT_CASE_PARAM (cache_present, sparse_cache_types_gen_params), -KUNIT_CASE_PARAM (cache_range_window_reg, real_cache_types_gen_params), +KUNIT_CASE_PARAM (cache_range_window_reg, real_cache_types_only_gen_params),KUNIT_CASE_PARAM (raw_read_defaults_single, raw_test_types_gen_params), KUNIT_CASE_PARAM(raw_read_defaults, raw_test_types_gen_params),
Signature · 1 line
2.39.2
PATCH 6/11 regmap: kunit: Add more cache-drop tests
In reply to Richard FitzgeraldExtend the testing of cache-drop.
- Added cache_drop_all_and_sync_marked_dirty(). If all registers are dropped from the cache a regcache_mark_dirty() followed by regcache_sync() should not write anything because the cache is empty.
- Added cache_drop_all_and_sync_no_defaults(). This is similar to cache_drop_all_and_sync_marked_dirty() except that regcache_mark_dirty() is NOT called. All registers were dropped so regcache_sync() should not write anything.
- Added cache_drop_all_and_sync_has_defaults(). This is the same as cache_drop_all_and_sync_no_defaults() except that the regmap has a table of default values.
--- drivers/base/regmap/regmap-kunit.c | 135 +++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+)
drivers/base/regmap/regmap-kunit.c +135 -0
@@ -920,6 +920,138 @@ static void cache_drop(struct kunit *test)regmap_exit (map); } +static void cache_drop_all_and_sync_marked_dirty (struct kunit *test) +{ +const struct regmap_test_param *param = test->param_value; +struct regmap *map; +struct regmap_config config; +struct regmap_ram_data *data; +unsigned int rval[BLOCK_TEST_SIZE ]; +int i; + + config = test_regmap_config; + config.num_reg_defaults =BLOCK_TEST_SIZE ; + + map =gen_regmap (test, &config, &data); +KUNIT_ASSERT_FALSE (test,IS_ERR (map)); +if (IS_ERR (map)) +return ; + +/* Ensure the data is read from the cache */ +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->read[param->from_reg + i] = false; +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_read (map, param->from_reg, rval, +BLOCK_TEST_SIZE )); +KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], rval,sizeof (rval)); + +/* Change all values in cache from defaults */ +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, param->from_reg + i, rval[i] +1 )); + +/* Drop all registers */ +KUNIT_EXPECT_EQ (test,0 ,regcache_drop_region (map,0 , config.max_register)); + +/* Mark dirty and cache sync should not write anything. */ +regcache_mark_dirty (map); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->written[param->from_reg + i] = false; + +KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map)); +for (i =0 ; i <= config.max_register; i++) +KUNIT_EXPECT_FALSE (test, data->written[i]); + +regmap_exit (map); +} + +static void cache_drop_all_and_sync_no_defaults (struct kunit *test) +{ +const struct regmap_test_param *param = test->param_value; +struct regmap *map; +struct regmap_config config; +struct regmap_ram_data *data; +unsigned int rval[BLOCK_TEST_SIZE ]; +int i; + + config = test_regmap_config; + + map =gen_regmap (test, &config, &data); +KUNIT_ASSERT_FALSE (test,IS_ERR (map)); +if (IS_ERR (map)) +return ; + +/* Ensure the data is read from the cache */ +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->read[param->from_reg + i] = false; +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_read (map, param->from_reg, rval, +BLOCK_TEST_SIZE )); +KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], rval,sizeof (rval)); + +/* Change all values in cache */ +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, param->from_reg + i, rval[i] +1 )); + +/* Drop all registers */ +KUNIT_EXPECT_EQ (test,0 ,regcache_drop_region (map,0 , config.max_register)); + +/* +* Sync cache without marking it dirty. All registers were dropped +* so the cache should not have any entries to write out. +*/ +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->written[param->from_reg + i] = false; + +KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map)); +for (i =0 ; i <= config.max_register; i++) +KUNIT_EXPECT_FALSE (test, data->written[i]); + +regmap_exit (map); +} + +static void cache_drop_all_and_sync_has_defaults (struct kunit *test) +{ +const struct regmap_test_param *param = test->param_value; +struct regmap *map; +struct regmap_config config; +struct regmap_ram_data *data; +unsigned int rval[BLOCK_TEST_SIZE ]; +int i; + + config = test_regmap_config; + config.num_reg_defaults =BLOCK_TEST_SIZE ; + + map =gen_regmap (test, &config, &data); +KUNIT_ASSERT_FALSE (test,IS_ERR (map)); +if (IS_ERR (map)) +return ; + +/* Ensure the data is read from the cache */ +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->read[param->from_reg + i] = false; +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_read (map, param->from_reg, rval, +BLOCK_TEST_SIZE )); +KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], rval,sizeof (rval)); + +/* Change all values in cache from defaults */ +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, param->from_reg + i, rval[i] +1 )); + +/* Drop all registers */ +KUNIT_EXPECT_EQ (test,0 ,regcache_drop_region (map,0 , config.max_register)); + +/* +* Sync cache without marking it dirty. All registers were dropped +* so the cache should not have any entries to write out. +*/ +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->written[param->from_reg + i] = false; + +KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map)); +for (i =0 ; i <= config.max_register; i++) +KUNIT_EXPECT_FALSE (test, data->written[i]); + +regmap_exit (map); +} +static void cache_present (struct kunit *test) {const struct regmap_test_param *param = test->param_value;
@@ -1463,6 +1595,9 @@ static struct kunit_case regmap_test_cases[] = {KUNIT_CASE_PARAM (cache_sync_readonly, real_cache_types_gen_params),KUNIT_CASE_PARAM (cache_sync_patch, real_cache_types_gen_params),KUNIT_CASE_PARAM (cache_drop, sparse_cache_types_gen_params), +KUNIT_CASE_PARAM (cache_drop_all_and_sync_marked_dirty, sparse_cache_types_gen_params), +KUNIT_CASE_PARAM (cache_drop_all_and_sync_no_defaults, sparse_cache_types_gen_params), +KUNIT_CASE_PARAM (cache_drop_all_and_sync_has_defaults, sparse_cache_types_gen_params),KUNIT_CASE_PARAM (cache_present, sparse_cache_types_gen_params), KUNIT_CASE_PARAM(cache_range_window_reg, real_cache_types_only_gen_params),
Signature · 1 line
2.39.2
PATCH 7/11 regmap: kunit: Add more cache-sync tests
In reply to Richard FitzgeraldExtend the testing of cache-sync.
- cache_sync() renamed cache_sync_marked_dirty() for clarity of what conditions it is testing.
- cache_sync_defaults() renamed cache_sync_defaults_marked_dirty() for clarity. Added code to write the register back to its default value to check that a dirty sync doesn't write out the default value.
- Added cache_sync_after_cache_only(). Tests syncing the cache without calling regcache_mark_dirty(). A register written while in cache-only should be written out by regcache_sync().
- Added cache_sync_default_after_cache_only. This is similar to cache_sync_after_cache_only(), but the register is changed to its default value while in cache-only. Because regcache_mark_dirty() was NOT called, regacache_sync() should write out the register.
--- drivers/base/regmap/regmap-kunit.c | 126 ++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 4 deletions(-)
drivers/base/regmap/regmap-kunit.c +122 -4
@@ -706,7 +706,7 @@ static void cache_bypass(struct kunit *test)regmap_exit (map); } -static void cache_sync (struct kunit *test) +static void cache_sync_marked_dirty (struct kunit *test) {const struct regmap_test_param *param = test->param_value;struct regmap *map;
@@ -743,7 +743,58 @@ static void cache_sync(struct kunit *test)regmap_exit (map); } -static void cache_sync_defaults (struct kunit *test) +static void cache_sync_after_cache_only (struct kunit *test) +{ +const struct regmap_test_param *param = test->param_value; +struct regmap *map; +struct regmap_config config; +struct regmap_ram_data *data; +unsigned int val[BLOCK_TEST_SIZE ]; +unsigned int val_mask; +int i; + + config = test_regmap_config; + + map =gen_regmap (test, &config, &data); +KUNIT_ASSERT_FALSE (test,IS_ERR (map)); +if (IS_ERR (map)) +return ; + + val_mask =GENMASK (config.val_bits -1 ,0 ); +get_random_bytes (&val,sizeof (val)); + +/* Put some data into the cache */ +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_write (map, param->from_reg, val, +BLOCK_TEST_SIZE )); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->written[param->from_reg + i] = false; + +/* Set cache-only and change the values */ +regcache_cache_only (map, true); +for (i =0 ; i <ARRAY_SIZE (val); ++i) + val[i] = ~val[i] & val_mask; + +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_write (map, param->from_reg, val, +BLOCK_TEST_SIZE )); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_FALSE (test, data->written[param->from_reg + i]); + +KUNIT_EXPECT_MEMNEQ (test, &data->vals[param->from_reg], val,sizeof (val)); + +/* Exit cache-only and sync the cache without marking hardware registers dirty */ +regcache_cache_only (map, false); + +KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map)); + +/* Did we just write the correct data out? */ +KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], val,sizeof (val)); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_TRUE (test, data->written[param->from_reg + i]); + +regmap_exit (map); +} + +static void cache_sync_defaults_marked_dirty (struct kunit *test) {const struct regmap_test_param *param = test->param_value;struct regmap *map;
@@ -775,6 +826,71 @@ static void cache_sync_defaults(struct kunit *test)for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_EXPECT_EQ (test, i ==2 , data->written[param->from_reg + i]); +/* Rewrite registers back to their defaults */ +for (i =0 ; i < config.num_reg_defaults; ++i) +KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, config.reg_defaults[i].reg, + config.reg_defaults[i].def)); + +/* +* Resync after regcache_mark_dirty() should not write out registers +* that are at default value +*/ +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->written[param->from_reg + i] = false; +regcache_mark_dirty (map); +KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map)); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_FALSE (test, data->written[param->from_reg + i]); + +regmap_exit (map); +} + +static void cache_sync_default_after_cache_only (struct kunit *test) +{ +const struct regmap_test_param *param = test->param_value; +struct regmap *map; +struct regmap_config config; +struct regmap_ram_data *data; +unsigned int orig_val; +int i; + + config = test_regmap_config; + config.num_reg_defaults =BLOCK_TEST_SIZE ; + + map =gen_regmap (test, &config, &data); +KUNIT_ASSERT_FALSE (test,IS_ERR (map)); +if (IS_ERR (map)) +return ; + +KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, param->from_reg +2 , &orig_val)); + +/* Enter cache-only and change the value of one register */ +regcache_cache_only (map, true); +KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, param->from_reg +2 , orig_val +1 )); + +/* Exit cache-only and resync, should write out the changed register */ +regcache_cache_only (map, false); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->written[param->from_reg + i] = false; +KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map)); + +/* Was the register written out? */ +KUNIT_EXPECT_TRUE (test, data->written[param->from_reg +2 ]); +KUNIT_EXPECT_EQ (test, data->vals[param->from_reg +2 ], orig_val +1 ); + +/* Enter cache-only and write register back to its default value */ +regcache_cache_only (map, true); +KUNIT_EXPECT_EQ (test,0 ,regmap_write (map, param->from_reg +2 , orig_val)); + +/* Resync should write out the new value */ +regcache_cache_only (map, false); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) + data->written[param->from_reg + i] = false; + +KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map)); +KUNIT_EXPECT_TRUE (test, data->written[param->from_reg +2 ]); +KUNIT_EXPECT_EQ (test, data->vals[param->from_reg +2 ], orig_val); +regmap_exit (map); }
@@ -1590,8 +1706,10 @@ static struct kunit_case regmap_test_cases[] = {KUNIT_CASE_PARAM (basic_ranges, regcache_types_gen_params),KUNIT_CASE_PARAM (stress_insert, regcache_types_gen_params),KUNIT_CASE_PARAM (cache_bypass, real_cache_types_gen_params), -KUNIT_CASE_PARAM (cache_sync, real_cache_types_gen_params), -KUNIT_CASE_PARAM (cache_sync_defaults, real_cache_types_gen_params), +KUNIT_CASE_PARAM (cache_sync_marked_dirty, real_cache_types_gen_params), +KUNIT_CASE_PARAM (cache_sync_after_cache_only, real_cache_types_gen_params), +KUNIT_CASE_PARAM (cache_sync_defaults_marked_dirty, real_cache_types_gen_params), +KUNIT_CASE_PARAM (cache_sync_default_after_cache_only, real_cache_types_gen_params),KUNIT_CASE_PARAM (cache_sync_readonly, real_cache_types_gen_params),KUNIT_CASE_PARAM (cache_sync_patch, real_cache_types_gen_params), KUNIT_CASE_PARAM(cache_drop, sparse_cache_types_gen_params),
Signature · 1 line
2.39.2
PATCH 8/11 regmap: kunit: Use a KUnit action to call regmap_exit()
In reply to Richard FitzgeraldRegistert a KUnit action handler to call regmap_exit() when a test terminates. This ensures that regmap_exit() will be called if a test function returns early or aborts.
--- drivers/base/regmap/regmap-kunit.c | 62 ++++-------------------------- 1 file changed, 7 insertions(+), 55 deletions(-)
drivers/base/regmap/regmap-kunit.c +7 -55
@@ -5,11 +5,14 @@// Copyright 2023 Arm Ltd #include <kunit/device.h> +#include <kunit/resource.h> #include <kunit/test.h> #include "internal.h" #define BLOCK_TEST_SIZE 12 +KUNIT_DEFINE_ACTION_WRAPPER(regmap_exit_action, regmap_exit, struct regmap *); +struct regmap_test_priv {struct device *dev; };
@@ -190,6 +193,8 @@ static struct regmap *gen_regmap(struct kunit *test,if (IS_ERR (ret)) {kfree (buf);kfree (*data); + }else { +kunit_add_action (test, regmap_exit_action, ret); }return ret;
@@ -226,8 +231,6 @@ static void basic_read_write(struct kunit *test)/* If using a cache the cache satisfied the read */ KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[0 ]); - -regmap_exit (map); }static void bulk_write (struct kunit *test)
@@ -261,8 +264,6 @@ static void bulk_write(struct kunit *test)/* If using a cache the cache satisfied the read */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]); - -regmap_exit (map); }static void bulk_read (struct kunit *test)
@@ -292,8 +293,6 @@ static void bulk_read(struct kunit *test)/* If using a cache the cache satisfied the read */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]); - -regmap_exit (map); }static void write_readonly (struct kunit *test)
@@ -325,8 +324,6 @@ static void write_readonly(struct kunit *test)/* Did that match what we see on the device? */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_EXPECT_EQ (test, i !=5 , data->written[i]); - -regmap_exit (map); }static void read_writeonly (struct kunit *test)
@@ -363,8 +360,6 @@ static void read_writeonly(struct kunit *test)/* Did we trigger a hardware access? */ KUNIT_EXPECT_FALSE (test, data->read[5 ]); - -regmap_exit (map); }static void reg_defaults (struct kunit *test)
@@ -471,8 +466,6 @@ static void register_patch(struct kunit *test)break ; } } - -regmap_exit (map); }static void stride (struct kunit *test)
@@ -512,8 +505,6 @@ static void stride(struct kunit *test)KUNIT_EXPECT_TRUE (test, data->written[i]); } } - -regmap_exit (map); }static struct regmap_range_cfg test_range = {
@@ -612,8 +603,6 @@ static void basic_ranges(struct kunit *test)KUNIT_EXPECT_FALSE (test, data->read[i]);KUNIT_EXPECT_FALSE (test, data->written[i]); } - -regmap_exit (map); }/* Try to stress dynamic creation of cache data structures */
@@ -665,8 +654,6 @@ static void stress_insert(struct kunit *test)KUNIT_EXPECT_EQ (test, rval, vals[i]);KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]); } - -regmap_exit (map); }static void cache_bypass (struct kunit *test)
@@ -702,8 +689,6 @@ static void cache_bypass(struct kunit *test)regcache_cache_bypass (map, false);KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, param->from_reg, &rval));KUNIT_EXPECT_EQ (test, val, rval); - -regmap_exit (map); }static void cache_sync_marked_dirty (struct kunit *test)
@@ -739,8 +724,6 @@ static void cache_sync_marked_dirty(struct kunit *test)KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], val,sizeof (val));for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_EXPECT_EQ (test, true, data->written[param->from_reg + i]); - -regmap_exit (map); }static void cache_sync_after_cache_only (struct kunit *test)
@@ -790,8 +773,6 @@ static void cache_sync_after_cache_only(struct kunit *test)KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], val,sizeof (val));for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_EXPECT_TRUE (test, data->written[param->from_reg + i]); - -regmap_exit (map); }static void cache_sync_defaults_marked_dirty (struct kunit *test)
@@ -841,8 +822,6 @@ static void cache_sync_defaults_marked_dirty(struct kunit *test)KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map));for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_EXPECT_FALSE (test, data->written[param->from_reg + i]); - -regmap_exit (map); }static void cache_sync_default_after_cache_only (struct kunit *test)
@@ -890,8 +869,6 @@ static void cache_sync_default_after_cache_only(struct kunit *test)KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map));KUNIT_EXPECT_TRUE (test, data->written[param->from_reg +2 ]);KUNIT_EXPECT_EQ (test, data->vals[param->from_reg +2 ], orig_val); - -regmap_exit (map); }static void cache_sync_readonly (struct kunit *test)
@@ -930,8 +907,6 @@ static void cache_sync_readonly(struct kunit *test)/* Did that match what we see on the device? */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_EXPECT_EQ (test, i !=5 , data->written[param->from_reg + i]); - -regmap_exit (map); }static void cache_sync_patch (struct kunit *test)
@@ -990,8 +965,6 @@ static void cache_sync_patch(struct kunit *test)break ; } } - -regmap_exit (map); }static void cache_drop (struct kunit *test)
@@ -1032,8 +1005,6 @@ static void cache_drop(struct kunit *test)for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_EXPECT_EQ (test, data->read[param->from_reg + i], i >=3 && i <=5 );KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], rval,sizeof (rval)); - -regmap_exit (map); }static void cache_drop_all_and_sync_marked_dirty (struct kunit *test)
@@ -1075,8 +1046,6 @@ static void cache_drop_all_and_sync_marked_dirty(struct kunit *test)KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map));for (i =0 ; i <= config.max_register; i++)KUNIT_EXPECT_FALSE (test, data->written[i]); - -regmap_exit (map); }static void cache_drop_all_and_sync_no_defaults (struct kunit *test)
@@ -1119,8 +1088,6 @@ static void cache_drop_all_and_sync_no_defaults(struct kunit *test)KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map));for (i =0 ; i <= config.max_register; i++)KUNIT_EXPECT_FALSE (test, data->written[i]); - -regmap_exit (map); }static void cache_drop_all_and_sync_has_defaults (struct kunit *test)
@@ -1164,8 +1131,6 @@ static void cache_drop_all_and_sync_has_defaults(struct kunit *test)KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map));for (i =0 ; i <= config.max_register; i++)KUNIT_EXPECT_FALSE (test, data->written[i]); - -regmap_exit (map); }static void cache_present (struct kunit *test)
@@ -1202,8 +1167,6 @@ static void cache_present(struct kunit *test)/* Now everything should be cached */ for (i =0 ; i <BLOCK_TEST_SIZE ; i++)KUNIT_ASSERT_TRUE (test,regcache_reg_cached (map, param->from_reg + i)); - -regmap_exit (map); }/* Check that caching the window register works with sync */
@@ -1350,6 +1313,8 @@ static struct regmap *gen_raw_regmap(struct kunit *test,if (IS_ERR (ret)) {kfree (buf);kfree (*data); + }else { +kunit_add_action (test, regmap_exit_action, ret); }return ret;
@@ -1375,8 +1340,6 @@ static void raw_read_defaults_single(struct kunit *test)KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, i, &rval));KUNIT_EXPECT_EQ (test, config.reg_defaults[i].def, rval); } - -regmap_exit (map); }static void raw_read_defaults (struct kunit *test)
@@ -1414,7 +1377,6 @@ static void raw_read_defaults(struct kunit *test) }kfree (rval); -regmap_exit (map); }static void raw_write_read_single (struct kunit *test)
@@ -1438,8 +1400,6 @@ static void raw_write_read_single(struct kunit *test)KUNIT_EXPECT_EQ (test,0 ,regmap_write (map,0 , val));KUNIT_EXPECT_EQ (test,0 ,regmap_read (map,0 , &rval));KUNIT_EXPECT_EQ (test, val, rval); - -regmap_exit (map); }static void raw_write (struct kunit *test)
@@ -1489,8 +1449,6 @@ static void raw_write(struct kunit *test)/* The values should appear in the "hardware" */ KUNIT_EXPECT_MEMEQ (test, &hw_buf[2 ], val,sizeof (val)); - -regmap_exit (map); }static bool reg_zero (struct device *dev,unsigned int reg)
@@ -1548,8 +1506,6 @@ static void raw_noinc_write(struct kunit *test)/* Make sure we didn't touch the register after the noinc register */ KUNIT_EXPECT_EQ (test,0 ,regmap_read (map,1 , &val));KUNIT_ASSERT_EQ (test, val_test, val); - -regmap_exit (map); }static void raw_sync (struct kunit *test)
@@ -1625,8 +1581,6 @@ static void raw_sync(struct kunit *test)/* The values should now appear in the "hardware" */ KUNIT_EXPECT_MEMEQ (test, &hw_buf[2 ], &val[0 ],sizeof (val)); - -regmap_exit (map); }static void raw_ranges (struct kunit *test)
@@ -1689,8 +1643,6 @@ static void raw_ranges(struct kunit *test)KUNIT_EXPECT_FALSE (test, data->read[i]);KUNIT_EXPECT_FALSE (test, data->written[i]); } - -regmap_exit (map); }static struct kunit_case regmap_test_cases[] = {
Signature · 1 line
2.39.2
PATCH 9/11 regmap: kunit: Replace a kmalloc/kfree() pair with KUnit-managed alloc
In reply to Richard FitzgeraldReplace the kmalloc() and kfree() in raw_read_defaults() with a kunit_kmalloc() so that KUnit will free it automatically.
--- drivers/base/regmap/regmap-kunit.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/base/regmap/regmap-kunit.c +1 -3
@@ -1360,7 +1360,7 @@ static void raw_read_defaults(struct kunit *test)return ; val_len =sizeof (*rval) * (config.max_register +1 ); - rval =kmalloc (val_len,GFP_KERNEL ); + rval =kunit_kmalloc (test, val_len,GFP_KERNEL );KUNIT_ASSERT_TRUE (test, rval !=NULL );if (!rval)return ;
@@ -1375,8 +1375,6 @@ static void raw_read_defaults(struct kunit *test)KUNIT_EXPECT_EQ (test, def,le16_to_cpu ((__force __le16 )rval[i])); } } - -kfree (rval); }static void raw_write_read_single (struct kunit *test)
Signature · 1 line
2.39.2
PATCH 10/11 regmap: kunit: Add cache-drop test with multiple cache blocks
In reply to Richard FitzgeraldAdd a test case for dropping only some cache blocks and leaving others unchanged.
The regmap is divided into 8 register ranges, and only 4 of these are written with values. This creates 4 non-contiguous ranges of registers with cached values.
One whole range is then dropped, and part of another range. A cache sync is then performed to check that the correct registers were written, and the correct values were written to these registers.
--- drivers/base/regmap/regmap-kunit.c | 103 +++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+)
drivers/base/regmap/regmap-kunit.c +103 -0
@@ -1007,6 +1007,108 @@ static void cache_drop(struct kunit *test)KUNIT_EXPECT_MEMEQ (test, &data->vals[param->from_reg], rval,sizeof (rval)); } +static void cache_drop_with_non_contiguous_ranges (struct kunit *test) +{ +const struct regmap_test_param *param = test->param_value; +struct regmap *map; +struct regmap_config config; +struct regmap_ram_data *data; +unsigned int val[4 ][BLOCK_TEST_SIZE ]; +unsigned int reg; +const int num_ranges =ARRAY_SIZE (val) *2 ; +int rangeidx, i; + +static_assert (ARRAY_SIZE (val) ==4 ); + + config = test_regmap_config; + config.max_register = param->from_reg + (num_ranges *BLOCK_TEST_SIZE ); + + map =gen_regmap (test, &config, &data); +KUNIT_ASSERT_FALSE (test,IS_ERR (map)); +if (IS_ERR (map)) +return ; + +for (i =0 ; i < config.max_register +1 ; i++) + data->written[i] = false; + +/* Create non-contiguous cache blocks by writing every other range */ +get_random_bytes (&val,sizeof (val)); +for (rangeidx =0 ; rangeidx < num_ranges; rangeidx +=2 ) { + reg = param->from_reg + (rangeidx *BLOCK_TEST_SIZE ); +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_write (map, reg, + &val[rangeidx /2 ], +BLOCK_TEST_SIZE )); +KUNIT_EXPECT_MEMEQ (test, &data->vals[reg], + &val[rangeidx /2 ],sizeof (val[rangeidx /2 ])); + } + +/* Check that odd ranges weren't written */ +for (rangeidx =1 ; rangeidx < num_ranges; rangeidx +=2 ) { + reg = param->from_reg + (rangeidx *BLOCK_TEST_SIZE ); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_FALSE (test, data->written[reg + i]); + } + +/* Drop range 2 */ + reg = param->from_reg + (2 *BLOCK_TEST_SIZE ); +KUNIT_EXPECT_EQ (test,0 ,regcache_drop_region (map, reg, reg +BLOCK_TEST_SIZE -1 )); + +/* Drop part of range 4 */ + reg = param->from_reg + (4 *BLOCK_TEST_SIZE ); +KUNIT_EXPECT_EQ (test,0 ,regcache_drop_region (map, reg +3 , reg +5 )); + +/* Mark dirty and reset mock registers to 0 */ +regcache_mark_dirty (map); +for (i =0 ; i < config.max_register +1 ; i++) { + data->vals[i] =0 ; + data->written[i] = false; + } + +/* The registers that were dropped from range 4 should now remain at 0 */ + val[4 /2 ][3 ] =0 ; + val[4 /2 ][4 ] =0 ; + val[4 /2 ][5 ] =0 ; + +/* Sync and check that the expected register ranges were written */ +KUNIT_EXPECT_EQ (test,0 ,regcache_sync (map)); + +/* Check that odd ranges weren't written */ +for (rangeidx =1 ; rangeidx < num_ranges; rangeidx +=2 ) { + reg = param->from_reg + (rangeidx *BLOCK_TEST_SIZE ); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_FALSE (test, data->written[reg + i]); + } + +/* Check that even ranges (except 2 and 4) were written */ +for (rangeidx =0 ; rangeidx < num_ranges; rangeidx +=2 ) { +if ((rangeidx ==2 ) || (rangeidx ==4 )) +continue ; + + reg = param->from_reg + (rangeidx *BLOCK_TEST_SIZE ); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_TRUE (test, data->written[reg + i]); + +KUNIT_EXPECT_MEMEQ (test, &data->vals[reg], + &val[rangeidx /2 ],sizeof (val[rangeidx /2 ])); + } + +/* Check that range 2 wasn't written */ + reg = param->from_reg + (2 *BLOCK_TEST_SIZE ); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_FALSE (test, data->written[reg + i]); + +/* Check that range 4 was partially written */ + reg = param->from_reg + (4 *BLOCK_TEST_SIZE ); +for (i =0 ; i <BLOCK_TEST_SIZE ; i++) +KUNIT_EXPECT_EQ (test, data->written[reg + i], i <3 || i >5 ); + +KUNIT_EXPECT_MEMEQ (test, &data->vals[reg], &val[4 /2 ],sizeof (val[4 /2 ])); + +/* Nothing before param->from_reg should have been written */ +for (i =0 ; i < param->from_reg; i++) +KUNIT_EXPECT_FALSE (test, data->written[i]); +} +static void cache_drop_all_and_sync_marked_dirty (struct kunit *test) {const struct regmap_test_param *param = test->param_value;
@@ -1663,6 +1765,7 @@ static struct kunit_case regmap_test_cases[] = {KUNIT_CASE_PARAM (cache_sync_readonly, real_cache_types_gen_params),KUNIT_CASE_PARAM (cache_sync_patch, real_cache_types_gen_params),KUNIT_CASE_PARAM (cache_drop, sparse_cache_types_gen_params), +KUNIT_CASE_PARAM (cache_drop_with_non_contiguous_ranges, sparse_cache_types_gen_params),KUNIT_CASE_PARAM (cache_drop_all_and_sync_marked_dirty, sparse_cache_types_gen_params),KUNIT_CASE_PARAM (cache_drop_all_and_sync_no_defaults, sparse_cache_types_gen_params), KUNIT_CASE_PARAM(cache_drop_all_and_sync_has_defaults, sparse_cache_types_gen_params),
Signature · 1 line
2.39.2
PATCH 11/11 regmap: kunit: Add test cases for regmap_read_bypassed()
In reply to Richard FitzgeraldThis adds test cases to prove that regmap_read_bypassed() reads the hardware value while the regmap is in cache-only.
---
This depends on pending commit ("regmap: Add regmap_read_bypassed()")
https://lore.kernel.org/linux-sound/[email protected]/T/#m2b99b1e01872bfc3597e89dee57dcdd5dbaf1b55
--- drivers/base/regmap/regmap-kunit.c | 131 +++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+)
drivers/base/regmap/regmap-kunit.c +131 -0
@@ -295,6 +295,135 @@ static void bulk_read(struct kunit *test)KUNIT_EXPECT_EQ (test, config.cache_type ==REGCACHE_NONE , data->read[i]); } +static void read_bypassed (struct kunit *test) +{ +const struct regmap_test_param *param = test->param_value; +struct regmap *map; +struct regmap_config config; +struct regmap_ram_data *data; +unsigned int val[BLOCK_TEST_SIZE ], rval; +int i; + + config = test_regmap_config; + + map =gen_regmap (test, &config, &data); +KUNIT_ASSERT_FALSE (test,IS_ERR (map)); +if (IS_ERR (map)) +return ; + +KUNIT_EXPECT_FALSE (test, map->cache_bypass); + +get_random_bytes (&val,sizeof (val)); + +/* Write some test values */ +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_write (map, param->from_reg, val,ARRAY_SIZE (val))); + +regcache_cache_only (map, true); + +/* +* While in cache-only regmap_read_bypassed() should return the register +* value and leave the map in cache-only. +*/ +for (i =0 ; i <ARRAY_SIZE (val); i++) { +/* Put inverted bits in rval to prove we really read the value */ + rval = ~val[i]; +KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, param->from_reg + i, &rval)); +KUNIT_EXPECT_EQ (test, val[i], rval); + + rval = ~val[i]; +KUNIT_EXPECT_EQ (test,0 ,regmap_read_bypassed (map, param->from_reg + i, &rval)); +KUNIT_EXPECT_EQ (test, val[i], rval); +KUNIT_EXPECT_TRUE (test, map->cache_only); +KUNIT_EXPECT_FALSE (test, map->cache_bypass); + } + +/* +* Change the underlying register values to prove it is returning +* real values not cached values. +*/ +for (i =0 ; i <ARRAY_SIZE (val); i++) { + val[i] = ~val[i]; + data->vals[param->from_reg + i] = val[i]; + } + +for (i =0 ; i <ARRAY_SIZE (val); i++) { + rval = ~val[i]; +KUNIT_EXPECT_EQ (test,0 ,regmap_read (map, param->from_reg + i, &rval)); +KUNIT_EXPECT_NE (test, val[i], rval); + + rval = ~val[i]; +KUNIT_EXPECT_EQ (test,0 ,regmap_read_bypassed (map, param->from_reg + i, &rval)); +KUNIT_EXPECT_EQ (test, val[i], rval); +KUNIT_EXPECT_TRUE (test, map->cache_only); +KUNIT_EXPECT_FALSE (test, map->cache_bypass); + } +} + +static void read_bypassed_volatile (struct kunit *test) +{ +const struct regmap_test_param *param = test->param_value; +struct regmap *map; +struct regmap_config config; +struct regmap_ram_data *data; +unsigned int val[BLOCK_TEST_SIZE ], rval; +int i; + + config = test_regmap_config; +/* All registers except #5 volatile */ + config.volatile_reg = reg_5_false; + + map =gen_regmap (test, &config, &data); +KUNIT_ASSERT_FALSE (test,IS_ERR (map)); +if (IS_ERR (map)) +return ; + +KUNIT_EXPECT_FALSE (test, map->cache_bypass); + +get_random_bytes (&val,sizeof (val)); + +/* Write some test values */ +KUNIT_EXPECT_EQ (test,0 ,regmap_bulk_write (map, param->from_reg, val,ARRAY_SIZE (val))); + +regcache_cache_only (map, true); + +/* +* While in cache-only regmap_read_bypassed() should return the register +* value and leave the map in cache-only. +*/ +for (i =0 ; i <ARRAY_SIZE (val); i++) { +/* Register #5 is non-volatile so should read from cache */ +KUNIT_EXPECT_EQ (test, (i ==5 ) ?0 : -EBUSY , +regmap_read (map, param->from_reg + i, &rval)); + +/* Put inverted bits in rval to prove we really read the value */ + rval = ~val[i]; +KUNIT_EXPECT_EQ (test,0 ,regmap_read_bypassed (map, param->from_reg + i, &rval)); +KUNIT_EXPECT_EQ (test, val[i], rval); +KUNIT_EXPECT_TRUE (test, map->cache_only); +KUNIT_EXPECT_FALSE (test, map->cache_bypass); + } + +/* +* Change the underlying register values to prove it is returning +* real values not cached values. +*/ +for (i =0 ; i <ARRAY_SIZE (val); i++) { + val[i] = ~val[i]; + data->vals[param->from_reg + i] = val[i]; + } + +for (i =0 ; i <ARRAY_SIZE (val); i++) { +if (i ==5 ) +continue ; + + rval = ~val[i]; +KUNIT_EXPECT_EQ (test,0 ,regmap_read_bypassed (map, param->from_reg + i, &rval)); +KUNIT_EXPECT_EQ (test, val[i], rval); +KUNIT_EXPECT_TRUE (test, map->cache_only); +KUNIT_EXPECT_FALSE (test, map->cache_bypass); + } +} +static void write_readonly (struct kunit *test) {struct regmap *map;
@@ -1747,6 +1876,8 @@ static void raw_ranges(struct kunit *test)static struct kunit_case regmap_test_cases[] = {KUNIT_CASE_PARAM (basic_read_write, regcache_types_gen_params), +KUNIT_CASE_PARAM (read_bypassed, real_cache_types_gen_params), +KUNIT_CASE_PARAM (read_bypassed_volatile, real_cache_types_gen_params),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),
Signature · 1 line
2.39.2
Mark Brown
maintainerQuoted 9 lines · Richard Fitzgerald
This series adds some more test cases, mainly for testing:
commit
eaa03486d932("regmap: maple: Fix uninitialized symbol 'ret' warnings") commit00bb549d7d63("regmap: maple: Fix cache corruption inregcache_maple_drop()")And the pending patch ("regmap: Add
regmap_read_bypassed()")
https://lore.kernel.org/linux-sound/[email protected]/T/#m2b99b1e01872bfc3597e89dee57dcdd5dbaf1b55[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
Thanks!
[01/11] regmap: kunit: Fix warnings of implicit casts to __le16 and __be16
commit: 866f70211bf43927ca44d8e98b5266926fd51315
[02/11] regmap: kunit: Create a struct device for the regmap
commit: 7b7982f14315e0f6910e13b22ed38a47144a83ec
[03/11] regmap: kunit: Introduce struct for test case parameters
commit: 48bccea96fead1b212e19e38e50bf8e69287c45d
[04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
commit: 710915743d53d19a1baf0326302aa1f743ab018e
[05/11] regmap: kunit: Run non-sparse cache tests at non-zero register addresses
commit: ac4394bf9c5e065919a0e491bfd95e2106b1b9b2
[06/11] regmap: kunit: Add more cache-drop tests
commit: 7dd52d301cfcff9a67be19d00289e03d80d05e46
[07/11] regmap: kunit: Add more cache-sync tests
commit: 7903d15f008056c8c152f2aa3b36217917853264
[08/11] regmap: kunit: Use a KUnit action to call regmap_exit()
commit: ce75e06eea9cfdddaa0082cef663cf2d4aa5ed1d
[09/11] regmap: kunit: Replace a kmalloc/kfree() pair with KUnit-managed alloc
commit: d6f2fd7adcb5f25ac661808be9409f846b1de6fe
[10/11] regmap: kunit: Add cache-drop test with multiple cache blocks
commit: 468d277e6fb112e7a5e816ef5f1f6bd86c29bea6
[11/11] regmap: kunit: Add test cases for regmap_read_bypassed()
commit: f63eb9ae085dc6da27eebfe35317e07a6a02a160All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark