Skip to content

Cover failed assertions #5636

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

Conversation

hannes-steffenhagen-diffblue
Copy link
Contributor

This adds an option --cover-failed-assertions that prevents the
default behaviour of coverage stopping at failed assertions by turning
assertions into skips rather than assumes (which is the default
behaviour for coverage criteria other than assertion, which behaves
the same with or without the flag).

This is one way to address #5543

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

These were previously duplicated between 3 different executables.
}
else
{
i_it->turn_into_skip();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Btw we have to skip them rather than just leaving them be because otherwise cbmc would consider these assertions coverage goals.

Copy link
Member

Choose a reason for hiding this comment

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

Why not make --no-assertions (aka turn-assertions-into-skips) useable with --cover then (as @martin-cs suggests)? That would make the behaviour more transparent to the user.

This adds an option `--cover-failed-assertions` that prevents the
default behaviour of coverage stopping at failed assertions by turning
assertions into skips rather than assumes (which is the default
behaviour for coverage criteria other than `assertion`, which behaves
the same with or without the flag).
proceeds the same as in all-properties mode. Coverage solving is implemented by
`bmc_covert`, but is structurally practically identical to
equation solver; In cases where this behaviour is undesirable you can pass the
`--cover-failed-assertions` which makes coverage checking continue even for
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW shouldn’t this file be under doc rather than src? I don’t really understand our documentation structure...

Copy link
Member

Choose a reason for hiding this comment

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

The READMEs which are in each module are pulled into here: http://cprover.diffblue.com/folder-walkthrough.html (click on cbmc, for example).
We decided to keep them in the source folders so that they are as close as possible to the code.

@codecov
Copy link

codecov bot commented Nov 27, 2020

Codecov Report

Merging #5636 (bad0d16) into develop (3fec6e1) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #5636   +/-   ##
========================================
  Coverage    69.35%   69.35%           
========================================
  Files         1241     1241           
  Lines       100596   100601    +5     
========================================
+ Hits         69771    69776    +5     
  Misses       30825    30825           
Flag Coverage Δ
cproversmt2 43.28% <100.00%> (+0.12%) ⬆️
regression 66.25% <100.00%> (+<0.01%) ⬆️
unit 32.27% <77.77%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
jbmc/src/jdiff/jdiff_parse_options.cpp 68.50% <ø> (ø)
jbmc/src/jdiff/jdiff_parse_options.h 100.00% <ø> (ø)
src/cbmc/cbmc_parse_options.cpp 77.62% <ø> (ø)
src/cbmc/cbmc_parse_options.h 100.00% <ø> (ø)
src/goto-diff/goto_diff_parse_options.cpp 66.20% <ø> (ø)
src/goto-diff/goto_diff_parse_options.h 100.00% <ø> (ø)
src/goto-instrument/cover.h 100.00% <ø> (ø)
src/goto-instrument/cover.cpp 85.31% <100.00%> (+0.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3fec6e1...bad0d16. Read the comment docs.

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

Approve because the refactor is good. I would prefer if the new option could be added in to the argument for --cover and I would prefer it even more if we could make assertion transformation orthogonal to and preceeding coverage assertions or at least have a conversation about it but I also realise that you need to get stuff done so approve.

" --cover CC create test-suite with coverage criterion CC\n"
#define OPT_COVER \
"(cover):" \
"(cover-failed-assertions)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to have this as an argument to --cover?

@@ -22,6 +22,10 @@ class message_handlert;
class cmdlinet;
class optionst;

#define OPT_COVER "(cover):"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for this refactoring. Finding an removing unnecessary and redundant repetition is always good.

There is one further BMC mode that differs more fundamentally: when `--cover` is
passed, assertions in the program text are converted into assumptions (these
There is one further BMC mode that differs more fundamentally: when `--cover`
is passed, assertions in the program text are converted into assumptions (these
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't want to open a massive can of worms here but ... why is this the default? Is this actually useful? Given that there are options for --no-assertions, --no-assumptions and --assert-to-assume (whether they work or even do anything at all ... is an open question) could we make the transformation of assertions and assumptions orthogonal to --cover. It feels like this should be possible and even desirable...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@martin-cs I think this is the default because whoever wrote this had the expectation that programs should stop at failed assertions. I suppose we could change it, but I’m always a bit wary about changing defaults.

Copy link
Contributor Author

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue Dec 11, 2020

Choose a reason for hiding this comment

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

@martin-cs FWIW because cover treats each failed goal as something relating to coverage right now we have to do something with asserts. That said, I think the alternative (just making cover cleverer about how it counts coverage) would be more desirable.

I'd consider that as something we can take a look at in terms of future work though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, if you are doing a naive count then, I see the need to do something with pre-existing assertions or otherwise true assertions (generally a good thing) will count against your coverage. Smarter counting would certainly be one way to address this.

It feels to me that making the "doing something about asserts" independent might be a desirable option as well. I can see use-cases for converting to SKIP, to ASSUME and leaving as they are.

Then again, I am not a user of this code at the moment and do not have time to work on it so my views maybe not so important.

NlightNFotis and others added 3 commits December 7, 2020 11:31
The tests are failing when the `--paths` flag is set.
This is because we understand that the paths code hasn't
been exercised thoroughly, and as a result this behaviour
may or may not indicate a potential issue -  we need to
investigate this at a later point.
@@ -34,6 +34,9 @@
['unknown-argument-suggestion', 'test.desc'],
# this one produces XML intermingled with main XML output when used with --xml-ui
['graphml_witness2', 'test.desc'],
# these are producing coverage goals which aren't including in the schema
Copy link
Member

Choose a reason for hiding this comment

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

including -> included?

}
else
{
i_it->turn_into_skip();
Copy link
Member

Choose a reason for hiding this comment

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

Why not make --no-assertions (aka turn-assertions-into-skips) useable with --cover then (as @martin-cs suggests)? That would make the behaviour more transparent to the user.

@hannes-steffenhagen-diffblue
Copy link
Contributor Author

hannes-steffenhagen-diffblue commented Dec 14, 2020

@peterschrammel --no-assertions applies to goto_check assertions, it only turns user provided assertions into skips. What we'd want for cover is to turn all non-cover related assertions into skips, user added or not. Making it work differently depending on whether or not --cover is passed would be confusing.

That said, maybe the better solution would be to make sure cover only checks cover-added assertions for coverage metrics instead of this skip-workaround...

@peterschrammel
Copy link
Member

...unless you use --cover assertion.

@hannes-steffenhagen-diffblue
Copy link
Contributor Author

hannes-steffenhagen-diffblue commented Dec 14, 2020

I don’t think the behaviour is any different for --cover assertion? It still only removes user assertions (from what I can tell --cover assertions doesn’t care specifically about this option at all, this is all happening in goto check), and the original complaint this is meant to address is that coverage changes based on whether or not you pass in the various *-check flags (which I think may well be expected behaviour in some circumstances, but is clearly not the only reasonable behaviour).

It’s just that (only) removing user assertions is actually what we want for --cover assertion I guess.

Copy link
Contributor

@thomasspriggs thomasspriggs left a comment

Choose a reason for hiding this comment

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

Seems reasonable. If it was up to me, I would squash the commits fixing the tests back into the commit where they were added. This is because it could make use of git bisect easier, if we ever need to use it. Please fix the spelling error noted by Peter before this is merged.

@@ -73,8 +75,9 @@ class optionst;
"(property):(stop-on-fail)(trace)" \
"(error-label):(verbosity):(no-library)" \
"(nondet-static)" \
"(version)" \
"(cover):(symex-coverage-report):" \
"(version)" \
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Is this additional spacing accidental?

^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ It would be nice to have a comment in each of .desc files explaining what the test is intended to test. Even something pretty short could make this a while lot easier to maintain.

#define HELP_COVER \
" --cover CC create test-suite with coverage criterion " \
"CC\n" \
" --cover-failed-assertions do not stop coverage checking at failed " \
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ Because of the preceding refactor, this option now applies to jdiff and goto-diff as well as cbmc. This means that we should probably test that it works with those entry points.

" --cover CC create test-suite with coverage criterion CC\n"
#define OPT_COVER \
"(cover):" \
"(cover-failed-assertions)"
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ If we keep this as a separate option from --cover then we should check that --cover-failed-assertions is not passed without --cover and exit with a suitable error message in the case of that particular invalid usage.

Copy link
Member

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

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

I understand that this needs a quick fix. But I don't think that the current solution will be the last. The options around goto check assertions, user assertions, cover, the various -no-X options, etc need to be made consistent so that they can be used in a clearly understandable and orthogonal way without subtle side effects.

@martin-cs
Copy link
Collaborator

I realise this is easy for me to say as 1. it's not me doing the work and 2. it's not me in need of the urgent fix but... +1 agree with @peterschrammel . This has been a mess for too long. I will leave it up to others (those that 1 and 2 apply to) to decide how this PR should relate to that work.

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue merged commit 932599e into diffblue:develop Jan 8, 2021
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