parameters: (lcov_path)
return_statement: return lines
docstring: Parse code coverage data into coverage results per source node.
  
    Use lcov and linecount data to create a map of source nodes to
    corresponding total and tested line counts.
  
    Args:
      lcov_path: File path to lcov coverage data.
  
    Returns:
      List of strings with comma separated source node and coverage.
docstring_summary: Parse code coverage data into coverage results per source node.
docstring_tokens: Parse code coverage data into coverage results per source node .
function: def ParseCoverageDataForDashboard(lcov_path):
    """Parse code coverage data into coverage results per source node.
  
    Use lcov and linecount data to create a map of source nodes to
    corresponding total and tested line counts.
  
    Args:
      lcov_path: File path to lcov coverage data.
  
    Returns:
      List of strings with comma separated source node and coverage.
    """
    results = {}
    linecount_path = lcov_path + '.csv'
    assert(os.path.exists(linecount_path),
           'linecount csv does not exist at: %s' % linecount_path)
    csv_file = open(linecount_path, 'r')
    linecounts = csv_file.readlines()
    csv_file.close()
    lcov_file = open(lcov_path, 'r')
    srcfile_index = 0
    for line in lcov_file:
      line = line.strip()
  
      # Set the current srcfile name for a new src file declaration.
      if line[:len('SF:')] == 'SF:':
        instrumented_set = {}
        executed_set = {}
        srcfile_name = line[len('SF:'):]
  
      # Mark coverage data points hashlist style for the current src file.
      if line[:len('DA:')] == 'DA:':
        line_info = line[len('DA:'):].split(',')
        assert(len(line_info) == 2, 'DA: line format unexpected - %s' % line)
        (line_num, line_was_executed) = line_info
        instrumented_set[line_num] = True
        # line_was_executed is '0' or '1'
        if int(line_was_executed):
          executed_set[line_num] = True
  
      # Update results for the current src file at record end.
      if line == 'end_of_record':
        instrumented = len(instrumented_set.keys())
        executed = len(executed_set.keys())
        parent_directory = srcfile_name[:srcfile_name.rfind('/') + 1]
        linecount_point = linecounts[srcfile_index].strip().split(',')
        assert(len(linecount_point) == 2,
               'lintcount format unexpected - %s' % linecounts[srcfile_index])
        (linecount_path, linecount_count) = linecount_point
        srcfile_index += 1
  
        # Sanity check that path names in the lcov and linecount are lined up.
        if linecount_path[-10:] != srcfile_name[-10:]:
          print 'NAME MISMATCH: %s :: %s' % (srcfile_name, linecount_path)
        if instrumented > int(linecount_count):
          linecount_count = instrumented
  
        # Keep counts the same way that it is done in the genhtml utility.
        # Count the coverage of a file towards the file,
        # the parent directory, and the source root.
        AddResults(results, srcfile_name, int(linecount_count), executed)
        AddResults(results, parent_directory, int(linecount_count), executed)
        AddResults(results, '/', instrumented, executed)
  
    lcov_file.close()
    keys = results.keys()
    keys.sort()
    # The first key (sorted) will be the base directory '/'
    # but its full path may be '/mnt/chrome_src/src/'
    # using this offset will ignore the part '/mnt/chrome_src/src'.
    # Offset is the last '/' that isn't the last character for the
    # first directory name in results (position 1 in keys).
    offset = len(keys[1][:keys[1][:-1].rfind('/')])
    lines = []
    for key in keys:
      if len(key) > offset:
        node_path = key[offset:]
      else:
        node_path = key
      (total, covered) = results[key]
      percent = float(covered) * 100 / total
      lines.append('%s,%.2f' % (node_path, percent))
    return lines
function_tokens: def ParseCoverageDataForDashboard ( lcov_path ) : results = { } linecount_path = lcov_path + '.csv' assert ( os . path . exists ( linecount_path ) , 'linecount csv does not exist at: %s' % linecount_path ) csv_file = open ( linecount_path , 'r' ) linecounts = csv_file . readlines ( ) csv_file . close ( ) lcov_file = open ( lcov_path , 'r' ) srcfile_index = 0 for line in lcov_file : line = line . strip ( ) # Set the current srcfile name for a new src file declaration. if line [ : len ( 'SF:' ) ] == 'SF:' : instrumented_set = { } executed_set = { } srcfile_name = line [ len ( 'SF:' ) : ] # Mark coverage data points hashlist style for the current src file. if line [ : len ( 'DA:' ) ] == 'DA:' : line_info = line [ len ( 'DA:' ) : ] . split ( ',' ) assert ( len ( line_info ) == 2 , 'DA: line format unexpected - %s' % line ) ( line_num , line_was_executed ) = line_info instrumented_set [ line_num ] = True # line_was_executed is '0' or '1' if int ( line_was_executed ) : executed_set [ line_num ] = True # Update results for the current src file at record end. if line == 'end_of_record' : instrumented = len ( instrumented_set . keys ( ) ) executed = len ( executed_set . keys ( ) ) parent_directory = srcfile_name [ : srcfile_name . rfind ( '/' ) + 1 ] linecount_point = linecounts [ srcfile_index ] . strip ( ) . split ( ',' ) assert ( len ( linecount_point ) == 2 , 'lintcount format unexpected - %s' % linecounts [ srcfile_index ] ) ( linecount_path , linecount_count ) = linecount_point srcfile_index += 1 # Sanity check that path names in the lcov and linecount are lined up. if linecount_path [ - 10 : ] != srcfile_name [ - 10 : ] : print 'NAME MISMATCH: %s :: %s' % ( srcfile_name , linecount_path ) if instrumented > int ( linecount_count ) : linecount_count = instrumented # Keep counts the same way that it is done in the genhtml utility. # Count the coverage of a file towards the file, # the parent directory, and the source root. AddResults ( results , srcfile_name , int ( linecount_count ) , executed ) AddResults ( results , parent_directory , int ( linecount_count ) , executed ) AddResults ( results , '/' , instrumented , executed ) lcov_file . close ( ) keys = results . keys ( ) keys . sort ( ) # The first key (sorted) will be the base directory '/' # but its full path may be '/mnt/chrome_src/src/' # using this offset will ignore the part '/mnt/chrome_src/src'. # Offset is the last '/' that isn't the last character for the # first directory name in results (position 1 in keys). offset = len ( keys [ 1 ] [ : keys [ 1 ] [ : - 1 ] . rfind ( '/' ) ] ) lines = [ ] for key in keys : if len ( key ) > offset : node_path = key [ offset : ] else : node_path = key ( total , covered ) = results [ key ] percent = float ( covered ) * 100 / total lines . append ( '%s,%.2f' % ( node_path , percent ) ) return lines