about summary refs log tree commit diff homepage
path: root/test/Replay
diff options
context:
space:
mode:
authorDan Liew <daniel.liew@imperial.ac.uk>2017-01-14 17:55:07 +0000
committerDan Liew <daniel.liew@imperial.ac.uk>2017-01-14 21:37:19 +0000
commit3c8cb4600392675a34f2505f630523a494844d3d (patch)
treebbe0cf8b9d2e369175ad03020d7bdb47e9e11aa9 /test/Replay
parent23e656156e4790a06a295d48932db53f2a582227 (diff)
downloadklee-3c8cb4600392675a34f2505f630523a494844d3d.tar.gz
Write tests to test `libkleeRuntest`. The `replay_posix_runtime.c`
test is marked XFAIL because there is a bug in the implementation
of `libkleeRuntest`.

Quite a few changes had to be made to the lit configuration in
order to support these tests.

To run the tests I had to fix #480 for the autoconf/Makefile build
system otherwise the `libkleeRuntest` library would not be found
by the system linker at runtime.
Diffstat (limited to 'test/Replay')
-rw-r--r--test/Replay/libkleeruntest/replay_posix_runtime.c36
-rw-r--r--test/Replay/libkleeruntest/replay_simple.c28
-rw-r--r--test/Replay/libkleeruntest/replay_two_objects.c33
3 files changed, 97 insertions, 0 deletions
diff --git a/test/Replay/libkleeruntest/replay_posix_runtime.c b/test/Replay/libkleeruntest/replay_posix_runtime.c
new file mode 100644
index 00000000..57f97dd0
--- /dev/null
+++ b/test/Replay/libkleeruntest/replay_posix_runtime.c
@@ -0,0 +1,36 @@
+// REQUIRES: posix-runtime
+// FIXME: We need to fix a bug in libkleeRuntest
+// XFAIL: *
+// RUN: %llvmgcc %s -emit-llvm -g -O0 -c -o %t.bc
+// RUN: rm -rf %t.klee-out
+// RUN: %klee --output-dir=%t.klee-out --posix-runtime --search=dfs %t.bc
+// RUN: test -f %t.klee-out/test000001.ktest
+// RUN: test -f %t.klee-out/test000002.ktest
+
+// Now try to replay with libkleeRuntest
+// RUN: %cc %s %libkleeruntest -Wl,-rpath=%libkleeruntestdir -o %t_runner
+// RUN: %ktest-tool %t.klee-out/test000001.ktest | FileCheck -check-prefix=CHECKMODEL %s
+// RUN: env KTEST_FILE=%t.klee-out/test000001.ktest %t_runner | FileCheck -check-prefix=TESTONE %s
+// RUN: env KTEST_FILE=%t.klee-out/test000002.ktest %t_runner | FileCheck -check-prefix=TESTTWO %s
+
+#include "klee/klee.h"
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+  int x = 0;
+  klee_make_symbolic(&x, sizeof(x), "x");
+
+  if (x == 0) {
+    printf("x is 0\n");
+  } else {
+    printf("x is not 0\n");
+  }
+  return 0;
+}
+
+// CHECKMODEL: num objects: 2
+// CHECKMODEL: object 0: name: {{b*}}'model_version'
+// CHECKMODEL: object 1: name: {{b*}}'x'
+
+// TESTONE: x is not 0
+// TESTTWO: x is 0
diff --git a/test/Replay/libkleeruntest/replay_simple.c b/test/Replay/libkleeruntest/replay_simple.c
new file mode 100644
index 00000000..cb9dfb85
--- /dev/null
+++ b/test/Replay/libkleeruntest/replay_simple.c
@@ -0,0 +1,28 @@
+// RUN: %llvmgcc %s -emit-llvm -g -O0 -c -o %t.bc
+// RUN: rm -rf %t.klee-out
+// RUN: %klee --output-dir=%t.klee-out --search=dfs %t.bc
+// RUN: test -f %t.klee-out/test000001.ktest
+// RUN: test -f %t.klee-out/test000002.ktest
+
+// Now try to replay with libkleeRuntest
+// RUN: %cc %s %libkleeruntest -Wl,-rpath=%libkleeruntestdir -o %t_runner
+// RUN: env KTEST_FILE=%t.klee-out/test000001.ktest %t_runner | FileCheck -check-prefix=TESTONE %s
+// RUN: env KTEST_FILE=%t.klee-out/test000002.ktest %t_runner | FileCheck -check-prefix=TESTTWO %s
+
+#include "klee/klee.h"
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+  int x = 0;
+  klee_make_symbolic(&x, sizeof(x), "x");
+
+  if (x == 0) {
+    printf("x is 0\n");
+  } else {
+    printf("x is not 0\n");
+  }
+  return 0;
+}
+
+// TESTONE: x is not 0
+// TESTTWO: x is 0
diff --git a/test/Replay/libkleeruntest/replay_two_objects.c b/test/Replay/libkleeruntest/replay_two_objects.c
new file mode 100644
index 00000000..f5be657c
--- /dev/null
+++ b/test/Replay/libkleeruntest/replay_two_objects.c
@@ -0,0 +1,33 @@
+// RUN: %llvmgcc %s -emit-llvm -g -O0 -c -o %t.bc
+// RUN: rm -rf %t.klee-out
+// RUN: %klee --output-dir=%t.klee-out --search=dfs %t.bc 2>&1 | FileCheck %s
+// RUN: test -f %t.klee-out/test000001.ktest
+// RUN: test ! -f %t.klee-out/test000002.ktest
+
+// Now try to replay with libkleeRuntest
+// RUN: %cc -DPRINT_VALUES %s %libkleeruntest -Wl,-rpath=%libkleeruntestdir -o %t_runner
+// RUN: env KTEST_FILE=%t.klee-out/test000001.ktest %t_runner | FileCheck -check-prefix=TESTONE %s
+
+#include "klee/klee.h"
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+  int x = 0;
+  int y = 0;
+  klee_make_symbolic(&x, sizeof(x), "x");
+  klee_make_symbolic(&y, sizeof(x), "y");
+
+  klee_assume(x == 1);
+  klee_assume(y == 128);
+
+#ifdef PRINT_VALUES
+  printf("x=%d\n", x);
+  printf("y=%d\n", y);
+#endif
+
+  return 0;
+}
+// CHECK: KLEE: done: completed paths = 1
+
+// TESTONE: x=1
+// TESTONE: y=128