···4747 IDA_BUG_ON(ida, !ida_is_empty(ida));4848}49495050+/*5151+ * Check allocations up to and slightly above the maximum allowed (2^31-1) ID.5252+ * Allocating up to 2^31-1 should succeed, and then allocating the next one5353+ * should fail.5454+ */5555+static void ida_check_max(struct ida *ida)5656+{5757+ unsigned long i, j;5858+5959+ for (j = 1; j < 65537; j *= 2) {6060+ unsigned long base = (1UL << 31) - j;6161+ for (i = 0; i < j; i++) {6262+ IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) !=6363+ base + i);6464+ }6565+ IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) !=6666+ -ENOSPC);6767+ ida_destroy(ida);6868+ IDA_BUG_ON(ida, !ida_is_empty(ida));6969+ }7070+}7171+5072static int ida_checks(void)5173{5274 DEFINE_IDA(ida);···7755 ida_check_leaf(&ida, 0);7856 ida_check_leaf(&ida, 1024);7957 ida_check_leaf(&ida, 1024 * 64);5858+ ida_check_max(&ida);80598160 printk("IDA: %u of %u tests passed\n", tests_passed, tests_run);8261 return (tests_run != tests_passed) ? 0 : -EINVAL;
-28
tools/testing/radix-tree/idr-test.c
···396396 ida_destroy(&ida);397397}398398399399-/*400400- * Check allocations up to and slightly above the maximum allowed (2^31-1) ID.401401- * Allocating up to 2^31-1 should succeed, and then allocating the next one402402- * should fail.403403- */404404-void ida_check_max(void)405405-{406406- DEFINE_IDA(ida);407407- int id, err;408408- unsigned long i, j;409409-410410- for (j = 1; j < 65537; j *= 2) {411411- unsigned long base = (1UL << 31) - j;412412- for (i = 0; i < j; i++) {413413- assert(ida_pre_get(&ida, GFP_KERNEL));414414- assert(!ida_get_new_above(&ida, base, &id));415415- assert(id == base + i);416416- }417417- assert(ida_pre_get(&ida, GFP_KERNEL));418418- err = ida_get_new_above(&ida, base, &id);419419- assert(err == -ENOSPC);420420- ida_destroy(&ida);421421- assert(ida_is_empty(&ida));422422- rcu_barrier();423423- }424424-}425425-426399void ida_check_random(void)427400{428401 DEFINE_IDA(ida);···507534 ida_destroy(&ida);508535 assert(ida_is_empty(&ida));509536510510- ida_check_max();511537 ida_check_conv();512538 ida_check_random();513539 ida_simple_get_remove_test();