Skip to content

Commit 27ca92f

Browse files
committed
Add --paths tests for exploration strategies
This commit introduces a regression test suite specifically for testing path exploration strategies when using cbmc with --paths. This test suite is intended to ensure that paths are pushed and popped onto the workqueue in the correct order as specified by their search strategy. This commit contains a test suite for the FIFO exploration strategy. This commit introduces a script for generating test.desc files. This is needed because the multi-line regexes for matching the order of path pushes and pops are very cumbersome to write and difficult to read. Thus, the test.desc files are generated from a test.in file, which includes a human-friendly description of what push, pop and execute events should be expected during symbolic execution. A new script, scripts/make_descs.py, interprets those events and generates a test.desc from them before running the test suite.
1 parent 466452f commit 27ca92f

File tree

11 files changed

+389
-0
lines changed

11 files changed

+389
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ regression/**/*.smt2
5757
# regression/coverage file
5858
/regression/coverage_**
5959

60+
# These files are generated from the test.in file in their directories
61+
regression/cbmc-path-fifo/*/test.desc
62+
6063
# files stored by editors
6164
*~
6265

regression/cbmc-path-fifo/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
default: tests.log
2+
3+
test: gen-desc
4+
@../test.pl -j 12 -p -c "../../../src/cbmc/cbmc --paths --verbosity 10"
5+
6+
tests.log: ../test.pl gen-desc
7+
@../test.pl -j 12 -p -c "../../../src/cbmc/cbmc --paths --verbosity 10"
8+
9+
gen-desc:
10+
@../../scripts/make_descs.py
11+
12+
show:
13+
@for dir in *; do \
14+
if [ -d "$$dir" ]; then \
15+
vim -o "$$dir/*.c" "$$dir/*.out"; \
16+
fi; \
17+
done;
18+
19+
clean:
20+
find -name 'test.desc' -execdir $(RM) '{}' \;
21+
find -name '*.out' -execdir $(RM) '{}' \;
22+
find -name '*.gb' -execdir $(RM) '{}' \;
23+
$(RM) tests.log

regression/cbmc-path-fifo/if/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int main()
2+
{
3+
int x;
4+
if(x)
5+
x = 1;
6+
else
7+
x = 0;
8+
}

regression/cbmc-path-fifo/if/test.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CORE
2+
main.c
3+
4+
activate-multi-line-match
5+
EXIT=0
6+
SIGNAL=0
7+
--
8+
^warning: ignoring
9+
--
10+
Test that the following happens in order:
11+
execute line 4
12+
save line 7
13+
execute line 5
14+
any lines
15+
path is successful
16+
any lines
17+
execute line 4
18+
resume line 7
19+
execute line 7
20+
any lines
21+
path is successful
22+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int main()
2+
{
3+
int x;
4+
__CPROVER_assume(x > 0);
5+
6+
while(x)
7+
--x;
8+
9+
assert(x);
10+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CORE
2+
main.c
3+
--unwind 2
4+
activate-multi-line-match
5+
SIGNAL=0
6+
EXIT=10
7+
--
8+
^warning: ignoring
9+
--
10+
This tests the following:
11+
12+
- Symex saves the path that traverses the loop once, then the path that
13+
traverses the loop twice;
14+
15+
- Symex pops the path that traverses the loop once, then the path that
16+
traverses the loop twice.
17+
18+
The path that traverses the loop twice is the one that would cause an
19+
assertion failure, thus that result must appear last rather than second
20+
last.
21+
22+
Test that the following happens in order:
23+
// Loop 0 times
24+
path is successful
25+
any lines
26+
// Loop once
27+
path is successful
28+
any lines
29+
// Loop twice
30+
path is unsuccessful
31+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int main()
2+
{
3+
int x,y;
4+
if(x)
5+
{
6+
if(y)
7+
y = 1;
8+
else
9+
y = 0;
10+
}
11+
else
12+
{
13+
if(y)
14+
y = 1;
15+
else
16+
y = 0;
17+
}
18+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CORE
2+
main.c
3+
4+
activate-multi-line-match
5+
EXIT=0
6+
SIGNAL=0
7+
--
8+
^warning: ignoring
9+
--
10+
Test that the following happens in order:
11+
execute line 4
12+
save line 13
13+
execute line 6
14+
save line 9
15+
execute line 7
16+
any lines
17+
path is successful
18+
any lines
19+
execute line 4
20+
resume line 13
21+
execute line 13
22+
save line 16
23+
execute line 14
24+
any lines
25+
path is successful
26+
any lines
27+
execute line 6
28+
resume line 9
29+
execute line 9
30+
any lines
31+
path is successful
32+
any lines
33+
execute line 13
34+
resume line 16
35+
execute line 16
36+
any lines
37+
path is successful
38+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int main()
2+
{
3+
int x;
4+
while(x)
5+
{
6+
int y;
7+
}
8+
int y;
9+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
CORE
2+
main.c
3+
--unwind 2
4+
activate-multi-line-match
5+
EXIT=0
6+
SIGNAL=0
7+
--
8+
^warning: ignoring
9+
--
10+
Test that the following happens in order:
11+
execute line 4
12+
//
13+
// Save that the loop condition was never satisfied
14+
//
15+
save line 8
16+
execute line 6
17+
any lines
18+
execute line 4
19+
unwind
20+
//
21+
// Save that the loop condition was satisfied once but not twice
22+
//
23+
save line 8
24+
execute line 6
25+
any lines
26+
//
27+
// Escape the loop
28+
//
29+
execute line 8
30+
any lines
31+
path is successful
32+
//
33+
// Now do the first break out of the loop...
34+
//
35+
any lines
36+
execute line 4
37+
resume line 8
38+
execute line 8
39+
any lines
40+
path is successful
41+
//
42+
// ...and the second.
43+
//
44+
any lines
45+
execute line 4
46+
resume line 8
47+
execute line 8
48+
any lines
49+
path is successful
50+
end

0 commit comments

Comments
 (0)