Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: tools/purify/purify_test.py

Issue 20097: Allow purify scripts to take a --report_dir argument which specifies where th... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/purify/purify_analyze.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/env python 1 #!/bin/env 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 Purify and verifies that Purify was 8 '''Runs an exe through Purify and verifies that Purify was
9 able to successfully instrument and run it. The original purpose was 9 able to successfully instrument and run it. The original purpose was
10 to be able to identify when a change to our code breaks our ability to Purify 10 to be able to identify when a change to our code breaks our ability to Purify
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 "(used for output filenames)") 52 "(used for output filenames)")
53 self._parser.add_option("", "--source_dir", 53 self._parser.add_option("", "--source_dir",
54 help="path to top of source tree for this build" 54 help="path to top of source tree for this build"
55 "(used to normalize source paths in baseline)") 55 "(used to normalize source paths in baseline)")
56 self._parser.add_option("", "--exe", 56 self._parser.add_option("", "--exe",
57 help="The actual exe to instrument which is " 57 help="The actual exe to instrument which is "
58 "different than the program being run. This " 58 "different than the program being run. This "
59 "is useful when the exe you want to purify is " 59 "is useful when the exe you want to purify is "
60 "run by another script or program.") 60 "run by another script or program.")
61 self._parser.add_option("", "--data_dir", 61 self._parser.add_option("", "--data_dir",
62 help="path to where purify data files live") 62 help="path where global purify data files live")
63 self._parser.add_option("", "--report_dir",
64 help="path where report files are saved")
63 65
64 def ParseArgv(self): 66 def ParseArgv(self):
65 if common.Rational.ParseArgv(self): 67 if common.Rational.ParseArgv(self):
66 if self._options.exe: 68 if self._options.exe:
67 self._exe = self._options.exe; 69 self._exe = self._options.exe;
68 if not os.path.isfile(self._exe): 70 if not os.path.isfile(self._exe):
69 logging.error("file doesn't exist " + self._exe) 71 logging.error("file doesn't exist " + self._exe)
70 return False 72 return False
71 self._exe_dir = common.FixPath(os.path.abspath(os.path.dirname(self._exe ))) 73 self._exe_dir = common.FixPath(os.path.abspath(os.path.dirname(self._exe )))
72 self._echo_to_stdout = self._options.echo_to_stdout 74 self._echo_to_stdout = self._options.echo_to_stdout
73 self._baseline = self._options.baseline 75 self._baseline = self._options.baseline
74 self._name = self._options.name 76 self._name = self._options.name
75 if not self._name: 77 if not self._name:
76 self._name = os.path.basename(self._exe) 78 self._name = os.path.basename(self._exe)
79 self._report_dir = self._options.report_dir
80 if not self._report_dir:
81 self._report_dir = os.path.join(script_dir, "latest")
77 # _out_file can be set in common.Rational.ParseArgv 82 # _out_file can be set in common.Rational.ParseArgv
78 if not self._out_file: 83 if not self._out_file:
79 self._out_file = os.path.join(self._latest_dir, "%s.txt" % self._name) 84 self._out_file = os.path.join(self._report_dir, "%s.txt" % self._name)
80 self._source_dir = self._options.source_dir 85 self._source_dir = self._options.source_dir
81 self._data_dir = self._options.data_dir 86 self._data_dir = self._options.data_dir
82 if not self._data_dir: 87 if not self._data_dir:
83 self._data_dir = os.path.join(script_dir, "data") 88 self._data_dir = os.path.join(script_dir, "data")
84 return True 89 return True
85 return False 90 return False
86 91
87 def _PurifyCommand(self): 92 def _PurifyCommand(self):
88 cmd = [common.PURIFY_PATH, "/CacheDir=" + self._cache_dir] 93 cmd = [common.PURIFY_PATH, "/CacheDir=" + self._cache_dir]
89 return cmd 94 return cmd
90 95
91 def Setup(self): 96 def Setup(self):
92 script_dir = google.path_utils.ScriptDir() 97 script_dir = google.path_utils.ScriptDir()
93 self._latest_dir = os.path.join(script_dir, "latest")
94 if common.Rational.Setup(self): 98 if common.Rational.Setup(self):
95 if self._instrument_only: 99 if self._instrument_only:
96 return True 100 return True
97 pft_file = os.path.join(script_dir, "data", "filters.pft") 101 pft_file = os.path.join(script_dir, "data", "filters.pft")
98 shutil.copyfile(pft_file, self._exe.replace(".exe", "_exe.pft")) 102 shutil.copyfile(pft_file, self._exe.replace(".exe", "_exe.pft"))
99 string_list = [ 103 string_list = [
100 "[Purify]", 104 "[Purify]",
101 "option -cache-dir=\"%s\"" % (self._cache_dir), 105 "option -cache-dir=\"%s\"" % (self._cache_dir),
102 "option -save-text-data=\"%s\"" % (common.FixPath(self._out_file)), 106 "option -save-text-data=\"%s\"" % (common.FixPath(self._out_file)),
103 # Change the recorded stack depth to be much larger than the default. 107 # Change the recorded stack depth to be much larger than the default.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 # determine if the run was valid. 186 # determine if the run was valid.
183 return True 187 return True
184 188
185 def Analyze(self): 189 def Analyze(self):
186 out_files = self._ExistingOutputFiles() 190 out_files = self._ExistingOutputFiles()
187 if not len(out_files): 191 if not len(out_files):
188 logging.info("no output files matching %s" % self._out_file) 192 logging.info("no output files matching %s" % self._out_file)
189 return -1 193 return -1
190 pa = purify_analyze.PurifyAnalyze(out_files, self._echo_to_stdout, 194 pa = purify_analyze.PurifyAnalyze(out_files, self._echo_to_stdout,
191 self._name, self._source_dir, 195 self._name, self._source_dir,
192 self._data_dir) 196 self._data_dir, self._report_dir)
193 if not pa.ReadFile(): 197 if not pa.ReadFile():
194 # even though there was a fatal error during Purify, it's still useful 198 # even though there was a fatal error during Purify, it's still useful
195 # to see the normalized output 199 # to see the normalized output
196 pa.PrintSummary() 200 pa.PrintSummary()
197 if self._baseline: 201 if self._baseline:
198 logging.warning("baseline not generated due to fatal error") 202 logging.warning("baseline not generated due to fatal error")
199 else: 203 else:
200 logging.warning("baseline comparison skipped due to fatal error") 204 logging.warning("baseline comparison skipped due to fatal error")
201 return -1 205 return -1
202 if self._baseline: 206 if self._baseline:
203 pa.PrintSummary(False) 207 pa.PrintSummary(False)
204 if pa.SaveResults(): 208 if pa.SaveResults():
205 return 0 209 return 0
206 return -1 210 return -1
207 else: 211 else:
208 retcode = pa.CompareResults() 212 retcode = pa.CompareResults()
209 if retcode != 0: 213 if retcode != 0:
210 pa.SaveResults(self._latest_dir) 214 pa.SaveResults(self._report_dir)
211 pa.PrintSummary() 215 pa.PrintSummary()
212 # with more than one output file, it's also important to emit the bug 216 # with more than one output file, it's also important to emit the bug
213 # report which includes info on the arguments that generated each stack 217 # report which includes info on the arguments that generated each stack
214 if len(out_files) > 1: 218 if len(out_files) > 1:
215 pa.PrintBugReport() 219 pa.PrintBugReport()
216 return retcode 220 return retcode
217 221
218 def Cleanup(self): 222 def Cleanup(self):
219 common.Rational.Cleanup(self); 223 common.Rational.Cleanup(self);
220 if self._instrument_only: 224 if self._instrument_only:
(...skipping 16 matching lines...) Expand all
237 if os.path.isfile(pft_file): 241 if os.path.isfile(pft_file):
238 os.remove(pft_file) 242 os.remove(pft_file)
239 243
240 244
241 if __name__ == "__main__": 245 if __name__ == "__main__":
242 rational = Purify() 246 rational = Purify()
243 retcode = rational.Run() 247 retcode = rational.Run()
244 sys.exit(retcode) 248 sys.exit(retcode)
245 249
246 250
OLDNEW
« no previous file with comments | « tools/purify/purify_analyze.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698