diff options
Diffstat (limited to 'lib/test_xarray.c')
| -rw-r--r-- | lib/test_xarray.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c index 5d4bad8bd96a..9d631a7b6a70 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c | |||
| @@ -38,6 +38,12 @@ static void *xa_store_index(struct xarray *xa, unsigned long index, gfp_t gfp) | |||
| 38 | return xa_store(xa, index, xa_mk_index(index), gfp); | 38 | return xa_store(xa, index, xa_mk_index(index), gfp); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | static void xa_insert_index(struct xarray *xa, unsigned long index) | ||
| 42 | { | ||
| 43 | XA_BUG_ON(xa, xa_insert(xa, index, xa_mk_index(index), | ||
| 44 | GFP_KERNEL) != 0); | ||
| 45 | } | ||
| 46 | |||
| 41 | static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp) | 47 | static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp) |
| 42 | { | 48 | { |
| 43 | u32 id; | 49 | u32 id; |
| @@ -338,6 +344,37 @@ static noinline void check_xa_shrink(struct xarray *xa) | |||
| 338 | } | 344 | } |
| 339 | } | 345 | } |
| 340 | 346 | ||
| 347 | static noinline void check_insert(struct xarray *xa) | ||
| 348 | { | ||
| 349 | unsigned long i; | ||
| 350 | |||
| 351 | for (i = 0; i < 1024; i++) { | ||
| 352 | xa_insert_index(xa, i); | ||
| 353 | XA_BUG_ON(xa, xa_load(xa, i - 1) != NULL); | ||
| 354 | XA_BUG_ON(xa, xa_load(xa, i + 1) != NULL); | ||
| 355 | xa_erase_index(xa, i); | ||
| 356 | } | ||
| 357 | |||
| 358 | for (i = 10; i < BITS_PER_LONG; i++) { | ||
| 359 | xa_insert_index(xa, 1UL << i); | ||
| 360 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 1) != NULL); | ||
| 361 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) + 1) != NULL); | ||
| 362 | xa_erase_index(xa, 1UL << i); | ||
| 363 | |||
| 364 | xa_insert_index(xa, (1UL << i) - 1); | ||
| 365 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 2) != NULL); | ||
| 366 | XA_BUG_ON(xa, xa_load(xa, 1UL << i) != NULL); | ||
| 367 | xa_erase_index(xa, (1UL << i) - 1); | ||
| 368 | } | ||
| 369 | |||
| 370 | xa_insert_index(xa, ~0UL); | ||
| 371 | XA_BUG_ON(xa, xa_load(xa, 0UL) != NULL); | ||
| 372 | XA_BUG_ON(xa, xa_load(xa, ~1UL) != NULL); | ||
| 373 | xa_erase_index(xa, ~0UL); | ||
| 374 | |||
| 375 | XA_BUG_ON(xa, !xa_empty(xa)); | ||
| 376 | } | ||
| 377 | |||
| 341 | static noinline void check_cmpxchg(struct xarray *xa) | 378 | static noinline void check_cmpxchg(struct xarray *xa) |
| 342 | { | 379 | { |
| 343 | void *FIVE = xa_mk_value(5); | 380 | void *FIVE = xa_mk_value(5); |
| @@ -1527,6 +1564,7 @@ static int xarray_checks(void) | |||
| 1527 | check_xa_mark(&array); | 1564 | check_xa_mark(&array); |
| 1528 | check_xa_shrink(&array); | 1565 | check_xa_shrink(&array); |
| 1529 | check_xas_erase(&array); | 1566 | check_xas_erase(&array); |
| 1567 | check_insert(&array); | ||
| 1530 | check_cmpxchg(&array); | 1568 | check_cmpxchg(&array); |
| 1531 | check_reserve(&array); | 1569 | check_reserve(&array); |
| 1532 | check_reserve(&xa0); | 1570 | check_reserve(&xa0); |
