15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#!/usr/bin/env python
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Copyright (c) 2012 The Chromium Authors. All rights reserved.
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# found in the LICENSE file.
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)''' Runs various chrome tests through valgrind_test.py.'''
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import glob
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import logging
107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochimport multiprocessing
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import optparse
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import os
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import stat
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import sys
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import logging_utils
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import path_utils
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import common
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import valgrind_test
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TestNotFound(Exception): pass
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MultipleGTestFiltersSpecified(Exception): pass
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BuildDirNotFound(Exception): pass
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BuildDirAmbiguous(Exception): pass
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ChromeTests:
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SLOW_TOOLS = ["memcheck", "tsan", "tsan_rv", "drmemory"]
320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  LAYOUT_TESTS_DEFAULT_CHUNK_SIZE = 300
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def __init__(self, options, args, test):
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if ':' in test:
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      (self._test, self._gtest_filter) = test.split(':', 1)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    else:
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      self._test = test
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      self._gtest_filter = options.gtest_filter
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if self._test not in self._test_list:
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      raise TestNotFound("Unknown test: %s" % test)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if options.gtest_filter and options.gtest_filter != self._gtest_filter:
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      raise MultipleGTestFiltersSpecified("Can not specify both --gtest_filter "
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          "and --test %s" % test)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._options = options
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._args = args
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    script_dir = path_utils.ScriptDir()
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Compute the top of the tree (the "source dir") from the script dir (where
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # this script lives).  We assume that the script dir is in tools/valgrind/
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # relative to the top of the tree.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._source_dir = os.path.dirname(os.path.dirname(script_dir))
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # since this path is used for string matching, make sure it's always
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # an absolute Unix-style path
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._source_dir = os.path.abspath(self._source_dir).replace('\\', '/')
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    valgrind_test_script = os.path.join(script_dir, "valgrind_test.py")
604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    self._command_preamble = ["--source-dir=%s" % (self._source_dir)]
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if not self._options.build_dir:
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      dirs = [
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        os.path.join(self._source_dir, "xcodebuild", "Debug"),
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        os.path.join(self._source_dir, "out", "Debug"),
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        os.path.join(self._source_dir, "build", "Debug"),
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ]
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      build_dir = [d for d in dirs if os.path.isdir(d)]
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if len(build_dir) > 1:
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        raise BuildDirAmbiguous("Found more than one suitable build dir:\n"
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                "%s\nPlease specify just one "
724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                                "using --build-dir" % ", ".join(build_dir))
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      elif build_dir:
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        self._options.build_dir = build_dir[0]
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      else:
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        self._options.build_dir = None
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if self._options.build_dir:
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      build_dir = os.path.abspath(self._options.build_dir)
804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      self._command_preamble += ["--build-dir=%s" % (self._options.build_dir)]
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def _EnsureBuildDirFound(self):
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if not self._options.build_dir:
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      raise BuildDirNotFound("Oops, couldn't find a build dir, please "
854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             "specify it manually using --build-dir")
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None):
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    '''Generates the default command array that most tests will use.'''
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if exe and common.IsWindows():
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      exe += '.exe'
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd = list(self._command_preamble)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Find all suppressions matching the following pattern:
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # tools/valgrind/TOOL/suppressions[_PLATFORM].txt
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # and list them with --suppressions= prefix.
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    script_dir = path_utils.ScriptDir()
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    tool_name = tool.ToolName();
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    suppression_file = os.path.join(script_dir, tool_name, "suppressions.txt")
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if os.path.exists(suppression_file):
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cmd.append("--suppressions=%s" % suppression_file)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Platform-specific suppression
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for platform in common.PlatformNames():
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      platform_suppression_file = \
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          os.path.join(script_dir, tool_name, 'suppressions_%s.txt' % platform)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if os.path.exists(platform_suppression_file):
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        cmd.append("--suppressions=%s" % platform_suppression_file)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if self._options.valgrind_tool_flags:
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cmd += self._options.valgrind_tool_flags.split(" ")
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if self._options.keep_logs:
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cmd += ["--keep_logs"]
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if valgrind_test_args != None:
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      for arg in valgrind_test_args:
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        cmd.append(arg)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if exe:
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      self._EnsureBuildDirFound()
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cmd.append(os.path.join(self._options.build_dir, exe))
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      # Valgrind runs tests slowly, so slow tests hurt more; show elapased time
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      # so we can find the slowpokes.
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cmd.append("--gtest_print_time")
122a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      # Built-in test launcher for gtest-based executables runs tests using
123a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      # multiple process by default. Force the single-process mode back.
124a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      cmd.append("--single-process-tests")
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if self._options.gtest_repeat:
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cmd.append("--gtest_repeat=%s" % self._options.gtest_repeat)
127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if self._options.gtest_shuffle:
128f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      cmd.append("--gtest_shuffle")
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if self._options.brave_new_test_launcher:
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      cmd.append("--brave-new-test-launcher")
1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if self._options.test_launcher_bot_mode:
1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      cmd.append("--test-launcher-bot-mode")
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return cmd
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def Run(self):
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ''' Runs the test specified by command-line argument --test '''
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    logging.info("running test %s" % (self._test))
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self._test_list[self._test](self)
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def _AppendGtestFilter(self, tool, name, cmd):
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    '''Append an appropriate --gtest_filter flag to the googletest binary
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       invocation.
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       If the user passed his own filter mentioning only one test, just use it.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       Othewise, filter out tests listed in the appropriate gtest_exclude files.
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    '''
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (self._gtest_filter and
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        ":" not in self._gtest_filter and
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        "?" not in self._gtest_filter and
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        "*" not in self._gtest_filter):
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cmd.append("--gtest_filter=%s" % self._gtest_filter)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    filters = []
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gtest_files_dir = os.path.join(path_utils.ScriptDir(), "gtest_exclude")
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gtest_filter_files = [
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        os.path.join(gtest_files_dir, name + ".gtest-%s.txt" % tool.ToolName())]
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Use ".gtest.txt" files only for slow tools, as they now contain
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Valgrind- and Dr.Memory-specific filters.
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # TODO(glider): rename the files to ".gtest_slow.txt"
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if tool.ToolName() in ChromeTests.SLOW_TOOLS:
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      gtest_filter_files += [os.path.join(gtest_files_dir, name + ".gtest.txt")]
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for platform_suffix in common.PlatformNames():
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      gtest_filter_files += [
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        os.path.join(gtest_files_dir, name + ".gtest_%s.txt" % platform_suffix),
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        os.path.join(gtest_files_dir, name + ".gtest-%s_%s.txt" % \
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            (tool.ToolName(), platform_suffix))]
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    logging.info("Reading gtest exclude filter files:")
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for filename in gtest_filter_files:
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      # strip the leading absolute path (may be very long on the bot)
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      # and the following / or \.
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      readable_filename = filename.replace("\\", "/")  # '\' on Windows
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      readable_filename = readable_filename.replace(self._source_dir, "")[1:]
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if not os.path.exists(filename):
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        logging.info("  \"%s\" - not found" % readable_filename)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        continue
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      logging.info("  \"%s\" - OK" % readable_filename)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      f = open(filename, 'r')
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      for line in f.readlines():
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if line.startswith("#") or line.startswith("//") or line.isspace():
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          continue
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        line = line.rstrip()
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        test_prefixes = ["FLAKY", "FAILS"]
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        for p in test_prefixes:
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          # Strip prefixes from the test names.
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          line = line.replace(".%s_" % p, ".")
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        # Exclude the original test name.
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        filters.append(line)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if line[-2:] != ".*":
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          # List all possible prefixes if line doesn't end with ".*".
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          for p in test_prefixes:
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            filters.append(line.replace(".", ".%s_" % p))
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Get rid of duplicates.
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    filters = set(filters)
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gtest_filter = self._gtest_filter
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if len(filters):
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if gtest_filter:
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        gtest_filter += ":"
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if gtest_filter.find("-") < 0:
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          gtest_filter += "-"
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      else:
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        gtest_filter = "-"
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      gtest_filter += ":".join(filters)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if gtest_filter:
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cmd.append("--gtest_filter=%s" % gtest_filter)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  @staticmethod
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def ShowTests():
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_to_names = {}
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for name, test_function in ChromeTests._test_list.iteritems():
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      test_to_names.setdefault(test_function, []).append(name)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    name_to_aliases = {}
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for names in test_to_names.itervalues():
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      names.sort(key=lambda name: len(name))
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      name_to_aliases[names[0]] = names[1:]
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    print
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    print "Available tests:"
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    print "----------------"
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for name, aliases in sorted(name_to_aliases.iteritems()):
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if aliases:
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        print "   {} (aka {})".format(name, ', '.join(aliases))
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      else:
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        print "   {}".format(name)
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def SetupLdPath(self, requires_build_dir):
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if requires_build_dir:
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      self._EnsureBuildDirFound()
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    elif not self._options.build_dir:
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Append build_dir to LD_LIBRARY_PATH so external libraries can be loaded.
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (os.getenv("LD_LIBRARY_PATH")):
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      os.putenv("LD_LIBRARY_PATH", "%s:%s" % (os.getenv("LD_LIBRARY_PATH"),
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                              self._options.build_dir))
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    else:
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      os.putenv("LD_LIBRARY_PATH", self._options.build_dir)
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def SimpleTest(self, module, name, valgrind_test_args=None, cmd_args=None):
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    tool = valgrind_test.CreateTool(self._options.valgrind_tool)
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd = self._DefaultCommand(tool, name, valgrind_test_args)
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._AppendGtestFilter(tool, name, cmd)
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd.extend(['--test-tiny-timeout=1000'])
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if cmd_args:
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cmd.extend(cmd_args)
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self.SetupLdPath(True)
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return tool.Run(cmd, module)
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def RunCmdLine(self):
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    tool = valgrind_test.CreateTool(self._options.valgrind_tool)
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd = self._DefaultCommand(tool, None, self._args)
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self.SetupLdPath(False)
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return tool.Run(cmd, None)
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
257116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestAccessibility(self):
258116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("accessibility", "accessibility_unittests")
259116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
260116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestAddressInput(self):
261116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("addressinput", "libaddressinput_unittests")
262116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
263116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestAngle(self):
264116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("angle", "angle_unittests")
265116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  def TestAppList(self):
267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return self.SimpleTest("app_list", "app_list_unittests")
268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestAsh(self):
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("ash", "ash_unittests")
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
272116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestAshShell(self):
273116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("ash_shelf", "ash_shell_unittests")
274116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestAura(self):
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("aura", "aura_unittests")
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestBase(self):
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("base", "base_unittests")
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
281116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestBlinkHeap(self):
282116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("blink_heap", "blink_heap_unittests")
283116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
284116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestBlinkPlatform(self):
285116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("blink_platform", "blink_platform_unittests")
286116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
287116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestCacheInvalidation(self):
288116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("cacheinvalidation", "cacheinvalidation_unittests")
289116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  def TestCast(self):
2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return self.SimpleTest("chrome", "cast_unittests")
2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
293116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestCC(self):
294116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("cc", "cc_unittests")
295116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
296116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestChromeApp(self):
297116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("chrome_app", "chrome_app_unittests")
298116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
299116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestChromeElf(self):
300116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("chrome_elf", "chrome_elf_unittests")
301116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
302116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestChromeDriver(self):
303116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("chromedriver", "chromedriver_unittests")
304116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestChromeOS(self):
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chromeos", "chromeos_unittests")
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
308116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestCloudPrint(self):
309116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("cloud_print", "cloud_print_unittests")
310116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  def TestComponents(self):
3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return self.SimpleTest("components", "components_unittests")
3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestCompositor(self):
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("compositor", "compositor_unittests")
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestContent(self):
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("content", "content_unittests")
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestCourgette(self):
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("courgette", "courgette_unittests")
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestCrypto(self):
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("crypto", "crypto_unittests")
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestDevice(self):
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("device", "device_unittests")
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
329116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestDisplay(self):
330116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("display", "display_unittests")
331116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
332f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  def TestEvents(self):
333f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return self.SimpleTest("events", "events_unittests")
334f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
335116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestExtensions(self):
336116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("extensions", "extensions_unittests")
337116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestFFmpeg(self):
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "ffmpeg_unittests")
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestFFmpegRegressions(self):
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "ffmpeg_regression_tests")
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  def TestGCM(self):
3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return self.SimpleTest("gcm", "gcm_unit_tests")
3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
347116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestGfx(self):
348116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("gfx", "gfx_unittests")
349116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
350116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestGin(self):
351116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("gin", "gin_unittests")
352116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
353116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestGoogleApis(self):
354116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("google_apis", "google_apis_unittests")
355116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestGPU(self):
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("gpu", "gpu_unittests")
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestIpc(self):
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("ipc", "ipc_tests",
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           valgrind_test_args=["--trace_children"])
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
363116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestInstallerUtil(self):
364116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("installer_util", "installer_util_unittests")
365116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestJingle(self):
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "jingle_unittests")
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
369116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestKeyboard(self):
370116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("keyboard", "keyboard_unittests")
371116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestMedia(self):
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "media_unittests")
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  def TestMessageCenter(self):
376eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return self.SimpleTest("message_center", "message_center_unittests")
377eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
378116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoAppsJS(self):
379116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_apps_js", "mojo_apps_js_unittests")
380116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
381116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoCommon(self):
382116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_common", "mojo_common_unittests")
383116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
384116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoJS(self):
385116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_js", "mojo_js_unittests")
386116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
387116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoPublicBindings(self):
388116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_public_bindings",
389116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                           "mojo_public_bindings_unittests")
390116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
391116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoPublicEnv(self):
392116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_public_env",
393116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                           "mojo_public_environment_unittests")
394116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
395116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoPublicSystem(self):
396116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_public_system",
397116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                           "mojo_public_system_unittests")
398116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
399116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoPublicSysPerf(self):
400116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_public_sysperf",
401116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                           "mojo_public_system_perftests")
402116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
403116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoPublicUtility(self):
404116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_public_utility",
405116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                           "mojo_public_utility_unittests")
406116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
4076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  def TestMojoApplicationManager(self):
4086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    return self.SimpleTest("mojo_application_manager",
4096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                           "mojo_application_manager_unittests")
410116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
411116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoSystem(self):
412116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_system", "mojo_system_unittests")
413116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
414116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestMojoViewManager(self):
415116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("mojo_view_manager", "mojo_view_manager_unittests")
416116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestNet(self):
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("net", "net_unittests")
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
42090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  def TestNetPerf(self):
42190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return self.SimpleTest("net", "net_perftests")
42290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
423116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  def TestPhoneNumber(self):
424116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return self.SimpleTest("phonenumber", "libphonenumber_unittests")
425116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestPPAPI(self):
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "ppapi_unittests")
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestPrinting(self):
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "printing_unittests")
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestRemoting(self):
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "remoting_unittests",
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           cmd_args=[
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               "--ui-test-action-timeout=60000",
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               "--ui-test-action-max-timeout=150000"])
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestSql(self):
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "sql_unittests")
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestSync(self):
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "sync_unit_tests")
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  def TestLinuxSandbox(self):
4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return self.SimpleTest("sandbox", "sandbox_linux_unittests")
4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestUnit(self):
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # http://crbug.com/51716
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Disabling all unit tests
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Problems reappeared after r119922
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if common.IsMac() and (self._options.valgrind_tool == "memcheck"):
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      logging.warning("unit_tests are disabled for memcheck on MacOS.")
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return 0;
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "unit_tests")
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestUIUnit(self):
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "ui_unittests")
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  def TestURL(self):
4607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return self.SimpleTest("chrome", "url_unittests")
4617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestViews(self):
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("views", "views_unittests")
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4656d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # Valgrind timeouts are in seconds.
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UI_VALGRIND_ARGS = ["--timeout=14400", "--trace_children", "--indirect"]
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # UI test timeouts are in milliseconds.
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UI_TEST_ARGS = ["--ui-test-action-timeout=60000",
4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  "--ui-test-action-max-timeout=150000",
4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  "--no-sandbox"]
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # TODO(thestig) fine-tune these values.
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # Valgrind timeouts are in seconds.
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BROWSER_VALGRIND_ARGS = ["--timeout=50000", "--trace_children", "--indirect"]
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # Browser test timeouts are in milliseconds.
477eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  BROWSER_TEST_ARGS = ["--ui-test-action-timeout=400000",
478eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                       "--ui-test-action-max-timeout=800000",
4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       "--no-sandbox"]
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestBrowser(self):
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "browser_tests",
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           valgrind_test_args=self.BROWSER_VALGRIND_ARGS,
4840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                           cmd_args=self.BROWSER_TEST_ARGS)
4850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
4860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  def TestContentBrowser(self):
4870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return self.SimpleTest("content", "content_browsertests",
4880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                           valgrind_test_args=self.BROWSER_VALGRIND_ARGS,
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           cmd_args=self.BROWSER_TEST_ARGS)
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestInteractiveUI(self):
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "interactive_ui_tests",
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           valgrind_test_args=self.UI_VALGRIND_ARGS,
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           cmd_args=self.UI_TEST_ARGS)
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestSafeBrowsing(self):
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "safe_browsing_tests",
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           valgrind_test_args=self.UI_VALGRIND_ARGS,
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           cmd_args=(["--ui-test-action-max-timeout=450000"]))
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestSyncIntegration(self):
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return self.SimpleTest("chrome", "sync_integration_tests",
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           valgrind_test_args=self.UI_VALGRIND_ARGS,
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           cmd_args=(["--ui-test-action-max-timeout=450000"]))
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestLayoutChunk(self, chunk_num, chunk_size):
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Run tests [chunk_num*chunk_size .. (chunk_num+1)*chunk_size) from the
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # list of tests.  Wrap around to beginning of list at end.
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # If chunk_size is zero, run all tests in the list once.
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # If a text file is given as argument, it is used as the list of tests.
5115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    assert((chunk_size == 0) != (len(self._args) == 0))
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Build the ginormous commandline in 'cmd'.
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # It's going to be roughly
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    #  python valgrind_test.py ... python run_webkit_tests.py ...
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # but we'll use the --indirect flag to valgrind_test.py
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # to avoid valgrinding python.
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Start by building the valgrind_test.py commandline.
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    tool = valgrind_test.CreateTool(self._options.valgrind_tool)
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd = self._DefaultCommand(tool)
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd.append("--trace_children")
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd.append("--indirect_webkit_layout")
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd.append("--ignore_exit_code")
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Now build script_cmd, the run_webkits_tests.py commandline
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Store each chunk in its own directory so that we can find the data later
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    chunk_dir = os.path.join("layout", "chunk_%05d" % chunk_num)
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    out_dir = os.path.join(path_utils.ScriptDir(), "latest")
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    out_dir = os.path.join(out_dir, chunk_dir)
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if os.path.exists(out_dir):
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      old_files = glob.glob(os.path.join(out_dir, "*.txt"))
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      for f in old_files:
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        os.remove(f)
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    else:
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      os.makedirs(out_dir)
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    script = os.path.join(self._source_dir, "webkit", "tools", "layout_tests",
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          "run_webkit_tests.py")
5367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    # http://crbug.com/260627: After the switch to content_shell from DRT, each
5377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    # test now brings up 3 processes.  Under Valgrind, they become memory bound
5387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    # and can eventually OOM if we don't reduce the total count.
5395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    # It'd be nice if content_shell automatically throttled the startup of new
5405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    # tests if we're low on memory.
5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    jobs = max(1, int(multiprocessing.cpu_count() * 0.3))
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    script_cmd = ["python", script, "-v",
543010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                  # run a separate DumpRenderTree for each test
544010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                  "--batch-size=1",
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  "--fully-parallel",
5467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                  "--child-processes=%d" % jobs,
547010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                  "--time-out-ms=800000",
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  "--no-retry-failures",  # retrying takes too much time
5492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  # http://crbug.com/176908: Don't launch a browser when done.
5502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  "--no-show-results",
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  "--nocheck-sys-deps"]
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Pass build mode to run_webkit_tests.py.  We aren't passed it directly,
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # so parse it out of build_dir.  run_webkit_tests.py can only handle
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # the two values "Release" and "Debug".
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # TODO(Hercules): unify how all our scripts pass around build mode
5564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    # (--mode / --target / --build-dir / --debug)
5573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    if self._options.build_dir:
5583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      build_root, mode = os.path.split(self._options.build_dir)
5593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      script_cmd.extend(["--build-directory", build_root, "--target", mode])
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (chunk_size > 0):
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      script_cmd.append("--run-chunk=%d:%d" % (chunk_num, chunk_size))
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if len(self._args):
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      # if the arg is a txt file, then treat it as a list of tests
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if os.path.isfile(self._args[0]) and self._args[0][-4:] == ".txt":
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        script_cmd.append("--test-list=%s" % self._args[0])
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      else:
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        script_cmd.extend(self._args)
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._AppendGtestFilter(tool, "layout", script_cmd)
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Now run script_cmd with the wrapper in cmd
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd.extend(["--"])
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cmd.extend(script_cmd)
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Layout tests often times fail quickly, but the buildbot remains green.
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Detect this situation when running with the default chunk size.
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if chunk_size == self.LAYOUT_TESTS_DEFAULT_CHUNK_SIZE:
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      min_runtime_in_seconds=120
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    else:
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      min_runtime_in_seconds=0
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ret = tool.Run(cmd, "layout", min_runtime_in_seconds=min_runtime_in_seconds)
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return ret
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def TestLayout(self):
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # A "chunk file" is maintained in the local directory so that each test
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # runs a slice of the layout tests of size chunk_size that increments with
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # each run.  Since tests can be added and removed from the layout tests at
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # any time, this is not going to give exact coverage, but it will allow us
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # to continuously run small slices of the layout tests under valgrind rather
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # than having to run all of them in one shot.
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    chunk_size = self._options.num_tests
5915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    if chunk_size == 0 or len(self._args):
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return self.TestLayoutChunk(0, 0)
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    chunk_num = 0
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    chunk_file = os.path.join("valgrind_layout_chunk.txt")
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    logging.info("Reading state from " + chunk_file)
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    try:
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      f = open(chunk_file)
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if f:
599010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        chunk_str = f.read()
600010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        if len(chunk_str):
601010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          chunk_num = int(chunk_str)
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        # This should be enough so that we have a couple of complete runs
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        # of test data stored in the archive (although note that when we loop
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        # that we almost guaranteed won't be at the end of the test list)
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if chunk_num > 10000:
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          chunk_num = 0
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        f.close()
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    except IOError, (errno, strerror):
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      logging.error("error reading from file %s (%d, %s)" % (chunk_file,
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    errno, strerror))
6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    # Save the new chunk size before running the tests. Otherwise if a
6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    # particular chunk hangs the bot, the chunk number will never get
6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    # incremented and the bot will be wedged.
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    logging.info("Saving state to " + chunk_file)
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    try:
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      f = open(chunk_file, "w")
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chunk_num += 1
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      f.write("%d" % chunk_num)
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      f.close()
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    except IOError, (errno, strerror):
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      logging.error("error writing to file %s (%d, %s)" % (chunk_file, errno,
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    strerror))
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # Since we're running small chunks of the layout tests, it's important to
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # mark the ones that have errors in them.  These won't be visible in the
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # summary list for long, but will be useful for someone reviewing this bot.
6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return self.TestLayoutChunk(chunk_num, chunk_size)
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # The known list of tests.
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # Recognise the original abbreviations as well as full executable names.
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  _test_list = {
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "cmdline" : RunCmdLine,
632116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "addressinput": TestAddressInput,
633116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "libaddressinput_unittests": TestAddressInput,
634116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "accessibility": TestAccessibility,
635116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "angle": TestAngle,          "angle_unittests": TestAngle,
636eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    "app_list": TestAppList,     "app_list_unittests": TestAppList,
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "ash": TestAsh,              "ash_unittests": TestAsh,
638116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "ash_shell": TestAshShell,   "ash_shell_unittests": TestAshShell,
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "aura": TestAura,            "aura_unittests": TestAura,
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "base": TestBase,            "base_unittests": TestBase,
641116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "blink_heap": TestBlinkHeap,
642116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "blink_platform": TestBlinkPlatform,
6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "browser": TestBrowser,      "browser_tests": TestBrowser,
644116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "cacheinvalidation": TestCacheInvalidation,
645116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "cacheinvalidation_unittests": TestCacheInvalidation,
6465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    "cast": TestCast,            "cast_unittests": TestCast,
647116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "cc": TestCC,                "cc_unittests": TestCC,
648116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "chrome_app": TestChromeApp,
649116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "chrome_elf": TestChromeElf,
650116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "chromedriver": TestChromeDriver,
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "chromeos": TestChromeOS,    "chromeos_unittests": TestChromeOS,
652116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "cloud_print": TestCloudPrint,
653116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "cloud_print_unittests": TestCloudPrint,
6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "components": TestComponents,"components_unittests": TestComponents,
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "compositor": TestCompositor,"compositor_unittests": TestCompositor,
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "content": TestContent,      "content_unittests": TestContent,
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "content_browsertests": TestContentBrowser,
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "courgette": TestCourgette,  "courgette_unittests": TestCourgette,
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "crypto": TestCrypto,        "crypto_unittests": TestCrypto,
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "device": TestDevice,        "device_unittests": TestDevice,
661116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "display": TestDisplay,      "display_unittests": TestDisplay,
662f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    "events": TestEvents,        "events_unittests": TestEvents,
6636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    "extensions": TestExtensions, "extensions_unittests": TestExtensions,
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "ffmpeg": TestFFmpeg,        "ffmpeg_unittests": TestFFmpeg,
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "ffmpeg_regression_tests": TestFFmpegRegressions,
6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    "gcm": TestGCM,              "gcm_unit_tests": TestGCM,
667116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "gin": TestGin,              "gin_unittests": TestGin,
668116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "gfx": TestGfx,              "gfx_unittests": TestGfx,
669116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "google_apis": TestGoogleApis,
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "gpu": TestGPU,              "gpu_unittests": TestGPU,
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "ipc": TestIpc,              "ipc_tests": TestIpc,
672116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "installer_util": TestInstallerUtil,
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "interactive_ui": TestInteractiveUI,
6747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "jingle": TestJingle,        "jingle_unittests": TestJingle,
675116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "keyboard": TestKeyboard,    "keyboard_unittests": TestKeyboard,
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "layout": TestLayout,        "layout_tests": TestLayout,
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "media": TestMedia,          "media_unittests": TestMedia,
678eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    "message_center": TestMessageCenter,
679eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    "message_center_unittests" : TestMessageCenter,
680116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_apps_js": TestMojoAppsJS,
681116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_common": TestMojoCommon,
682116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_js": TestMojoJS,
683116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_system": TestMojoSystem,
684116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_public_system": TestMojoPublicSystem,
685116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_public_utility": TestMojoPublicUtility,
686116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_public_bindings": TestMojoPublicBindings,
687116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_public_env": TestMojoPublicEnv,
688116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_public_sysperf": TestMojoPublicSysPerf,
6896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    "mojo_application_manager": TestMojoApplicationManager,
690116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "mojo_view_manager": TestMojoViewManager,
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "net": TestNet,              "net_unittests": TestNet,
69290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    "net_perf": TestNetPerf,     "net_perftests": TestNetPerf,
693116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "phonenumber": TestPhoneNumber,
694116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "libphonenumber_unittests": TestPhoneNumber,
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "ppapi": TestPPAPI,          "ppapi_unittests": TestPPAPI,
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "printing": TestPrinting,    "printing_unittests": TestPrinting,
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "remoting": TestRemoting,    "remoting_unittests": TestRemoting,
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "safe_browsing": TestSafeBrowsing, "safe_browsing_tests": TestSafeBrowsing,
6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "sandbox": TestLinuxSandbox, "sandbox_linux_unittests": TestLinuxSandbox,
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "sql": TestSql,              "sql_unittests": TestSql,
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "sync": TestSync,            "sync_unit_tests": TestSync,
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "sync_integration_tests": TestSyncIntegration,
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "sync_integration": TestSyncIntegration,
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "ui_unit": TestUIUnit,       "ui_unittests": TestUIUnit,
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "unit": TestUnit,            "unit_tests": TestUnit,
7067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "url": TestURL,              "url_unittests": TestURL,
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "views": TestViews,          "views_unittests": TestViews,
708116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    "webkit": TestLayout,
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)def _main():
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  parser = optparse.OptionParser("usage: %prog -b <dir> -t <test> "
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 "[-t <test> ...]")
7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("--help-tests", dest="help_tests", action="store_true",
7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    default=False, help="List all available tests")
7184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("-b", "--build-dir",
7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="the location of the compiler output")
7204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("--target", help="Debug or Release")
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  parser.add_option("-t", "--test", action="append", default=[],
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="which test to run, supports test:gtest_filter format "
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         "as well.")
7244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("--baseline", action="store_true", default=False,
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="generate baseline data instead of validating")
7264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("--gtest_filter",
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="additional arguments to --gtest_filter")
7284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("--gtest_repeat", help="argument for --gtest_repeat")
729f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  parser.add_option("--gtest_shuffle", action="store_true", default=False,
730f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                    help="Randomize tests' orders on every iteration.")
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  parser.add_option("-v", "--verbose", action="store_true", default=False,
7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="verbose output - enable debug log messages")
7334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("--tool", dest="valgrind_tool", default="memcheck",
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="specify a valgrind tool to run the tests under")
7354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("--tool_flags", dest="valgrind_tool_flags", default="",
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="specify custom flags for the selected valgrind tool")
7374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("--keep_logs", action="store_true", default=False,
7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="store memory tool logs in the <tool>.logs directory "
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         "instead of /tmp.\nThis can be useful for tool "
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         "developers/maintainers.\nPlease note that the <tool>"
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         ".logs directory will be clobbered on tool startup.")
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  parser.add_option("-n", "--num_tests", type="int",
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    default=ChromeTests.LAYOUT_TESTS_DEFAULT_CHUNK_SIZE,
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="for layout tests: # of subtests per run.  0 for all.")
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # TODO(thestig) Remove this if we can.
7464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  parser.add_option("--gtest_color", dest="gtest_color", default="no",
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    help="dummy compatibility flag for sharding_supervisor.")
7485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  parser.add_option("--brave-new-test-launcher", action="store_true",
7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    help="run the tests with --brave-new-test-launcher")
7505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  parser.add_option("--test-launcher-bot-mode", action="store_true",
7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    help="run the tests with --test-launcher-bot-mode")
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  options, args = parser.parse_args()
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  # Bake target into build_dir.
7561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if options.target and options.build_dir:
7571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    assert (options.target !=
7581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            os.path.basename(os.path.dirname(options.build_dir)))
7591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    options.build_dir = os.path.join(os.path.abspath(options.build_dir),
7601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                     options.target)
7614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if options.verbose:
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    logging_utils.config_root(logging.DEBUG)
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  else:
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    logging_utils.config_root()
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if options.help_tests:
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ChromeTests.ShowTests()
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return 0
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if not options.test:
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    parser.error("--test not specified")
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if len(options.test) != 1 and options.gtest_filter:
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    parser.error("--gtest_filter and multiple tests don't make sense together")
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for t in options.test:
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    tests = ChromeTests(options, args, t)
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ret = tests.Run()
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if ret: return ret
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return 0
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)if __name__ == "__main__":
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  sys.exit(_main())
786