Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | Run the test suite using a separate process for each test file. |
| 5 | """ |
| 6 | |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 7 | import multiprocessing |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 8 | import os |
| 9 | import platform |
| 10 | import sys |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 11 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 12 | from optparse import OptionParser |
| 13 | |
| 14 | # Command template of the invocation of the test driver. |
Todd Fiala | a4ec2fc | 2014-06-02 17:49:35 +0000 | [diff] [blame] | 15 | template = '%s %s/dotest.py %s -p %s %s' |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 16 | |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 17 | def process_dir(root, files, test_root, dotest_options): |
| 18 | """Examine a directory for tests, and invoke any found within it.""" |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 19 | failed = [] |
| 20 | passed = [] |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 21 | for name in files: |
| 22 | path = os.path.join(root, name) |
| 23 | |
| 24 | # We're only interested in the test file with the "Test*.py" naming pattern. |
| 25 | if not name.startswith("Test") or not name.endswith(".py"): |
| 26 | continue |
| 27 | |
| 28 | # Neither a symbolically linked file. |
| 29 | if os.path.islink(path): |
| 30 | continue |
| 31 | |
Todd Fiala | a4ec2fc | 2014-06-02 17:49:35 +0000 | [diff] [blame] | 32 | command = template % (sys.executable, test_root, dotest_options if dotest_options else "", name, root) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 33 | if 0 != os.system(command): |
| 34 | failed.append(name) |
| 35 | else: |
| 36 | passed.append(name) |
| 37 | return (failed, passed) |
| 38 | |
| 39 | in_q = None |
| 40 | out_q = None |
| 41 | |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 42 | def process_dir_worker(arg_tuple): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 43 | """Worker thread main loop when in multithreaded mode. |
| 44 | Takes one directory specification at a time and works on it.""" |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 45 | (root, files, test_root, dotest_options) = arg_tuple |
| 46 | return process_dir(root, files, test_root, dotest_options) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 47 | |
| 48 | def walk_and_invoke(test_root, dotest_options, num_threads): |
| 49 | """Look for matched files and invoke test driver on each one. |
| 50 | In single-threaded mode, each test driver is invoked directly. |
| 51 | In multi-threaded mode, submit each test driver to a worker |
| 52 | queue, and then wait for all to complete.""" |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 53 | |
| 54 | # Collect the test files that we'll run. |
| 55 | test_work_items = [] |
| 56 | for root, dirs, files in os.walk(test_root, topdown=False): |
| 57 | test_work_items.append((root, files, test_root, dotest_options)) |
| 58 | |
| 59 | # Run the items, either in a pool (for multicore speedup) or |
| 60 | # calling each individually. |
| 61 | if num_threads > 1: |
| 62 | pool = multiprocessing.Pool(num_threads) |
| 63 | test_results = pool.map(process_dir_worker, test_work_items) |
| 64 | else: |
| 65 | test_results = [] |
| 66 | for work_item in test_work_items: |
| 67 | test_results.append(process_dir_worker(work_item)) |
| 68 | |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 69 | failed = [] |
| 70 | passed = [] |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 71 | |
| 72 | for test_result in test_results: |
| 73 | (dir_failed, dir_passed) = test_result |
| 74 | failed += dir_failed |
| 75 | passed += dir_passed |
| 76 | |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 77 | return (failed, passed) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 78 | |
| 79 | def main(): |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 80 | test_root = sys.path[0] |
| 81 | |
| 82 | parser = OptionParser(usage="""\ |
| 83 | Run lldb test suite using a separate process for each test file. |
| 84 | """) |
| 85 | parser.add_option('-o', '--options', |
| 86 | type='string', action='store', |
| 87 | dest='dotest_options', |
| 88 | help="""The options passed to 'dotest.py' if specified.""") |
| 89 | |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 90 | parser.add_option('-t', '--threads', |
| 91 | type='int', |
| 92 | dest='num_threads', |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame^] | 93 | help="""The number of threads to use when running tests separately.""") |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 94 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 95 | opts, args = parser.parse_args() |
| 96 | dotest_options = opts.dotest_options |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame^] | 97 | |
| 98 | if opts.num_threads: |
| 99 | num_threads = opts.num_threads |
| 100 | else: |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 101 | num_threads_str = os.environ.get("LLDB_TEST_THREADS") |
| 102 | if num_threads_str: |
| 103 | num_threads = int(num_threads_str) |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 104 | else: |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame^] | 105 | num_threads = multiprocessing.cpu_count() |
| 106 | if num_threads < 1: |
| 107 | num_threads = 1 |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 108 | |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 109 | system_info = " ".join(platform.uname()) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 110 | (failed, passed) = walk_and_invoke(test_root, dotest_options, num_threads) |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 111 | num_tests = len(failed) + len(passed) |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 112 | |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 113 | print "Ran %d tests." % num_tests |
| 114 | if len(failed) > 0: |
Shawn Best | 13491c4 | 2014-10-22 19:29:00 +0000 | [diff] [blame] | 115 | failed.sort() |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 116 | print "Failing Tests (%d)" % len(failed) |
| 117 | for f in failed: |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 118 | print "FAIL: LLDB (suite) :: %s (%s)" % (f, system_info) |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 119 | sys.exit(1) |
| 120 | sys.exit(0) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 121 | |
| 122 | if __name__ == '__main__': |
| 123 | main() |