示例#1
0
def compare_gcov(fname, dir_base, dir_unit, dir_diff=None):
    gcov_base = read_gcov.read_gcov(os.path.join(dir_base, fname))
    gcov_unit = read_gcov.read_gcov(os.path.join(dir_unit, fname))
    gcov_diff = compute_gcov_diff(gcov_base, gcov_unit)
    if dir_diff and gcov_diff:
        out_fname = os.path.join(dir_diff, fname)
        read_gcov.write_gcov(gcov_diff, open(out_fname, 'w'))
示例#2
0
def handle_uncovered(gcov_base, fname, dir_diff, always_copy=False):
    # Need to see if there are any covered lines in the file
    file_coverage = get_total_covered_lines(gcov_base)
    if always_copy or file_coverage.covered > 0:
        gcov_diff = mark_as_uncovered(gcov_base)
        out_fname = os.path.join(dir_diff, fname)
        if gcov_diff:
            read_gcov.write_gcov(gcov_diff, open(out_fname, 'w'))
示例#3
0
def merge_two_gcov_files(fname1, fname2, output_fname):
    gcov1 = read_gcov.read_gcov(fname1)
    gcov2 = read_gcov.read_gcov(fname2)

    source_file1 = gcov1.tags['Source']
    source_file2 = gcov2.tags['Source']
    if source_file1 != source_file2:
        print 'Source files do not match', source_file1, source_file2
        return

    gcov_out = merge_two_gcovs(gcov1, gcov2)

    out_f = sys.stdout
    if output_fname:
        out_f = open(output_fname, 'w')
    read_gcov.write_gcov(gcov_out, out_f)
示例#4
0
def compare_gcov_files(both, only_base, only_unit, base_gcov_map,
                       unit_gcov_map, dir_unit, dir_diff):
    for fname in both:
        gcov_base = base_gcov_map[fname]
        gcov_unit = unit_gcov_map[fname]
        gcov_diff = compute_gcov_diff(gcov_base, gcov_unit)
        out_fname = os.path.join(dir_diff, fname)
        if gcov_diff:
            read_gcov.write_gcov(gcov_diff, open(out_fname, 'w'))

    # completely uncovered in unit tests
    # Assign all to unit tests
    # Assign to diff only if some coverage in base
    for fname in only_base:
        gcov_base = base_gcov_map[fname]
        handle_uncovered(gcov_base, fname, dir_diff)
        handle_uncovered(gcov_base, fname, dir_unit, always_copy=True)
示例#5
0
def merge_gcov_files(fnames, output_fname, src_prefix_to_add=None):
    gcovs = [read_gcov.read_gcov(f) for f in fnames]
    source_names = [g.tags['Source'] for g in gcovs]
    for source in source_names[1:]:
        if source_names[0] != source:
            print 'Source file names do not match', source_names[0], source
            return

    gcov_out = merge_gcovs(gcovs)

    # The gcov '--source-prefix' options strips a directory from the file name and the
    #  'Source' tag.   Restore it to the tag so gcovr can find the source file.
    if src_prefix_to_add is not None:
        src_filename = gcov_out.tags['Source']
        gcov_out.tags['Source'] = os.path.join(src_prefix_to_add, src_filename)

    out_f = sys.stdout
    if output_fname:
        out_f = open(output_fname, 'w')
    read_gcov.write_gcov(gcov_out, out_f)