Skip to content

Create harness to initialize memory from snapshot #4150

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 7 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion regression/goto-harness/chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ if [ -e "${name}-mod.gb" ] ; then
fi

# `# some comment` is an inline comment - basically, cause bash to execute an empty command

$cbmc --show-goto-functions "${name}.gb"

Choose a reason for hiding this comment

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

Do you need this information for the tests or is this just intended to make debugging a bit easier?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not need, so I guess debugging.

$goto_harness "${name}.gb" "${name}-mod.gb" --harness-function-name $entry_point ${args}
$cbmc --show-goto-functions "${name}-mod.gb"
$cbmc --function $entry_point "${name}-mod.gb" \
--pointer-check `# because we want to see out of bounds errors` \
--unwind 11 `# with the way we set up arrays symex can't figure out loop bounds automatically` \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"symbolTable": {
"x": {
"baseName": "x",
"isAuxiliary": false,
"isExported": false,
"isExtern": false,
"isFileLocal": false,
"isInput": false,
"isLvalue": true,
"isMacro": false,
"isOutput": false,
"isParameter": false,
"isProperty": false,
"isStateVar": false,
"isStaticLifetime": true,
"isThreadLocal": false,
"isType": false,
"isVolatile": false,
"isWeak": false,
"location": {},
"mode": "C",
"module": "main",
"name": "x",
"prettyName": "x",
"type": {
"id": "signedbv",
"namedSub": {
"#c_type": {
"id": "signed_int"
},
"width": {
"id": "32"
}
}
},
"value": {
"id": "constant",
"namedSub": {
"#base": {
"id": "10"
},
"#source_location": {},
"type": {
"id": "signedbv",
"namedSub": {
"#c_type": {
"id": "signed_int"
},
"width": {
"id": "32"
}
}
},
"value": {
"id": "1"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
int x;
int flag;

int main()
{
x = 0;

assert(flag != 0 || x == 1);
assert(flag != 1 || x == 0);

if(flag == 0)
{
flag = 1;
main();
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--harness-type initialise-with-memory-snapshot --memory-snapshot ../load-snapshot-json-snapshots/global-int-x-1-snapshot.json --initial-location main:1
^EXIT=0$
^SIGNAL=0$
VERIFICATION SUCCESSFUL
--
^warning: ignoring
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
int x[] = {1, 2, 3};

int main()
{
assert(x[0] == 4);
assert(x[1] == 5);
assert(x[2] == 6);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
"symbolTable": {
"x": {
"baseName": "x",
"isAuxiliary": false,
"isExported": false,
"isExtern": false,
"isFileLocal": false,
"isInput": false,
"isLvalue": true,
"isMacro": false,
"isOutput": false,
"isParameter": false,
"isProperty": false,
"isStateVar": false,
"isStaticLifetime": true,
"isThreadLocal": false,
"isType": false,
"isVolatile": false,
"isWeak": false,
"location": {},
"mode": "C",
"module": "test",
"name": "x",
"prettyName": "x",
"type": {
"id": "array",
"namedSub": {
"#source_location": {},
"size": {
"id": "constant",
"namedSub": {
"type": {
"id": "signedbv",
"namedSub": {
"#c_type": {
"id": "signed_long_int"
},
"width": {
"id": "64"
}
}
},
"value": {
"id": "3"
}
}
}
},
"sub": [
{
"id": "signedbv",
"namedSub": {
"#c_type": {
"id": "signed_int"
},
"width": {
"id": "32"
}
}
}
]
},
"value": {
"id": "array",
"namedSub": {
"#source_location": {},
"type": {
"id": "array",
"namedSub": {
"#source_location": {},
"size": {
"id": "constant",
"namedSub": {
"type": {
"id": "signedbv",
"namedSub": {
"#c_type": {
"id": "signed_long_int"
},
"width": {
"id": "64"
}
}
},
"value": {
"id": "3"
}
}
}
},
"sub": [
{
"id": "signedbv",
"namedSub": {
"#c_type": {
"id": "signed_int"
},
"width": {
"id": "32"
}
}
}
]
}
},
"sub": [
{
"id": "constant",
"namedSub": {
"#base": {
"id": "10"
},
"#source_location": {},
"type": {
"id": "signedbv",
"namedSub": {
"#c_type": {
"id": "signed_int"
},
"width": {
"id": "32"
}
}
},
"value": {
"id": "4"
}
}
},
{
"id": "constant",
"namedSub": {
"#base": {
"id": "10"
},
"#source_location": {},
"type": {
"id": "signedbv",
"namedSub": {
"#c_type": {
"id": "signed_int"
},
"width": {
"id": "32"
}
}
},
"value": {
"id": "5"
}
}
},
{
"id": "constant",
"namedSub": {
"#base": {
"id": "10"
},
"#source_location": {},
"type": {
"id": "signedbv",
"namedSub": {
"#c_type": {
"id": "signed_int"
},
"width": {
"id": "32"
}
}
},
"value": {
"id": "6"
}
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--harness-type initialise-with-memory-snapshot --memory-snapshot snapshot.json --initial-location main:0
^EXIT=0$
^SIGNAL=0$
VERIFICATION SUCCESSFUL
--
^warning: ignoring
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int x;

int main()
{
assert(x == 1);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--harness-type initialise-with-memory-snapshot --memory-snapshot ../load-snapshot-json-snapshots/global-int-x-1-snapshot.json --initial-location main:0
^EXIT=0$
^SIGNAL=0$
VERIFICATION SUCCESSFUL
--
^warning: ignoring
10 changes: 10 additions & 0 deletions regression/goto-harness/load-snapshot-static-global-int-02/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
int x;
int y; // snapshot contains no value for y

int main()
{
assert(x == 1);
assert(y == 1);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--harness-type initialise-with-memory-snapshot --memory-snapshot ../load-snapshot-json-snapshots/global-int-x-1-snapshot.json --initial-location main:0
^EXIT=10$
^SIGNAL=0$
\[main.assertion.1\] line [0-9]+ assertion x == 1: SUCCESS
\[main.assertion.2\] line [0-9]+ assertion y == 1: FAILURE
--
^warning: ignoring
14 changes: 14 additions & 0 deletions regression/goto-harness/load-snapshot-static-global-int-03/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int x;

void func()
{
}

int main()
{
func();

assert(x == 1);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--harness-type initialise-with-memory-snapshot --memory-snapshot ../load-snapshot-json-snapshots/global-int-x-1-snapshot.json --initial-location main:0
^EXIT=0$
^SIGNAL=0$
VERIFICATION SUCCESSFUL
--
^warning: ignoring
10 changes: 10 additions & 0 deletions regression/goto-harness/load-snapshot-static-global-int-04/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
int x;

int main()
{
x = 0; // should be skipped

assert(x == 1);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--harness-type initialise-with-memory-snapshot --memory-snapshot ../load-snapshot-json-snapshots/global-int-x-1-snapshot.json --initial-location main:1
^EXIT=0$
^SIGNAL=0$
VERIFICATION SUCCESSFUL
--
^warning: ignoring
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
int x;
int *p; // has value &x in the snapshot

int main()
{
x = 1;

assert(*p == 1);

return 0;
}
Loading