@@ -920,6 +920,138 @@ static void cache_drop(struct kunit *test)
920920 regmap_exit (map );
921921}
922922
923+ static void cache_drop_all_and_sync_marked_dirty (struct kunit * test )
924+ {
925+ const struct regmap_test_param * param = test -> param_value ;
926+ struct regmap * map ;
927+ struct regmap_config config ;
928+ struct regmap_ram_data * data ;
929+ unsigned int rval [BLOCK_TEST_SIZE ];
930+ int i ;
931+
932+ config = test_regmap_config ;
933+ config .num_reg_defaults = BLOCK_TEST_SIZE ;
934+
935+ map = gen_regmap (test , & config , & data );
936+ KUNIT_ASSERT_FALSE (test , IS_ERR (map ));
937+ if (IS_ERR (map ))
938+ return ;
939+
940+ /* Ensure the data is read from the cache */
941+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
942+ data -> read [param -> from_reg + i ] = false;
943+ KUNIT_EXPECT_EQ (test , 0 , regmap_bulk_read (map , param -> from_reg , rval ,
944+ BLOCK_TEST_SIZE ));
945+ KUNIT_EXPECT_MEMEQ (test , & data -> vals [param -> from_reg ], rval , sizeof (rval ));
946+
947+ /* Change all values in cache from defaults */
948+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
949+ KUNIT_EXPECT_EQ (test , 0 , regmap_write (map , param -> from_reg + i , rval [i ] + 1 ));
950+
951+ /* Drop all registers */
952+ KUNIT_EXPECT_EQ (test , 0 , regcache_drop_region (map , 0 , config .max_register ));
953+
954+ /* Mark dirty and cache sync should not write anything. */
955+ regcache_mark_dirty (map );
956+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
957+ data -> written [param -> from_reg + i ] = false;
958+
959+ KUNIT_EXPECT_EQ (test , 0 , regcache_sync (map ));
960+ for (i = 0 ; i <= config .max_register ; i ++ )
961+ KUNIT_EXPECT_FALSE (test , data -> written [i ]);
962+
963+ regmap_exit (map );
964+ }
965+
966+ static void cache_drop_all_and_sync_no_defaults (struct kunit * test )
967+ {
968+ const struct regmap_test_param * param = test -> param_value ;
969+ struct regmap * map ;
970+ struct regmap_config config ;
971+ struct regmap_ram_data * data ;
972+ unsigned int rval [BLOCK_TEST_SIZE ];
973+ int i ;
974+
975+ config = test_regmap_config ;
976+
977+ map = gen_regmap (test , & config , & data );
978+ KUNIT_ASSERT_FALSE (test , IS_ERR (map ));
979+ if (IS_ERR (map ))
980+ return ;
981+
982+ /* Ensure the data is read from the cache */
983+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
984+ data -> read [param -> from_reg + i ] = false;
985+ KUNIT_EXPECT_EQ (test , 0 , regmap_bulk_read (map , param -> from_reg , rval ,
986+ BLOCK_TEST_SIZE ));
987+ KUNIT_EXPECT_MEMEQ (test , & data -> vals [param -> from_reg ], rval , sizeof (rval ));
988+
989+ /* Change all values in cache */
990+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
991+ KUNIT_EXPECT_EQ (test , 0 , regmap_write (map , param -> from_reg + i , rval [i ] + 1 ));
992+
993+ /* Drop all registers */
994+ KUNIT_EXPECT_EQ (test , 0 , regcache_drop_region (map , 0 , config .max_register ));
995+
996+ /*
997+ * Sync cache without marking it dirty. All registers were dropped
998+ * so the cache should not have any entries to write out.
999+ */
1000+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
1001+ data -> written [param -> from_reg + i ] = false;
1002+
1003+ KUNIT_EXPECT_EQ (test , 0 , regcache_sync (map ));
1004+ for (i = 0 ; i <= config .max_register ; i ++ )
1005+ KUNIT_EXPECT_FALSE (test , data -> written [i ]);
1006+
1007+ regmap_exit (map );
1008+ }
1009+
1010+ static void cache_drop_all_and_sync_has_defaults (struct kunit * test )
1011+ {
1012+ const struct regmap_test_param * param = test -> param_value ;
1013+ struct regmap * map ;
1014+ struct regmap_config config ;
1015+ struct regmap_ram_data * data ;
1016+ unsigned int rval [BLOCK_TEST_SIZE ];
1017+ int i ;
1018+
1019+ config = test_regmap_config ;
1020+ config .num_reg_defaults = BLOCK_TEST_SIZE ;
1021+
1022+ map = gen_regmap (test , & config , & data );
1023+ KUNIT_ASSERT_FALSE (test , IS_ERR (map ));
1024+ if (IS_ERR (map ))
1025+ return ;
1026+
1027+ /* Ensure the data is read from the cache */
1028+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
1029+ data -> read [param -> from_reg + i ] = false;
1030+ KUNIT_EXPECT_EQ (test , 0 , regmap_bulk_read (map , param -> from_reg , rval ,
1031+ BLOCK_TEST_SIZE ));
1032+ KUNIT_EXPECT_MEMEQ (test , & data -> vals [param -> from_reg ], rval , sizeof (rval ));
1033+
1034+ /* Change all values in cache from defaults */
1035+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
1036+ KUNIT_EXPECT_EQ (test , 0 , regmap_write (map , param -> from_reg + i , rval [i ] + 1 ));
1037+
1038+ /* Drop all registers */
1039+ KUNIT_EXPECT_EQ (test , 0 , regcache_drop_region (map , 0 , config .max_register ));
1040+
1041+ /*
1042+ * Sync cache without marking it dirty. All registers were dropped
1043+ * so the cache should not have any entries to write out.
1044+ */
1045+ for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
1046+ data -> written [param -> from_reg + i ] = false;
1047+
1048+ KUNIT_EXPECT_EQ (test , 0 , regcache_sync (map ));
1049+ for (i = 0 ; i <= config .max_register ; i ++ )
1050+ KUNIT_EXPECT_FALSE (test , data -> written [i ]);
1051+
1052+ regmap_exit (map );
1053+ }
1054+
9231055static void cache_present (struct kunit * test )
9241056{
9251057 const struct regmap_test_param * param = test -> param_value ;
@@ -1463,6 +1595,9 @@ static struct kunit_case regmap_test_cases[] = {
14631595 KUNIT_CASE_PARAM (cache_sync_readonly , real_cache_types_gen_params ),
14641596 KUNIT_CASE_PARAM (cache_sync_patch , real_cache_types_gen_params ),
14651597 KUNIT_CASE_PARAM (cache_drop , sparse_cache_types_gen_params ),
1598+ KUNIT_CASE_PARAM (cache_drop_all_and_sync_marked_dirty , sparse_cache_types_gen_params ),
1599+ KUNIT_CASE_PARAM (cache_drop_all_and_sync_no_defaults , sparse_cache_types_gen_params ),
1600+ KUNIT_CASE_PARAM (cache_drop_all_and_sync_has_defaults , sparse_cache_types_gen_params ),
14661601 KUNIT_CASE_PARAM (cache_present , sparse_cache_types_gen_params ),
14671602 KUNIT_CASE_PARAM (cache_range_window_reg , real_cache_types_only_gen_params ),
14681603
0 commit comments