OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 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 # purify_test.py | 6 # purify_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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 common.RunSubprocess(proc, self._timeout) | 129 common.RunSubprocess(proc, self._timeout) |
130 | 130 |
131 # Always return true, even if running the subprocess failed. We depend on | 131 # Always return true, even if running the subprocess failed. We depend on |
132 # Analyze to determine if the run was valid. (This behaviour copied from | 132 # Analyze to determine if the run was valid. (This behaviour copied from |
133 # the purify_test.py script.) | 133 # the purify_test.py script.) |
134 return True | 134 return True |
135 | 135 |
136 def Analyze(self): | 136 def Analyze(self): |
137 # Glob all the files in the "valgrind.tmp" directory | 137 # Glob all the files in the "valgrind.tmp" directory |
138 filenames = glob.glob(self.TMP_DIR + "/valgrind.*") | 138 filenames = glob.glob(self.TMP_DIR + "/valgrind.*") |
| 139 # TODO(dkegel): use new xml suppressions feature when it lands |
| 140 if self._generate_suppressions: |
| 141 # Just concatenate all the output files. Lame... |
| 142 for filename in filenames: |
| 143 print "## %s" % filename |
| 144 f = file(filename) |
| 145 while True: |
| 146 line = f.readline() |
| 147 if len(line) == 0: |
| 148 break |
| 149 print line, # comma means don't add newline |
| 150 f.close() |
| 151 return 0 |
139 analyzer = valgrind_analyze.ValgrindAnalyze(self._source_dir, filenames, sel
f._options.show_all_leaks) | 152 analyzer = valgrind_analyze.ValgrindAnalyze(self._source_dir, filenames, sel
f._options.show_all_leaks) |
140 return analyzer.Report() | 153 return analyzer.Report() |
141 | 154 |
142 def Cleanup(self): | 155 def Cleanup(self): |
143 # Right now, we can cleanup by deleting our temporary directory. Other | 156 # Right now, we can cleanup by deleting our temporary directory. Other |
144 # cleanup is still a TODO? | 157 # cleanup is still a TODO? |
145 shutil.rmtree(self.TMP_DIR) | 158 shutil.rmtree(self.TMP_DIR) |
146 return True | 159 return True |
147 | 160 |
148 def RunTestsAndAnalyze(self): | 161 def RunTestsAndAnalyze(self): |
149 self.PrepareForTest() | 162 self.PrepareForTest() |
150 self.Execute() | 163 self.Execute() |
151 if self._generate_suppressions: | |
152 logging.info("Skipping analysis to let you look at the raw output...") | |
153 return 0 | |
154 | 164 |
155 retcode = self.Analyze() | 165 retcode = self.Analyze() |
156 if retcode: | 166 if retcode: |
157 logging.error("Analyze failed.") | 167 logging.error("Analyze failed.") |
158 return retcode | 168 return retcode |
159 logging.info("Execution and analysis completed successfully.") | 169 logging.info("Execution and analysis completed successfully.") |
160 return 0 | 170 return 0 |
161 | 171 |
162 def Main(self): | 172 def Main(self): |
163 '''Call this to run through the whole process: Setup, Execute, Analyze''' | 173 '''Call this to run through the whole process: Setup, Execute, Analyze''' |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 227 |
218 suppression_count = 0 | 228 suppression_count = 0 |
219 for suppression_file in self._suppressions: | 229 for suppression_file in self._suppressions: |
220 if os.path.exists(suppression_file): | 230 if os.path.exists(suppression_file): |
221 suppression_count += 1 | 231 suppression_count += 1 |
222 proc += ["--suppressions=%s" % suppression_file] | 232 proc += ["--suppressions=%s" % suppression_file] |
223 | 233 |
224 if not suppression_count: | 234 if not suppression_count: |
225 logging.warning("WARNING: NOT USING SUPPRESSIONS!") | 235 logging.warning("WARNING: NOT USING SUPPRESSIONS!") |
226 | 236 |
227 if not self._generate_suppressions: | 237 proc += ["--log-file=" + self.TMP_DIR + "/valgrind.%p"] |
228 # We don't currently collect suppressions from individual log files, | 238 |
229 # so let it all go to stdout. This leads to occasional | |
230 # corruption; see above TODO. | |
231 proc += ["--log-file=" + self.TMP_DIR + "/valgrind.%p"] | |
232 # The Valgrind command is constructed. | 239 # The Valgrind command is constructed. |
233 | 240 |
234 if self._options.indirect: | 241 if self._options.indirect: |
235 # The program being run invokes Python or something else | 242 # The program being run invokes Python or something else |
236 # that can't stand to be valgrinded, and also invokes | 243 # that can't stand to be valgrinded, and also invokes |
237 # the Chrome browser. Set an environment variable to | 244 # the Chrome browser. Set an environment variable to |
238 # tell the program to prefix the Chrome commandline | 245 # tell the program to prefix the Chrome commandline |
239 # with a magic wrapper. Build the magic wrapper here. | 246 # with a magic wrapper. Build the magic wrapper here. |
240 (fd, indirect_fname) = tempfile.mkstemp(dir=self.TMP_DIR, prefix="browser_
wrapper.", text=True) | 247 (fd, indirect_fname) = tempfile.mkstemp(dir=self.TMP_DIR, prefix="browser_
wrapper.", text=True) |
241 f = os.fdopen(fd, "w"); | 248 f = os.fdopen(fd, "w"); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 valgrind = ValgrindMac() | 332 valgrind = ValgrindMac() |
326 retcode = valgrind.Main() | 333 retcode = valgrind.Main() |
327 sys.exit(retcode) | 334 sys.exit(retcode) |
328 elif sys.platform == 'linux2': # Linux | 335 elif sys.platform == 'linux2': # Linux |
329 valgrind = ValgrindLinux() | 336 valgrind = ValgrindLinux() |
330 retcode = valgrind.Main() | 337 retcode = valgrind.Main() |
331 sys.exit(retcode) | 338 sys.exit(retcode) |
332 else: | 339 else: |
333 logging.error("Unknown platform: %s" % sys.platform) | 340 logging.error("Unknown platform: %s" % sys.platform) |
334 sys.exit(1) | 341 sys.exit(1) |
OLD | NEW |