def Create(self, tool_name): if tool_name == "memcheck": return Memcheck() if tool_name == "tsan": if common.IsWindows(): return ThreadSanitizerWindows() else: return ThreadSanitizerPosix() if tool_name == "drmemory" or tool_name == "drmemory_light": # TODO(timurrrr): remove support for "drmemory" when buildbots are # switched to drmemory_light OR make drmemory==drmemory_full the default # mode when the tool is mature enough. return DrMemory(False, False) if tool_name == "drmemory_full": return DrMemory(True, False) if tool_name == "drmemory_pattern": return DrMemory(False, True) if tool_name == "tsan_rv": return RaceVerifier() if tool_name == "asan": return Asan() try: platform_name = common.PlatformNames()[0] except common.NotImplementedError: platform_name = sys.platform + "(Unknown)" raise RuntimeError, "Unknown tool (tool=%s, platform=%s)" % (tool_name, platform_name)
def Create(self, tool_name): if tool_name == "memcheck": return Memcheck() try: platform_name = common.PlatformNames()[0] except common.NotImplementedError: platform_name = sys.platform + "(Unknown)" raise RuntimeError, "Unknown tool (tool=%s, platform=%s)" % (tool_name, platform_name)
def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None): '''Generates the default command array that most tests will use.''' if exe and common.IsWindows(): exe += '.exe' cmd = list(self._command_preamble) # Find all suppressions matching the following pattern: # tools/valgrind/TOOL/suppressions[_PLATFORM].txt # and list them with --suppressions= prefix. script_dir = path_utils.ScriptDir() suppression_file = os.path.join(script_dir, "..", "suppressions.txt") if os.path.exists(suppression_file): cmd.append("--suppressions=%s" % suppression_file) # Platform-specific suppression for platform in common.PlatformNames(): platform_suppression_file = \ os.path.join(script_dir, "..", 'suppressions_%s.txt' % platform) if os.path.exists(platform_suppression_file): cmd.append("--suppressions=%s" % platform_suppression_file) if self._options.valgrind_tool_flags: cmd += self._options.valgrind_tool_flags.split(" ") if self._options.keep_logs: cmd += ["--keep_logs"] if valgrind_test_args != None: for arg in valgrind_test_args: cmd.append(arg) if exe: self._EnsureBuildDirFound() exe_path = os.path.join(self._options.build_dir, exe) if not os.path.exists(exe_path): raise ExecutableNotFound("Couldn't find '%s'" % exe_path) cmd.append(exe_path) # Valgrind runs tests slowly, so slow tests hurt more; show elapased time # so we can find the slowpokes. cmd.append("--gtest_print_time") # Built-in test launcher for gtest-based executables runs tests using # multiple process by default. Force the single-process mode back. cmd.append("--single-process-tests") if self._options.gtest_repeat: cmd.append("--gtest_repeat=%s" % self._options.gtest_repeat) if self._options.gtest_shuffle: cmd.append("--gtest_shuffle") if self._options.gtest_break_on_failure: cmd.append("--gtest_break_on_failure") if self._options.test_launcher_bot_mode: cmd.append("--test-launcher-bot-mode") if self._options.test_launcher_total_shards is not None: cmd.append("--test-launcher-total-shards=%d" % self._options.test_launcher_total_shards) if self._options.test_launcher_shard_index is not None: cmd.append("--test-launcher-shard-index=%d" % self._options.test_launcher_shard_index) return cmd
def _DefaultCommand(self, tool, module, exe=None, valgrind_test_args=None): '''Generates the default command array that most tests will use.''' if exe and common.IsWindows(): exe = exe + '.exe' if not self._options.build_dir: if common.IsWine(): self._options.build_dir = os.path.join( self._source_dir, "chrome", "Debug") else: dirs = [ os.path.join(self._source_dir, "xcodebuild", "Debug"), os.path.join(self._source_dir, "out", "Debug"), os.path.join(self._source_dir, "build", "Debug"), ] if exe: self._options.build_dir = FindDirContainingNewestFile(dirs, exe) else: self._options.build_dir = FindNewestDir(dirs) cmd = list(self._command_preamble) # Find all suppressions matching the following pattern: # tools/valgrind/TOOL/suppressions[_PLATFORM].txt # and list them with --suppressions= prefix. script_dir = path_utils.ScriptDir() tool_name = tool.ToolName(); suppression_file = os.path.join(script_dir, tool_name, "suppressions.txt") if os.path.exists(suppression_file): cmd.append("--suppressions=%s" % suppression_file) # Platform-specific suppression for platform in common.PlatformNames(): platform_suppression_file = \ os.path.join(script_dir, tool_name, 'suppressions_%s.txt' % platform) if os.path.exists(platform_suppression_file): cmd.append("--suppressions=%s" % platform_suppression_file) if self._options.valgrind_tool_flags: cmd += self._options.valgrind_tool_flags.split(" ") if valgrind_test_args != None: for arg in valgrind_test_args: cmd.append(arg) if exe: if common.IsWine(): cmd.append(os.environ.get('WINE')) exe = exe + '.exe' cmd.append(os.path.join(self._options.build_dir, exe)) # Valgrind runs tests slowly, so slow tests hurt more; show elapased time # so we can find the slowpokes. cmd.append("--gtest_print_time") if self._options.gtest_repeat: cmd.append("--gtest_repeat=%s" % self._options.gtest_repeat) return cmd
def ToolSpecificFlags(self): ret = [] ignore_files = ["ignores.txt"] for platform_suffix in common.PlatformNames(): ignore_files.append("ignores_%s.txt" % platform_suffix) for ignore_file in ignore_files: fullname = os.path.join(self._source_dir, "tools", "valgrind", "tsan", ignore_file) if os.path.exists(fullname): ret += ["--ignore=%s" % fullname] # This should shorten filepaths for local builds. ret += ["--file-prefix-to-cut=%s/" % self._source_dir] # This should shorten filepaths on bots. ret += ["--file-prefix-to-cut=build/src/"] # This should shorten filepaths for functions intercepted in TSan. ret += ["--file-prefix-to-cut=scripts/tsan/tsan/"] ret += ["--gen-suppressions=true"] if self.EvalBoolFlag(self._options.hybrid): ret += ["--hybrid=yes"] # "no" is the default value for TSAN if self.EvalBoolFlag(self._options.announce_threads): ret += ["--announce-threads"] if self.EvalBoolFlag(self._options.free_is_write): ret += ["--free-is-write=yes"] else: ret += ["--free-is-write=no"] # --show-pc flag is needed for parsing the error logs on Darwin. if platform_suffix == 'mac': ret += ["--show-pc=yes"] ret += ["--show-pid=no"] # Don't show googletest frames in stacks. # TODO(timurrrr): we should have an array of functions (since used by # different tools in different formats and .join it ret += ["--cut_stack_below=testing*Test*Run*"] ret += [ "--cut_stack_below=testing*Handle*ExceptionsInMethodIfSupported" ] ret += ["--cut_stack_below=MessageLoop*Run"] ret += ["--cut_stack_below=RunnableMethod*"] ret += ["--cut_stack_below=RunnableFunction*"] ret += ["--cut_stack_below=DispatchToMethod*"] return ret
def ToolSpecificFlags(self): ret = [] ignore_files = ["ignores.txt"] for platform_suffix in common.PlatformNames(): ignore_files.append("ignores_%s.txt" % platform_suffix) for ignore_file in ignore_files: fullname = os.path.join(self._source_dir, "tools", "valgrind", "tsan", ignore_file) if os.path.exists(fullname): fullname = common.NormalizeWindowsPath(fullname) ret += ["--ignore=%s" % fullname] # This should shorten filepaths for local builds. ret += ["--file-prefix-to-cut=%s/" % self._source_dir] # This should shorten filepaths on bots. ret += ["--file-prefix-to-cut=build/src/"] ret += ["--file-prefix-to-cut=out/Release/../../"] # This should shorten filepaths for functions intercepted in TSan. ret += ["--file-prefix-to-cut=scripts/tsan/tsan/"] ret += ["--file-prefix-to-cut=src/tsan/tsan/"] ret += ["--gen-suppressions=true"] if self.EvalBoolFlag(self._options.hybrid): ret += ["--hybrid=yes"] # "no" is the default value for TSAN if self.EvalBoolFlag(self._options.announce_threads): ret += ["--announce-threads"] if self.EvalBoolFlag(self._options.free_is_write): ret += ["--free-is-write=yes"] else: ret += ["--free-is-write=no"] # --show-pc flag is needed for parsing the error logs on Darwin. if platform_suffix == 'mac': ret += ["--show-pc=yes"] ret += ["--show-pid=no"] boring_callers = common.BoringCallers(mangled=False, use_re_wildcards=False) # TODO(timurrrr): In fact, we want "starting from .." instead of "below .." for bc in boring_callers: ret += ["--cut_stack_below=%s" % bc] return ret
def _ReadGtestFilterFile(self, tool, name, cmd): '''Read a file which is a list of tests to filter out with --gtest_filter and append the command-line option to cmd. ''' filters = [] gtest_files_dir = os.path.join(path_utils.ScriptDir(), "gtest_exclude") gtest_filter_files = [ os.path.join(gtest_files_dir, name + ".gtest.txt"), os.path.join(gtest_files_dir, name + ".gtest-%s.txt" % tool.ToolName())] for platform_suffix in common.PlatformNames(): gtest_filter_files += [ os.path.join(gtest_files_dir, name + ".gtest_%s.txt" % platform_suffix), os.path.join(gtest_files_dir, name + ".gtest-%s_%s.txt" % \ (tool.ToolName(), platform_suffix))] for filename in gtest_filter_files: if not os.path.exists(filename): logging.info("gtest filter file %s not found - skipping" % filename) continue logging.info("Reading gtest filters from %s" % filename) f = open(filename, 'r') for line in f.readlines(): if line.startswith("#") or line.startswith("//") or line.isspace(): continue line = line.rstrip() test_prefixes = ["FLAKY", "FAILS"] for p in test_prefixes: # Strip prefixes from the test names. line = line.replace(".%s_" % p, ".") # Exclude the original test name. filters.append(line) if line[-2:] != ".*": # List all possible prefixes if line doesn't end with ".*". for p in test_prefixes: filters.append(line.replace(".", ".%s_" % p)) # Get rid of duplicates. filters = set(filters) gtest_filter = self._gtest_filter if len(filters): if gtest_filter: gtest_filter += ":" if gtest_filter.find("-") < 0: gtest_filter += "-" else: gtest_filter = "-" gtest_filter += ":".join(filters) if gtest_filter: cmd.append("--gtest_filter=%s" % gtest_filter)
def Create(self, tool_name): if tool_name == "drmemory" or tool_name == "drmemory_light": # TODO(timurrrr): remove support for "drmemory" when buildbots are # switched to drmemory_light OR make drmemory==drmemory_full the default # mode when the tool is mature enough. return DrMemory(False, False) if tool_name == "drmemory_full": return DrMemory(True, False) if tool_name == "drmemory_pattern": return DrMemory(False, True) try: platform_name = common.PlatformNames()[0] except common.NotImplementedError: platform_name = sys.platform + "(Unknown)" raise RuntimeError, "Unknown tool (tool=%s, platform=%s)" % (tool_name, platform_name)
def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None): '''Generates the default command array that most tests will use.''' if exe and common.IsWindows(): exe += '.exe' cmd = list(self._command_preamble) # Find all suppressions matching the following pattern: # tools/valgrind/TOOL/suppressions[_PLATFORM].txt # and list them with --suppressions= prefix. script_dir = path_utils.ScriptDir() tool_name = tool.ToolName() suppression_file = os.path.join(script_dir, tool_name, "suppressions.txt") if os.path.exists(suppression_file): cmd.append("--suppressions=%s" % suppression_file) # Platform-specific suppression for platform in common.PlatformNames(): platform_suppression_file = \ os.path.join(script_dir, tool_name, 'suppressions_%s.txt' % platform) if os.path.exists(platform_suppression_file): cmd.append("--suppressions=%s" % platform_suppression_file) if self._options.valgrind_tool_flags: cmd += self._options.valgrind_tool_flags.split(" ") if self._options.keep_logs: cmd += ["--keep_logs"] if valgrind_test_args != None: for arg in valgrind_test_args: cmd.append(arg) if exe: self._EnsureBuildDirFound() cmd.append(os.path.join(self._options.build_dir, exe)) # Valgrind runs tests slowly, so slow tests hurt more; show elapased time # so we can find the slowpokes. cmd.append("--gtest_print_time") if self._options.gtest_repeat: cmd.append("--gtest_repeat=%s" % self._options.gtest_repeat) return cmd
def _AppendGtestFilter(self, tool, name, cmd): '''Append an appropriate --gtest_filter flag to the googletest binary invocation. If the user passed his own filter mentioning only one test, just use it. Othewise, filter out tests listed in the appropriate gtest_exclude files. ''' if (self._gtest_filter and ":" not in self._gtest_filter and "?" not in self._gtest_filter and "*" not in self._gtest_filter): cmd.append("--gtest_filter=%s" % self._gtest_filter) return filters = [] gtest_files_dir = os.path.join(path_utils.ScriptDir(), "gtest_exclude") gtest_filter_files = [ os.path.join(gtest_files_dir, name + ".gtest-%s.txt" % tool.ToolName()) ] # Use ".gtest.txt" files only for slow tools, as they now contain # Valgrind- and Dr.Memory-specific filters. # TODO(glider): rename the files to ".gtest_slow.txt" if tool.ToolName() in ChromeTests.SLOW_TOOLS: gtest_filter_files += [ os.path.join(gtest_files_dir, name + ".gtest.txt") ] for platform_suffix in common.PlatformNames(): gtest_filter_files += [ os.path.join(gtest_files_dir, name + ".gtest_%s.txt" % platform_suffix), os.path.join(gtest_files_dir, name + ".gtest-%s_%s.txt" % \ (tool.ToolName(), platform_suffix))] logging.info("Reading gtest exclude filter files:") for filename in gtest_filter_files: # strip the leading absolute path (may be very long on the bot) # and the following / or \. readable_filename = filename.replace("\\", "/") # '\' on Windows readable_filename = readable_filename.replace( self._source_dir, "")[1:] if not os.path.exists(filename): logging.info(" \"%s\" - not found" % readable_filename) continue logging.info(" \"%s\" - OK" % readable_filename) f = open(filename, 'r') for line in f.readlines(): if line.startswith("#") or line.startswith( "//") or line.isspace(): continue line = line.rstrip() test_prefixes = ["FLAKY", "FAILS"] for p in test_prefixes: # Strip prefixes from the test names. line = line.replace(".%s_" % p, ".") # Exclude the original test name. filters.append(line) if line[-2:] != ".*": # List all possible prefixes if line doesn't end with ".*". for p in test_prefixes: filters.append(line.replace(".", ".%s_" % p)) # Get rid of duplicates. filters = set(filters) gtest_filter = self._gtest_filter if len(filters): if gtest_filter: gtest_filter += ":" if gtest_filter.find("-") < 0: gtest_filter += "-" else: gtest_filter = "-" gtest_filter += ":".join(filters) if gtest_filter: cmd.append("--gtest_filter=%s" % gtest_filter)
def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None): '''Generates the default command array that most tests will use.''' if exe and common.IsWindows(): exe += '.exe' cmd = list(self._command_preamble) # Find all suppressions matching the following pattern: # tools/valgrind/TOOL/suppressions[_PLATFORM].txt # and list them with --suppressions= prefix. script_dir = path_utils.ScriptDir() tool_name = tool.ToolName() suppression_file = os.path.join(script_dir, tool_name, "suppressions.txt") if os.path.exists(suppression_file): cmd.append("--suppressions=%s" % suppression_file) # Platform-specific suppression for platform in common.PlatformNames(): platform_suppression_file = \ os.path.join(script_dir, tool_name, 'suppressions_%s.txt' % platform) if os.path.exists(platform_suppression_file): cmd.append("--suppressions=%s" % platform_suppression_file) if tool_name == "drmemory": if self._options.drmemory_ops: # prepending " " to avoid Dr. Memory's option confusing optparse cmd += ["--drmemory_ops", " " + self._options.drmemory_ops] if self._options.valgrind_tool_flags: cmd += self._options.valgrind_tool_flags.split(" ") if self._options.keep_logs: cmd += ["--keep_logs"] if valgrind_test_args != None: for arg in valgrind_test_args: cmd.append(arg) if exe: self._EnsureBuildDirFound() exe_path = os.path.join(self._options.build_dir, exe) if not os.path.exists(exe_path): raise ExecutableNotFound("Couldn't find '%s'" % exe_path) # Make sure we don't try to test ASan-built binaries # with other dynamic instrumentation-based tools. # TODO(timurrrr): also check TSan and MSan? # `nm` might not be available, so use try-except. try: # Do not perform this check on OS X, as 'nm' on 10.6 can't handle # binaries built with Clang 3.5+. if not common.IsMac(): nm_output = subprocess.check_output(["nm", exe_path]) if nm_output.find("__asan_init") != -1: raise BadBinary( "You're trying to run an executable instrumented " "with AddressSanitizer under %s. Please provide " "an uninstrumented executable." % tool_name) except OSError: pass cmd.append(exe_path) # Valgrind runs tests slowly, so slow tests hurt more; show elapased time # so we can find the slowpokes. cmd.append("--gtest_print_time") # Built-in test launcher for gtest-based executables runs tests using # multiple process by default. Force the single-process mode back. cmd.append("--single-process-tests") if self._options.gtest_repeat: cmd.append("--gtest_repeat=%s" % self._options.gtest_repeat) if self._options.gtest_shuffle: cmd.append("--gtest_shuffle") if self._options.gtest_break_on_failure: cmd.append("--gtest_break_on_failure") if self._options.test_launcher_bot_mode: cmd.append("--test-launcher-bot-mode") if self._options.test_launcher_total_shards is not None: cmd.append("--test-launcher-total-shards=%d" % self._options.test_launcher_total_shards) if self._options.test_launcher_shard_index is not None: cmd.append("--test-launcher-shard-index=%d" % self._options.test_launcher_shard_index) return cmd