about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorCristian Cadar <c.cadar@imperial.ac.uk>2024-02-17 14:50:41 +0000
committerMartinNowack <2443641+MartinNowack@users.noreply.github.com>2024-02-27 09:45:01 +0000
commit85858749a65f599b88098662de332b6878e6af4c (patch)
tree5110362dc5cc7e87caed03ba6b0acd9c8ac5fb2f
parent38c0f6796e15c409e05aea39c670ac0063a336e0 (diff)
downloadklee-85858749a65f599b88098662de332b6878e6af4c.tar.gz
Two test cases exercising two policies for calling external calls with symbolic arguments. One of them is currently expected to fail.
-rw-r--r--test/Feature/ExtCall.c24
-rw-r--r--test/Feature/ExtCallOverapprox.c26
2 files changed, 50 insertions, 0 deletions
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 <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+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 <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+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
+  }
+}