-
Notifications
You must be signed in to change notification settings - Fork 277
Selective modelling of volatile variables #5374
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
Changes from all commits
611f8a1
4b841c7
47bb11e
d08257e
cc46483
47ad91a
d8c6441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <assert.h> | ||
|
||
volatile int x; | ||
int y; | ||
|
||
void main() | ||
{ | ||
y = x; | ||
assert(x == y); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
test.c | ||
--nondet-volatile | ||
^\[main.assertion.1\] line \d+ assertion x == y: FAILURE$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
Check interaction between a volatile and a non-volatile variable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <assert.h> | ||
|
||
volatile int a; | ||
volatile int b; | ||
|
||
int model() | ||
{ | ||
int value; | ||
__CPROVER_assume(value >= 0); | ||
return value; | ||
} | ||
|
||
void main() | ||
{ | ||
assert(a == 0); | ||
|
||
assert(b >= 0); | ||
assert(b == 0); | ||
assert(b != 0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
test.c | ||
--nondet-volatile-model b:model | ||
\[main.assertion.1\] line \d+ assertion a == 0: SUCCESS | ||
\[main.assertion.2\] line \d+ assertion b >= 0: SUCCESS | ||
\[main.assertion.3\] line \d+ assertion b == 0: FAILURE | ||
\[main.assertion.4\] line \d+ assertion b != 0: FAILURE | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
Checks that the read from b is modelled via the given model |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <assert.h> | ||
|
||
volatile int a; | ||
volatile int b; | ||
volatile int c; | ||
|
||
int model() | ||
{ | ||
int value; | ||
__CPROVER_assume(value >= 0); | ||
return value; | ||
} | ||
|
||
void main() | ||
{ | ||
assert(a == 0); | ||
|
||
assert(b >= 0); | ||
assert(b == 0); | ||
assert(b != 0); | ||
|
||
assert(c >= 0); | ||
assert(c == 0); | ||
assert(c != 0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CORE | ||
test.c | ||
--nondet-volatile-variable b --nondet-volatile-model c:model | ||
\[main.assertion.1\] line \d+ assertion a == 0: SUCCESS | ||
\[main.assertion.2\] line \d+ assertion b >= 0: FAILURE | ||
\[main.assertion.3\] line \d+ assertion b == 0: FAILURE | ||
\[main.assertion.4\] line \d+ assertion b != 0: FAILURE | ||
\[main.assertion.5\] line \d+ assertion c >= 0: SUCCESS | ||
\[main.assertion.6\] line \d+ assertion c == 0: FAILURE | ||
\[main.assertion.7\] line \d+ assertion c != 0: FAILURE | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
Checks that both options for selectively havocking/modelling volatile reads can | ||
be used together |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <assert.h> | ||
|
||
volatile int a; | ||
volatile int b; | ||
|
||
int model_a() | ||
{ | ||
return 1; | ||
} | ||
|
||
int model_b() | ||
{ | ||
return 2; | ||
} | ||
|
||
void main() | ||
{ | ||
int result = a + b; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, does this work if the global is read via volatile pointer? (I'm assuming no, just for clarification). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that's right, it currently only works for direct variable reads. (One could also mark a pointer as nondet, in which case the pointer dereferences would be nondet as well. Though when |
||
assert(result == 3); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CORE | ||
test.c | ||
--nondet-volatile-model a:model_a --nondet-volatile-model b:model_b | ||
\[main.assertion.1\] line \d+ assertion result == 3: SUCCESS | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
VERIFICATION SUCCESSFUL | ||
-- | ||
-- | ||
Checks that two volatile reads in the same expression can both be modelled by | ||
given functions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <assert.h> | ||
|
||
volatile int a; | ||
|
||
float model() | ||
{ | ||
return 1; | ||
} | ||
|
||
void main() | ||
{ | ||
a; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CORE | ||
test.c | ||
--nondet-volatile-model a:model | ||
^Invalid User Input$ | ||
return type of model .* is not compatible with the type of the modelled variable | ||
^EXIT=1$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
Check that the command line typechecking reports when a model with a return type | ||
that is incompatible with the type of the modelled variable is given |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CORE | ||
test.c | ||
--nondet-volatile-model a:non_existing_model | ||
^Invalid User Input$ | ||
given model name .* not found in symbol table | ||
^EXIT=1$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
Check that the command line typechecking reports when a given model for a | ||
variable cannot be found |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <assert.h> | ||
|
||
volatile int a; | ||
|
||
int model_a() | ||
{ | ||
return 1; | ||
} | ||
|
||
int model_b() | ||
{ | ||
return 2; | ||
} | ||
|
||
void main() | ||
{ | ||
a; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CORE | ||
test.c | ||
--nondet-volatile-model a:model_a --nondet-volatile-model a:model_b | ||
^Invalid User Input$ | ||
conflicting models for variable | ||
^EXIT=1$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
Check that the command line typechecking reports when two conflicting models are | ||
given for a variable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CORE | ||
test.c | ||
--nondet-volatile-model a:model_a --nondet-volatile-variable a | ||
^Invalid User Input$ | ||
conflicting options for variable | ||
^EXIT=1$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
Check that the command line typechecking reports when conflicting options are | ||
given for a variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one of these should have a regression test involving the interaction with non-volatile variables; E.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added