Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Coverage] Support Branch Coverage #2056

Merged
merged 12 commits into from
Oct 9, 2024
Merged

[Coverage] Support Branch Coverage #2056

merged 12 commits into from
Oct 9, 2024

Conversation

ChenfengWei0
Copy link
Collaborator

@ChenfengWei0 ChenfengWei0 commented Oct 7, 2024

Strategy

We follow the strategy as CBMC. That is, we not only count the entry of branches, but also count the entry of functions.

e.g.

int main()
{
    int f = 2;
    if(f==2)
        f =1;
    f = 3;
}
ESBMC Output >

#--branch-coverage-claims --unwind 2 --no-unwinding-assertions
[Coverage]

Function Entry Points & Branches : 3
Reached : 2
  0     file 1.c line 6 column 5 function main
  !(f == 2)     file 1.c line 7 column 5 function main
Branch Coverage: 66.66666666666667%

CBMC Output >

#--cover branch --timestamp wall --unwind 3
** coverage results:
2024-10-07T00:58:30.565926 [main.coverage.1] file 1.c line 6 function main entry point: SATISFIED
[main.coverage.2] file 1.c line 7 function main block 1 branch false: SATISFIED
[main.coverage.3] file 1.c line 7 function main block 1 branch true: FAILED

2024-10-07T00:58:30.565950 ** 2 of 3 covered (66.7%)
2024-10-07T00:58:30.565956 ** Used 2 iterations

I am not sure if this is the "Branch Coverage" expected by Testcomp, as the typical branch coverage seems to only count the entry of branches


Known Issue

Currently cannot use this with k-induction or incremental-bmc. It seems in kind/incr, the goto_functions used during the BMC is simplified and incomplete

goto functions in unwind mode >

        // 20 file 1.c line 6 column 5 function main
        ASSERT 0 // 0
        // 21 file 1.c line 6 column 5 function main
        DECL signed int f;
        // 22 file 1.c line 6 column 5 function main
        ASSIGN f=2;
        // 23 file 1.c line 7 column 5 function main
        ASSERT !(f == 2) // !(f == 2)
        // 24 file 1.c line 7 column 5 function main
        ASSERT !(!(f == 2)) // !(!(f == 2))
        // 25 file 1.c line 7 column 5 function main
        IF !(f == 2) THEN GOTO 1
        // 26 file 1.c line 8 column 9 function main
        ASSIGN f=1;
        // 27 file 1.c line 10 column 5 function main
     1: ASSIGN f=3;
        // 28 file 1.c line 11 column 1 function main
        DEAD c:1.c@39@F@main@f
        // 29 file 1.c line 11 column 1 function main
        RETURN: NONDET(signed int)
        // 30 file 1.c line 11 column 1 function main
        END_FUNCTION // main

goto functions in kind mode >

        // 20 file 1.c line 6 column 5 function main
        SKIP
        // 21 file 1.c line 6 column 5 function main
        DECL signed int f;
        // 22 file 1.c line 6 column 5 function main
        ASSIGN f=2;
        // 23 file 1.c line 7 column 5 function main
        SKIP
        // 24 file 1.c line 7 column 5 function main
        ASSERT !(!(f == 2)) // !(!(f == 2))
        // 25 file 1.c line 7 column 5 function main
        IF !(f == 2) THEN GOTO 1
        // 26 file 1.c line 8 column 9 function main
        ASSIGN f=1;
        // 27 file 1.c line 10 column 5 function main
     1: ASSIGN f=3;
        // 28 file 1.c line 11 column 1 function main
        DEAD c:1.c@39@F@main@f
        // 29 file 1.c line 11 column 1 function main
        RETURN: NONDET(signed int)
        // 30 file 1.c line 11 column 1 function main
        END_FUNCTION // main

Would anyone happen to know how to disable this simplification feature

src/esbmc/bmc.cpp Outdated Show resolved Hide resolved
src/esbmc/bmc.cpp Outdated Show resolved Hide resolved
src/esbmc/bmc.cpp Outdated Show resolved Hide resolved
src/goto-programs/goto_coverage.cpp Outdated Show resolved Hide resolved
src/goto-programs/goto_coverage.cpp Outdated Show resolved Hide resolved
@@ -47,32 +58,77 @@ void goto_coveraget::replace_assert_to_guard(
it->location.user_provided(true);
}

void goto_coveraget::add_false_asserts()
/*
Branch coverage applies to any control structure that can alter the flow of execution, including:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarifications:

How do we handle `try-catch' here?

What would be the difference between branch coverage and statement coverage?

Should our branch coverage also consider conditional expressions in control structures, ensuring all possible outcomes are tested?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I tried supporting 'try-catch' today. The difficulty is that, during the goto conversion, esbmc may add some auxiliary if-goto inside the try-catch body, thereby affecting the counting of the branches. No solution so far.
  2. Branch Coverage = Decision Coverage: Measures whether each possible branch (decision) in the code has been executed. Statement Coverage: check if every line of code is executed at least once
  3. In C, they all converted to if-goto, including if, else if, while, do-while, for, switch-case

@mikhailramalho
Copy link
Member

What do you mean by incomplete?

@ChenfengWei0
Copy link
Collaborator Author

What do you mean by incomplete?

The goto program is simplified, so the count of the total instrumentation is incomplete. E.g.

        // 20 file 1.c line 6 column 5 function main
        SKIP
        // 21 file 1.c line 6 column 5 function main
        DECL signed int f;
        // 22 file 1.c line 6 column 5 function main
        ASSIGN f=2;
        // 23 file 1.c line 7 column 5 function main
        SKIP
        // 24 file 1.c line 7 column 5 function main
        ASSERT !(!(f == 2)) // !(!(f == 2))

Has been simplified to

        // 20 file 1.c line 6 column 5 function main
        ASSERT 0 // 0
        // 21 file 1.c line 6 column 5 function main
        DECL signed int f;
        // 22 file 1.c line 6 column 5 function main
        ASSIGN f=2;
        // 23 file 1.c line 7 column 5 function main
        ASSERT !(f == 2) // !(f == 2)
        // 24 file 1.c line 7 column 5 function main
        ASSERT !(!(f == 2)) // !(!(f == 2))

in kind/incr. The unwind looks fine.

@mikhailramalho
Copy link
Member

I think you mean the assertions were simplified to skips, not the other way around, right?

@ChenfengWei0
Copy link
Collaborator Author

I think you mean the assertions were simplified to skips, not the other way around, right?

Yes

@ChenfengWei0
Copy link
Collaborator Author

ChenfengWei0 commented Oct 8, 2024

Update: temporarily fix the kind/incr issues by using static member

Copy link
Contributor

@lucasccordeiro lucasccordeiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChenfengWei0: please consider addressing Rafael's suggestion.

Copy link
Contributor

@lucasccordeiro lucasccordeiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChenfengWei0: please consider addressing Rafael's suggestion.

@lucasccordeiro lucasccordeiro merged commit a4f82bb into master Oct 9, 2024
13 checks passed
@lucasccordeiro lucasccordeiro deleted the branch_cov branch October 9, 2024 06:46
@lucasccordeiro
Copy link
Contributor

Thanks for submitting this PR, @ChenfengWei0.

@ChenfengWei0 ChenfengWei0 restored the branch_cov branch October 10, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants