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

radix-tree: add test for radix_tree_locate_item()

Add a unit test that provides coverage for the bug fixed in the commit
entitled "radix-tree: rewrite radix_tree_locate_item fix" from Hugh
Dickins. I've verified that this test fails before his patch due to
miscalculated 'index' values in __locate() in lib/radix-tree.c, and
passes with his fix.

Link: http://lkml.kernel.org/r/1462307263-20623-1-git-send-email-ross.zwisler@linux.intel.com
Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ross Zwisler and committed by
Linus Torvalds
eb73f7f3 0a2efc6c

+15 -1
+1
tools/testing/radix-tree/linux/init.h
··· 1 + /* An empty file stub that allows radix-tree.c to compile. */
+14 -1
tools/testing/radix-tree/main.c
··· 232 232 item_kill_tree(&tree); 233 233 } 234 234 235 - void __locate_check(struct radix_tree_root *tree, unsigned long index, 235 + static void __locate_check(struct radix_tree_root *tree, unsigned long index, 236 236 unsigned order) 237 237 { 238 238 struct item *item; ··· 248 248 } 249 249 } 250 250 251 + static void __order_0_locate_check(void) 252 + { 253 + RADIX_TREE(tree, GFP_KERNEL); 254 + int i; 255 + 256 + for (i = 0; i < 50; i++) 257 + __locate_check(&tree, rand() % INT_MAX, 0); 258 + 259 + item_kill_tree(&tree); 260 + } 261 + 251 262 static void locate_check(void) 252 263 { 253 264 RADIX_TREE(tree, GFP_KERNEL); 254 265 unsigned order; 255 266 unsigned long offset, index; 267 + 268 + __order_0_locate_check(); 256 269 257 270 for (order = 0; order < 20; order++) { 258 271 for (offset = 0; offset < (1 << (order + 3));