9
9
10
10
#define BLOCK_TEST_SIZE 12
11
11
12
+ static void get_changed_bytes (void * orig , void * new , size_t size )
13
+ {
14
+ char * o = orig ;
15
+ char * n = new ;
16
+ int i ;
17
+
18
+ get_random_bytes (new , size );
19
+
20
+ /*
21
+ * This could be nicer and more efficient but we shouldn't
22
+ * super care.
23
+ */
24
+ for (i = 0 ; i < size ; i ++ )
25
+ while (n [i ] == o [i ])
26
+ get_random_bytes (& n [i ], 1 );
27
+ }
28
+
12
29
static const struct regmap_config test_regmap_config = {
13
30
.max_register = BLOCK_TEST_SIZE ,
14
31
.reg_stride = 1 ,
@@ -1202,7 +1219,8 @@ static void raw_noinc_write(struct kunit *test)
1202
1219
struct regmap * map ;
1203
1220
struct regmap_config config ;
1204
1221
struct regmap_ram_data * data ;
1205
- unsigned int val , val_test , val_last ;
1222
+ unsigned int val ;
1223
+ u16 val_test , val_last ;
1206
1224
u16 val_array [BLOCK_TEST_SIZE ];
1207
1225
1208
1226
config = raw_regmap_config ;
@@ -1251,7 +1269,7 @@ static void raw_sync(struct kunit *test)
1251
1269
struct regmap * map ;
1252
1270
struct regmap_config config ;
1253
1271
struct regmap_ram_data * data ;
1254
- u16 val [2 ];
1272
+ u16 val [3 ];
1255
1273
u16 * hw_buf ;
1256
1274
unsigned int rval ;
1257
1275
int i ;
@@ -1265,17 +1283,13 @@ static void raw_sync(struct kunit *test)
1265
1283
1266
1284
hw_buf = (u16 * )data -> vals ;
1267
1285
1268
- get_random_bytes ( & val , sizeof (val ));
1286
+ get_changed_bytes ( & hw_buf [ 2 ], & val [ 0 ] , sizeof (val ));
1269
1287
1270
1288
/* Do a regular write and a raw write in cache only mode */
1271
1289
regcache_cache_only (map , true);
1272
- KUNIT_EXPECT_EQ (test , 0 , regmap_raw_write (map , 2 , val , sizeof (val )));
1273
- if (config .val_format_endian == REGMAP_ENDIAN_BIG )
1274
- KUNIT_EXPECT_EQ (test , 0 , regmap_write (map , 6 ,
1275
- be16_to_cpu (val [0 ])));
1276
- else
1277
- KUNIT_EXPECT_EQ (test , 0 , regmap_write (map , 6 ,
1278
- le16_to_cpu (val [0 ])));
1290
+ KUNIT_EXPECT_EQ (test , 0 , regmap_raw_write (map , 2 , val ,
1291
+ sizeof (u16 ) * 2 ));
1292
+ KUNIT_EXPECT_EQ (test , 0 , regmap_write (map , 4 , val [2 ]));
1279
1293
1280
1294
/* We should read back the new values, and defaults for the rest */
1281
1295
for (i = 0 ; i < config .max_register + 1 ; i ++ ) {
@@ -1284,24 +1298,34 @@ static void raw_sync(struct kunit *test)
1284
1298
switch (i ) {
1285
1299
case 2 :
1286
1300
case 3 :
1287
- case 6 :
1288
1301
if (config .val_format_endian == REGMAP_ENDIAN_BIG ) {
1289
1302
KUNIT_EXPECT_EQ (test , rval ,
1290
- be16_to_cpu (val [i % 2 ]));
1303
+ be16_to_cpu (val [i - 2 ]));
1291
1304
} else {
1292
1305
KUNIT_EXPECT_EQ (test , rval ,
1293
- le16_to_cpu (val [i % 2 ]));
1306
+ le16_to_cpu (val [i - 2 ]));
1294
1307
}
1295
1308
break ;
1309
+ case 4 :
1310
+ KUNIT_EXPECT_EQ (test , rval , val [i - 2 ]);
1311
+ break ;
1296
1312
default :
1297
1313
KUNIT_EXPECT_EQ (test , config .reg_defaults [i ].def , rval );
1298
1314
break ;
1299
1315
}
1300
1316
}
1317
+
1318
+ /*
1319
+ * The value written via _write() was translated by the core,
1320
+ * translate the original copy for comparison purposes.
1321
+ */
1322
+ if (config .val_format_endian == REGMAP_ENDIAN_BIG )
1323
+ val [2 ] = cpu_to_be16 (val [2 ]);
1324
+ else
1325
+ val [2 ] = cpu_to_le16 (val [2 ]);
1301
1326
1302
1327
/* The values should not appear in the "hardware" */
1303
- KUNIT_EXPECT_MEMNEQ (test , & hw_buf [2 ], val , sizeof (val ));
1304
- KUNIT_EXPECT_MEMNEQ (test , & hw_buf [6 ], val , sizeof (u16 ));
1328
+ KUNIT_EXPECT_MEMNEQ (test , & hw_buf [2 ], & val [0 ], sizeof (val ));
1305
1329
1306
1330
for (i = 0 ; i < config .max_register + 1 ; i ++ )
1307
1331
data -> written [i ] = false;
@@ -1312,8 +1336,7 @@ static void raw_sync(struct kunit *test)
1312
1336
KUNIT_EXPECT_EQ (test , 0 , regcache_sync (map ));
1313
1337
1314
1338
/* The values should now appear in the "hardware" */
1315
- KUNIT_EXPECT_MEMEQ (test , & hw_buf [2 ], val , sizeof (val ));
1316
- KUNIT_EXPECT_MEMEQ (test , & hw_buf [6 ], val , sizeof (u16 ));
1339
+ KUNIT_EXPECT_MEMEQ (test , & hw_buf [2 ], & val [0 ], sizeof (val ));
1317
1340
1318
1341
regmap_exit (map );
1319
1342
}
0 commit comments