From 85858749a65f599b88098662de332b6878e6af4c Mon Sep 17 00:00:00 2001 From: Cristian Cadar Date: Sat, 17 Feb 2024 14:50:41 +0000 Subject: Two test cases exercising two policies for calling external calls with symbolic arguments. One of them is currently expected to fail. --- test/Feature/ExtCall.c | 24 ++++++++++++++++++++++++ test/Feature/ExtCallOverapprox.c | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 test/Feature/ExtCall.c create mode 100644 test/Feature/ExtCallOverapprox.c diff --git a/test/Feature/ExtCall.c b/test/Feature/ExtCall.c new file mode 100644 index 00000000..5d9c0684 --- /dev/null +++ b/test/Feature/ExtCall.c @@ -0,0 +1,24 @@ +// XFAIL: * +// This test checks that symbolic arguments to a function call are correctly concretized +// RUN: %clang %s -emit-llvm %O0opt -g -c -o %t.bc + +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --external-calls=all --exit-on-error %t.bc 2>&1 | FileCheck %s + +#include "klee/klee.h" + +#include +#include +#include + +int main() { + int x; + klee_make_symbolic(&x, sizeof(x), "x"); + klee_assume(x >= 0); + + int y = abs(x); + printf("y = %d\n", y); + // CHECK: calling external: abs((ReadLSB w32 0 x)) + + assert(x == y); +} diff --git a/test/Feature/ExtCallOverapprox.c b/test/Feature/ExtCallOverapprox.c new file mode 100644 index 00000000..83f73163 --- /dev/null +++ b/test/Feature/ExtCallOverapprox.c @@ -0,0 +1,26 @@ +// This test checks that under using the under-approximate external call policy, the symbolic arguments are left unconstrained by the external call + +// RUN: %clang %s -emit-llvm %O0opt -g -c -o %t.bc +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --external-calls=all %t.bc 2>&1 | FileCheck %s + +#include "klee/klee.h" + +#include +#include +#include + +int main() { + int x; + klee_make_symbolic(&x, sizeof(x), "x"); + + printf("%d\n", x); + // CHECK: calling external: printf + if (x > 0) { + printf("Yes\n"); + // CHECK-DAG: Yes + } else { + printf("No\n"); + // CHECK-DAG: No + } +} -- cgit 1.4.1