-
Notifications
You must be signed in to change notification settings - Fork 274
--cover assume
: Add assert statements before assume to check for coverage
#6329
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
16d3a2b
Enfold `assume` in an `assert(false)` to allow for easier debugging.
NlightNFotis ba0d138
Add reference test case for `--cover assume` code.
NlightNFotis 9b7d9e2
Add second test case that features assume statement hidden behind
NlightNFotis 3514772
[DOCS] Add documentation for the new `--cover assume` coverage criter…
NlightNFotis f869882
Fix Windows error by changing scope of namespace
TGWDB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <assert.h> | ||
|
||
int main() | ||
{ | ||
int x; | ||
__CPROVER_assume(x > 0); | ||
__CPROVER_assume(x < 0); | ||
assert(0 == 1); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CORE | ||
assume_assert.c | ||
--cover assume | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\[main.coverage.1\] file assume_assert.c line \d function main assert\(false\) before assume\(x > 0\): SATISFIED$ | ||
^\[main.coverage.2\] file assume_assert.c line \d function main assert\(false\) after assume\(x > 0\): SATISFIED$ | ||
^\[main.coverage.3\] file assume_assert.c line \d function main assert\(false\) before assume\(x < 0\): SATISFIED$ | ||
^\[main.coverage.4\] file assume_assert.c line \d function main assert\(false\) after assume\(x < 0\): FAILED$ | ||
-- | ||
^warning: ignoring |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <assert.h> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int a; | ||
|
||
if(a > 0) | ||
{ | ||
assert(a > 0); | ||
} | ||
else if(a < 0) | ||
{ | ||
__CPROVER_assume(a >= 0); | ||
assert(a < 0); | ||
} | ||
else | ||
{ | ||
assert(a == 0); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
assume_assert.c | ||
--cover assume | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\[main.coverage.1\] file assume_assert.c line \d+ function main assert\(false\) before assume\(a >= 0\): SATISFIED$ | ||
^\[main.coverage.2\] file assume_assert.c line \d+ function main assert\(false\) after assume\(a >= 0\): FAILED$ | ||
-- | ||
^warning: ignoring |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ class optionst; | |
|
||
enum class coverage_criteriont | ||
{ | ||
ASSUME, | ||
LOCATION, | ||
BRANCH, | ||
DECISION, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/// \file cover_instrument_assume.cpp | ||
/// Author: Diffblue Ltd. | ||
/// Coverage Instrumentation for ASSUME instructions. | ||
|
||
#include "cover_instrument.h" | ||
|
||
#include "ansi-c/expr2c.h" | ||
#include "goto-programs/goto_program.h" | ||
#include "util/std_expr.h" | ||
#include <util/namespace.h> | ||
|
||
/// Instrument program to check coverage of assume statements. | ||
/// \param function_id The name of the function under instrumentation. | ||
/// \param goto_program The goto-program (function under instrumentation). | ||
/// \param i_it The current instruction (instruction under instrumentation). | ||
/// \param make_assertion The assertion generator function. | ||
void cover_assume_instrumentert::instrument( | ||
const irep_idt &function_id, | ||
goto_programt &goto_program, | ||
goto_programt::targett &i_it, | ||
const cover_blocks_baset &, | ||
const assertion_factoryt &make_assertion) const | ||
{ | ||
if(i_it->is_assume()) | ||
{ | ||
const auto location = i_it->source_location; | ||
const auto assume_condition = | ||
expr2c(i_it->get_condition(), namespacet{symbol_tablet()}); | ||
const auto comment_before = | ||
"assert(false) before assume(" + assume_condition + ")"; | ||
const auto comment_after = | ||
"assert(false) after assume(" + assume_condition + ")"; | ||
|
||
const auto assert_before = make_assertion(false_exprt{}, location); | ||
goto_programt::targett t = goto_program.insert_before(i_it, assert_before); | ||
initialize_source_location(t, comment_before, function_id); | ||
|
||
const auto assert_after = make_assertion(false_exprt{}, location); | ||
t = goto_program.insert_after(i_it, assert_after); | ||
initialize_source_location(t, comment_after, function_id); | ||
} | ||
// Otherwise, skip existing assertions. | ||
else if(i_it->is_assert()) | ||
{ | ||
const auto location = i_it->source_location; | ||
// Filter based on if assertion was added by us as part of instrumentation. | ||
if(location.get_property_class() != "coverage") | ||
{ | ||
i_it->turn_into_skip(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.