Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: tools/clang/blink_gc_plugin/tests/test.py

Issue 1135363003: Rewrite blink_gc_plugin test script in Python. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nit Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/clang/blink_gc_plugin/tests/.gitignore ('k') | tools/clang/blink_gc_plugin/tests/test.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
113 print 'Using clang %s...' % clang_path
114 print 'Using plugin %s...' % plugin_path
115
116 passing, failing = run_tests(clang_path, plugin_path)
117 print 'Ran %d tests: %d succeeded, %d failed' % (
118 len(passing) + len(failing), len(passing), len(failing))
119 for test in failing:
120 print ' %s' % test
121
122
123 if __name__ == '__main__':
124 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/clang/blink_gc_plugin/tests/.gitignore ('k') | tools/clang/blink_gc_plugin/tests/test.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698