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

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

Issue 11274053: Store coverage.info file in separate folders based on commandline parameters to coverage_posix.py. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « no previous file | 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 print 'Clearing of coverage data NOT performed.' 755 print 'Clearing of coverage data NOT performed.'
756 return 756 return
757 print 'Clearing coverage data from previous runs.' 757 print 'Clearing coverage data from previous runs.'
758 if os.path.exists(self.coverage_info_file): 758 if os.path.exists(self.coverage_info_file):
759 os.remove(self.coverage_info_file) 759 os.remove(self.coverage_info_file)
760 if self.IsPosix(): 760 if self.IsPosix():
761 subprocess.call([self.lcov, 761 subprocess.call([self.lcov,
762 '--directory', self.directory_parent, 762 '--directory', self.directory_parent,
763 '--zerocounters']) 763 '--zerocounters'])
764 shutil.rmtree(os.path.join(self.directory, 'coverage')) 764 shutil.rmtree(os.path.join(self.directory, 'coverage'))
765 if self.options.all_unittests:
766 if os.path.exists(os.path.join(self.directory, 'unittests_coverage')):
767 shutil.rmtree(os.path.join(self.directory, 'unittests_coverage'))
768 else:
769 if os.path.exists(os.path.join(self.directory, 'total_coverage')):
770 shutil.rmtree(os.path.join(self.directory, 'total_coverage'))
765 771
766 def BeforeRunOneTest(self, testname): 772 def BeforeRunOneTest(self, testname):
767 """Do things before running each test.""" 773 """Do things before running each test."""
768 if not self.IsWindows(): 774 if not self.IsWindows():
769 return 775 return
770 # Stop old counters if needed 776 # Stop old counters if needed
771 cmdlist = [self.perf, '-shutdown'] 777 cmdlist = [self.perf, '-shutdown']
772 self.Run(cmdlist, ignore_error=True) 778 self.Run(cmdlist, ignore_error=True)
773 # Instrument binaries 779 # Instrument binaries
774 for fulltest in self.tests: 780 for fulltest in self.tests:
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 """Stop Xvfb if needed. Linux only.""" 947 """Stop Xvfb if needed. Linux only."""
942 if self.xvfb_pid: 948 if self.xvfb_pid:
943 logging.info('Xvfb: killing') 949 logging.info('Xvfb: killing')
944 try: 950 try:
945 os.kill(self.xvfb_pid, signal.SIGKILL) 951 os.kill(self.xvfb_pid, signal.SIGKILL)
946 except: 952 except:
947 pass 953 pass
948 del os.environ['DISPLAY'] 954 del os.environ['DISPLAY']
949 self.xvfb_pid = 0 955 self.xvfb_pid = 0
950 956
957 def CopyCoverageFileToDestination(self, coverage_folder):
958 coverage_dir = os.path.join(self.directory, coverage_folder)
959 if not os.path.exists(coverage_dir):
960 os.makedirs(coverage_dir)
961 shutil.copyfile(self.coverage_info_file, os.path.join(coverage_dir,
962 'coverage.info'))
951 963
952 def GenerateLcovPosix(self): 964 def GenerateLcovPosix(self):
953 """Convert profile data to lcov on Mac or Linux.""" 965 """Convert profile data to lcov on Mac or Linux."""
954 start_dir = os.getcwd() 966 start_dir = os.getcwd()
955 logging.info('GenerateLcovPosix: start_dir=' + start_dir) 967 logging.info('GenerateLcovPosix: start_dir=' + start_dir)
956 if self.IsLinux(): 968 if self.IsLinux():
957 # With Linux/make (e.g. the coverage_run target), the current 969 # With Linux/make (e.g. the coverage_run target), the current
958 # directory for this command is .../build/src/chrome but we need 970 # directory for this command is .../build/src/chrome but we need
959 # to be in .../build/src for the relative path of source files 971 # to be in .../build/src for the relative path of source files
960 # to be correct. However, when run from buildbot, the current 972 # to be correct. However, when run from buildbot, the current
(...skipping 23 matching lines...) Expand all
984 os.path.join(start_dir, self.coverage_info_file)] 996 os.path.join(start_dir, self.coverage_info_file)]
985 logging.info('Assembly command: ' + ' '.join(command)) 997 logging.info('Assembly command: ' + ' '.join(command))
986 retcode = subprocess.call(command) 998 retcode = subprocess.call(command)
987 if retcode: 999 if retcode:
988 logging.fatal('COVERAGE: %s failed; return code: %d' % 1000 logging.fatal('COVERAGE: %s failed; return code: %d' %
989 (command[0], retcode)) 1001 (command[0], retcode))
990 if self.options.strict: 1002 if self.options.strict:
991 sys.exit(retcode) 1003 sys.exit(retcode)
992 if self.IsLinux(): 1004 if self.IsLinux():
993 os.chdir(start_dir) 1005 os.chdir(start_dir)
1006
1007 # Copy the unittests coverage information to a different folder.
1008 if self.options.all_unittests:
1009 self.CopyCoverageFileToDestination('unittests_coverage')
1010 else:
1011 # Save the overall coverage information.
1012 self.CopyCoverageFileToDestination('total_coverage')
1013
994 if not os.path.exists(self.coverage_info_file): 1014 if not os.path.exists(self.coverage_info_file):
995 logging.fatal('%s was not created. Coverage run failed.' % 1015 logging.fatal('%s was not created. Coverage run failed.' %
996 self.coverage_info_file) 1016 self.coverage_info_file)
997 sys.exit(1) 1017 sys.exit(1)
998 1018
999 def GenerateLcovWindows(self, testname=None): 1019 def GenerateLcovWindows(self, testname=None):
1000 """Convert VSTS format to lcov. Appends coverage data to sum file.""" 1020 """Convert VSTS format to lcov. Appends coverage data to sum file."""
1001 lcov_file = self.vsts_output + '.lcov' 1021 lcov_file = self.vsts_output + '.lcov'
1002 if os.path.exists(lcov_file): 1022 if os.path.exists(lcov_file):
1003 os.remove(lcov_file) 1023 os.remove(lcov_file)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 if options.trim: 1162 if options.trim:
1143 coverage.TrimTests() 1163 coverage.TrimTests()
1144 coverage.RunTests() 1164 coverage.RunTests()
1145 if options.genhtml: 1165 if options.genhtml:
1146 coverage.GenerateHtml() 1166 coverage.GenerateHtml()
1147 return 0 1167 return 0
1148 1168
1149 1169
1150 if __name__ == '__main__': 1170 if __name__ == '__main__':
1151 sys.exit(main()) 1171 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698