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'))
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)
def read_and_filter_gcov_files(fnames, directory): new_fnames = set() gcov_map = dict() for fname in fnames: gcov = read_gcov.read_gcov(os.path.join(directory, fname)) keep = remove_unwanted_file(gcov, fname, directory) if keep: source_file = gcov.tags['Source'] new_fnames.add(fname) gcov_map[fname] = gcov return new_fnames, gcov_map
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)