diff options
Diffstat (limited to 'test/Replay')
9 files changed, 357 insertions, 0 deletions
diff --git a/test/Replay/libkleeruntest/replay_invalid_klee_assume.c b/test/Replay/libkleeruntest/replay_invalid_klee_assume.c new file mode 100644 index 00000000..12ac006e --- /dev/null +++ b/test/Replay/libkleeruntest/replay_invalid_klee_assume.c @@ -0,0 +1,44 @@ +// RUN: %llvmgcc -DASSUME_VALUE=1 %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 but build the binary to use a different +// value for the `klee_assume()` call. +// RUN: %cc -DASSUME_VALUE=32 -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 <stdint.h> +#include <stdio.h> + +#ifndef ASSUME_VALUE +#error ASSUME_VALUE must be defined +#endif + + +int main(int argc, char** argv) { + int x = 54; + klee_make_symbolic(&x, sizeof(x), "x"); + klee_assume(x == ASSUME_VALUE); + +#ifdef PRINT_VALUE + printf("x=%d\n", x); +#endif + + return 0; +} +// CHECK: KLEE_RUN_TEST_ERROR: invalid klee_assume +// CHECK: KLEE_RUN_TEST_ERROR: Forcing execution to continue +// CHECK: x=1 + +// CHECK_FATAL: KLEE_RUN_TEST_ERROR: invalid klee_assume +// CHECK_FATAL-NOT: x=1 + diff --git a/test/Replay/libkleeruntest/replay_invalid_klee_choose.c b/test/Replay/libkleeruntest/replay_invalid_klee_choose.c new file mode 100644 index 00000000..62f514bf --- /dev/null +++ b/test/Replay/libkleeruntest/replay_invalid_klee_choose.c @@ -0,0 +1,45 @@ +// RUN: %llvmgcc -DBOUND_VALUE=32 -DFORCE_VALUE=20 %s -emit-llvm -g -O0 -c -o %t.bc +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --libc=klee --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 but build the binary to use a different +// bound for `klee_choose()`. +// RUN: %cc -DBOUND_VALUE=2 -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 <stdint.h> +#include <stdio.h> + +#ifndef BOUND_VALUE +#error BOUND_VALUE must be defined +#endif + + +int main(int argc, char** argv) { + int x = klee_choose(BOUND_VALUE); +#ifdef FORCE_VALUE + klee_assume(x == FORCE_VALUE); +#endif + +#ifdef PRINT_VALUE + printf("x=%d\n", x); +#endif + + return 0; +} +// CHECK: KLEE_RUN_TEST_ERROR: klee_choose failure. max = 2, got = 20 +// CHECK: KLEE_RUN_TEST_ERROR: Forcing execution to continue +// CHECK: x=20 + +// CHECK_FATAL: KLEE_RUN_TEST_ERROR: klee_choose failure. max = 2, got = 20 +// CHECK_FATAL-NOT: x=20 + diff --git a/test/Replay/libkleeruntest/replay_invalid_klee_range.c b/test/Replay/libkleeruntest/replay_invalid_klee_range.c new file mode 100644 index 00000000..c7d62027 --- /dev/null +++ b/test/Replay/libkleeruntest/replay_invalid_klee_range.c @@ -0,0 +1,45 @@ +// RUN: %llvmgcc -DBOUND_VALUE=32 -DFORCE_VALUE=20 %s -emit-llvm -g -O0 -c -o %t.bc +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --libc=klee --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 but build the binary to use a different +// bound for `klee_range()`. +// RUN: %cc -DBOUND_VALUE=2 -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 <stdint.h> +#include <stdio.h> + +#ifndef BOUND_VALUE +#error BOUND_VALUE must be defined +#endif + + +int main(int argc, char** argv) { + int x = klee_range(0, BOUND_VALUE, "x"); +#ifdef FORCE_VALUE + klee_assume(x == FORCE_VALUE); +#endif + +#ifdef PRINT_VALUE + printf("x=%d\n", x); +#endif + + return 0; +} +// CHECK: KLEE_RUN_TEST_ERROR: invalid klee_range(0,2,x) value, got: 20 +// CHECK: KLEE_RUN_TEST_ERROR: Forcing execution to continue +// CHECK: x=20 + +// CHECK_FATAL: KLEE_RUN_TEST_ERROR: invalid klee_range(0,2,x) value, got: 20 +// CHECK_FATAL-NOT: x=20 + diff --git a/test/Replay/libkleeruntest/replay_invalid_num_objects.c b/test/Replay/libkleeruntest/replay_invalid_num_objects.c new file mode 100644 index 00000000..43bc4867 --- /dev/null +++ b/test/Replay/libkleeruntest/replay_invalid_num_objects.c @@ -0,0 +1,39 @@ +// Compile program that only makes one klee_make_symbolic() call +// 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 + +// Now try to replay with libkleeRuntest but build the binary so it +// makes two calls to klee_make_symbolic. +// RUN: %cc -DEXTRA_MAKE_SYMBOLIC %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> + +int main(int argc, char** argv) { + int x = 0; + klee_make_symbolic(&x, sizeof(x), "x"); + +#ifdef EXTRA_MAKE_SYMBOLIC + int y = 1; + klee_make_symbolic(&y, sizeof(y), "x"); + klee_assume(y == 0); + fprintf(stderr, "y is \"%d\"\n", y); +#endif + return 0; +} +// CHECK: KLEE_RUN_TEST_ERROR: out of inputs +// CHECK: KLEE_RUN_TEST_ERROR: Forcing execution to continue +// CHECK: y is "0" + +// CHECK_FATAL: KLEE_RUN_TEST_ERROR: out of inputs +// CHECK_FATAL-NOT: y is "0" + 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 + diff --git a/test/Replay/libkleeruntest/replay_invalid_object_size.c b/test/Replay/libkleeruntest/replay_invalid_object_size.c new file mode 100644 index 00000000..a1513ef9 --- /dev/null +++ b/test/Replay/libkleeruntest/replay_invalid_object_size.c @@ -0,0 +1,43 @@ +// RUN: %llvmgcc -DINT_TYPE=uint8_t %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 but build the binary to use a different +// size for variable `x`. +// RUN: %cc -DINT_TYPE=uint32_t -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 <stdint.h> +#include <stdio.h> + +#ifndef INT_TYPE +#error INT_TYPE must be defined +#endif + + +int main(int argc, char** argv) { + INT_TYPE x = 1; + klee_make_symbolic(&x, sizeof(x), "x"); + klee_assume(x == 0); + +#ifdef PRINT_VALUE + printf("x=%d\n", x); +#endif + + return 0; +} +// CHECK: KLEE_RUN_TEST_ERROR: object sizes differ. Expected 4 but got 1 +// CHECK: KLEE_RUN_TEST_ERROR: Forcing execution to continue +// CHECK: x=0 + +// CHECK_FATAL: KLEE_RUN_TEST_ERROR: object sizes differ. Expected 4 but got 1 +// CHECK_FATAL-NOT: x=0 + diff --git a/test/Replay/libkleeruntest/replay_posix_runtime.c b/test/Replay/libkleeruntest/replay_posix_runtime.c new file mode 100644 index 00000000..70d8a1d9 --- /dev/null +++ b/test/Replay/libkleeruntest/replay_posix_runtime.c @@ -0,0 +1,35 @@ +// REQUIRES: posix-runtime +// FIXME: We need to fix a bug in libkleeRuntest +// 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 |