Skip to content

Tests to check inconsistent assumptions involving __CPROVER_r_ok #5321

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 2 commits into from
May 6, 2020

Conversation

danpoe
Copy link
Contributor

@danpoe danpoe commented Apr 24, 2020

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a 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).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@danpoe danpoe force-pushed the tests/pointer-primitives branch from 85de939 to fa60778 Compare April 24, 2020 15:16
@danpoe danpoe added the aws Bugs or features of importance to AWS CBMC users label Apr 24, 2020
Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

Looks good - some general comments, also I note these are only for r_ok, we presumably need them for the other primitives.

Overall comments:

  • Do we need to test the local and global pointer every time? Produces a lot of duplication, do they end up looking very different in the formulas?
  • Should we be testing pointers to memory mallocd with > size of the object (e.g. arrays)
  • Should we be testing pointers to statically allocated arrays
  • Should we best testing pointers that are passed in from another function

Also, this is a lot of quite specific tests. I'd be tempted to move them out of regression/cbmc (perhaps into a folder called cprover-primitives, or perhaps tag them as THROUGH when they are enabled

--
^warning: ignoring
--
Tests that an inconsistent assumption involving a pointer to an out of scope
Copy link
Contributor

Choose a reason for hiding this comment

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

💚 Thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

Though an explanation of why FUTURE (and link to relevant ticket) would be good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the test and the test description already provide this explanation. The FUTURE just indicates that the test does not currently pass.

@@ -0,0 +1,10 @@
FUTURE
main.c
--function test_global_pointer --pointer-check --no-simplify --no-propagation
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Could we include somewhere an explanation why the no-propagation flag is needed to be tested separately?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think I should add an explanation to every .desc file? Basically we want to test with --no-simplify --no-propagation (which turns off expression simplification and constant propagation) and without those two, so as to check that both the constraint encoding and the simplification/constant propagation work correctly.

@@ -0,0 +1,11 @@
KNOWNBUG
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this knownbug rather than future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This particular test made cbmc crash. I'll add a comment to say that, and will add a simpler test too that shows the same bug.

__CPROVER_assume(p1 != NULL);

__CPROVER_assume(
!__CPROVER_r_ok(p1, 1) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd highlight the negation here with a comment explaining the purpose

Copy link
Contributor

Choose a reason for hiding this comment

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

Ehh only if you think worth it - it is of course also explained in the description

}

__CPROVER_assume(__CPROVER_r_ok(p, 1));
assert(0); // fails
Copy link
Contributor

Choose a reason for hiding this comment

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

What does "fails" mean. Do you really mean unreachable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It means that the assertion fails, i.e. is reachable.

@@ -0,0 +1,10 @@
FUTURE
Copy link
Contributor

Choose a reason for hiding this comment

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

What does FUTURE mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests that currently don't pass but are not bugs are marked as FUTURE. This is typically used for tests for unimplemented features. Here the test doesn't pass due to the overapproximate behaviour of __CPROVER_r_ok(). If it will be made more pecise in the future it should pass.

@danpoe danpoe force-pushed the tests/pointer-primitives branch from fa60778 to f514175 Compare April 28, 2020 16:04
@danpoe
Copy link
Contributor Author

danpoe commented Apr 28, 2020

@thk123 Indeed the separate tests for global and local pointers were unnecessary. The intention was to account for differences in the result of the local bitvector analysis but it gives the same result for both cases.

@danpoe danpoe force-pushed the tests/pointer-primitives branch 3 times, most recently from f0527ae to b34b155 Compare April 29, 2020 17:06
@danpoe
Copy link
Contributor Author

danpoe commented Apr 30, 2020

@thk123 I've now put the tests in a new directory cbmc-primitives. The tests are very quick so don't need to be tagged as THOROUGH.

Regarding your points (2) and (3) above, we don't necessarily need to separately test these cases as the behaviour is exactly the same for malloced objects of size 1 or > 1 and for static objects of size 1 or size > 1 (i.e. statically allocated arrays). Also the behaviour will be the same for pointers passed into functions.

@danpoe danpoe force-pushed the tests/pointer-primitives branch from b34b155 to e9b5146 Compare April 30, 2020 10:29
@danpoe danpoe marked this pull request as ready for review April 30, 2020 10:35
Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

Probably what CI is telling you, but your new folder will need a Makefile and CMakeLists.txt to tell it how to behave. (A short README.md explaining the purpose of the folder would be appreciated, but not required).

Do you think I should add an explanation to every .desc file? Basically we want to test with --no-simplify --no-propagation (which turns off expression simplification and constant propagation) and without those two, so as to check that both the constraint encoding and the simplification/constant propagation work correctly.

Frankly yes - since no way to know what test will be opened, best to put it in all of them. Should of course just be the same sentence copy-pasted!

Anyways, thanks for the tweaks, blocking comments addressed - though would appreciate raising and referencing bugs for the crashes to be sure we turn the tests back on when they're fixed. Just need to add the Make stuff to the folder and we should be good.

--
^warning: ignoring
--
Crashes during the flattening
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty bad! I guess we should raise a bug?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should raise a bug/cbmc issue for this and mention it in the .desc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue recorded as #5328, and added the number to the .desc file.


void main()
{
// pointer with object bits = 123 and offset = 123
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the improvement - as the reader, I'm still left with the question of why you're constructing such a pointer. I think this would still be improved with a comment as to why this is an interesting pointer. Is it because it tricks cbmc into thinking it is valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's a pointer that doesn't point to valid memory but isn't special in any other way. Added a description.

Comment on lines +17 to +33
char *p1 = &c1;

assert(!__CPROVER_r_ok(p1, 2));
assert(!__CPROVER_r_ok(p1 - 1, 1));
assert(!__CPROVER_r_ok(p1 + 1, 1));

char *p2 = &c2;

assert(!__CPROVER_r_ok(p2, 2));
assert(!__CPROVER_r_ok(p2 - 1, 1));
assert(!__CPROVER_r_ok(p2 + 1, 1));

char *p3 = malloc(1);

assert(!__CPROVER_r_ok(p3, 2));
assert(!__CPROVER_r_ok(p3 - 1, 1));
assert(!__CPROVER_r_ok(p3 + 1, 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is much better imo 💚

@danpoe danpoe force-pushed the tests/pointer-primitives branch 2 times, most recently from 09be997 to f6a0800 Compare May 1, 2020 08:55
danpoe added 2 commits May 6, 2020 14:06
…VER_r_ok()

Adds tests to check that inconsistent assumptions involving __CPROVER_r_ok() can
be detected by checking if a subsequent assert(0) fails.
@danpoe danpoe force-pushed the tests/pointer-primitives branch from f6a0800 to b1be232 Compare May 6, 2020 13:07
@danpoe danpoe merged commit 873daa9 into diffblue:develop May 6, 2020
@danpoe danpoe deleted the tests/pointer-primitives branch June 2, 2020 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants