-
Notifications
You must be signed in to change notification settings - Fork 275
Improved invariants #1063
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
Improved invariants #1063
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
driver |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
default: tests.log | ||
|
||
SRC = driver.cpp | ||
|
||
INCLUDES = -I ../../src | ||
|
||
OBJ += ../../src/util/util$(LIBEXT) | ||
|
||
include ../../src/config.inc | ||
include ../../src/common | ||
|
||
test: driver$(EXEEXT) | ||
@if ! ../test.pl -c ../driver ; then \ | ||
../failed-tests-printer.pl ; \ | ||
exit 1 ; \ | ||
fi | ||
|
||
tests.log: ../test.pl driver$(EXEEXT) | ||
@if ! ../test.pl -c ../driver ; then \ | ||
../failed-tests-printer.pl ; \ | ||
exit 1 ; \ | ||
fi | ||
|
||
show: | ||
@for dir in *; do \ | ||
if [ -d "$$dir" ]; then \ | ||
vim -o "$$dir/*.c" "$$dir/*.out"; \ | ||
fi; \ | ||
done; | ||
|
||
driver$(EXEEXT): $(OBJ) | ||
$(LINKBIN) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Invariant violation testing | ||
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. This should really go into 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. I think not - it isn't a unit test since it the test involves reading from In fact I believe this is one of the main problems with the use of To go back to @martin-cs's case for 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. True, I forgot that all the compile switches have gone now. |
||
|
||
Author: Chris Smowton, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Invariant violation testing | ||
|
||
#include <string> | ||
#include <sstream> | ||
#include <util/invariant.h> | ||
|
||
/// An example of structured invariants-- this contains fields to | ||
/// describe the error to a catcher, and also produces a human-readable | ||
/// message containing all the information for use by the current aborting | ||
/// invariant implementation and/or any generic error catcher in the future. | ||
class structured_error_testt: public invariant_failedt | ||
{ | ||
std::string pretty_print(int code, const std::string &desc) | ||
{ | ||
std::ostringstream ret; | ||
ret << "Error code: " << code | ||
<< "\nDescription: " << desc; | ||
return ret.str(); | ||
} | ||
|
||
public: | ||
const int error_code; | ||
const std::string description; | ||
|
||
structured_error_testt( | ||
const std::string &file, | ||
const std::string &function, | ||
int line, | ||
const std::string &backtrace, | ||
int code, | ||
const std::string &_description): | ||
invariant_failedt( | ||
file, | ||
function, | ||
line, | ||
backtrace, | ||
pretty_print(code, _description)), | ||
error_code(code), | ||
description(_description) | ||
{ | ||
} | ||
}; | ||
|
||
/// Causes an invariant failure dependent on first argument value. | ||
/// One ignored argument is accepted to conform with the test.pl script, | ||
/// which would be the input source file for other cbmc driver programs. | ||
/// Returns 1 on unexpected arguments. | ||
int main(int argc, char** argv) | ||
{ | ||
if(argc!=3) | ||
return 1; | ||
std::string arg=argv[1]; | ||
if(arg=="structured") | ||
INVARIANT_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT | ||
else if(arg=="string") | ||
INVARIANT(false, "Test invariant failure"); | ||
else if(arg=="precondition-structured") | ||
PRECONDITION_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT | ||
else if(arg=="precondition-string") | ||
PRECONDITION(false); | ||
else if(arg=="postcondition-structured") | ||
POSTCONDITION_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT | ||
else if(arg=="postcondition-string") | ||
POSTCONDITION(false); | ||
else if(arg=="check-return-structured") | ||
CHECK_RETURN_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT | ||
else if(arg=="check-return-string") | ||
CHECK_RETURN(false); | ||
else if(arg=="unreachable-structured") | ||
UNREACHABLE_STRUCTURED(structured_error_testt, 1, "Structured error"); // NOLINT | ||
else if(arg=="unreachable-string") | ||
UNREACHABLE; | ||
else if(arg=="data-invariant-structured") | ||
DATA_INVARIANT_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT | ||
else if(arg=="data-invariant-string") | ||
DATA_INVARIANT(false, "Test invariant failure"); | ||
else | ||
return 1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
dummy_parameter.c | ||
unreachable-structured | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Invariant check failed | ||
Error code: 1 | ||
Description: Structured error | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
dummy_parameter.c | ||
data-invariant-string | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Test invariant failure | ||
Invariant check failed | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
dummy_parameter.c | ||
data-invariant-structured | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Invariant check failed | ||
Error code: 1 | ||
Description: Structured error | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
dummy_parameter.c | ||
structured | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Invariant check failed | ||
Error code: 1 | ||
Description: Structured error | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
dummy_parameter.c | ||
precondition-string | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Precondition | ||
Invariant check failed | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
dummy_parameter.c | ||
precondition-structured | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Invariant check failed | ||
Error code: 1 | ||
Description: Structured error | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
dummy_parameter.c | ||
postcondition-string | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Postcondition | ||
Invariant check failed | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
dummy_parameter.c | ||
postcondition-structured | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Invariant check failed | ||
Error code: 1 | ||
Description: Structured error | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
dummy_parameter.c | ||
check-return-string | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Check return value | ||
Invariant check failed | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
dummy_parameter.c | ||
check-return-structured | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Invariant check failed | ||
Error code: 1 | ||
Description: Structured error | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
dummy_parameter.c | ||
unreachable-string | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Unreachable | ||
Invariant check failed | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
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 don't know - but I don't think the test.pl is required in the dependency list?