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_3 = vc_bvConstExprFromInt(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 ct_5 = vc_bvConstExprFromInt(vc, 32, 5); Expr a_of_0_div_5 = vc_bvDivExpr(vc, 32, a_of_0, ct_5); Expr a_of_0_div_5_eq_5 = vc_eqExpr(vc, a_of_0_div_5, ct_5); vc_printExpr(vc, a_of_0_div_5_eq_5); printf("\n"); /* Query 1 */ vc_push(vc); int query = vc_query(vc, a_of_0_div_5_eq_5); vc_pop(vc); printf("query = %d\n", query); vc_assertFormula(vc, a_of_0_div_5_eq_5); vc_printExpr(vc, a_of_0_div_5_eq_5); /* query(false) */ vc_push(vc); query = vc_query(vc, vc_falseExpr(vc)); vc_pop(vc); printf("query = %d\n", query); assert(!query); assert(vc_counterexample_size(vc)); int* a_val = (int*) malloc(sizeof *a_val); char *p = (char*) a_val; //a_of_1 = vc_simplify(vc, a_of_1); // BUG here for (i=0; i<=3; i++) { Expr elem = vc_readExpr(vc, a, vc_bvConstExprFromInt(vc, 32, i)); Expr ce = vc_getCounterExample(vc, elem); unsigned long long v = getBVUnsigned(ce); fprintf(stderr, "a[%d] = %ld\n", i, v); *p = v; p++; } printf("a = %d\n", *a_val); assert((*a_val)/5 == 5); vc_Destroy(vc); }
int main() { VC vc = vc_createValidityChecker(); vc_setFlags(vc,'n'); vc_setFlags(vc,'d'); vc_setFlags(vc,'p'); vc_setFlags(vc,'m'); Expr q; Expr asserts; const char* s = "(benchmark fg.smt\n" ":logic QF_AUFBV\n" ":extrafuns ((x_32 BitVec[32]))\n" ":extrafuns ((y32 BitVec[32]))\n" ":assumption true\n)\n"; vc_parseMemExpr(vc,s,&q,&asserts); vc_printExpr(vc, q); vc_printExpr(vc, asserts); printf("\n"); vc_Destroy(vc); return 0; }
int main() { VC vc = vc_createValidityChecker(); vc_setFlags(vc,'n'); vc_setFlags(vc,'d'); vc_setFlags(vc,'p'); Expr ct_3 = vc_bvConstExprFromStr(vc, "00000000000000000000000000000011"); vc_printExpr(vc, ct_3); printf("\n"); ct_3 = vc_bvConstExprFromInt(vc, 32, 5); vc_printExpr(vc, ct_3); printf("\n"); vc_Destroy(vc); }
int main(int argc, char *argv[]) { VC vc = vc_createValidityChecker(); vc_setFlags('n'); vc_setFlags('d'); vc_setFlags('p'); Expr nresp1 = vc_varExpr(vc, "nresp1", vc_bv32Type(vc)); Expr packet_get_int0 = vc_varExpr(vc, "packet_get_int0", vc_bv32Type(vc)); Expr exprs[] = { // nresp1 == packet_get_int0 vc_eqExpr(vc, nresp1, packet_get_int0), // nresp1 > 0 vc_bvGtExpr(vc, nresp1, vc_bv32ConstExprFromInt(vc, 0)) }; Expr res = vc_andExprN(vc, exprs, sizeof(exprs)/sizeof(exprs[0])); vc_printExpr(vc, res); int x = vc_query(vc, res); printf("vc_query result = %d\n", x); vc_printCounterExample(vc); Expr cex = vc_getCounterExample(vc, res); //vc_printExpr(vc, cex); }
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); } }
TEST(print,one) { VC vc = vc_createValidityChecker(); vc_setFlags(vc,'n'); vc_setFlags(vc,'d'); vc_setFlags(vc,'p'); Expr ct_3 = vc_bvConstExprFromStr(vc, "00000000000000000000000000000011"); vc_printExpr(vc, ct_3); printf("\n"); ct_3 = vc_bvConstExprFromInt(vc, 32, 5); vc_printExpr(vc, ct_3); printf("\n"); vc_Destroy(vc); // FIXME: Actually test something //ASSERT_TRUE(false && "FIXME: Actually test something"); }
int printImpliedLiterals(VC vc) { int count = 0; Expr impLit = vc_getImpliedLiteral(vc); printf("Implied Literals:\n"); while (impLit) { ++count; vc_printExpr(vc, impLit); vc_deleteExpr(impLit); impLit = vc_getImpliedLiteral(vc); } return count; }
TEST(parsefile,CVC) { VC vc = vc_createValidityChecker(); vc_setFlags(vc,'n'); vc_setFlags(vc,'d'); vc_setFlags(vc,'p'); // CVC_FILE is a macro that expands to a file path Expr c = vc_parseExpr(vc, CVC_FILE); // FIXME: We shouldn't trigger an exit on failure. Libraries DON'T DO THAT! vc_printExpr(vc, c); vc_DeleteExpr(c); printf("\n"); vc_Destroy(vc); ASSERT_TRUE(false && "FIXME: We should actually test something!"); }
int check(VC vc, Expr e) { int res; printf("Query: "); vc_printExpr(vc, e); check_error("Error occured during query"); res = vc_query(vc, e); switch (res) { case 0: printf("Invalid\n\n"); break; case 1: printf("Valid\n\n"); break; } return res; }
TEST(parsefile,missing_file) { VC vc = vc_createValidityChecker(); vc_setFlags(vc,'n'); vc_setFlags(vc,'d'); vc_setFlags(vc,'p'); const char* nonExistantFile="./iShOuLdNoTExiSt.cvc"; std::ifstream file(nonExistantFile, std::ifstream::in); ASSERT_FALSE( file.good() ); // Check the file does not exist Expr c = vc_parseExpr(vc, nonExistantFile); // FIXME: We shouldn't trigger an exit on failure. Libraries DON'T DO THAT! vc_printExpr(vc, c); vc_DeleteExpr(c); printf("\n"); vc_Destroy(vc); ASSERT_TRUE(false && "FIXME: We should actually test something!"); }
TEST(push_pop, two) { VC vc = vc_createValidityChecker(); vc_setFlags(vc, 'n'); vc_setFlags(vc, 'd'); vc_setFlags(vc, 'p'); vc_setFlags(vc, 'v'); vc_setFlags(vc, 's'); vc_setFlags(vc, 'c'); vc_push(vc); Type bv8 = vc_bvType(vc, 8); Expr a = vc_varExpr(vc, "a", bv8); Expr ct_0 = vc_bvConstExprFromInt(vc, 8, 0); Expr a_eq_0 = vc_eqExpr(vc, a, ct_0); int query; // query = vc_query(vc, a_eq_0); // printf("query = %d\n", query); Expr a_neq_0 = vc_notExpr(vc, a_eq_0); vc_assertFormula(vc, a_eq_0); vc_printAsserts(vc); vc_push(vc); Expr queryexp = vc_eqExpr(vc, a, vc_bvConstExprFromInt(vc, 8, 0)); vc_printExpr(vc, queryexp); query = vc_query(vc, queryexp); vc_printCounterExample(vc); vc_pop(vc); vc_pop(vc); printf("query = %d\n", query); // 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); }
TEST(reported_issue_120, one) { VC vc = vc_createValidityChecker(); // Numbers will be non-negatives integers bounded at 2^32 Type bv32 = vc_bvType(vc, 32); // Determine whether the following equations are satisfiable: // v + 4 = n // 4 = n // Construct variable n Expr n = vc_varExpr(vc, "n", bv32); // Construct v + 4 Expr v = vc_varExpr(vc, "v", bv32); Expr ct_4 = vc_bvConstExprFromInt(vc, 32, 4); Expr add_v_4 = vc_bvPlusExpr(vc, 32, v, ct_4); // Because numbers are represented as bit vectors, // addition can roll over. So construct a constraint // expresses that v+4 does not overflow the bounds: // v + 4 >= v // Expr ge = vc_bvGeExpr(vc, add_v_4, v); // Push a new context printf("Push\n"); vc_push(vc); // Assert v + 4 = n printf("Assert v + 4 = n\n"); Expr f_add = vc_eqExpr(vc, add_v_4, n); vc_assertFormula(vc, f_add); vc_printExpr(vc, f_add); printf("\n------\n"); // Assert the bounds constraint printf("Assert v + 4 >= v\n"); vc_assertFormula(vc, ge); vc_printExpr(vc, ge); printf("\n------\n"); // Assert 4 = n printf("Assert 4 = n\n"); Expr f_numeq = vc_eqExpr(vc, ct_4, n); vc_assertFormula(vc, f_numeq); vc_printExpr(vc, f_numeq); printf("\n------\n"); // Check for satisfiability printf("Check\n"); vc_printAsserts(vc); printf("\n------\n"); int query = vc_query(vc, vc_falseExpr(vc)); ASSERT_EQ(query, 0); // Pop context printf("Pop\n"); vc_pop(vc); printf("query = %d\n", query); }
value caml_vc_printExpr(value vc, value e) { CAMLparam2(vc,e); vc_printExpr(VC_val(vc),Expr_val(e)); CAMLreturn(Val_unit); }