mirror of
https://github.com/Z3Prover/z3
synced 2025-06-26 15:53:41 +00:00
Unit test: catch exceptions during instance setup
This commit is contained in:
parent
3713f51c15
commit
3a92641ca0
1 changed files with 140 additions and 98 deletions
|
@ -9,6 +9,17 @@
|
||||||
namespace {
|
namespace {
|
||||||
using namespace dd;
|
using namespace dd;
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
std::string concat(Args... args) {
|
||||||
|
std::stringstream s;
|
||||||
|
int dummy[sizeof...(Args)] = {
|
||||||
|
// use dummy initializer list to sequence stream writes, cf. https://en.cppreference.com/w/cpp/language/parameter_pack
|
||||||
|
(s << args, 0)...
|
||||||
|
};
|
||||||
|
(void)dummy;
|
||||||
|
return s.str();
|
||||||
|
}
|
||||||
|
|
||||||
void permute_args(unsigned k, pdd& a, pdd& b, pdd& c) {
|
void permute_args(unsigned k, pdd& a, pdd& b, pdd& c) {
|
||||||
SASSERT(k < 6);
|
SASSERT(k < 6);
|
||||||
unsigned i = k % 3;
|
unsigned i = k % 3;
|
||||||
|
@ -276,6 +287,29 @@ namespace polysat {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Test, typename... Args>
|
||||||
|
void run(Test tst, Args... args)
|
||||||
|
{
|
||||||
|
bool got_exception = false;
|
||||||
|
try {
|
||||||
|
tst(args...);
|
||||||
|
}
|
||||||
|
catch(z3_exception const& e) {
|
||||||
|
// TODO: collect in record
|
||||||
|
got_exception = true;
|
||||||
|
}
|
||||||
|
catch(std::exception const& e) {
|
||||||
|
// TODO: collect in record
|
||||||
|
got_exception = true;
|
||||||
|
}
|
||||||
|
catch(...) {
|
||||||
|
got_exception = true;
|
||||||
|
}
|
||||||
|
if (got_exception && !collect_test_records)
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define RUN(tst) run([]() { tst; })
|
||||||
|
|
||||||
class test_polysat {
|
class test_polysat {
|
||||||
public:
|
public:
|
||||||
|
@ -581,7 +615,7 @@ namespace polysat {
|
||||||
* We do overflow checks by doubling the base bitwidth here.
|
* We do overflow checks by doubling the base bitwidth here.
|
||||||
*/
|
*/
|
||||||
static void test_monot(unsigned base_bw = 5) {
|
static void test_monot(unsigned base_bw = 5) {
|
||||||
scoped_solver s(std::string{__func__} + "(" + std::to_string(base_bw) + ")");
|
scoped_solver s(concat(__func__, "(", base_bw, ")"));
|
||||||
|
|
||||||
auto max_int_const = rational::power_of_two(base_bw) - 1;
|
auto max_int_const = rational::power_of_two(base_bw) - 1;
|
||||||
|
|
||||||
|
@ -1226,49 +1260,51 @@ namespace polysat {
|
||||||
s.check();
|
s.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_band(unsigned bw = 32) {
|
static void test_band1(unsigned bw = 32) {
|
||||||
{
|
scoped_solver s(concat(__func__, " bw=", bw));
|
||||||
scoped_solver s(__func__);
|
auto p = s.var(s.add_var(bw));
|
||||||
auto p = s.var(s.add_var(bw));
|
auto q = s.var(s.add_var(bw));
|
||||||
auto q = s.var(s.add_var(bw));
|
s.add_diseq(p - s.band(p, q));
|
||||||
s.add_diseq(p - s.band(p, q));
|
s.add_diseq(p - q);
|
||||||
s.add_diseq(p - q);
|
s.check();
|
||||||
s.check();
|
s.expect_sat();
|
||||||
s.expect_sat();
|
}
|
||||||
}
|
|
||||||
{
|
static void test_band2(unsigned bw = 32) {
|
||||||
scoped_solver s(__func__);
|
scoped_solver s(concat(__func__, " bw=", bw));
|
||||||
auto p = s.var(s.add_var(bw));
|
auto p = s.var(s.add_var(bw));
|
||||||
auto q = s.var(s.add_var(bw));
|
auto q = s.var(s.add_var(bw));
|
||||||
s.add_ult(p, s.band(p, q));
|
s.add_ult(p, s.band(p, q));
|
||||||
s.check();
|
s.check();
|
||||||
s.expect_unsat();
|
s.expect_unsat();
|
||||||
}
|
}
|
||||||
{
|
|
||||||
scoped_solver s(__func__);
|
static void test_band3(unsigned bw = 32) {
|
||||||
auto p = s.var(s.add_var(bw));
|
scoped_solver s(concat(__func__, " bw=", bw));
|
||||||
auto q = s.var(s.add_var(bw));
|
auto p = s.var(s.add_var(bw));
|
||||||
s.add_ult(q, s.band(p, q));
|
auto q = s.var(s.add_var(bw));
|
||||||
s.check();
|
s.add_ult(q, s.band(p, q));
|
||||||
s.expect_unsat();
|
s.check();
|
||||||
}
|
s.expect_unsat();
|
||||||
{
|
}
|
||||||
scoped_solver s(__func__);
|
|
||||||
auto p = s.var(s.add_var(bw));
|
static void test_band4(unsigned bw = 32) {
|
||||||
auto q = s.var(s.add_var(bw));
|
scoped_solver s(concat(__func__, " bw=", bw));
|
||||||
s.add_ule(p, s.band(p, q));
|
auto p = s.var(s.add_var(bw));
|
||||||
s.check();
|
auto q = s.var(s.add_var(bw));
|
||||||
s.expect_sat();
|
s.add_ule(p, s.band(p, q));
|
||||||
}
|
s.check();
|
||||||
{
|
s.expect_sat();
|
||||||
scoped_solver s(__func__);
|
}
|
||||||
auto p = s.var(s.add_var(bw));
|
|
||||||
auto q = s.var(s.add_var(bw));
|
static void test_band5(unsigned bw = 32) {
|
||||||
s.add_ule(p, s.band(p, q));
|
scoped_solver s(concat(__func__, " bw=", bw));
|
||||||
s.add_diseq(p - s.band(p, q));
|
auto p = s.var(s.add_var(bw));
|
||||||
s.check();
|
auto q = s.var(s.add_var(bw));
|
||||||
s.expect_unsat();
|
s.add_ule(p, s.band(p, q));
|
||||||
}
|
s.add_diseq(p - s.band(p, q));
|
||||||
|
s.check();
|
||||||
|
s.expect_unsat();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_fi_zero() {
|
static void test_fi_zero() {
|
||||||
|
@ -1475,10 +1511,15 @@ void tst_polysat() {
|
||||||
|
|
||||||
#if 0 // Enable this block to run a single unit test with detailed output.
|
#if 0 // Enable this block to run a single unit test with detailed output.
|
||||||
collect_test_records = false;
|
collect_test_records = false;
|
||||||
|
// test_polysat::test_l2();
|
||||||
// test_polysat::test_ineq1();
|
// test_polysat::test_ineq1();
|
||||||
// test_polysat::test_quot_rem();
|
// test_polysat::test_quot_rem();
|
||||||
test_polysat::test_ineq_non_axiom1(32, 3);
|
// test_polysat::test_ineq_non_axiom1(32, 3);
|
||||||
// test_polysat::test_monot(5);
|
// test_polysat::test_monot_bounds_full();
|
||||||
|
// test_polysat::test_band2();
|
||||||
|
// test_polysat::test_quot_rem_incomplete();
|
||||||
|
// test_polysat::test_monot();
|
||||||
|
test_polysat::test_fixed_point_arith_div_mul_inverse();
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1490,67 +1531,68 @@ void tst_polysat() {
|
||||||
set_log_enabled(false);
|
set_log_enabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
test_polysat::test_clause_simplify1();
|
RUN(test_polysat::test_clause_simplify1());
|
||||||
|
|
||||||
test_polysat::test_add_conflicts(); // ok
|
RUN(test_polysat::test_add_conflicts());
|
||||||
test_polysat::test_wlist(); // ok
|
RUN(test_polysat::test_wlist());
|
||||||
test_polysat::test_cjust(); // uses viable_fallback; weak lemmas
|
RUN(test_polysat::test_cjust());
|
||||||
// test_polysat::test_subst(); // TODO: resource limit; needs polynomial superposition
|
// RUN(test_polysat::test_subst());
|
||||||
// test_polysat::test_subst_signed();
|
// RUN(test_polysat::test_subst_signed());
|
||||||
test_polysat::test_pop_conflict(); // ok now (had bad conflict/pop interaction)
|
RUN(test_polysat::test_pop_conflict());
|
||||||
|
|
||||||
test_polysat::test_l1(); // ok
|
RUN(test_polysat::test_l1());
|
||||||
test_polysat::test_l2(); // ok but enumerates values
|
RUN(test_polysat::test_l2());
|
||||||
test_polysat::test_l3(); // ok
|
RUN(test_polysat::test_l3());
|
||||||
test_polysat::test_l4(); // ok now (had assertion failure in conflict::insert)
|
RUN(test_polysat::test_l4());
|
||||||
test_polysat::test_l4b(); // ok
|
RUN(test_polysat::test_l4b());
|
||||||
test_polysat::test_l5(); // inefficient conflicts (needs equality reasoning)
|
RUN(test_polysat::test_l5());
|
||||||
test_polysat::test_l6(); // ok (refine-equal-lin)
|
RUN(test_polysat::test_l6());
|
||||||
|
|
||||||
test_polysat::test_p1(); // ok (conflict @0 by viable_fallback)
|
RUN(test_polysat::test_p1());
|
||||||
test_polysat::test_p2(); // ok (viable_fallback finds the correct value)
|
RUN(test_polysat::test_p2());
|
||||||
test_polysat::test_p3(); // TODO: resource limit
|
RUN(test_polysat::test_p3());
|
||||||
|
|
||||||
test_polysat::test_ineq_basic1(); // ok
|
RUN(test_polysat::test_ineq_basic1());
|
||||||
test_polysat::test_ineq_basic2(); // ok
|
RUN(test_polysat::test_ineq_basic2());
|
||||||
test_polysat::test_ineq_basic3(); // ok
|
RUN(test_polysat::test_ineq_basic3());
|
||||||
test_polysat::test_ineq_basic4(); // TODO: resource limit
|
RUN(test_polysat::test_ineq_basic4());
|
||||||
test_polysat::test_ineq_basic5(); // works, but only because variable order changes after the conflict
|
RUN(test_polysat::test_ineq_basic5());
|
||||||
// TODO: non-asserting lemma
|
RUN(test_polysat::test_ineq_basic6());
|
||||||
// possible variable selection heuristic: start with the most restricted interval?
|
|
||||||
// (if we have a restricted and non-restricted variable; we should probably pick the restricted one first. hoping that we can propagate and uncover restrictions on the other variable.)
|
|
||||||
test_polysat::test_ineq_basic6(); // same as ineq_basic5
|
|
||||||
|
|
||||||
test_polysat::test_var_minimize(); // works but var_minimized isn't used (UNSAT before lemma is created)
|
RUN(test_polysat::test_var_minimize()); // works but var_minimize isn't used (UNSAT before lemma is created)
|
||||||
|
|
||||||
test_polysat::test_ineq1(); // TODO: resource limit
|
RUN(test_polysat::test_ineq1());
|
||||||
test_polysat::test_ineq2(); // TODO: resource limit
|
RUN(test_polysat::test_ineq2());
|
||||||
test_polysat::test_monot(); // TODO: assertion failure; resource limit
|
RUN(test_polysat::test_monot());
|
||||||
test_polysat::test_monot_bounds(2);
|
RUN(test_polysat::test_monot_bounds(2));
|
||||||
test_polysat::test_monot_bounds(8);
|
RUN(test_polysat::test_monot_bounds(8));
|
||||||
test_polysat::test_monot_bounds();
|
RUN(test_polysat::test_monot_bounds());
|
||||||
test_polysat::test_monot_bounds_full();
|
RUN(test_polysat::test_monot_bounds_full());
|
||||||
test_polysat::test_monot_bounds_simple(8);
|
RUN(test_polysat::test_monot_bounds_simple(8));
|
||||||
test_polysat::test_fixed_point_arith_div_mul_inverse();
|
RUN(test_polysat::test_fixed_point_arith_div_mul_inverse());
|
||||||
|
|
||||||
test_polysat::test_ineq_axiom1();
|
RUN(test_polysat::test_ineq_axiom1());
|
||||||
test_polysat::test_ineq_axiom2();
|
RUN(test_polysat::test_ineq_axiom2());
|
||||||
test_polysat::test_ineq_axiom3();
|
RUN(test_polysat::test_ineq_axiom3());
|
||||||
test_polysat::test_ineq_axiom4();
|
RUN(test_polysat::test_ineq_axiom4());
|
||||||
test_polysat::test_ineq_axiom5();
|
RUN(test_polysat::test_ineq_axiom5());
|
||||||
test_polysat::test_ineq_axiom6();
|
RUN(test_polysat::test_ineq_axiom6());
|
||||||
test_polysat::test_ineq_non_axiom1();
|
RUN(test_polysat::test_ineq_non_axiom1());
|
||||||
test_polysat::test_ineq_non_axiom4();
|
RUN(test_polysat::test_ineq_non_axiom4());
|
||||||
|
|
||||||
test_polysat::test_quot_rem_incomplete();
|
RUN(test_polysat::test_quot_rem_incomplete());
|
||||||
test_polysat::test_quot_rem_fixed();
|
RUN(test_polysat::test_quot_rem_fixed());
|
||||||
test_polysat::test_band();
|
RUN(test_polysat::test_band1());
|
||||||
test_polysat::test_quot_rem();
|
RUN(test_polysat::test_band2());
|
||||||
|
RUN(test_polysat::test_band3());
|
||||||
|
RUN(test_polysat::test_band4());
|
||||||
|
RUN(test_polysat::test_band5());
|
||||||
|
RUN(test_polysat::test_quot_rem());
|
||||||
|
|
||||||
test_polysat::test_fi_zero();
|
RUN(test_polysat::test_fi_zero());
|
||||||
test_polysat::test_fi_nonzero();
|
RUN(test_polysat::test_fi_nonzero());
|
||||||
test_polysat::test_fi_nonmax();
|
RUN(test_polysat::test_fi_nonmax());
|
||||||
test_polysat::test_fi_disequal_mild();
|
RUN(test_polysat::test_fi_disequal_mild());
|
||||||
|
|
||||||
// test_fi::exhaustive();
|
// test_fi::exhaustive();
|
||||||
// test_fi::randomized();
|
// test_fi::randomized();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue