Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
TEST(sbdiv, one)
{
  VC vc = vc_createValidityChecker();
  vc_setFlags(vc, 'p');

  Type int_type = vc_bv32Type(vc);
  Expr zero = vc_bv32ConstExprFromInt(vc, 0);
  Expr int_max = vc_bvConstExprFromInt(vc, 32, 0x7fffffff);
  Expr a = vc_varExpr(vc, "a", int_type);
  Expr b = vc_varExpr(vc, "b", int_type);
  vc_assertFormula(vc, vc_sbvGtExpr(vc, b, zero));
  vc_assertFormula(vc, vc_sbvLeExpr(vc, a, vc_sbvDivExpr(vc, 32, int_max, b)));
  std::cout << vc_query(vc, vc_falseExpr(vc)) << std::endl;
  // FIXME: Actually test something
  // ASSERT_TRUE(false && "FIXME: Actually test something");
}
Exemplo n.º 3
0
Arquivo: sbvdiv.cpp Projeto: stp/stp
TEST(sbdiv, one)
{
  VC vc = vc_createValidityChecker();
  //vc_setFlags(vc, 'p');
  vc_setFlags(vc, 'd');

  Type int_type = vc_bv32Type(vc);
  Expr zero = vc_bv32ConstExprFromInt(vc, 0);
  Expr int_max = vc_bvConstExprFromInt(vc, 32, 0x7fffffff);
  Expr a = vc_varExpr(vc, "a", int_type);
  Expr b = vc_varExpr(vc, "b", int_type);
  vc_assertFormula(vc, vc_sbvGtExpr(vc, b, zero));
  vc_assertFormula(vc, vc_sbvLeExpr(vc, a, vc_sbvDivExpr(vc, 32, int_max, b)));
  int query = vc_query(vc, vc_falseExpr(vc));
  ASSERT_FALSE(query);
}
Exemplo n.º 4
0
// 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");
}
Exemplo n.º 5
0
TEST(stp_array_model,one) {  
  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) */
  ASSERT_TRUE(vc_query(vc, vc_falseExpr(vc)) == 0); // Should be invalid

  ASSERT_FALSE(vc_counterexample_size(vc) == 0);

  Expr *indices;
  Expr *values;
  int size;
  vc_getCounterExampleArray(vc, a, &indices, &values, &size);

  ASSERT_FALSE(size == 0); // No array entries

  int j;
  for (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);

}
Exemplo n.º 6
0
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);
}
Exemplo n.º 7
0
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!
}
Exemplo n.º 8
0
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);
}
Exemplo n.º 9
0
value caml_vc_falseExpr(value vc)
{
  CAMLparam1(vc);
  CAMLreturn(alloc_Expr(vc_falseExpr(VC_val(vc))));
}