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 20 #include "test.h" 21 22 static void multiorder_check(unsigned long index, int order) 23 { 24 unsigned long i; 25 unsigned long min = index & ~((1UL << order) - 1); 26 unsigned long max = min + (1UL << order); 27 RADIX_TREE(tree, GFP_KERNEL); 28 29 printf("Multiorder index %ld, order %d\n", index, order); 30 31 assert(item_insert_order(&tree, index, order) == 0); 32 33 for (i = min; i < max; i++) { 34 struct item *item = item_lookup(&tree, i); 35 assert(item != 0); 36 assert(item->index == index); 37 } 38 for (i = 0; i < min; i++) 39 item_check_absent(&tree, i); 40 for (i = max; i < 2*max; i++) 41 item_check_absent(&tree, i); 42 43 assert(item_delete(&tree, index) != 0); 44 45 for (i = 0; i < 2*max; i++) 46 item_check_absent(&tree, i); 47 } 48 49 void multiorder_checks(void) 50 { 51 int i; 52 53 for (i = 0; i < 20; i++) { 54 multiorder_check(200, i); 55 multiorder_check(0, i); 56 multiorder_check((1UL << i) + 1, i); 57 } 58 } 59