blob: dfdb7f28ce822ea1ef6435bec7c61cd033da2766 [file] [log] [blame]
mblighfa29a2a2008-05-16 22:48:09 +00001#!/usr/bin/python
mblighf9751332008-04-08 18:25:33 +00002
mblighda958462008-07-11 17:10:33 +00003import os, sys, unittest
mblighdc906012008-06-27 19:29:11 +00004import common
mblighf9751332008-04-08 18:25:33 +00005
mbligh671c5922008-07-28 19:34:38 +00006
7LONG_TESTS = set((
8 'monitor_db_unittest.py',
9 'barrier_unittest.py',
10 'migrate_unittest.py',
11 'frontend_unittest.py',
12 ))
13
14
mbligh3c9c93d2008-05-21 18:19:38 +000015root = os.path.abspath(os.path.dirname(__file__))
mbligh671c5922008-07-28 19:34:38 +000016modules = []
17
18def lister(short, dirname, files):
jadmanski0afbb632008-06-06 21:10:57 +000019 for f in files:
20 if f.endswith('_unittest.py'):
mbligh671c5922008-07-28 19:34:38 +000021 if short and f in LONG_TESTS:
22 continue
mbligh4205d892008-07-14 16:23:20 +000023 temp = os.path.join(dirname, f).strip('.py')
24 mod_name = ['autotest_lib'] + temp[len(root)+1:].split('/')
mbligh671c5922008-07-28 19:34:38 +000025 modules.append(mod_name)
26
27
28def run_test(mod_name):
29 mod = common.setup_modules.import_module(mod_name[-1],
30 '.'.join(mod_name[:-1]))
31 test = unittest.defaultTestLoader.loadTestsFromModule(mod)
32 suite = unittest.TestSuite(test)
33 runner = unittest.TextTestRunner(verbosity=2)
34 result = runner.run(suite)
35 return (result.errors, result.failures)
36
37
38def run_tests(start, short=False):
39 os.path.walk(start, lister, short)
40
41 errors = []
42 for module in modules:
43 pid = os.fork()
44 if pid == 0:
45 errors, failures = run_test(module)
46 if errors or failures:
47 os._exit(1)
48 os._exit(0)
49
50 _, status = os.waitpid(pid, 0)
51 if status != 0:
52 errors.append('.'.join(module))
53 return errors
mblighf9751332008-04-08 18:25:33 +000054
55
56if __name__ == "__main__":
mbligh8c435fe2008-06-12 19:39:14 +000057 if len(sys.argv) == 2:
58 start = os.path.join(root, sys.argv[1])
59 else:
60 start = root
mbligh671c5922008-07-28 19:34:38 +000061
62 errors = run_tests(start)
63 if errors:
64 print "%d tests resulted in an error/failure:" % len(errors)
65 for error in errors:
66 print "\t%s" % error
67 sys.exit(1)
68 else:
69 print "All passed!"
70 sys.exit(0)