Skip to content

Commit e7c387d

Browse files
committed
Regression tests for symex shortest path search heuristics
This is all the regression tests from regression/symex that only have one property, and all the regression tests from regression/symex-infeasibility that the default symex search heuristic (dfs) can complete in a reasonable amount of time.
1 parent 23854dc commit e7c387d

File tree

64 files changed

+1525
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1525
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
default: tests.log
2+
3+
test:
4+
@../test.pl -c "../../../src/symex/symex --shortest-path"
5+
@../test.pl -c "../../../src/symex/symex --shortest-path --randomize"
6+
7+
tests.log: ../test.pl
8+
@../test.pl -c "../../../src/symex/symex --shortest-path"
9+
@../test.pl -c "../../../src/symex/symex --shortest-path --randomize"
10+
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 '*.out' -execdir $(RM) '{}' \;
21+
find -name '*.gb' -execdir $(RM) '{}' \;
22+
$(RM) tests.log
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// This file contains code snippets from "Algorithms in C, Third Edition,
2+
// Parts 1-4," by Robert Sedgewick.
3+
//
4+
// See https://www.cs.princeton.edu/~rs/Algs3.c1-4/code.txt
5+
6+
#include <stdlib.h>
7+
#include <assert.h>
8+
9+
#define N 1000
10+
11+
12+
#ifdef ENABLE_KLEE
13+
#include <klee/klee.h>
14+
#endif
15+
16+
typedef int Key;
17+
typedef int Item;
18+
19+
#define eq(A, B) (!less(A, B) && !less(B, A))
20+
#define key(A) (A)
21+
#define less(A, B) (key(A) < key(B))
22+
#define NULLitem 0
23+
24+
struct STnode;
25+
typedef struct STnode* link;
26+
27+
struct STnode { Item item; link l, r; int n; };
28+
static link head, z;
29+
30+
static link NEW(Item item, link l, link r, int n) {
31+
link x = malloc(sizeof *x);
32+
x->item = item; x->l = l; x->r = r; x->n = n;
33+
return x;
34+
}
35+
36+
void STinit() {
37+
head = (z = NEW(NULLitem, 0, 0, 0));
38+
}
39+
40+
int STcount() { return head->n; }
41+
42+
static link insertR(link h, Item item) {
43+
Key v = key(item), t = key(h->item);
44+
if (h == z) return NEW(item, z, z, 1);
45+
46+
if (less(v, t))
47+
h->l = insertR(h->l, item);
48+
else
49+
h->r = insertR(h->r, item);
50+
51+
(h->n)++; return h;
52+
}
53+
54+
void STinsert(Item item) { head = insertR(head, item); }
55+
56+
static void sortR(link h, void (*visit)(Item)) {
57+
if (h == z) return;
58+
sortR(h->l, visit);
59+
visit(h->item);
60+
sortR(h->r, visit);
61+
}
62+
63+
void STsort(void (*visit)(Item)) { sortR(head, visit); }
64+
65+
66+
static Item a[N];
67+
static unsigned k = 0;
68+
void sorter(Item item) {
69+
a[k++] = item;
70+
}
71+
72+
#ifdef ENABLE_CPROVER
73+
int nondet_int();
74+
#endif
75+
76+
// Unwind N+1 times
77+
int main() {
78+
#ifdef ENABLE_KLEE
79+
klee_make_symbolic(a, sizeof(a), "a");
80+
#endif
81+
82+
STinit();
83+
84+
for (unsigned i = 0; i < N; i++) {
85+
#ifdef ENABLE_CPROVER
86+
STinsert(nondet_int());
87+
#elif ENABLE_KLEE
88+
STinsert(a[i]);
89+
a[i] = NULLitem;
90+
#endif
91+
}
92+
93+
STsort(sorter);
94+
95+
#ifndef FORCE_BRANCH
96+
for (unsigned i = 0; i < N - 1; i++)
97+
assert(a[i] <= a[i+1]);
98+
#endif
99+
100+
return 0;
101+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <assert.h>
2+
3+
#define N 40000
4+
5+
int main(void) {
6+
unsigned n = 1;
7+
unsigned sum = 0;
8+
9+
while (n <= N)
10+
{
11+
sum = sum + n;
12+
n = n + 1;
13+
}
14+
15+
assert(sum != ((N * (N + 1)) / 2));
16+
17+
return 0;
18+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
main.c
3+
4+
^VERIFICATION FAILED$
5+
--
6+
^warning: ignoring
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
int main(void) {
4+
unsigned n = 1;
5+
unsigned sum = 0;
6+
7+
while (n <= N)
8+
{
9+
sum = sum + n;
10+
n = n + 1;
11+
}
12+
13+
assert(sum != ((N * (N + 1)) / 2));
14+
15+
return 0;
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <assert.h>
2+
3+
#define N 40000
4+
5+
// conservatively safe for N <= 46340
6+
int main(void) {
7+
unsigned n = 1;
8+
unsigned sum = 0;
9+
10+
while (n <= N)
11+
{
12+
sum = sum + n;
13+
n = n + 1;
14+
}
15+
16+
//#ifndef FORCE_BRANCH
17+
assert(sum == ((N * (N + 1)) / 2));
18+
//#endif
19+
20+
return 0;
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Similar to SV-COMP'14 (loops/count_up_down_false.c) except
2+
// that we use explicit signedness constraints to support
3+
// benchmarks with tools that are not bit precise.
4+
5+
#include <assert.h>
6+
7+
#define N 10
8+
#define ENABLE_CPROVER
9+
10+
#ifdef ENABLE_KLEE
11+
#include <klee/klee.h>
12+
#endif
13+
14+
#ifdef ENABLE_CPROVER
15+
int nondet_int();
16+
#endif
17+
18+
// It suffices to unwind N times
19+
int main() {
20+
#ifdef ENABLE_CPROVER
21+
int n = nondet_int();
22+
__CPROVER_assume(0 <= n && n < N);
23+
#elif ENABLE_KLEE
24+
int n;
25+
klee_make_symbolic(&n, sizeof(n), "n");
26+
if (0 > n)
27+
return 0;
28+
if (n >= N)
29+
return 0;
30+
#endif
31+
32+
int x = n, y = 0;
33+
while (x > 0) {
34+
x = x - 1;
35+
y = y + 1;
36+
}
37+
assert(0 <= y && y != n);
38+
return 0;
39+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
main.c
3+
4+
^VERIFICATION FAILED$
5+
--
6+
^warning: ignoring
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
void main()
2+
{
3+
int i,x,y=0,z=0;
4+
for(i=0;i < 10;++i)
5+
//while(1)
6+
{
7+
if(x)
8+
y++;
9+
else
10+
z++;
11+
}
12+
assert(1);
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <assert.h>
2+
3+
void (*f_ptr)(void);
4+
5+
int global;
6+
7+
void f1(void)
8+
{
9+
global=1;
10+
}
11+
12+
void f2(void)
13+
{
14+
global=2;
15+
}
16+
17+
int main()
18+
{
19+
int input;
20+
21+
f_ptr=f1;
22+
f_ptr();
23+
// assert(global==1);
24+
25+
f_ptr=f2;
26+
f_ptr();
27+
// assert(global==2);
28+
29+
f_ptr=input?f1:f2;
30+
f_ptr();
31+
assert(global==(input?1:2));
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file contains modified code snippets from "Algorithms in C, Third Edition,
2+
// Parts 1-4," by Robert Sedgewick. The code is intentionally buggy!
3+
//
4+
// For the correct code, see https://www.cs.princeton.edu/~rs/Algs3.c1-4/code.txt
5+
6+
#include <assert.h>
7+
8+
#define N 5
9+
10+
11+
#ifdef ENABLE_KLEE
12+
#include <klee/klee.h>
13+
#endif
14+
15+
typedef int Item;
16+
#define key(A) (A)
17+
#define less(A, B) (key(A) < key(B))
18+
#define exch(A, B) { Item t = A; A = B; B = t; }
19+
#define compexch(A, B) if (less(B, A)) exch(A, B)
20+
21+
void insertion_sort(Item a[], int l, int r) {
22+
int i;
23+
for (i = l+1; i <= r; i++) compexch(a[l], a[i]);
24+
for (i = l+2; i <= r; i++) {
25+
int j = i; Item v = a[i];
26+
while (0 < j && less(v, a[j-1])) {
27+
a[j] = a[j]; j--;
28+
// ^ bug due to wrong index (it should be j-1)
29+
}
30+
a[j] = v;
31+
}
32+
}
33+
34+
// To find bug, let N >= 4.
35+
int main() {
36+
int a[N];
37+
38+
#ifdef ENABLE_KLEE
39+
klee_make_symbolic(a, sizeof(a), "a");
40+
#endif
41+
42+
insertion_sort(a, 0, N-1);
43+
for (unsigned i = 0; i < N - 1; i++)
44+
assert(a[i] <= a[i+1]);
45+
46+
return 0;
47+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
main.c
3+
4+
^VERIFICATION FAILED$
5+
--
6+
^warning: ignoring

0 commit comments

Comments
 (0)