TEST(Leaks, boolean) { VC vc; vc = vc_createValidityChecker(); Expr x = vc_varExpr(vc, "x", vc_boolType(vc)); Expr y = vc_varExpr(vc, "y", vc_boolType(vc)); Expr x_and_y = vc_andExpr(vc, x, y); Expr not_x_and_y = vc_notExpr(vc, x_and_y); Expr not_x = vc_notExpr(vc, x); Expr not_y = vc_notExpr(vc, y); Expr not_x_or_not_y = vc_orExpr(vc, not_x, not_y); Expr equiv = vc_iffExpr(vc, not_x_and_y, not_x_or_not_y); printf("%d\n", vc_query(vc, equiv)); vc_DeleteExpr(equiv); vc_DeleteExpr(not_x_or_not_y); vc_DeleteExpr(not_y); vc_DeleteExpr(not_x); vc_DeleteExpr(not_x_and_y); vc_DeleteExpr(x_and_y); vc_DeleteExpr(y); vc_DeleteExpr(x); vc_Destroy(vc); }
// FIXME: this test name sucks! TEST(x,one) { VC vc = vc_createValidityChecker(); vc_setFlags(vc,'n'); vc_setFlags(vc,'d'); vc_setFlags(vc,'p'); Expr nresp1 = vc_varExpr(vc, "nresp1", vc_bv32Type(vc)); Expr packet_get_int0 = vc_varExpr(vc, "packet_get_int0", vc_bv32Type(vc)); Expr sz = vc_varExpr(vc, "sz", vc_bv32Type(vc)); Expr d0,d1,d2; Expr exprs[] = { // nresp1 == packet_get_int0 vc_eqExpr(vc, nresp1, packet_get_int0), // nresp1 > 0 vc_bvGtExpr(vc, nresp1, vc_bv32ConstExprFromInt(vc, 0)), // sz == nresp1 * 4 vc_eqExpr(vc, sz, d0=vc_bv32MultExpr(vc, nresp1, vc_bv32ConstExprFromInt(vc, 4))), // sz > nresp1 || sz < 0 vc_orExpr(vc, d1=vc_sbvGeExpr(vc, sz, nresp1), d2=vc_sbvLtExpr(vc, sz, vc_bv32ConstExprFromInt(vc, 0))), }; Expr res = vc_andExprN(vc, exprs, sizeof(exprs)/sizeof(exprs[0])); //vc_printExpr(vc, res); vc_query(vc,res); vc_DeleteExpr(nresp1); vc_DeleteExpr(packet_get_int0); vc_DeleteExpr(sz); vc_DeleteExpr(d0); vc_DeleteExpr(d1); vc_DeleteExpr(d2); vc_DeleteExpr(exprs[0]); vc_DeleteExpr(exprs[1]); vc_DeleteExpr(exprs[2]); vc_DeleteExpr(exprs[3]); vc_DeleteExpr(res); vc_Destroy(vc); // FIXME: Actually test something //ASSERT_TRUE(false && "FIXME: Actually test something"); }
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); }
value caml_vc_orExpr(value vc, value e1, value e2) { CAMLparam3(vc,e1,e2); CAMLreturn(alloc_Expr(vc_orExpr(VC_val(vc),Expr_val(e1),Expr_val(e2)))); }