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