about summary refs log tree commit diff homepage
path: root/test/Replay/libkleeruntest/replay_invalid_object_names.c
diff options
context:
space:
mode:
authorDan Liew <daniel.liew@imperial.ac.uk>2017-01-14 19:44:08 +0000
committerDan Liew <daniel.liew@imperial.ac.uk>2017-01-14 23:03:06 +0000
commitdcc709dd23fc8a50d5dc087d4d5961dea041bf01 (patch)
tree84c553f78bc9e8bdcdd5b7aa2e2c9c78d84494dc /test/Replay/libkleeruntest/replay_invalid_object_names.c
parent6137888c07ab45bee354ff7b66f6f313ea158da8 (diff)
downloadklee-dcc709dd23fc8a50d5dc087d4d5961dea041bf01.tar.gz
Change how error handling is done in libkleeRuntest.
Previously error messages would be emitted but execution would continue
which might not be desirable.

Now a wrapper function (for fprintf) `report_internal_error()` is used
which will cause the program to exit. The older behaviour of continuing
to execute after an error can be achieved by setting a new environment
variable `KLEE_RUN_TEST_ERRORS_NON_FATAL`.

This commit also adds a test for each error case.
Diffstat (limited to 'test/Replay/libkleeruntest/replay_invalid_object_names.c')
-rw-r--r--test/Replay/libkleeruntest/replay_invalid_object_names.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/Replay/libkleeruntest/replay_invalid_object_names.c b/test/Replay/libkleeruntest/replay_invalid_object_names.c
new file mode 100644
index 00000000..9c75bebc
--- /dev/null
+++ b/test/Replay/libkleeruntest/replay_invalid_object_names.c
@@ -0,0 +1,45 @@
+// RUN: %llvmgcc -DOBJ_NAME=simple_name %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
+
+// Now try to replay with libkleeRuntest but build the binary to use a different
+// object name
+// RUN: %cc -DOBJ_NAME=wrong_name -DPRINT_VALUE %s %libkleeruntest -Wl,-rpath=%libkleeruntestdir -o %t_runner
+
+// Check that the default is to exit with an error
+// RUN: not env KTEST_FILE=%t.klee-out/test000001.ktest %t_runner 2>&1 | FileCheck -check-prefix=CHECK_FATAL %s
+
+// Check that setting `KLEE_RUN_TEST_ERRORS_NON_FATAL` will not exit with an error
+// and will continue executing.
+// RUN: env KTEST_FILE=%t.klee-out/test000001.ktest KLEE_RUN_TEST_ERRORS_NON_FATAL=1 %t_runner 2>&1 | FileCheck %s
+
+#include "klee/klee.h"
+#include <stdio.h>
+
+#ifndef OBJ_NAME
+#error OBJ_NAME must be defined
+#endif
+
+#define STRINGIFY(X) #X
+#define XSTRINGIFY(X) STRINGIFY(X)
+
+
+int main(int argc, char** argv) {
+  int x = 1;
+  klee_make_symbolic(&x, sizeof(x), XSTRINGIFY(OBJ_NAME));
+  klee_assume(x == 0);
+
+#ifdef PRINT_VALUE
+  printf("x=%d\n", x);
+#endif
+
+  return 0;
+}
+// CHECK: KLEE_RUN_TEST_ERROR: object name mismatch. Requesting "wrong_name" but returning "simple_name"
+// CHECK: KLEE_RUN_TEST_ERROR: Forcing execution to continue
+// CHECK: x=0
+
+// CHECK_FATAL: KLEE_RUN_TEST_ERROR: object name mismatch. Requesting "wrong_name" but returning "simple_name"
+// CHECK_FATAL-NOT: x=0
+