aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/tests/extent-io-tests.c87
1 files changed, 51 insertions, 36 deletions
diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c
index d19ab0317283..caad80bb9bd0 100644
--- a/fs/btrfs/tests/extent-io-tests.c
+++ b/fs/btrfs/tests/extent-io-tests.c
@@ -273,20 +273,37 @@ out:
273 return ret; 273 return ret;
274} 274}
275 275
276/** 276static int check_eb_bitmap(unsigned long *bitmap, struct extent_buffer *eb,
277 * test_bit_in_byte - Determine whether a bit is set in a byte 277 unsigned long len)
278 * @nr: bit number to test
279 * @addr: Address to start counting from
280 */
281static inline int test_bit_in_byte(int nr, const u8 *addr)
282{ 278{
283 return 1UL & (addr[nr / BITS_PER_BYTE] >> (nr & (BITS_PER_BYTE - 1))); 279 unsigned long i;
280
281 for (i = 0; i < len * BITS_PER_BYTE; i++) {
282 int bit, bit1;
283
284 bit = !!test_bit(i, bitmap);
285 bit1 = !!extent_buffer_test_bit(eb, 0, i);
286 if (bit1 != bit) {
287 test_msg("Bits do not match\n");
288 return -EINVAL;
289 }
290
291 bit1 = !!extent_buffer_test_bit(eb, i / BITS_PER_BYTE,
292 i % BITS_PER_BYTE);
293 if (bit1 != bit) {
294 test_msg("Offset bits do not match\n");
295 return -EINVAL;
296 }
297 }
298 return 0;
284} 299}
285 300
286static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb, 301static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb,
287 unsigned long len) 302 unsigned long len)
288{ 303{
289 unsigned long i, x; 304 unsigned long i, j;
305 u32 x;
306 int ret;
290 307
291 memset(bitmap, 0, len); 308 memset(bitmap, 0, len);
292 memset_extent_buffer(eb, 0, 0, len); 309 memset_extent_buffer(eb, 0, 0, len);
@@ -297,16 +314,18 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb,
297 314
298 bitmap_set(bitmap, 0, len * BITS_PER_BYTE); 315 bitmap_set(bitmap, 0, len * BITS_PER_BYTE);
299 extent_buffer_bitmap_set(eb, 0, 0, len * BITS_PER_BYTE); 316 extent_buffer_bitmap_set(eb, 0, 0, len * BITS_PER_BYTE);
300 if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { 317 ret = check_eb_bitmap(bitmap, eb, len);
318 if (ret) {
301 test_msg("Setting all bits failed\n"); 319 test_msg("Setting all bits failed\n");
302 return -EINVAL; 320 return ret;
303 } 321 }
304 322
305 bitmap_clear(bitmap, 0, len * BITS_PER_BYTE); 323 bitmap_clear(bitmap, 0, len * BITS_PER_BYTE);
306 extent_buffer_bitmap_clear(eb, 0, 0, len * BITS_PER_BYTE); 324 extent_buffer_bitmap_clear(eb, 0, 0, len * BITS_PER_BYTE);
307 if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { 325 ret = check_eb_bitmap(bitmap, eb, len);
326 if (ret) {
308 test_msg("Clearing all bits failed\n"); 327 test_msg("Clearing all bits failed\n");
309 return -EINVAL; 328 return ret;
310 } 329 }
311 330
312 /* Straddling pages test */ 331 /* Straddling pages test */
@@ -316,9 +335,10 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb,
316 sizeof(long) * BITS_PER_BYTE); 335 sizeof(long) * BITS_PER_BYTE);
317 extent_buffer_bitmap_set(eb, PAGE_SIZE - sizeof(long) / 2, 0, 336 extent_buffer_bitmap_set(eb, PAGE_SIZE - sizeof(long) / 2, 0,
318 sizeof(long) * BITS_PER_BYTE); 337 sizeof(long) * BITS_PER_BYTE);
319 if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { 338 ret = check_eb_bitmap(bitmap, eb, len);
339 if (ret) {
320 test_msg("Setting straddling pages failed\n"); 340 test_msg("Setting straddling pages failed\n");
321 return -EINVAL; 341 return ret;
322 } 342 }
323 343
324 bitmap_set(bitmap, 0, len * BITS_PER_BYTE); 344 bitmap_set(bitmap, 0, len * BITS_PER_BYTE);
@@ -328,9 +348,10 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb,
328 extent_buffer_bitmap_set(eb, 0, 0, len * BITS_PER_BYTE); 348 extent_buffer_bitmap_set(eb, 0, 0, len * BITS_PER_BYTE);
329 extent_buffer_bitmap_clear(eb, PAGE_SIZE - sizeof(long) / 2, 0, 349 extent_buffer_bitmap_clear(eb, PAGE_SIZE - sizeof(long) / 2, 0,
330 sizeof(long) * BITS_PER_BYTE); 350 sizeof(long) * BITS_PER_BYTE);
331 if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { 351 ret = check_eb_bitmap(bitmap, eb, len);
352 if (ret) {
332 test_msg("Clearing straddling pages failed\n"); 353 test_msg("Clearing straddling pages failed\n");
333 return -EINVAL; 354 return ret;
334 } 355 }
335 } 356 }
336 357
@@ -339,28 +360,22 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb,
339 * something repetitive that could miss some hypothetical off-by-n bug. 360 * something repetitive that could miss some hypothetical off-by-n bug.
340 */ 361 */
341 x = 0; 362 x = 0;
342 for (i = 0; i < len / sizeof(long); i++) { 363 bitmap_clear(bitmap, 0, len * BITS_PER_BYTE);
343 x = (0x19660dULL * (u64)x + 0x3c6ef35fULL) & 0xffffffffUL; 364 extent_buffer_bitmap_clear(eb, 0, 0, len * BITS_PER_BYTE);
344 bitmap[i] = x; 365 for (i = 0; i < len * BITS_PER_BYTE / 32; i++) {
345 } 366 x = (0x19660dULL * (u64)x + 0x3c6ef35fULL) & 0xffffffffU;
346 write_extent_buffer(eb, bitmap, 0, len); 367 for (j = 0; j < 32; j++) {
347 368 if (x & (1U << j)) {
348 for (i = 0; i < len * BITS_PER_BYTE; i++) { 369 bitmap_set(bitmap, i * 32 + j, 1);
349 int bit, bit1; 370 extent_buffer_bitmap_set(eb, 0, i * 32 + j, 1);
350 371 }
351 bit = !!test_bit_in_byte(i, (u8 *)bitmap);
352 bit1 = !!extent_buffer_test_bit(eb, 0, i);
353 if (bit1 != bit) {
354 test_msg("Testing bit pattern failed\n");
355 return -EINVAL;
356 } 372 }
373 }
357 374
358 bit1 = !!extent_buffer_test_bit(eb, i / BITS_PER_BYTE, 375 ret = check_eb_bitmap(bitmap, eb, len);
359 i % BITS_PER_BYTE); 376 if (ret) {
360 if (bit1 != bit) { 377 test_msg("Random bit pattern failed\n");
361 test_msg("Testing bit pattern with offset failed\n"); 378 return ret;
362 return -EINVAL;
363 }
364 } 379 }
365 380
366 return 0; 381 return 0;