Home > User Support > CoverageMaster winAMS FAQ

CoverageMaster winAMS FAQ

Coverage Measurement

102_01: I set sufficient test data to cover all branches in my function, but C1 coverage is not 100%. Why?

Question:

I want to perform branch coverage (C1) measurement for a function. I set sufficient input test data to cover all branches, but the C1 coverage result is not 100%. Why?

Answer:

CoverageMaster WinAMS runs tests on a MPU Simulator executing the target MPU’s assembly code. By default, C code coverage is measured by tracing the execution of the assembly instructions corresponding to each line of source code. For branch coverage (C1), a branch in the source code is evaluated by analyzing the assembly code generated by the compiler.

Because of this, in some cases depending on the compiler’s settings, CoverageMaster cannot recognize a branch, or incorrectly marks it as executed or not executed.

Ex:
- If the compiled code for an IF statement doesn’t contain any branch instructions in the assembly code
- If the compiler’s optimizations result in a code with a logic structure different from the C source code’s structure
- If the ELSE part of an IF/ELSE statement contains no code and no instruction is generated for the FALSE branch of the IF condition.

For additional details, please refer to the "C1 Coverage Restrictions" section of the "Program Restrictions" page of the WinAMS help manual. The WinAMS help manual is accessible from the Start Menu (WinAMS->WinAMS Help) or from SSTManager’s window (Help -> Help).

[Example of Incorrect C1 Coverage: No instruction for one of the branches]

In the example below, the IF statement of Line 1008 might not be measured as 100% even when data to cover both TRUE and FALSE cases is set.

In this example, the problem is that the structure of the assembled code differs from the C code. To consider the TRUE branch of the IF on Line 1008 as covered, CoverageMaster checks that the BREAK statement in Line 1009 is executed.
But in the Coverage view shown above, the BREAK statement at Line 1009 is not colored at all, which means that no assembly code was generated for this line.
Since CoverageMaster cannot detect if the BREAK statement has been executed or not, the TRUE branch of the IF statement cannot be evaluated, and the resulting C1 coverage will not be 100%.

[Example of Incorrect C1 Coverage: Conditional Skip Instructions]
With some MPUs and compilers, code branches like IF statements may be compiled into SKIP instructions ("Skip the next instruction if").

For example, with RL78 assembly code an IF statement can be compiled into a condition test, and the next instruction will be either executed or skipped depending on the resulting flags. In the following example, a SKZ (Skip next Instruction if Z Flag is 1) instruction is created.

[Note]: RL78 also has the following Skip instructions: SKC, SKNC, SKNZ, SKH, SKNH.

Example of Skip Instruction:
if(condition)
{
         func();
}

//After compilation for RL78: mov ax, condition

cmp 0, ax
skz      ;If the result of the Comparison instruction CMP is 0, the next CALL instruction is skipped
call func
...

With SKIP instructions, the assembly code doesn’t have a branch structure. The execution path is similar for both TRUE and FALSE cases of the condition (the program counter still goes through all instructions, even the skipped ones). CoverageMaster cannot evaluate which branch has been executed, and C1 coverage cannot be measured properly.

[Solution]: Measure Code Coverage with an Object with Hook Code

If the C0 or C1 Code coverage cannot be measured properly using the original compiled object, the solution is to measure coverage with an additional object file with hook code inserted specifically for coverage measurement. (This is also the only method for measuring MC/DC coverage). This way coverage measurement doesn’t rely on the original assembly code and can be measured independently of the compiler’s settings.

For additional details on how to generate an object with hook code, please refer to the MC/DC Setup Guide.

This guide is focused on MC/DC coverage measurement, but the process is identical for C0 and C1 coverage. For C0 Coverage simply check "Insert Hook Code for C0 Coverage" in the Hook Code Settings screen (see MC/DC Setup guide’s "Copy the target build environment" section).

 


Related Technical Tips Search

Other technical tips in GAIO's web site can be searched for using the links below.

Search key word link: C1 Measurement
Technical Tips Google Search


Information Links