1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
//===-- Z3SolverTest.cpp
//----------------------------------------------------===//
//
// The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <algorithm>
#include <iterator>
#include <vector>
#include "gtest/gtest.h"
#include "klee/Expr/ArrayCache.h"
#include "klee/Expr/Constraints.h"
#include "klee/Expr/Expr.h"
#include "klee/Solver/Solver.h"
using namespace klee;
namespace {
ArrayCache AC;
}
class Z3SolverTest : public ::testing::Test {
protected:
Z3SolverTest() : Z3Solver_(createCoreSolver(CoreSolverType::Z3_SOLVER)) {
Z3Solver_->setCoreSolverTimeout(time::Span("10s"));
}
virtual ~Z3SolverTest() { delete Z3Solver_; }
Solver *Z3Solver_;
};
TEST_F(Z3SolverTest, GetConstraintLog) {
ConstraintManager Constraints;
const std::vector<uint64_t> ConstantValues{1, 2, 3, 4};
std::vector<ref<ConstantExpr>> ConstantExpressions;
std::transform(
ConstantValues.begin(), ConstantValues.end(),
std::back_inserter(ConstantExpressions), [](const uint64_t Value) {
ref<ConstantExpr> ConstantExpr(ConstantExpr::alloc(Value, Expr::Int8));
return ConstantExpr;
});
const Array *ConstantArray =
AC.CreateArray("const_array", 4, ConstantExpressions.data(),
ConstantExpressions.data() + ConstantExpressions.size());
const UpdateList ConstantArrayUL(ConstantArray, nullptr);
const ref<Expr> Index = ConstantExpr::alloc(1, Expr::Int32);
const ref<Expr> Lhs = ReadExpr::alloc(ConstantArrayUL, Index);
const ref<Expr> Rhs = ConstantExpr::alloc(2, Expr::Int8);
const ref<Expr> Eqn = EqExpr::alloc(Lhs, Rhs);
Query TheQuery(Constraints, Eqn);
// Ensure this is not buggy as fixed in https://github.com/klee/klee/pull/1235
// If the bug is still present this fail due to an internal assertion
char *ConstraintsString = Z3Solver_->getConstraintLog(TheQuery);
const char *ExpectedArraySelection = "(= (select const_array0";
const char *Occurence = std::strstr(ConstraintsString, ExpectedArraySelection);
ASSERT_STRNE(Occurence, nullptr);
free(ConstraintsString);
}
|