OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # valgrind_test.py | 6 # valgrind_test.py |
7 | 7 |
8 """Runs an exe through Valgrind and puts the intermediate files in a | 8 """Runs an exe through Valgrind and puts the intermediate files in a |
9 directory. | 9 directory. |
10 """ | 10 """ |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 ret = cmd2.Main(args, check_sanity) | 953 ret = cmd2.Main(args, check_sanity) |
954 else: | 954 else: |
955 logging.info("No reports, skipping RaceVerifier second pass") | 955 logging.info("No reports, skipping RaceVerifier second pass") |
956 logging.info("Please see " + self.MORE_INFO_URL + " for more information " + | 956 logging.info("Please see " + self.MORE_INFO_URL + " for more information " + |
957 "on RaceVerifier") | 957 "on RaceVerifier") |
958 return ret | 958 return ret |
959 | 959 |
960 def Run(self, args, module): | 960 def Run(self, args, module): |
961 return self.Main(args, False) | 961 return self.Main(args, False) |
962 | 962 |
| 963 class EmbeddedTool(BaseTool): |
| 964 """Abstract class for tools embedded directly into the test binary.""" |
| 965 def __init__(self): |
| 966 super(EmbeddedTool, self).__init__() |
| 967 self._env = {} |
| 968 |
| 969 def ToolCommand(self): |
| 970 """Basically just the args of the script.""" |
| 971 return self._args |
| 972 |
| 973 def NeedsPipes(self): |
| 974 """True iff the tool needs to chain several subprocesses.""" |
| 975 raise NotImplementedError, "This method should be implemented " \ |
| 976 "in the tool-specific subclass" |
| 977 |
| 978 def Execute(self): |
| 979 """Executes the app to be tested.""" |
| 980 for var in self._env: |
| 981 self.PutEnvAndLog(var, self._env[var]) |
| 982 proc = self.ToolCommand() |
| 983 logging.info('starting execution...') |
| 984 if self.NeedsPipes(): |
| 985 return common.RunSubprocessChain(proc, self._timeout) |
| 986 else: |
| 987 return common.RunSubprocess(proc, self._timeout) |
| 988 |
| 989 def PutEnvAndLog(self, env_name, env_value): |
| 990 """Sets the env var |env_name| to |env_value| and writes to logging.info. |
| 991 """ |
| 992 os.putenv(env_name, env_value) |
| 993 logging.info('export %s=%s', env_name, env_value) |
| 994 |
| 995 |
| 996 class Asan(EmbeddedTool): |
| 997 def __init__(self): |
| 998 super(Asan, self).__init__() |
| 999 self._timeout = 1200 |
| 1000 |
| 1001 def ToolName(self): |
| 1002 return "asan" |
| 1003 |
| 1004 def NeedsPipes(self): |
| 1005 return True |
| 1006 |
| 1007 def ToolCommand(self): |
| 1008 procs = [self._args] |
| 1009 procs.append([os.path.join(self._source_dir, "third_party", "asan", |
| 1010 "scripts", "asan_symbolize.py")]) |
| 1011 procs.append(["c++filt"]) |
| 1012 return procs |
| 1013 |
| 1014 def Analyze(sels, unused_check_sanity): |
| 1015 return 0 |
963 | 1016 |
964 class ToolFactory: | 1017 class ToolFactory: |
965 def Create(self, tool_name): | 1018 def Create(self, tool_name): |
966 if tool_name == "memcheck": | 1019 if tool_name == "memcheck": |
967 return Memcheck() | 1020 return Memcheck() |
968 if tool_name == "tsan": | 1021 if tool_name == "tsan": |
969 if common.IsWindows(): | 1022 if common.IsWindows(): |
970 return ThreadSanitizerWindows() | 1023 return ThreadSanitizerWindows() |
971 else: | 1024 else: |
972 return ThreadSanitizerPosix() | 1025 return ThreadSanitizerPosix() |
973 if tool_name == "drmemory": | 1026 if tool_name == "drmemory": |
974 return DrMemory() | 1027 return DrMemory() |
975 if tool_name == "tsan_rv": | 1028 if tool_name == "tsan_rv": |
976 return RaceVerifier() | 1029 return RaceVerifier() |
| 1030 if tool_name == "asan": |
| 1031 return Asan() |
977 try: | 1032 try: |
978 platform_name = common.PlatformNames()[0] | 1033 platform_name = common.PlatformNames()[0] |
979 except common.NotImplementedError: | 1034 except common.NotImplementedError: |
980 platform_name = sys.platform + "(Unknown)" | 1035 platform_name = sys.platform + "(Unknown)" |
981 raise RuntimeError, "Unknown tool (tool=%s, platform=%s)" % (tool_name, | 1036 raise RuntimeError, "Unknown tool (tool=%s, platform=%s)" % (tool_name, |
982 platform_name) | 1037 platform_name) |
983 | 1038 |
984 def CreateTool(tool): | 1039 def CreateTool(tool): |
985 return ToolFactory().Create(tool) | 1040 return ToolFactory().Create(tool) |
986 | 1041 |
987 if __name__ == '__main__': | 1042 if __name__ == '__main__': |
988 logging.error(sys.argv[0] + " can not be run from command line") | 1043 logging.error(sys.argv[0] + " can not be run from command line") |
989 sys.exit(1) | 1044 sys.exit(1) |
OLD | NEW |