multiorder.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * multiorder.c: Multi-order radix tree entry testing
  3. * Copyright (c) 2016 Intel Corporation
  4. * Author: Ross Zwisler <ross.zwisler@linux.intel.com>
  5. * Author: Matthew Wilcox <matthew.r.wilcox@intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. */
  16. #include <linux/radix-tree.h>
  17. #include <linux/slab.h>
  18. #include <linux/errno.h>
  19. #include "test.h"
  20. static void multiorder_check(unsigned long index, int order)
  21. {
  22. unsigned long i;
  23. unsigned long min = index & ~((1UL << order) - 1);
  24. unsigned long max = min + (1UL << order);
  25. RADIX_TREE(tree, GFP_KERNEL);
  26. printf("Multiorder index %ld, order %d\n", index, order);
  27. assert(item_insert_order(&tree, index, order) == 0);
  28. for (i = min; i < max; i++) {
  29. struct item *item = item_lookup(&tree, i);
  30. assert(item != 0);
  31. assert(item->index == index);
  32. }
  33. for (i = 0; i < min; i++)
  34. item_check_absent(&tree, i);
  35. for (i = max; i < 2*max; i++)
  36. item_check_absent(&tree, i);
  37. assert(item_delete(&tree, index) != 0);
  38. for (i = 0; i < 2*max; i++)
  39. item_check_absent(&tree, i);
  40. }
  41. void multiorder_checks(void)
  42. {
  43. int i;
  44. for (i = 0; i < 20; i++) {
  45. multiorder_check(200, i);
  46. multiorder_check(0, i);
  47. multiorder_check((1UL << i) + 1, i);
  48. }
  49. }