matlabmingwcode-coveragegcov

Does Branch coverage implies Condition Coverage?


i need some help understanding and right interpreting the gcov results.

Lines executed: 25% of 24 Branches executed:30% of 20 Taken at least once: 15% of 20 Calls executed: 50% of 2

Lines executed gives me the Statement Coverage. Branches executed gives me the decision coverage and condition coverage

Am I right if i am saying that 100% Branch coverage implies 100% Decision Coverage and Condition Coverage?

Because my understanding is that the if statement if(a<1 || b>2){...}else{...} has not two branches but 4 because i have two conditions. That means if i am going through all 4 branches i should have the condition coverage or does the branch coverage provides no information about the condition coverage

Thanks for your help.

Cheers


Solution

  • If you're talking specifically about the gcov tools, the branch coverage is really counting the points at which the end of each basic block is reached. See Understanding branches in gcov files.

    Condition coverage is something different. See Is it possible to check condition coverage with gcov? (The answer is no, it's not, at least not with just gcov. Update 20 Jan 2025: it is now, with new flags at compile and gcov time: see the link.) As Marc Gilsse's comment notes, you can use gcov -a to count executions through each basic block, and use that as a reasonable approximation—but it's not the same thing.

    C++'s exceptions make dealing with branch coverage messy; see LCOV/GCOV branch coverage with C++ producing branches all over the place. This means you won't necessarily be able to cover all branches in the first place.

    See also, e.g., Understanding blocks in gcov files.