Skip to contentSkip to conversation

regmap: Initial KUnit coverage

PATCH In review Mark Brown 1 participant 4 messages Mar 26, 2023 – Mar 30, 2023

Subsystems (3)
lore
Share & tools
lore

Mark Brown

author maintainer
#0 lore raw

v2 cover regmap: Initial KUnit coverage

This series provides some initial KUnit coverage for regmap, covering most of the interfaces that operate at the register level using an instrumented RAM backed bus type.

Without the current regmap tree the paging tests will fail as the RAM backed regmap doesn't support the required operations.

Changes in v2:
- Add a test for regcache_drop_region().
- Add a stress test for inserting registers into a sparse cache.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Mark Brown (2):
regmap: Add RAM backed register map
regmap: Add some basic kunit tests

 drivers/base/regmap/Kconfig        |  10 +
 drivers/base/regmap/Makefile       |   2 +
 drivers/base/regmap/internal.h     |  19 +
 drivers/base/regmap/regmap-kunit.c | 736 +++++++++++++++++++++++++++++++++++++
 drivers/base/regmap/regmap-ram.c   |  85 +++++
 5 files changed, 852 insertions(+)

---
base-commit: e8d018dd0257f744ca50a729e3d042cf2ec9da65
change-id: 20230324-regmap-kunit-bb3c3e81e35c

Best regards,

Signature · 1 line
Mark Brown <[email protected]>
author maintainer
#1 lore raw

PATCH v2 1/2 regmap: Add RAM backed register map

Add a register map that is a simple array of memory, for use in KUnit testing of the framework. This is not exposed in regmap.h since I can't think of a non-test use case, it is purely for use internally. To facilitate testing we track if registers have been read or written to.

---
 drivers/base/regmap/Kconfig      |  3 ++
 drivers/base/regmap/Makefile     |  1 +
 drivers/base/regmap/internal.h   | 19 +++++++++
 drivers/base/regmap/regmap-ram.c | 85 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 108 insertions(+)
drivers/base/regmap/Kconfig +3 -0
index cd4bb642b9de..65ce888d7c04 100644
@@ -46,6 +46,9 @@ config REGMAP_MMIO
 config REGMAP_IRQ
 	bool
 
+config REGMAP_RAM
+	tristate
+
 config REGMAP_SOUNDWIRE
 	tristate
 	depends on SOUNDWIRE
drivers/base/regmap/Makefile +1 -0
index 6990de7ca9a9..5ef6f129497c 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_REGCACHE_COMPRESSED) += regcache-lzo.o
 obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o
 obj-$(CONFIG_REGMAP_AC97) += regmap-ac97.o
 obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
+obj-$(CONFIG_REGMAP_RAM) += regmap-ram.o
 obj-$(CONFIG_REGMAP_SLIMBUS) += regmap-slimbus.o
 obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
 obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o
drivers/base/regmap/internal.h +19 -0
index da8996e7a1f1..aa98a5284fb3 100644
@@ -307,4 +307,23 @@ static inline unsigned int regcache_get_index_by_order(const struct regmap *map,
 	return reg >> map->reg_stride_order;
 }
 
+struct regmap_ram_data {
+	unsigned int *vals;  /* Allocatd by caller */
+	bool *read;
+	bool *written;
+};
+
+/*
+ * 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_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)
+
+
 #endif
drivers/base/regmap/regmap-ram.c new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v2 2/2 regmap: Add some basic kunit tests

In reply to Mark Brown

On the theory that it's better to make a start let's add some KUnit tests for regmap. Currently this is a bit of a mess but it passes and hopefully will at some point help catch problems. We provide very basic cover for most of the core functionality that operates at the register level, repeating each test for each cache type in order to exercise the caches. There is no coverage of anything to do with the bulk operations at the bus level or formatting for byte stream buses yet.

Each test creates it's own regmap since the cache structures are built incrementally, meaning we gain coverage from the different access patterns, and some of the tests cover different init scenarios.

---
 drivers/base/regmap/Kconfig        |   7 +
 drivers/base/regmap/Makefile       |   1 +
 drivers/base/regmap/regmap-kunit.c | 736 +++++++++++++++++++++++++++++++++++++
 3 files changed, 744 insertions(+)
drivers/base/regmap/Kconfig +7 -0
index 65ce888d7c04..6e77bf96569c 100644
@@ -14,6 +14,13 @@ config REGCACHE_COMPRESSED
 	select LZO_DECOMPRESS
 	bool
 
+config REGMAP_KUNIT
+	tristate "KUnit tests for regmap"
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	select REGMAP
+	select REGMAP_RAM
+
 config REGMAP_AC97
 	tristate
 
drivers/base/regmap/Makefile +1 -0
index 5ef6f129497c..fe2775fc76c6 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_REGMAP) += regmap.o regcache.o
 obj-$(CONFIG_REGMAP) += regcache-rbtree.o regcache-flat.o
 obj-$(CONFIG_REGCACHE_COMPRESSED) += regcache-lzo.o
 obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o
+obj-$(CONFIG_REGMAP_KUNIT) += regmap-kunit.o
 obj-$(CONFIG_REGMAP_AC97) += regmap-ac97.o
 obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
 obj-$(CONFIG_REGMAP_RAM) += regmap-ram.o
drivers/base/regmap/regmap-kunit.c new file +736 -0

736 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#3 lore raw
In reply to Mark Brown
Quoted 8 lines · Mark Brown

This series provides some initial KUnit coverage for regmap, covering most of the interfaces that operate at the register level using an instrumented RAM backed bus type.

Without the current regmap tree the paging tests will fail as the RAM backed regmap doesn't support the required operations.

[...]

Applied to

broonie/regmap.git for-next

Thanks!

[1/2] regmap: Add RAM backed register map

      commit: f6352424e37e7bf72291ceab87dc620172be0999
[2/2] regmap: Add some basic kunit tests
      commit: 2238959b6ad27040275439edd6893e309bc729a3

All 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