diff options
author | niranjan@google.com <niranjan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-24 21:48:25 +0000 |
---|---|---|
committer | niranjan@google.com <niranjan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-24 21:48:25 +0000 |
commit | 718ab478be8ce44969ea2d02963d16d09648a5d9 (patch) | |
tree | db5df096be576f60eed9d288bf61c9d895c4fc0c /tools/code_coverage | |
parent | 60a0b7543a1ffef1828de9574648deebaec7b876 (diff) | |
download | chromium_src-718ab478be8ce44969ea2d02963d16d09648a5d9.zip chromium_src-718ab478be8ce44969ea2d02963d16d09648a5d9.tar.gz chromium_src-718ab478be8ce44969ea2d02963d16d09648a5d9.tar.bz2 |
Added CSV format output for process_coverage.py which will be used by the code coverage dashboard to show a more accurate count of the actual code coverage. Also fixed a couple of bugs with this script.
Review URL: http://codereview.chromium.org/7983
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3941 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/code_coverage')
-rw-r--r-- | tools/code_coverage/process_coverage.py | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/tools/code_coverage/process_coverage.py b/tools/code_coverage/process_coverage.py index 6cec95b..e52fd15 100644 --- a/tools/code_coverage/process_coverage.py +++ b/tools/code_coverage/process_coverage.py @@ -41,6 +41,7 @@ import os import shutil import sys import tempfile +import subprocess # These are source files that were generated during compile time. We want to @@ -48,8 +49,8 @@ import tempfile # throw an error. win32_srcs_exclude = ['parse.y', 'xpathgrammar.cpp', - 'cssgrammar.cpp'] - + 'cssgrammar.cpp', + 'csspropertynames.gperf'] def CleanPathNames(dir): """Clean the pathnames of the HTML generated by genhtml. @@ -66,10 +67,11 @@ def CleanPathNames(dir): None """ # Stip off the ^M characters that get appended to the file name - for file in os.walk(dir): - file_clean = file.replace('\r', '') - if file_clean != file: - os.rename(file, file_clean) + for dirpath, dirname, filenames in os.walk(dir): + for file in filenames: + file_clean = file.replace('\r', '') + if file_clean != file: + os.rename(file, file_clean) def GenerateHtml(lcov_path, dash_root): @@ -101,12 +103,12 @@ def GenerateHtml(lcov_path, dash_root): revision = buffer[len(buffer) - 1] if os.path.exists(os.path.join(dash_root, platform)) == False: os.mkdir(os.path.join(dash_root, platform)) - output_dir = os.join.path(dash_root, platform, revision) + output_dir = os.path.join(dash_root, platform, revision) os.mkdir(output_dir) else: # TODO(niranjan): Add failure logging here. return None # File not formatted correctly - + # Run genhtml os.system('/usr/bin/genhtml -o %s %s' % (output_dir, lcov_path)) # TODO(niranjan): Check the exit status of the genhtml command. @@ -142,7 +144,9 @@ def CleanWin32Lcov(lcov_path, src_root): """ strip_flag = False lcov = open(lcov_path, 'r') - (tmpfile, tmpfile_name) = tempfile.mkstemp() + loc_csv_file = open(lcov_path + '.csv', 'w') + (tmpfile_id, tmpfile_name) = tempfile.mkstemp() + tmpfile = open(tmpfile_name, 'w') src_root = src_root.rstrip('/') # Remove trailing '/' for line in lcov: if line.startswith('SF'): @@ -159,10 +163,33 @@ def CleanWin32Lcov(lcov_path, src_root): src_root, parse_buffer[2]) buffer = buffer.replace('\\', '/') - line = buffer + line = buffer.replace('\r', '') + + # We want an accurate count of the lines of code in a given file so that + # we can estimate the code coverage perscentage accurately. We use a + # third party script cloc.pl which gives that count and then just parse + # its command line output to filter out the other unnecessary data. + # TODO(niranjan): Find out a better way of doing this. + buffer = buffer.lstrip('SF:') + file_for_loc = buffer.replace('\r\n', '') + # TODO(niranjan): Add a check to see if cloc is present on the machine. + command = ["perl", + "cloc.pl", + file_for_loc] + output = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT).communicate()[0] + if output.rfind('error:'): + return None + + tmp_buf1 = output.split('=') + tmp_buf2 = tmp_buf1[len(tmp_buf1) - 2].split('x')[0].split(' ') + loc = tmp_buf2[len(tmp_buf2) - 2] + loc_csv_file.write('%s,%s\r\n' % (file_for_loc, loc)) # Write to the temp file if the section to write is valid if strip_flag == False: + # Also write this to the 'clean' LCOV file tmpfile.write('%s' % (line)) # Reset the strip flag @@ -172,6 +199,7 @@ def CleanWin32Lcov(lcov_path, src_root): # Close the files and replace the lcov file by the 'clean' tmpfile tmpfile.close() lcov.close() + loc_csv_file.close() shutil.move(tmpfile_name, lcov_path) @@ -186,14 +214,14 @@ def main(): '--platform', dest='platform', default=None, - help='Platform that the locv file was generated on. Must be - one of {win32, linux2, macosx}') + help=('Platform that the locv file was generated on. Must' + 'be one of {win32, linux2, macosx}')) parser.add_option('-s', '--source', dest='src_dir', default=None, help='Path to the source code and symbols') - parser.add_option('-d', + parser.add_option('-d', '--dash_root', dest='dash_root', default=None, @@ -204,7 +232,7 @@ def main(): default=None, help='Location of the LCOV file to process') (options, args) = parser.parse_args() - + if options.platform == None: parser.error('Platform not specified') if options.lcov_path == None: |