Adding a class that can be used to run tests in a random order. If you have
5 tests and 10 machines to run them on, there is a high probability that each
test will be run first on at least one machine, thus giving you initial
feedback much faster. In addition, the order the tests run will be different
which increases the chances you'll uncover weird and subtle problems.
To use this patch, instead of running tests like this:
job.run_test('tbench')
job.run_test('kernbench')
job.run_test('dbench')
Run tests like this:
run = run_randomly()
run.add('tbench')
run.add('kernbench')
run.add('dbench')
run.run(job.run_test)
Signed-off-by: Jeremy Orlow <jorlow@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1341 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 67c23e3..7f586e0 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -1,4 +1,4 @@
-import os, sys, re, shutil, urlparse, urllib, pickle
+import os, sys, re, shutil, urlparse, urllib, pickle, random
from error import *
def write_keyval(path, dictionary):
@@ -84,3 +84,20 @@
install(*args, **dargs)
if os.path.exists(srcdir):
pickle.dump(new_version, open(versionfile, 'w'))
+
+
+class run_randomly:
+ def __init__(self):
+ self.test_list = []
+
+
+ def add(self, *args, **dargs):
+ test = (args, dargs)
+ self.test_list.append(test)
+
+
+ def run(self, fn):
+ while self.test_list:
+ test_index = random.randint(0, len(self.test_list)-1)
+ (args, dargs) = self.test_list.pop(test_index)
+ fn(*args, **dargs)