0

How can I merge branch coverage of two or more runs? Is any tool or lcov command exist?

Let's say that I have two test runs and would like to see summary branch coverage

gcc -O0 --coverage main.c -o test-coverage
test-coverage param1
lcov --capture --rc lcov_branch_coverage=1 --directory . --config-file ./lcovrc --output coverage1.info
test-coverage param2
lcov --capture --rc lcov_branch_coverage=1 --directory . --config-file ./lcovrc --output coverage2.info

Looks like it is needed to parse and merge files coverage1.info and coverage2.info Is any solution exist already or I have to develop my own?

1 Answers1

0

Developed the python script, which merges a list of files (line coverage is not accurate here)

    def merge(files):
    if (len(files) == 0):
        return 0
    covs = [open(f, "r").readlines() for f in files]
    result = []
    branch_number = 0
    for i, line in enumerate(covs[0]):
        if ('end_of_record' in line):
            result.append(line)
        else:
            tmp = line.split(':')
            tag = tmp[0]
            data = tmp[1]
            if (tag == 'BRDA'):
                c = data.split(',')[-1]
                if (c == '1\n'):
                    branch_number += 1
                    result.append(line)
                else:
                    flag = 0
                    for j in covs[1:]:
                        if j[i].split(',')[-1] == '1\n':
                            branch_number += 1
                            result.append(j[i])
                            flag = 1
                            break
                    if flag == 0:
                        result.append(line)
            elif (tag == 'BRH'):
                result.append(tag + ":" + str(branch_number)+'\n')
            else:
                result.append(line)
    return result