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

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: Fix comment typo 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
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):
Nico 2015/05/13 17:43:58 add docstring that documents what return value mea
dcheng 2015/05/13 20:59:34 done
14 try:
15 actual = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
16 except subprocess.CalledProcessError as e:
17 # Some of the Blink GC plugin tests intentionally trigger compile errors, so
18 # just ignore an exit code that indicates failure.
19 actual = e.output
20 except Exception as e:
21 return 'could not execute %s (%s)' % (cmd, e)
22
23 # Some Blink GC plugins dump a JSON representation of the object graph, and
24 # use the processed results as the actual results of the test.
25 if 'dump-graph' in cmd:
Nico 2015/05/13 17:43:58 Why check this instead of checking for the existen
dcheng 2015/05/13 20:59:33 I guess I feel weird about checking something and
26 try:
27 actual = subprocess.check_output(
28 ['python', '../process-graph.py', '-c',
29 '%s.graph.json' % test_base_name],
30 stderr=subprocess.STDOUT)
31 except subprocess.CalledProcessError, e:
32 # The graph processing script returns a failure exit code if the graph is
33 # 'bad' (e.g. it has a cycle). Hope that the output returned contains the
Nico 2015/05/13 17:43:58 s/Hope/something else/
dcheng 2015/05/13 20:59:34 Done.
34 # right info.
35 actual = e.output
36
37 try:
38 expected = open('%s.txt' % test_base_name).read()
Nico 2015/05/13 17:43:58 Maybe this only needs an [:-1] to strip the newlin
dcheng 2015/05/13 20:59:33 I just added rstrip() to hack around this for now.
39 except IOError:
40 open('%s.txt' % test_base_name, 'w').write(actual)
41 return 'no expected file found'
42
43 if expected != actual:
44 open('%s.txt' % test_base_name, 'w').write(actual)
Nico 2015/05/13 17:43:58 This overwrites the input, is that intentional?
dcheng 2015/05/13 20:59:34 I wanted to experiment with something better than:
45 return 'expected and actual differed'
46
47
48 def run_tests(clang_path, plugin_path):
49 passing = []
50 failing = []
51
52 base_cmd = [clang_path, '-fsyntax-only', '-std=c++11']
53 base_cmd.extend(['-Wno-inaccessible-base'])
54 if plugin_path:
55 base_cmd.extend(['-Xclang', '-load', '-Xclang', plugin_path])
56 base_cmd.extend(['-Xclang', '-add-plugin', '-Xclang', 'blink-gc-plugin'])
57
58 tests = glob.glob('*.cpp')
59 for test in tests:
60 sys.stdout.write('Testing %s... ' % test)
61 test_base_name, _ = os.path.splitext(test)
62
63 cmd = base_cmd[:]
64 try:
65 cmd.extend(file('%s.flags' % test_base_name).read().split())
66 except IOError:
67 pass
68 cmd.append(test)
69
70 failure_message = run_test(test_base_name, cmd)
71 if failure_message:
72 print 'failed: %s' % failure_message
73 failing.append(test_base_name)
74 else:
75 print 'passed!'
76 passing.append(test_base_name)
77
78 return passing, failing
79
80
81 def main():
82 if len(sys.argv) < 2:
83 print 'Usage: <path to clang>[ <path to plugin>]'
84 return -1
85
86 os.chdir(os.path.dirname(os.path.realpath(__file__)))
87
88 clang_path = sys.argv[1]
89 plugin_path = sys.argv[2] if len(sys.argv) > 2 else None
90 passing, failing = run_tests(clang_path, plugin_path)
91 print 'Ran %d tests: %d succeeded, %d failed' % (
92 len(passing) + len(failing), len(passing), len(failing))
93 for test in failing:
94 print ' %s' % test
95
96
97 if __name__ == '__main__':
98 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698