• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6import argparse
7import os
8import subprocess
9import sys
10
11script_dir = os.path.dirname(os.path.realpath(__file__))
12tool_dir = os.path.abspath(os.path.join(script_dir, '../../pylib'))
13sys.path.insert(0, tool_dir)
14
15from clang import plugin_testing
16
17
18class BlinkGcPluginTest(plugin_testing.ClangPluginTest):
19  """Test harness for the Blink GC plugin."""
20
21  def AdjustClangArguments(self, clang_cmd):
22    clang_cmd.append('-Wno-inaccessible-base')
23
24  def ProcessOneResult(self, test_name, actual):
25    # Some Blink GC plugins dump a JSON representation of the object graph, and
26    # use the processed results as the actual results of the test.
27    if os.path.exists('%s.graph.json' % test_name):
28      try:
29        actual = subprocess.check_output(
30            ['python', '../process-graph.py', '-c',
31             '%s.graph.json' % test_name],
32            stderr=subprocess.STDOUT)
33      except subprocess.CalledProcessError, e:
34        # The graph processing script returns a failure exit code if the graph
35        # is bad (e.g. it has a cycle). The output still needs to be captured in
36        # that case, since the expected results capture the errors.
37        actual = e.output
38      finally:
39        # Clean up the .graph.json file to prevent false passes from stale
40        # results from a previous run.
41        os.remove('%s.graph.json' % test_name)
42    return super(BlinkGcPluginTest, self).ProcessOneResult(test_name, actual)
43
44
45def main():
46  parser = argparse.ArgumentParser()
47  parser.add_argument(
48      '--reset-results',
49      action='store_true',
50      help='If specified, overwrites the expected results in place.')
51  parser.add_argument('clang_path', help='The path to the clang binary.')
52  parser.add_argument('plugin_path',
53                      nargs='?',
54                      help='The path to the plugin library, if any.')
55  args = parser.parse_args()
56
57  return BlinkGcPluginTest(
58      os.path.dirname(os.path.realpath(__file__)),
59      args.clang_path,
60      args.plugin_path,
61      'blink-gc-plugin',
62      args.reset_results).Run()
63
64
65if __name__ == '__main__':
66  sys.exit(main())
67