From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: <broonie@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <patches@opensource.cirrus.com>,
"Richard Fitzgerald" <rf@opensource.cirrus.com>
Subject: [PATCH 07/11] regmap: kunit: Add more cache-sync tests
Date: Mon, 8 Apr 2024 15:45:56 +0100 [thread overview]
Message-ID: <20240408144600.230848-8-rf@opensource.cirrus.com> (raw)
In-Reply-To: <20240408144600.230848-1-rf@opensource.cirrus.com>
Extend 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.
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
drivers/base/regmap/regmap-kunit.c | 126 ++++++++++++++++++++++++++++-
1 file changed, 122 insertions(+), 4 deletions(-)
diff --git a/drivers/base/regmap/regmap-kunit.c b/drivers/base/regmap/regmap-kunit.c
index 3201f5f6406b..1b34f92b1aaf 100644
--- a/drivers/base/regmap/regmap-kunit.c
+++ b/drivers/base/regmap/regmap-kunit.c
@@ -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),
--
2.39.2
next prev parent reply other threads:[~2024-04-08 14:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-08 14:45 [PATCH 00/11] regmap: kunit: Add some test cases and a few small improvements Richard Fitzgerald
2024-04-08 14:45 ` [PATCH 01/11] regmap: kunit: Fix warnings of implicit casts to __le16 and __be16 Richard Fitzgerald
2024-04-08 14:45 ` [PATCH 02/11] regmap: kunit: Create a struct device for the regmap Richard Fitzgerald
2024-04-08 14:45 ` [PATCH 03/11] regmap: kunit: Introduce struct for test case parameters Richard Fitzgerald
2024-04-08 14:45 ` [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses Richard Fitzgerald
2024-05-16 19:53 ` Guenter Roeck
2024-05-17 11:28 ` Mark Brown
2024-05-17 15:19 ` Guenter Roeck
2024-05-17 11:58 ` Richard Fitzgerald
2024-05-17 13:10 ` Richard Fitzgerald
2024-05-17 15:44 ` Richard Fitzgerald
2024-05-17 15:57 ` Guenter Roeck
2024-04-08 14:45 ` [PATCH 05/11] regmap: kunit: Run non-sparse " Richard Fitzgerald
2024-04-08 14:45 ` [PATCH 06/11] regmap: kunit: Add more cache-drop tests Richard Fitzgerald
2024-04-08 14:45 ` Richard Fitzgerald [this message]
2024-04-08 14:45 ` [PATCH 08/11] regmap: kunit: Use a KUnit action to call regmap_exit() Richard Fitzgerald
2024-04-08 14:45 ` [PATCH 09/11] regmap: kunit: Replace a kmalloc/kfree() pair with KUnit-managed alloc Richard Fitzgerald
2024-04-08 14:45 ` [PATCH 10/11] regmap: kunit: Add cache-drop test with multiple cache blocks Richard Fitzgerald
2024-04-08 14:46 ` [PATCH 11/11] regmap: kunit: Add test cases for regmap_read_bypassed() Richard Fitzgerald
2024-04-09 23:34 ` [PATCH 00/11] regmap: kunit: Add some test cases and a few small improvements Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240408144600.230848-8-rf@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®