@@ -47,67 +47,116 @@ static const AnalyzerOptions DefaultOpts = [] {
4747 return Config;
4848}();
4949
50+ static const AnalyzerOptions LimitedOpts = [] {
51+ AnalyzerOptions Config = DefaultOpts;
52+ Config.Z3CrosscheckEQClassTimeoutThreshold = 700_ms;
53+ Config.Z3CrosscheckTimeoutThreshold = 300_step;
54+ Config.Z3CrosscheckRLimitThreshold = 400' 000_step;
55+ return Config;
56+ }();
57+
5058namespace {
5159
60+ template <const AnalyzerOptions &Opts>
5261class Z3CrosscheckOracleTest : public testing ::Test {
5362public:
5463 Z3Decision interpretQueryResult (const Z3Result &Result) {
5564 return Oracle.interpretQueryResult (Result);
5665 }
5766
5867private:
59- Z3CrosscheckOracle Oracle = Z3CrosscheckOracle(DefaultOpts );
68+ Z3CrosscheckOracle Oracle = Z3CrosscheckOracle(Opts );
6069};
6170
62- TEST_F (Z3CrosscheckOracleTest, AcceptsFirstSAT) {
71+ using DefaultZ3CrosscheckOracleTest = Z3CrosscheckOracleTest<DefaultOpts>;
72+ using LimitedZ3CrosscheckOracleTest = Z3CrosscheckOracleTest<LimitedOpts>;
73+
74+ TEST_F (DefaultZ3CrosscheckOracleTest, AcceptsFirstSAT) {
75+ ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 25_ms, 1000_step}));
76+ }
77+ TEST_F (LimitedZ3CrosscheckOracleTest, AcceptsFirstSAT) {
6378 ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 25_ms, 1000_step}));
6479}
6580
66- TEST_F (Z3CrosscheckOracleTest, AcceptsSAT) {
81+ TEST_F (DefaultZ3CrosscheckOracleTest, AcceptsSAT) {
82+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
83+ ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 25_ms, 1000_step}));
84+ }
85+ TEST_F (LimitedZ3CrosscheckOracleTest, AcceptsSAT) {
6786 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
6887 ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 25_ms, 1000_step}));
6988}
7089
71- TEST_F (Z3CrosscheckOracleTest, SATWhenItGoesOverTime) {
90+ TEST_F (DefaultZ3CrosscheckOracleTest, SATWhenItGoesOverTime) {
91+ // Even if it times out, if it is SAT, we should accept it.
92+ ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 310_ms, 1000_step}));
93+ }
94+ TEST_F (LimitedZ3CrosscheckOracleTest, SATWhenItGoesOverTime) {
7295 // Even if it times out, if it is SAT, we should accept it.
7396 ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 310_ms, 1000_step}));
7497}
7598
76- TEST_F (Z3CrosscheckOracleTest , UNSATWhenItGoesOverTime) {
99+ TEST_F (DefaultZ3CrosscheckOracleTest , UNSATWhenItGoesOverTime) {
77100 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 310_ms, 1000_step}));
78101}
102+ TEST_F (LimitedZ3CrosscheckOracleTest, UNSATWhenItGoesOverTime) {
103+ ASSERT_EQ (RejectEQClass, interpretQueryResult ({UNSAT, 310_ms, 1000_step}));
104+ }
79105
80- TEST_F (Z3CrosscheckOracleTest , RejectsTimeout) {
106+ TEST_F (DefaultZ3CrosscheckOracleTest , RejectsTimeout) {
81107 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
82108 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
83109 ASSERT_EQ (RejectReport, interpretQueryResult ({UNDEF, 310_ms, 1000_step}));
84110}
111+ TEST_F (LimitedZ3CrosscheckOracleTest, RejectsTimeout) {
112+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
113+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
114+ ASSERT_EQ (RejectEQClass, interpretQueryResult ({UNDEF, 310_ms, 1000_step}));
115+ }
85116
86- TEST_F (Z3CrosscheckOracleTest, RejectsUNSATs) {
117+ TEST_F (DefaultZ3CrosscheckOracleTest, RejectsUNSATs) {
118+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
119+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
120+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
121+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
122+ }
123+ TEST_F (LimitedZ3CrosscheckOracleTest, RejectsUNSATs) {
87124 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
88125 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
89126 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
90127 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
91128}
92129
93- // Testing cut heuristics:
94- // =======================
130+ // Testing cut heuristics of the two configurations :
131+ // =================================================
95132
96- TEST_F (Z3CrosscheckOracleTest , RejectEQClassIfSpendsTooMuchTotalTime) {
133+ TEST_F (DefaultZ3CrosscheckOracleTest , RejectEQClassIfSpendsTooMuchTotalTime) {
97134 // Simulate long queries, that barely doesn't trigger the timeout.
98135 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
99136 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
100137 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
101138}
139+ TEST_F (LimitedZ3CrosscheckOracleTest, RejectEQClassIfSpendsTooMuchTotalTime) {
140+ // Simulate long queries, that barely doesn't trigger the timeout.
141+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
142+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
143+ ASSERT_EQ (RejectEQClass, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
144+ }
102145
103- TEST_F (Z3CrosscheckOracleTest, SATWhenItSpendsTooMuchTotalTime) {
146+ TEST_F (DefaultZ3CrosscheckOracleTest, SATWhenItSpendsTooMuchTotalTime) {
147+ // Simulate long queries, that barely doesn't trigger the timeout.
148+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
149+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
150+ ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 290_ms, 1000_step}));
151+ }
152+ TEST_F (LimitedZ3CrosscheckOracleTest, SATWhenItSpendsTooMuchTotalTime) {
104153 // Simulate long queries, that barely doesn't trigger the timeout.
105154 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
106155 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 290_ms, 1000_step}));
107156 ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 290_ms, 1000_step}));
108157}
109158
110- TEST_F (Z3CrosscheckOracleTest , RejectEQClassIfAttemptsManySmallQueries) {
159+ TEST_F (DefaultZ3CrosscheckOracleTest , RejectEQClassIfAttemptsManySmallQueries) {
111160 // Simulate quick, but many queries: 35 quick UNSAT queries.
112161 // 35*20ms = 700ms, which is equal to the 700ms threshold.
113162 for (int i = 0 ; i < 35 ; ++i) {
@@ -116,8 +165,27 @@ TEST_F(Z3CrosscheckOracleTest, RejectEQClassIfAttemptsManySmallQueries) {
116165 // Do one more to trigger the heuristic.
117166 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 1_ms, 1000_step}));
118167}
168+ TEST_F (LimitedZ3CrosscheckOracleTest, RejectEQClassIfAttemptsManySmallQueries) {
169+ // Simulate quick, but many queries: 35 quick UNSAT queries.
170+ // 35*20ms = 700ms, which is equal to the 700ms threshold.
171+ for (int i = 0 ; i < 35 ; ++i) {
172+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 20_ms, 1000_step}));
173+ }
174+ // Do one more to trigger the heuristic.
175+ ASSERT_EQ (RejectEQClass, interpretQueryResult ({UNSAT, 1_ms, 1000_step}));
176+ }
119177
120- TEST_F (Z3CrosscheckOracleTest, SATWhenIfAttemptsManySmallQueries) {
178+ TEST_F (DefaultZ3CrosscheckOracleTest, SATWhenIfAttemptsManySmallQueries) {
179+ // Simulate quick, but many queries: 35 quick UNSAT queries.
180+ // 35*20ms = 700ms, which is equal to the 700ms threshold.
181+ for (int i = 0 ; i < 35 ; ++i) {
182+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 20_ms, 1000_step}));
183+ }
184+ // Do one more to trigger the heuristic, but given this was SAT, we still
185+ // accept the query.
186+ ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 200_ms, 1000_step}));
187+ }
188+ TEST_F (LimitedZ3CrosscheckOracleTest, SATWhenIfAttemptsManySmallQueries) {
121189 // Simulate quick, but many queries: 35 quick UNSAT queries.
122190 // 35*20ms = 700ms, which is equal to the 700ms threshold.
123191 for (int i = 0 ; i < 35 ; ++i) {
@@ -128,13 +196,23 @@ TEST_F(Z3CrosscheckOracleTest, SATWhenIfAttemptsManySmallQueries) {
128196 ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 200_ms, 1000_step}));
129197}
130198
131- TEST_F (Z3CrosscheckOracleTest , RejectEQClassIfExhaustsRLimit) {
199+ TEST_F (DefaultZ3CrosscheckOracleTest , RejectEQClassIfExhaustsRLimit) {
132200 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
133201 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
134202 ASSERT_EQ (RejectReport, interpretQueryResult ({UNDEF, 25_ms, 405' 000_step}));
135203}
204+ TEST_F (LimitedZ3CrosscheckOracleTest, RejectEQClassIfExhaustsRLimit) {
205+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
206+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
207+ ASSERT_EQ (RejectEQClass, interpretQueryResult ({UNDEF, 25_ms, 405' 000_step}));
208+ }
136209
137- TEST_F (Z3CrosscheckOracleTest, SATWhenItExhaustsRLimit) {
210+ TEST_F (DefaultZ3CrosscheckOracleTest, SATWhenItExhaustsRLimit) {
211+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
212+ ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
213+ ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 25_ms, 405' 000_step}));
214+ }
215+ TEST_F (LimitedZ3CrosscheckOracleTest, SATWhenItExhaustsRLimit) {
138216 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
139217 ASSERT_EQ (RejectReport, interpretQueryResult ({UNSAT, 25_ms, 1000_step}));
140218 ASSERT_EQ (AcceptReport, interpretQueryResult ({SAT, 25_ms, 405' 000_step}));
0 commit comments