| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 """Generate and process code coverage. | 6 """Generate and process code coverage. |
| 7 | 7 |
| 8 TODO(jrg): rename this from coverage_posix.py to coverage_all.py! | 8 TODO(jrg): rename this from coverage_posix.py to coverage_all.py! |
| 9 | 9 |
| 10 Written for and tested on Mac, Linux, and Windows. To use this script | 10 Written for and tested on Mac, Linux, and Windows. To use this script |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 # The "final" lcov-format file | 309 # The "final" lcov-format file |
| 310 self.coverage_info_file = os.path.join(self.directory, 'coverage.info') | 310 self.coverage_info_file = os.path.join(self.directory, 'coverage.info') |
| 311 # If needed, an intermediate VSTS-format file | 311 # If needed, an intermediate VSTS-format file |
| 312 self.vsts_output = os.path.join(self.directory, 'coverage.vsts') | 312 self.vsts_output = os.path.join(self.directory, 'coverage.vsts') |
| 313 # Needed for Windows. | 313 # Needed for Windows. |
| 314 self.src_root = options.src_root | 314 self.src_root = options.src_root |
| 315 self.FindPrograms() | 315 self.FindPrograms() |
| 316 self.ConfirmPlatformAndPaths() | 316 self.ConfirmPlatformAndPaths() |
| 317 self.tests = [] | 317 self.tests = [] |
| 318 self.xvfb_pid = 0 | 318 self.xvfb_pid = 0 |
| 319 logging.info('self.directory: ' + self.directory) |
| 320 logging.info('self.directory_parent: ' + self.directory_parent) |
| 319 | 321 |
| 320 def FindInPath(self, program): | 322 def FindInPath(self, program): |
| 321 """Find program in our path. Return abs path to it, or None.""" | 323 """Find program in our path. Return abs path to it, or None.""" |
| 322 if not 'PATH' in os.environ: | 324 if not 'PATH' in os.environ: |
| 323 logging.fatal('No PATH environment variable?') | 325 logging.fatal('No PATH environment variable?') |
| 324 sys.exit(1) | 326 sys.exit(1) |
| 325 paths = os.environ['PATH'].split(os.pathsep) | 327 paths = os.environ['PATH'].split(os.pathsep) |
| 326 for path in paths: | 328 for path in paths: |
| 327 fullpath = os.path.join(path, program) | 329 fullpath = os.path.join(path, program) |
| 328 if os.path.exists(fullpath): | 330 if os.path.exists(fullpath): |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 os.kill(self.xvfb_pid, signal.SIGKILL) | 717 os.kill(self.xvfb_pid, signal.SIGKILL) |
| 716 except: | 718 except: |
| 717 pass | 719 pass |
| 718 del os.environ['DISPLAY'] | 720 del os.environ['DISPLAY'] |
| 719 self.xvfb_pid = 0 | 721 self.xvfb_pid = 0 |
| 720 | 722 |
| 721 | 723 |
| 722 def GenerateLcovPosix(self): | 724 def GenerateLcovPosix(self): |
| 723 """Convert profile data to lcov on Mac or Linux.""" | 725 """Convert profile data to lcov on Mac or Linux.""" |
| 724 start_dir = os.getcwd() | 726 start_dir = os.getcwd() |
| 727 logging.info('GenerateLcovPosix: start_dir=' + start_dir) |
| 725 if self.IsLinux(): | 728 if self.IsLinux(): |
| 726 # With Linux/make (e.g. the coverage_run target), the current | 729 # With Linux/make (e.g. the coverage_run target), the current |
| 727 # directory for this command is .../build/src/chrome but we need | 730 # directory for this command is .../build/src/chrome but we need |
| 728 # to be in .../build/src for the relative path of source files | 731 # to be in .../build/src for the relative path of source files |
| 729 # to be correct. However, when run from buildbot, the current | 732 # to be correct. However, when run from buildbot, the current |
| 730 # directory is .../build. Accommodate. | 733 # directory is .../build. Accommodate. |
| 731 # On Mac source files are compiled with abs paths so this isn't | 734 # On Mac source files are compiled with abs paths so this isn't |
| 732 # a problem. | 735 # a problem. |
| 733 # This is a bit of a hack. The best answer is to require this | 736 # This is a bit of a hack. The best answer is to require this |
| 734 # script be run in a specific directory for all cases (from | 737 # script be run in a specific directory for all cases (from |
| 735 # Makefile or from buildbot). | 738 # Makefile or from buildbot). |
| 736 if start_dir.endswith('chrome'): | 739 if start_dir.endswith('chrome'): |
| 737 print 'coverage_posix.py: doing a "cd .." to accomodate Linux/make PWD' | 740 logging.info('coverage_posix.py: doing a "cd .." ' |
| 741 'to accomodate Linux/make PWD') |
| 738 os.chdir('..') | 742 os.chdir('..') |
| 739 elif start_dir.endswith('build'): | 743 elif start_dir.endswith('build'): |
| 740 print 'coverage_posix.py: doing a "cd src" to accomodate buildbot PWD' | 744 logging.info('coverage_posix.py: doing a "cd src" ' |
| 745 'to accomodate buildbot PWD') |
| 741 os.chdir('src') | 746 os.chdir('src') |
| 747 else: |
| 748 logging.info('coverage_posix.py: NOT changing directory.') |
| 742 elif self.IsMac(): | 749 elif self.IsMac(): |
| 743 pass | 750 pass |
| 744 | 751 |
| 745 command = [self.mcov, | 752 command = [self.mcov, |
| 746 '--directory', | 753 '--directory', |
| 747 os.path.join(start_dir, self.directory_parent), | 754 os.path.join(start_dir, self.directory_parent), |
| 748 '--output', | 755 '--output', |
| 749 os.path.join(start_dir, self.coverage_info_file)] | 756 os.path.join(start_dir, self.coverage_info_file)] |
| 750 logging.info('Assembly command: ' + ' '.join(command)) | 757 logging.info('Assembly command: ' + ' '.join(command)) |
| 751 retcode = subprocess.call(command) | 758 retcode = subprocess.call(command) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 if options.trim: | 907 if options.trim: |
| 901 coverage.TrimTests() | 908 coverage.TrimTests() |
| 902 coverage.RunTests() | 909 coverage.RunTests() |
| 903 if options.genhtml: | 910 if options.genhtml: |
| 904 coverage.GenerateHtml() | 911 coverage.GenerateHtml() |
| 905 return 0 | 912 return 0 |
| 906 | 913 |
| 907 | 914 |
| 908 if __name__ == '__main__': | 915 if __name__ == '__main__': |
| 909 sys.exit(main()) | 916 sys.exit(main()) |
| OLD | NEW |