mbligh | fa29a2a | 2008-05-16 22:48:09 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
mbligh | f975133 | 2008-04-08 18:25:33 +0000 | [diff] [blame] | 2 | |
mbligh | da95846 | 2008-07-11 17:10:33 +0000 | [diff] [blame] | 3 | import os, sys, unittest |
mbligh | dc90601 | 2008-06-27 19:29:11 +0000 | [diff] [blame] | 4 | import common |
mbligh | f975133 | 2008-04-08 18:25:33 +0000 | [diff] [blame] | 5 | |
mbligh | 671c592 | 2008-07-28 19:34:38 +0000 | [diff] [blame^] | 6 | |
| 7 | LONG_TESTS = set(( |
| 8 | 'monitor_db_unittest.py', |
| 9 | 'barrier_unittest.py', |
| 10 | 'migrate_unittest.py', |
| 11 | 'frontend_unittest.py', |
| 12 | )) |
| 13 | |
| 14 | |
mbligh | 3c9c93d | 2008-05-21 18:19:38 +0000 | [diff] [blame] | 15 | root = os.path.abspath(os.path.dirname(__file__)) |
mbligh | 671c592 | 2008-07-28 19:34:38 +0000 | [diff] [blame^] | 16 | modules = [] |
| 17 | |
| 18 | def lister(short, dirname, files): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 19 | for f in files: |
| 20 | if f.endswith('_unittest.py'): |
mbligh | 671c592 | 2008-07-28 19:34:38 +0000 | [diff] [blame^] | 21 | if short and f in LONG_TESTS: |
| 22 | continue |
mbligh | 4205d89 | 2008-07-14 16:23:20 +0000 | [diff] [blame] | 23 | temp = os.path.join(dirname, f).strip('.py') |
| 24 | mod_name = ['autotest_lib'] + temp[len(root)+1:].split('/') |
mbligh | 671c592 | 2008-07-28 19:34:38 +0000 | [diff] [blame^] | 25 | modules.append(mod_name) |
| 26 | |
| 27 | |
| 28 | def 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 | |
| 38 | def 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 |
mbligh | f975133 | 2008-04-08 18:25:33 +0000 | [diff] [blame] | 54 | |
| 55 | |
| 56 | if __name__ == "__main__": |
mbligh | 8c435fe | 2008-06-12 19:39:14 +0000 | [diff] [blame] | 57 | if len(sys.argv) == 2: |
| 58 | start = os.path.join(root, sys.argv[1]) |
| 59 | else: |
| 60 | start = root |
mbligh | 671c592 | 2008-07-28 19:34:38 +0000 | [diff] [blame^] | 61 | |
| 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) |