Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 | |
| 7 import glob | |
| 8 import os | |
| 9 import subprocess | |
| 10 import sys | |
| 11 | |
| 12 | |
| 13 def run_test(test_base_name, cmd): | |
| 14 """Run a test case. | |
| 15 | |
| 16 Args: | |
| 17 test_base_name: The name for the test C++ source file without the extension. | |
| 18 cmd: The actual command to run for the test. | |
| 19 | |
| 20 Returns: | |
| 21 None on pass, or a str with the description of the failure. | |
| 22 """ | |
| 23 try: | |
| 24 actual = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | |
| 25 except subprocess.CalledProcessError as e: | |
| 26 # Some of the Blink GC plugin tests intentionally trigger compile errors, so | |
| 27 # just ignore an exit code that indicates failure. | |
| 28 actual = e.output | |
| 29 except Exception as e: | |
| 30 return 'could not execute %s (%s)' % (cmd, e) | |
| 31 | |
| 32 # Some Blink GC plugins dump a JSON representation of the object graph, and | |
| 33 # use the processed results as the actual results of the test. | |
| 34 if os.path.exists('%s.graph.json' % test_base_name): | |
| 35 try: | |
| 36 actual = subprocess.check_output( | |
| 37 ['python', '../process-graph.py', '-c', | |
| 38 '%s.graph.json' % test_base_name], | |
| 39 stderr=subprocess.STDOUT) | |
| 40 except subprocess.CalledProcessError, e: | |
| 41 # The graph processing script returns a failure exit code if the graph is | |
| 42 # 'bad' (e.g. it has a cycle). The output still needs to be captured in | |
| 43 # that case, since the expected results capture the errors. | |
| 44 actual = e.output | |
| 45 | |
| 46 # TODO(dcheng): Remove the rstrip() and just rebaseline the tests to match. | |
| 47 actual = actual.rstrip() | |
| 48 | |
| 49 try: | |
| 50 expected = open('%s.txt' % test_base_name).read().rstrip() | |
| 51 except IOError: | |
| 52 open('%s.txt' % test_base_name, 'w').write(actual) | |
| 53 return 'no expected file found' | |
| 54 | |
| 55 if expected != actual: | |
| 56 open('%s.txt' % test_base_name, 'w').write(actual) | |
| 57 return 'expected and actual differed' | |
| 58 | |
| 59 | |
| 60 def run_tests(clang_path, plugin_path): | |
| 61 """Runs the tests. | |
| 62 | |
| 63 Args: | |
| 64 clang_path: The path to the clang binary to be tested. | |
| 65 plugin_path: An optional path to the plugin to test. This may be None, if | |
| 66 plugin is built directly into clang, like on Windows. | |
| 67 | |
| 68 Returns: | |
| 69 (passing, failing): Two lists containing the base names of the passing and | |
| 70 failing tests respectively. | |
| 71 """ | |
| 72 passing = [] | |
| 73 failing = [] | |
| 74 | |
| 75 base_cmd = [clang_path, '-fsyntax-only', '-std=c++11'] | |
| 76 base_cmd.extend(['-Wno-inaccessible-base']) | |
| 77 if plugin_path: | |
| 78 base_cmd.extend(['-Xclang', '-load', '-Xclang', plugin_path]) | |
| 79 base_cmd.extend(['-Xclang', '-add-plugin', '-Xclang', 'blink-gc-plugin']) | |
| 80 | |
| 81 tests = glob.glob('*.cpp') | |
| 82 for test in tests: | |
| 83 sys.stdout.write('Testing %s... ' % test) | |
| 84 test_base_name, _ = os.path.splitext(test) | |
| 85 | |
| 86 cmd = base_cmd[:] | |
| 87 try: | |
| 88 cmd.extend(file('%s.flags' % test_base_name).read().split()) | |
| 89 except IOError: | |
| 90 pass | |
| 91 cmd.append(test) | |
| 92 | |
| 93 failure_message = run_test(test_base_name, cmd) | |
| 94 if failure_message: | |
| 95 print 'failed: %s' % failure_message | |
| 96 failing.append(test_base_name) | |
| 97 else: | |
| 98 print 'passed!' | |
| 99 passing.append(test_base_name) | |
| 100 | |
| 101 return passing, failing | |
| 102 | |
| 103 | |
| 104 def main(): | |
| 105 if len(sys.argv) < 2: | |
| 106 print 'Usage: <path to clang>[ <path to plugin>]' | |
| 107 return -1 | |
| 108 | |
| 109 os.chdir(os.path.dirname(os.path.realpath(__file__))) | |
| 110 | |
| 111 clang_path = sys.argv[1] | |
| 112 plugin_path = sys.argv[2] if len(sys.argv) > 2 else None | |
|
Nico
2015/05/13 21:53:11
optional nit: The old script logged the path to co
dcheng
2015/05/14 05:25:37
Done.
| |
| 113 passing, failing = run_tests(clang_path, plugin_path) | |
| 114 print 'Ran %d tests: %d succeeded, %d failed' % ( | |
| 115 len(passing) + len(failing), len(passing), len(failing)) | |
| 116 for test in failing: | |
| 117 print ' %s' % test | |
| 118 | |
| 119 | |
| 120 if __name__ == '__main__': | |
| 121 sys.exit(main()) | |
| OLD | NEW |