f66ad85
#!/usr/bin/python
f66ad85
# Copyright 2015 Tomas Popela <tpopela@redhat.com>
f66ad85
# Permission is hereby granted, free of charge, to any person obtaining
f66ad85
# a copy of this software and associated documentation files (the
f66ad85
# "Software"), to deal in the Software without restriction, including
f66ad85
# without limitation the rights to use, copy, modify, merge, publish,
f66ad85
# distribute, sublicense, and/or sell copies of the Software, and to
f66ad85
# permit persons to whom the Software is furnished to do so, subject to
f66ad85
# the following conditions:
f66ad85
#
f66ad85
# The above copyright notice and this permission notice shall be included
f66ad85
# in all copies or substantial portions of the Software.
f66ad85
#
f66ad85
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
f66ad85
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
f66ad85
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
f66ad85
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
f66ad85
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
f66ad85
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
f66ad85
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
f66ad85
f66ad85
try:
f66ad85
  import argparse
f66ad85
  optparse = False
f66ad85
except ImportError:
f66ad85
  from optparse import OptionParser
f66ad85
  optparse = True
f66ad85
import locale
f66ad85
import simplejson as json
f66ad85
import sys
f66ad85
import os
f66ad85
f66ad85
if __name__ == "__main__":
f66ad85
f66ad85
  added = []
f66ad85
f66ad85
  # Create the parser object
f66ad85
  if optparse:
f66ad85
    parser = OptionParser()
f66ad85
    parser_add_argument = parser.add_option
f66ad85
  else:
f66ad85
    parser = argparse.ArgumentParser()
f66ad85
    parser_add_argument = parser.add_argument
f66ad85
f66ad85
  parser_add_argument(
f66ad85
      '--check',
f66ad85
      help='Check the tests against given SPEC file')
f66ad85
  parser_add_argument(
f66ad85
      '--spec', action='store_true',
f66ad85
      help='Prints the test targets in format suitable for SPEC file')
f66ad85
  parser_add_argument(
f66ad85
      'path', nargs='?', default=os.getcwd(),
f66ad85
      help='Path to Chromium sources')
f66ad85
f66ad85
  # Parse the args
f66ad85
  if optparse:
f66ad85
    args, options = parser.parse_args()
f66ad85
  else:
f66ad85
    args = parser.parse_args()
f66ad85
f66ad85
  tests_path = "%s/testing/buildbot/chromium.linux.json" % args.path
f66ad85
f66ad85
  try:
f66ad85
    with open(tests_path, "r") as input_file:
f66ad85
      json_file = json.load(input_file)
f66ad85
  except IOError:
f66ad85
    print "Cannot find JSON file with tests in path '%s'!" % args.path
f66ad85
    sys.exit(1)
f66ad85
f66ad85
f66ad85
  for test in json_file['Linux Tests']['gtest_tests']:
f66ad85
    if isinstance(test, dict):
f66ad85
        added.append(test['test'])
f66ad85
    else:
f66ad85
        added.append(test)
f66ad85
f66ad85
  if args.check:
f66ad85
    removed = []
f66ad85
    disabled = []
f66ad85
    in_tests = False
f66ad85
    spec_file = None
f66ad85
f66ad85
    with open(args.check) as f:
f66ad85
      for line in f:
f66ad85
        if "CHROMIUM_BROWSER_UNIT_TESTS=" in line:
f66ad85
          in_tests = True
f66ad85
          continue
f66ad85
f66ad85
        if in_tests and line.endswith('"\n'):
f66ad85
          break
f66ad85
f66ad85
        if in_tests:
f66ad85
          found = False
f66ad85
          for test in added:
f66ad85
            if test in line:
f66ad85
              if "#" in line:
f66ad85
                disabled.append(test)
f66ad85
              added.remove(test)
f66ad85
              found = True
f66ad85
              break
f66ad85
          if not found:
f66ad85
            if not "%" in line:
f66ad85
              removed.append(line)
f66ad85
f66ad85
    for test in removed:
f66ad85
      print "REMOVED"
f66ad85
      print "\t" + test;
f66ad85
    for test in added:
f66ad85
      print "ADDED"
f66ad85
      print "\t" + test;
f66ad85
    for test in disabled:
f66ad85
      print "DISABLED"
f66ad85
      print "\t" + test;
f66ad85
f66ad85
    sys.exit(0)
f66ad85
f66ad85
  for name in added:
f66ad85
    if args.spec:
f66ad85
      print "\t" + name + " \\"
f66ad85
    else:
f66ad85
      print name