Skip to content

Regression testing #6

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions regression/symex-shortest-path/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
default: tests.log

test:
@if ! ../../lib/cbmc/regression/test.pl -c "../../../src/symex/symex --shortest-path" ; then \
../../lib/cbmc/regression/failed-tests-printer.pl ; \
exit 1 ; \
fi

@if ! ../../lib/cbmc/regression/test.pl -c "../../../src/symex/symex --shortest-path --randomize" ; then \
../../lib/cbmc/regression/failed-tests-printer.pl ; \
exit 1 ; \
fi

tests.log: ../test.pl
@if ! ../../lib/cbmc/regression/test.pl -c "../../../src/symex/symex --shortest-path" ; then \
../../lib/cbmc/regression/failed-tests-printer.pl ; \
exit 1 ; \
fi

@if ! ../../lib/cbmc/regression/test.pl -c ../../../src/symex/symex "--shortest-path --randomize" ; then \
../../lib/cbmc/regression/failed-tests-printer.pl ; \
exit 1 ; \
fi

show:
@for dir in *; do \
if [ -d "$$dir" ]; then \
vim -o "$$dir/*.c" "$$dir/*.out"; \
fi; \
done;

clean:
find -name '*.out' -execdir $(RM) '{}' \;
find -name '*.gb' -execdir $(RM) '{}' \;
$(RM) tests.log
101 changes: 101 additions & 0 deletions regression/symex-shortest-path/bst-safe/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// This file contains code snippets from "Algorithms in C, Third Edition,
// Parts 1-4," by Robert Sedgewick.
//
// See https://www.cs.princeton.edu/~rs/Algs3.c1-4/code.txt

#include <stdlib.h>
#include <assert.h>

#define N 1000


#ifdef ENABLE_KLEE
#include <klee/klee.h>
#endif

typedef int Key;
typedef int Item;

#define eq(A, B) (!less(A, B) && !less(B, A))
#define key(A) (A)
#define less(A, B) (key(A) < key(B))
#define NULLitem 0

struct STnode;
typedef struct STnode* link;

struct STnode { Item item; link l, r; int n; };
static link head, z;

static link NEW(Item item, link l, link r, int n) {
link x = malloc(sizeof *x);
x->item = item; x->l = l; x->r = r; x->n = n;
return x;
}

void STinit() {
head = (z = NEW(NULLitem, 0, 0, 0));
}

int STcount() { return head->n; }

static link insertR(link h, Item item) {
Key v = key(item), t = key(h->item);
if (h == z) return NEW(item, z, z, 1);

if (less(v, t))
h->l = insertR(h->l, item);
else
h->r = insertR(h->r, item);

(h->n)++; return h;
}

void STinsert(Item item) { head = insertR(head, item); }

static void sortR(link h, void (*visit)(Item)) {
if (h == z) return;
sortR(h->l, visit);
visit(h->item);
sortR(h->r, visit);
}

void STsort(void (*visit)(Item)) { sortR(head, visit); }


static Item a[N];
static unsigned k = 0;
void sorter(Item item) {
a[k++] = item;
}

#ifdef ENABLE_CPROVER
int nondet_int();
#endif

// Unwind N+1 times
int main() {
#ifdef ENABLE_KLEE
klee_make_symbolic(a, sizeof(a), "a");
#endif

STinit();

for (unsigned i = 0; i < N; i++) {
#ifdef ENABLE_CPROVER
STinsert(nondet_int());
#elif ENABLE_KLEE
STinsert(a[i]);
a[i] = NULLitem;
#endif
}

STsort(sorter);

#ifndef FORCE_BRANCH
for (unsigned i = 0; i < N - 1; i++)
assert(a[i] <= a[i+1]);
#endif

return 0;
}
8 changes: 8 additions & 0 deletions regression/symex-shortest-path/bst-safe/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
18 changes: 18 additions & 0 deletions regression/symex-shortest-path/concrete-sum-unsafe/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <assert.h>

#define N 40000

int main(void) {
unsigned n = 1;
unsigned sum = 0;

while (n <= N)
{
sum = sum + n;
n = n + 1;
}

assert(sum != ((N * (N + 1)) / 2));

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
main.c

^VERIFICATION FAILED$
--
^warning: ignoring
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <assert.h>

int main(void) {
unsigned n = 1;
unsigned sum = 0;

while (n <= N)
{
sum = sum + n;
n = n + 1;
}

assert(sum != ((N * (N + 1)) / 2));

return 0;
}
21 changes: 21 additions & 0 deletions regression/symex-shortest-path/concrete-sum/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <assert.h>

#define N 40000

// conservatively safe for N <= 46340
int main(void) {
unsigned n = 1;
unsigned sum = 0;

while (n <= N)
{
sum = sum + n;
n = n + 1;
}

//#ifndef FORCE_BRANCH
assert(sum == ((N * (N + 1)) / 2));
//#endif

return 0;
}
8 changes: 8 additions & 0 deletions regression/symex-shortest-path/concrete-sum/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
39 changes: 39 additions & 0 deletions regression/symex-shortest-path/counter-unsafe/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Similar to SV-COMP'14 (loops/count_up_down_false.c) except
// that we use explicit signedness constraints to support
// benchmarks with tools that are not bit precise.

#include <assert.h>

#define N 10
#define ENABLE_CPROVER

#ifdef ENABLE_KLEE
#include <klee/klee.h>
#endif

#ifdef ENABLE_CPROVER
int nondet_int();
#endif

// It suffices to unwind N times
int main() {
#ifdef ENABLE_CPROVER
int n = nondet_int();
__CPROVER_assume(0 <= n && n < N);
#elif ENABLE_KLEE
int n;
klee_make_symbolic(&n, sizeof(n), "n");
if (0 > n)
return 0;
if (n >= N)
return 0;
#endif

int x = n, y = 0;
while (x > 0) {
x = x - 1;
y = y + 1;
}
assert(0 <= y && y != n);
return 0;
}
6 changes: 6 additions & 0 deletions regression/symex-shortest-path/counter-unsafe/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
main.c

^VERIFICATION FAILED$
--
^warning: ignoring
13 changes: 13 additions & 0 deletions regression/symex-shortest-path/for-loop/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
void main()
{
int i,x,y=0,z=0;
for(i=0;i < 10;++i)
//while(1)
{
if(x)
y++;
else
z++;
}
assert(1);
}
8 changes: 8 additions & 0 deletions regression/symex-shortest-path/for-loop/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
32 changes: 32 additions & 0 deletions regression/symex-shortest-path/function_pointer1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <assert.h>

void (*f_ptr)(void);

int global;

void f1(void)
{
global=1;
}

void f2(void)
{
global=2;
}

int main()
{
int input;

f_ptr=f1;
f_ptr();
// assert(global==1);

f_ptr=f2;
f_ptr();
// assert(global==2);

f_ptr=input?f1:f2;
f_ptr();
assert(global==(input?1:2));
}
8 changes: 8 additions & 0 deletions regression/symex-shortest-path/function_pointer1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
47 changes: 47 additions & 0 deletions regression/symex-shortest-path/insertion-sort-unsafe/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This file contains modified code snippets from "Algorithms in C, Third Edition,
// Parts 1-4," by Robert Sedgewick. The code is intentionally buggy!
//
// For the correct code, see https://www.cs.princeton.edu/~rs/Algs3.c1-4/code.txt

#include <assert.h>

#define N 5


#ifdef ENABLE_KLEE
#include <klee/klee.h>
#endif

typedef int Item;
#define key(A) (A)
#define less(A, B) (key(A) < key(B))
#define exch(A, B) { Item t = A; A = B; B = t; }
#define compexch(A, B) if (less(B, A)) exch(A, B)

void insertion_sort(Item a[], int l, int r) {
int i;
for (i = l+1; i <= r; i++) compexch(a[l], a[i]);
for (i = l+2; i <= r; i++) {
int j = i; Item v = a[i];
while (0 < j && less(v, a[j-1])) {
a[j] = a[j]; j--;
// ^ bug due to wrong index (it should be j-1)
}
a[j] = v;
}
}

// To find bug, let N >= 4.
int main() {
int a[N];

#ifdef ENABLE_KLEE
klee_make_symbolic(a, sizeof(a), "a");
#endif

insertion_sort(a, 0, N-1);
for (unsigned i = 0; i < N - 1; i++)
assert(a[i] <= a[i+1]);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
main.c

^VERIFICATION FAILED$
--
^warning: ignoring
Loading