aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/radix-tree/iteration_check.c
diff options
context:
space:
mode:
authorMatthew Wilcox <[email protected]>2016-12-14 23:08:08 +0000
committerLinus Torvalds <[email protected]>2016-12-15 00:04:09 +0000
commit061ef3936b16edc8f779d403d569392505665ed5 (patch)
tree80e389b4f09d7a11e45c60aa543aa407871ec2c5 /tools/testing/radix-tree/iteration_check.c
parentradix tree test suite: free preallocated nodes (diff)
downloadkernel-061ef3936b16edc8f779d403d569392505665ed5.tar.gz
kernel-061ef3936b16edc8f779d403d569392505665ed5.zip
radix tree test suite: make runs more reproducible
Instead of reseeding the random number generator every time around the loop in big_gang_check(), seed it at the beginning of execution. Use rand_r() and an independent base seed for each thread in iteration_test() so they don't stomp all over each others state. Since this particular test depends on the kernel scheduler, the iteration test can't be reproduced based purely on the random seed, but at least it won't pollute the other tests. Print the seed, and allow the seed to be specified so that a run which hits a problem can be reproduced. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox <[email protected]> Tested-by: Kirill A. Shutemov <[email protected]> Cc: Konstantin Khlebnikov <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Matthew Wilcox <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
Diffstat (limited to 'tools/testing/radix-tree/iteration_check.c')
-rw-r--r--tools/testing/radix-tree/iteration_check.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/tools/testing/radix-tree/iteration_check.c b/tools/testing/radix-tree/iteration_check.c
index 9adb8e7415a6..11d570c3fc83 100644
--- a/tools/testing/radix-tree/iteration_check.c
+++ b/tools/testing/radix-tree/iteration_check.c
@@ -20,6 +20,7 @@
#define TAG 0
static pthread_mutex_t tree_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_t threads[NUM_THREADS];
+static unsigned int seeds[3];
RADIX_TREE(tree, GFP_KERNEL);
bool test_complete;
@@ -71,7 +72,7 @@ static void *tagged_iteration_fn(void *arg)
continue;
}
- if (rand() % 50 == 0)
+ if (rand_r(&seeds[0]) % 50 == 0)
slot = radix_tree_iter_next(&iter);
}
rcu_read_unlock();
@@ -111,7 +112,7 @@ static void *untagged_iteration_fn(void *arg)
continue;
}
- if (rand() % 50 == 0)
+ if (rand_r(&seeds[1]) % 50 == 0)
slot = radix_tree_iter_next(&iter);
}
rcu_read_unlock();
@@ -129,7 +130,7 @@ static void *remove_entries_fn(void *arg)
while (!test_complete) {
int pgoff;
- pgoff = rand() % 100;
+ pgoff = rand_r(&seeds[2]) % 100;
pthread_mutex_lock(&tree_lock);
item_delete(&tree, pgoff);
@@ -146,9 +147,11 @@ void iteration_test(void)
printf("Running iteration tests for 10 seconds\n");
- srand(time(0));
test_complete = false;
+ for (i = 0; i < 3; i++)
+ seeds[i] = rand();
+
if (pthread_create(&threads[0], NULL, tagged_iteration_fn, NULL)) {
perror("pthread_create");
exit(1);