int main() { for(int j=0;j < 3; j++) { VC vc = vc_createValidityChecker(); vc_setFlags(vc,'n'); vc_setFlags(vc,'d'); vc_setFlags(vc,'p'); vc_setFlags(vc,'x'); Type bv8 = vc_bvType(vc, 8); Expr a = vc_bvCreateMemoryArray(vc, "a"); Expr index_3 = vc_bvConstExprFromLL(vc, 32, 3); Expr a_of_0 = vc_readExpr(vc, a, index_3); int i; for (i = 2; i >= 0; i--) a_of_0 = vc_bvConcatExpr(vc, a_of_0, vc_readExpr(vc, a, vc_bvConstExprFromInt(vc, 32, i))); Expr cast_32_to_8 = vc_bvExtract(vc, a_of_0, 7, 0); Expr cast_8_to_32 = vc_bvSignExtend(vc, cast_32_to_8, 32); vc_printExpr(vc, cast_8_to_32); cast_8_to_32 = vc_simplify(vc, cast_8_to_32); vc_Destroy(vc); } }
// FIXME: Pick a sensible testname that actually means something! TEST(array_cvcl02,one) { VC vc = vc_createValidityChecker(); vc_setFlag(vc,'n'); vc_setFlag(vc,'d'); vc_setFlag(vc,'p'); Expr cvcl_array = vc_varExpr1(vc, "a",32,32); Expr i = vc_varExpr1(vc, "i", 0, 8); Expr i32 = vc_bvConcatExpr(vc, vc_bvConstExprFromStr(vc, "000000000000000000000000"), i); Expr no_underflow = vc_bvLeExpr(vc, vc_bvConstExprFromInt(vc, 32, 0), i32); Expr no_overflow = vc_bvLeExpr(vc, i32, vc_bvConstExprFromInt(vc, 32, 9)); Expr in_bounds = vc_andExpr(vc, no_underflow, no_overflow); Expr a_of_i = vc_bvSignExtend(vc, vc_readExpr(vc,cvcl_array,i32), 32); Expr a_of_i_eq_11 = vc_eqExpr(vc, vc_bvConcatExpr(vc,i32,a_of_i), vc_bvConstExprFromInt(vc, 64, 11)); vc_assertFormula(vc, in_bounds); vc_assertFormula(vc, a_of_i_eq_11); vc_query(vc, vc_falseExpr(vc)); long long v; Expr pre = vc_bvConstExprFromInt(vc,24,0); int j; for(j=0;j<10;j++) { Expr exprj = vc_bvConstExprFromInt(vc,8,j); Expr index = vc_bvConcatExpr(vc, pre, exprj); index = vc_simplify(vc,index); Expr a_of_j = vc_readExpr(vc, cvcl_array, index); Expr ce = vc_getCounterExample(vc,a_of_j); } vc_Destroy(vc); //vc_printCounterExample(vc); // FIXME: Actually test something //ASSERT_TRUE(false && "FIXME: Actually test something"); }
int main() { VC vc = vc_createValidityChecker(); vc_setFlags('n'); vc_setFlags('d'); //vc_setFlags('p'); Type bv8 = vc_bvType(vc, 8); 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 ct_100 = vc_bvConstExprFromInt(vc, 8, 100); Expr a_of_1_eq_100 = vc_eqExpr(vc, a_of_1, ct_100); /* Query 1 */ vc_push(vc); int query = vc_query(vc, a_of_1_eq_100); vc_pop(vc); printf("query = %d\n", query); vc_assertFormula(vc, a_of_1_eq_100); /* query(false) */ vc_push(vc); query = vc_query(vc, vc_falseExpr(vc)); vc_pop(vc); printf("query = %d\n", query); if (vc_counterexample_size(vc) == 0) { printf("Counterexample size is 0\n"); exit(1); } a_of_1 = vc_simplify(vc, a_of_1); //vc_printExpr(vc, a_of_1); Expr ce = vc_getCounterExample(vc, a_of_1); unsigned long long v = getBVUnsigned(ce); fprintf(stderr, "a[1] = %ld\n", v); vc_Destroy(vc); }
TEST(stp_counterex,one) { VC vc = vc_createValidityChecker(); vc_setFlags(vc,'n'); vc_setFlags(vc,'d'); //vc_setFlags(vc,'p'); Type bv8 = vc_bvType(vc, 8); 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 ct_100 = vc_bvConstExprFromInt(vc, 8, 100); Expr a_of_1_eq_100 = vc_eqExpr(vc, a_of_1, ct_100); /* Query 1 */ vc_push(vc); int query = vc_query(vc, a_of_1_eq_100); vc_pop(vc); printf("query = %d\n", query); vc_assertFormula(vc, a_of_1_eq_100); /* query(false) */ vc_push(vc); query = vc_query(vc, vc_falseExpr(vc)); vc_pop(vc); printf("query = %d\n", query); ASSERT_FALSE(vc_counterexample_size(vc) == 0); a_of_1 = vc_simplify(vc, a_of_1); //vc_printExpr(vc, a_of_1); Expr ce = vc_getCounterExample(vc, a_of_1); unsigned long long v = getBVUnsigned(ce); fprintf(stderr, "a[1] = %llu\n", v); vc_Destroy(vc); // FIXME: we should test more things! }
TEST(Leaks, sqaures) { unsigned int i; /* Do some simple arithmetic by creating an expression involving constants and then simplifying it. Since we create and destroy a fresh VC each time, we shouldn't leak any memory. */ for (i = 1; i <= 100; i++) { VC vc = vc_createValidityChecker(); Expr arg = vc_bvConstExprFromLL(vc, 64, (unsigned long long)i); Expr product = vc_bvMultExpr(vc, 64, arg, arg); Expr simp = vc_simplify(vc, product); unsigned long long j = getBVUnsignedLongLong(simp); vc_DeleteExpr(arg); vc_DeleteExpr(product); vc_DeleteExpr(simp); if (i % 10000 == 0) printf("%u**2 = %llu\n", i, j); vc_Destroy(vc); } }
void test1() { Flags flags = vc_createFlags(); VC vc; Type b; Expr p, np, e; Type r, real2real; Expr x, y, fx, fy, xeqy, fxeqfy, w, z, weqx, yeqz, one, two, xeqone, xeqtwo, simp, simp2; Op f; Expr* assertions; int i, size, res; Kind k; vc_setStringFlag(flags, "dump-log", ".testc1.cvc"); vc_setStrSeqFlag(flags, "trace", "pushpop", 1); vc = vc_createValidityChecker(flags); // Check p OR ~p b = vc_boolType(vc); p = vc_varExpr(vc, "p", vc_boolType(vc)); np = vc_notExpr(vc, p); e = vc_orExpr(vc, p, np); res = check(vc, e); FatalAssert(res == 1, "Expected Valid"); FatalAssert(vc_getKind(e) == OR, "Expected TRUE for kind check"); FatalAssert(vc_getKind(vc_getType(vc, e)) == BOOLEAN, "Expected TRUE for type kind check"); vc_deleteType(b); vc_deleteExpr(p); vc_deleteExpr(np); vc_deleteExpr(e); /* Check x = y -> f(x) = f(y) */ r = vc_realType(vc); x = vc_varExpr(vc, "x", r); y = vc_varExpr(vc, "y", r); real2real = vc_funType1(vc, r, r); f = vc_createOp(vc, "f", real2real); fx = vc_funExpr1(vc, f, x); fy = vc_funExpr1(vc, f, y); xeqy = vc_eqExpr(vc, x, y); fxeqfy = vc_eqExpr(vc, fx, fy); e = vc_impliesExpr(vc, xeqy, fxeqfy); res = check(vc, e); FatalAssert(res == 1, "Expected Valid"); vc_deleteType(real2real); vc_deleteExpr(e); // Check f(x) = f(y) -> x = y e = vc_impliesExpr(vc, fxeqfy, xeqy); vc_push(vc); res = check(vc, e); FatalAssert(res == 0, "Expected Invalid"); vc_deleteExpr(e); // Get counter-example printf("Stack level: %d\n", vc_stackLevel(vc)); printf("Counter-example:\n"); assertions = vc_getCounterExample(vc, &size); for (i = 0; i < size; ++i) { vc_printExpr(vc, assertions[i]); } vc_deleteVector(assertions); printf("End of counter-example\n\n"); printf("Concrete model:\n"); assertions = vc_getConcreteModel(vc, &size); for (i = 0; i < size; ++i) { vc_printExpr(vc, assertions[i]); } vc_deleteVector(assertions); printf("End of concrete model\n\n"); // Reset to initial scope printf("Resetting\n"); vc_pop(vc); printf("Stack level: %d\n\n", vc_stackLevel(vc)); // Check w = x & x = y & y = z & f(x) = f(y) & x = 1 & z = 2 w = vc_varExpr(vc, "w", r); z = vc_varExpr(vc, "z", r); printf("Push Scope\n\n"); vc_push(vc); weqx = vc_eqExpr(vc, w, x); yeqz = vc_eqExpr(vc, y, z); one = vc_ratExpr(vc, 1, 1); two = vc_ratExpr(vc, 2, 1); xeqone = vc_eqExpr(vc, x, one); xeqtwo = vc_eqExpr(vc, x, two); newAssertion(vc, weqx); newAssertion(vc, xeqy); newAssertion(vc, yeqz); newAssertion(vc, fxeqfy); newAssertion(vc, xeqone); newAssertion(vc, xeqtwo); printf("\nsimplify(w) = "); simp = vc_simplify(vc, w); char* str = vc_printExprString(vc, simp); printf("%s\n", str); vc_deleteString(str); printf("Inconsistent?: %d\n", vc_inconsistent(vc, &assertions, &size)); check_error("Error occured during inconsistency check"); printf("Assumptions Used:\n"); for (i = 0; i < size; ++i) { vc_printExpr(vc, assertions[i]); } vc_deleteVector(assertions); printf("\nPop Scope\n\n"); vc_pop(vc); printf("simplify(w) = "); simp2 = vc_simplify(vc, w); vc_printExpr(vc, simp2); printf("\n"); printf("Inconsistent?: %d\n", vc_inconsistent(vc, &assertions, &size)); vc_deleteVector(assertions); vc_deleteType(r); vc_deleteExpr(x); vc_deleteExpr(y); vc_deleteOp(f); vc_deleteExpr(fx); vc_deleteExpr(fy); vc_deleteExpr(xeqy); vc_deleteExpr(fxeqfy); vc_deleteExpr(w); vc_deleteExpr(z); vc_deleteExpr(weqx); vc_deleteExpr(yeqz); vc_deleteExpr(one); vc_deleteExpr(two); vc_deleteExpr(xeqone); vc_deleteExpr(xeqtwo); vc_deleteExpr(simp); vc_deleteExpr(simp2); vc_destroyValidityChecker(vc); vc_deleteFlags(flags); }
// Simplify e w.r.t. the current context value caml_vc_simplify(value vc, value e) { CAMLparam2(vc,e); CAMLreturn(alloc_Expr(vc_simplify(VC_val(vc),Expr_val(e)))); }