Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

test_ida: check_ida_destroy and check_ida_alloc

Move these tests from the userspace test-suite to the kernel test-suite.
Also convert check_ida_random to the new API.

Signed-off-by: Matthew Wilcox <willy@infradead.org>

+58 -66
+54
lib/test_ida.c
··· 26 26 } while (0) 27 27 28 28 /* 29 + * Straightforward checks that allocating and freeing IDs work. 30 + */ 31 + static void ida_check_alloc(struct ida *ida) 32 + { 33 + int i, id; 34 + 35 + for (i = 0; i < 10000; i++) 36 + IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i); 37 + 38 + ida_free(ida, 20); 39 + ida_free(ida, 21); 40 + for (i = 0; i < 3; i++) { 41 + id = ida_alloc(ida, GFP_KERNEL); 42 + IDA_BUG_ON(ida, id < 0); 43 + if (i == 2) 44 + IDA_BUG_ON(ida, id != 10000); 45 + } 46 + 47 + for (i = 0; i < 5000; i++) 48 + ida_free(ida, i); 49 + 50 + IDA_BUG_ON(ida, ida_alloc_min(ida, 5000, GFP_KERNEL) != 10001); 51 + ida_destroy(ida); 52 + 53 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 54 + } 55 + 56 + /* Destroy an IDA with a single entry at @base */ 57 + static void ida_check_destroy_1(struct ida *ida, unsigned int base) 58 + { 59 + IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) != base); 60 + IDA_BUG_ON(ida, ida_is_empty(ida)); 61 + ida_destroy(ida); 62 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 63 + } 64 + 65 + /* Check that ida_destroy and ida_is_empty work */ 66 + static void ida_check_destroy(struct ida *ida) 67 + { 68 + /* Destroy an already-empty IDA */ 69 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 70 + ida_destroy(ida); 71 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 72 + 73 + ida_check_destroy_1(ida, 0); 74 + ida_check_destroy_1(ida, 1); 75 + ida_check_destroy_1(ida, 1023); 76 + ida_check_destroy_1(ida, 1024); 77 + ida_check_destroy_1(ida, 12345678); 78 + } 79 + 80 + /* 29 81 * Check what happens when we fill a leaf and then delete it. This may 30 82 * discover mishandling of IDR_FREE. 31 83 */ ··· 155 103 DEFINE_IDA(ida); 156 104 157 105 IDA_BUG_ON(&ida, !ida_is_empty(&ida)); 106 + ida_check_alloc(&ida); 107 + ida_check_destroy(&ida); 158 108 ida_check_leaf(&ida, 0); 159 109 ida_check_leaf(&ida, 1024); 160 110 ida_check_leaf(&ida, 1024 * 64);
+4 -66
tools/testing/radix-tree/idr-test.c
··· 364 364 { 365 365 DEFINE_IDA(ida); 366 366 DECLARE_BITMAP(bitmap, 2048); 367 - int id, err; 368 367 unsigned int i; 369 368 time_t s = time(NULL); 370 369 ··· 374 375 int bit = i & 2047; 375 376 if (test_bit(bit, bitmap)) { 376 377 __clear_bit(bit, bitmap); 377 - ida_remove(&ida, bit); 378 + ida_free(&ida, bit); 378 379 } else { 379 380 __set_bit(bit, bitmap); 380 - do { 381 - ida_pre_get(&ida, GFP_KERNEL); 382 - err = ida_get_new_above(&ida, bit, &id); 383 - } while (err == -EAGAIN); 384 - assert(!err); 385 - assert(id == bit); 381 + IDA_BUG_ON(&ida, ida_alloc_min(&ida, bit, GFP_KERNEL) 382 + != bit); 386 383 } 387 384 } 388 385 ida_destroy(&ida); ··· 406 411 407 412 void user_ida_checks(void) 408 413 { 409 - DEFINE_IDA(ida); 410 - int id; 411 - unsigned long i; 412 - 413 414 radix_tree_cpu_dead(1); 415 + 414 416 ida_check_nomem(); 415 - 416 - for (i = 0; i < 10000; i++) { 417 - assert(ida_pre_get(&ida, GFP_KERNEL)); 418 - assert(!ida_get_new(&ida, &id)); 419 - assert(id == i); 420 - } 421 - 422 - ida_remove(&ida, 20); 423 - ida_remove(&ida, 21); 424 - for (i = 0; i < 3; i++) { 425 - assert(ida_pre_get(&ida, GFP_KERNEL)); 426 - assert(!ida_get_new(&ida, &id)); 427 - if (i == 2) 428 - assert(id == 10000); 429 - } 430 - 431 - for (i = 0; i < 5000; i++) 432 - ida_remove(&ida, i); 433 - 434 - assert(ida_pre_get(&ida, GFP_KERNEL)); 435 - assert(!ida_get_new_above(&ida, 5000, &id)); 436 - assert(id == 10001); 437 - 438 - ida_destroy(&ida); 439 - 440 - assert(ida_is_empty(&ida)); 441 - 442 - assert(ida_pre_get(&ida, GFP_KERNEL)); 443 - assert(!ida_get_new_above(&ida, 1, &id)); 444 - assert(id == 1); 445 - 446 - ida_remove(&ida, id); 447 - assert(ida_is_empty(&ida)); 448 - ida_destroy(&ida); 449 - assert(ida_is_empty(&ida)); 450 - 451 - assert(ida_pre_get(&ida, GFP_KERNEL)); 452 - assert(!ida_get_new_above(&ida, 1, &id)); 453 - ida_destroy(&ida); 454 - assert(ida_is_empty(&ida)); 455 - 456 - assert(ida_pre_get(&ida, GFP_KERNEL)); 457 - assert(!ida_get_new_above(&ida, 1, &id)); 458 - assert(id == 1); 459 - assert(ida_pre_get(&ida, GFP_KERNEL)); 460 - assert(!ida_get_new_above(&ida, 1025, &id)); 461 - assert(id == 1025); 462 - assert(ida_pre_get(&ida, GFP_KERNEL)); 463 - assert(!ida_get_new_above(&ida, 10000, &id)); 464 - assert(id == 10000); 465 - ida_remove(&ida, 1025); 466 - ida_destroy(&ida); 467 - assert(ida_is_empty(&ida)); 468 - 469 417 ida_check_conv_user(); 470 418 ida_check_random(); 471 419 ida_simple_get_remove_test();