]> git.unchartedbackwaters.co.uk Git - francis/stp.git/commitdiff
Test case for r1410. Thanks to Stephan Falke.
authortrevor_hansen <trevor_hansen@e59a4935-1847-0410-ae03-e826735625c1>
Sun, 13 Nov 2011 03:59:36 +0000 (03:59 +0000)
committertrevor_hansen <trevor_hansen@e59a4935-1847-0410-ae03-e826735625c1>
Sun, 13 Nov 2011 03:59:36 +0000 (03:59 +0000)
git-svn-id: https://stp-fast-prover.svn.sourceforge.net/svnroot/stp-fast-prover/trunk/stp@1413 e59a4935-1847-0410-ae03-e826735625c1

tests/c-api-tests/Makefile
tests/c-api-tests/stp-array-model.c [new file with mode: 0644]

index e18e2b54324681aeb1bd1ec0f1ecb18e5a2b8d87..98bf6a81993d56d515afbce3d2d884e58013f071 100644 (file)
@@ -14,7 +14,7 @@ else
 endif
 
 
-all: 0 1 2 3 4 5 6 7 8 9 10 11 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
+all: 0 1 2 3 4 5 6 7 8 9 10 11 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
        rm -rf *.out
 
 0:     
@@ -114,5 +114,10 @@ all: 0 1 2 3 4 5 6 7 8 9 10 11 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
          ../../lib/libstp.a stp-test3.c ../../lib/libstp.a
        ./a26.out
 
+27:
+       g++ $(CXXFLAGS) -o a27.out \
+         ../../lib/libstp.a stp-array-model.c ../../lib/libstp.a
+       ./a27.out
+
 clean:
        rm -rf *~ *.out *.dSYM
diff --git a/tests/c-api-tests/stp-array-model.c b/tests/c-api-tests/stp-array-model.c
new file mode 100644 (file)
index 0000000..e0e2f2c
--- /dev/null
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "c_interface.h"
+
+int main() {  
+  VC vc = vc_createValidityChecker();
+
+  Expr a = vc_bvCreateMemoryArray(vc, "a");
+
+  Expr index_1 = vc_bvConstExprFromInt(vc, 32, 1);
+  Expr a_of_1 = vc_readExpr(vc, a, index_1);
+
+  Expr index_2 = vc_bvConstExprFromInt(vc, 32, 2);
+  Expr a_of_2 = vc_readExpr(vc, a, index_2);
+
+  Expr ct_42 = vc_bvConstExprFromInt(vc, 8, 42);
+  Expr a_of_1_eq_42 = vc_eqExpr(vc, a_of_1, ct_42);
+
+  Expr ct_77 = vc_bvConstExprFromInt(vc, 8, 77);
+  Expr a_of_2_eq_77 = vc_eqExpr(vc, a_of_2, ct_77);
+
+  vc_assertFormula(vc, a_of_1_eq_42);
+  vc_assertFormula(vc, a_of_2_eq_77);
+
+  /* query(false) */
+  if (vc_query(vc, vc_falseExpr(vc)) != 0) {
+    printf("Should be invalid...\n");
+    exit(1);
+  }
+
+  if (vc_counterexample_size(vc) == 0) {
+    printf("Counterexample size is 0\n");
+    exit(2);
+  }
+
+  Expr *indices;
+  Expr *values;
+  int size;
+  vc_getCounterExampleArray(vc, a, &indices, &values, &size);
+
+  if (size == 0) {
+    printf("No array entries!\n");
+    exit(3);
+  }
+
+  for (int j = 0; j < size; ++j) {
+    Expr index = vc_getCounterExample(vc, indices[j]);
+    Expr value = vc_getCounterExample(vc, values[j]);
+    unsigned long long i = getBVUnsigned(index);
+    unsigned long long v = getBVUnsigned(value);
+
+    fprintf(stderr, "a[%llu] = %llu\n", i, v);
+  }
+
+  vc_Destroy(vc);
+
+  return 0;
+}