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

Side by Side Diff: tools/code_coverage/coverage.py

Issue 8678023: Fix python scripts in src/tools/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 9 years 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/clang/scripts/update.py ('k') | tools/code_coverage/croc.py » ('j') | 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) 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 6
7 """Module to setup and generate code coverage data 7 """Module to setup and generate code coverage data
8 8
9 This module first sets up the environment for code coverage, instruments the 9 This module first sets up the environment for code coverage, instruments the
10 binaries, runs the tests and collects the code coverage data. 10 binaries, runs the tests and collects the code coverage data.
11 11
12 12
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 archive: Archive location for the intermediate .coverage results. 100 archive: Archive location for the intermediate .coverage results.
101 """ 101 """
102 google.logging_utils.config_root() 102 google.logging_utils.config_root()
103 self.revision = revision 103 self.revision = revision
104 self.instrumented = False 104 self.instrumented = False
105 self.tools_path = tools_path 105 self.tools_path = tools_path
106 self.src_path = src_path 106 self.src_path = src_path
107 self._dir = tempfile.mkdtemp() 107 self._dir = tempfile.mkdtemp()
108 self._archive = archive 108 self._archive = archive
109 109
110
111 def SetUp(self, binaries): 110 def SetUp(self, binaries):
112 """Set up the platform specific environment and instrument the binaries for 111 """Set up the platform specific environment and instrument the binaries for
113 coverage. 112 coverage.
114 113
115 This method sets up the environment, instruments all the compiled binaries 114 This method sets up the environment, instruments all the compiled binaries
116 and sets up the code coverage counters. 115 and sets up the code coverage counters.
117 116
118 Args: 117 Args:
119 binaries: List of binaries that need to be instrumented. 118 binaries: List of binaries that need to be instrumented.
120 119
(...skipping 29 matching lines...) Expand all
150 (retcode, output) = proc.RunCommandFull(instrument_command + binary, 149 (retcode, output) = proc.RunCommandFull(instrument_command + binary,
151 collect_output=True) 150 collect_output=True)
152 # Check if the file has been instrumented correctly. 151 # Check if the file has been instrumented correctly.
153 if output.pop().rfind('Successfully instrumented') == -1: 152 if output.pop().rfind('Successfully instrumented') == -1:
154 logging.error('Error instrumenting %s' % (binary)) 153 logging.error('Error instrumenting %s' % (binary))
155 return False 154 return False
156 # We are now ready to run tests and measure code coverage. 155 # We are now ready to run tests and measure code coverage.
157 self.instrumented = True 156 self.instrumented = True
158 return True 157 return True
159 158
160
161 def TearDown(self): 159 def TearDown(self):
162 """Tear down method. 160 """Tear down method.
163 161
164 This method shuts down the counters, and cleans up all the intermediate 162 This method shuts down the counters, and cleans up all the intermediate
165 artifacts. 163 artifacts.
166 """ 164 """
167 if self.instrumented == False: 165 if self.instrumented == False:
168 return 166 return
169 167
170 if IsWindows(): 168 if IsWindows():
(...skipping 10 matching lines...) Expand all
181 if self._archive: 179 if self._archive:
182 shutil.copytree(self._dir, os.path.join(self._archive, self.revision)) 180 shutil.copytree(self._dir, os.path.join(self._archive, self.revision))
183 logging.info('Archived the .coverage files') 181 logging.info('Archived the .coverage files')
184 # Delete all the temp files and folders 182 # Delete all the temp files and folders
185 if self._dir != None: 183 if self._dir != None:
186 shutil.rmtree(self._dir, ignore_errors=True) 184 shutil.rmtree(self._dir, ignore_errors=True)
187 logging.info('Cleaned up temporary files and folders') 185 logging.info('Cleaned up temporary files and folders')
188 # Reset the instrumented flag. 186 # Reset the instrumented flag.
189 self.instrumented = False 187 self.instrumented = False
190 188
191
192 def RunTest(self, src_root, test): 189 def RunTest(self, src_root, test):
193 """Run tests and collect the .coverage file 190 """Run tests and collect the .coverage file
194 191
195 Args: 192 Args:
196 src_root: Path to the root of the source. 193 src_root: Path to the root of the source.
197 test: Path to the test to be run. 194 test: Path to the test to be run.
198 195
199 Returns: 196 Returns:
200 Path of the intermediate .coverage file on success. 197 Path of the intermediate .coverage file on success.
201 None on error. 198 None on error.
(...skipping 29 matching lines...) Expand all
231 228
232 # Stop the counters 229 # Stop the counters
233 counters_command = ('%s -shutdown' % 230 counters_command = ('%s -shutdown' %
234 (os.path.join(self.tools_path, 'vsperfcmd.exe'))) 231 (os.path.join(self.tools_path, 'vsperfcmd.exe')))
235 (retcode, output) = proc.RunCommandFull(counters_command, 232 (retcode, output) = proc.RunCommandFull(counters_command,
236 collect_output=True) 233 collect_output=True)
237 logging.info('Counters shut down: %s' % (output)) 234 logging.info('Counters shut down: %s' % (output))
238 # Return the intermediate .coverage file 235 # Return the intermediate .coverage file
239 return coverage_file 236 return coverage_file
240 237
241
242 def Upload(self, list_coverage, upload_path, sym_path=None, src_root=None): 238 def Upload(self, list_coverage, upload_path, sym_path=None, src_root=None):
243 """Upload the results to the dashboard. 239 """Upload the results to the dashboard.
244 240
245 This method uploads the coverage data to a dashboard where it will be 241 This method uploads the coverage data to a dashboard where it will be
246 processed. On Windows, this method will first convert the .coverage file to 242 processed. On Windows, this method will first convert the .coverage file to
247 the lcov format. This method needs to be called before the TearDown method. 243 the lcov format. This method needs to be called before the TearDown method.
248 244
249 Args: 245 Args:
250 list_coverage: The list of coverage data files to consoliate and upload. 246 list_coverage: The list of coverage data files to consoliate and upload.
251 upload_path: Destination where the coverage data will be processed. 247 upload_path: Destination where the coverage data will be processed.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 357
362 cov.Upload(list_coverage, 358 cov.Upload(list_coverage,
363 options.upload_path, 359 options.upload_path,
364 os.path.join(options.src_root, 'chrome', 'Release'), 360 os.path.join(options.src_root, 'chrome', 'Release'),
365 options.src_root) 361 options.src_root)
366 cov.TearDown() 362 cov.TearDown()
367 363
368 364
369 if __name__ == '__main__': 365 if __name__ == '__main__':
370 sys.exit(main()) 366 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/clang/scripts/update.py ('k') | tools/code_coverage/croc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698