Skip to content

Commit acaeb24

Browse files
committed
Generalise option setting from strategy unit tests
The check_with_strategy methods previously took an argument to set the `unwind-limit` option with. This commit replaces that argument with a function that mutates the optionst that is passed into it. This can be used for setting `unwind-limit` or any other option from the client. This is in preparation for a new strategy that requires additional options to be set.
1 parent 80331d8 commit acaeb24

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

unit/path_strategies.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ SCENARIO("path strategies")
6565
std::string c;
6666
GIVEN("a simple conditional program")
6767
{
68+
std::function<void(optionst &)> opts_callback = [](optionst &opts) {};
69+
6870
c =
6971
"/* 1 */ int main() \n"
7072
"/* 2 */ { \n"
@@ -75,28 +77,28 @@ SCENARIO("path strategies")
7577
"/* 7 */ x = 0; \n"
7678
"/* 8 */ } \n";
7779

78-
const unsigned unwind_limit = 0U;
79-
8080
check_with_strategy(
8181
"lifo",
82+
opts_callback,
8283
c,
8384
{symex_eventt::resume(symex_eventt::enumt::JUMP, 7),
8485
symex_eventt::result(symex_eventt::enumt::SUCCESS),
8586
symex_eventt::resume(symex_eventt::enumt::NEXT, 5),
86-
symex_eventt::result(symex_eventt::enumt::SUCCESS)},
87-
unwind_limit);
87+
symex_eventt::result(symex_eventt::enumt::SUCCESS)});
8888
check_with_strategy(
8989
"fifo",
90+
opts_callback,
9091
c,
9192
{symex_eventt::resume(symex_eventt::enumt::NEXT, 5),
9293
symex_eventt::result(symex_eventt::enumt::SUCCESS),
9394
symex_eventt::resume(symex_eventt::enumt::JUMP, 7),
94-
symex_eventt::result(symex_eventt::enumt::SUCCESS)},
95-
unwind_limit);
95+
symex_eventt::result(symex_eventt::enumt::SUCCESS)});
9696
}
9797

9898
GIVEN("a program with nested conditionals")
9999
{
100+
std::function<void(optionst &)> opts_callback = [](optionst &opts) {};
101+
100102
c =
101103
"/* 1 */ int main() \n"
102104
"/* 2 */ { \n"
@@ -117,10 +119,9 @@ SCENARIO("path strategies")
117119
"/* 17 */ } \n"
118120
"/* 18 */ } \n";
119121

120-
const unsigned unwind_limit = 0U;
121-
122122
check_with_strategy(
123123
"lifo",
124+
opts_callback,
124125
c,
125126
{// Outer else, inner else
126127
symex_eventt::resume(symex_eventt::enumt::JUMP, 13),
@@ -135,11 +136,11 @@ SCENARIO("path strategies")
135136
symex_eventt::result(symex_eventt::enumt::SUCCESS),
136137
// Outer if, inner if
137138
symex_eventt::resume(symex_eventt::enumt::NEXT, 7),
138-
symex_eventt::result(symex_eventt::enumt::SUCCESS)},
139-
unwind_limit);
139+
symex_eventt::result(symex_eventt::enumt::SUCCESS)});
140140

141141
check_with_strategy(
142142
"fifo",
143+
opts_callback,
143144
c,
144145
{// Expand outer if, but don't continue depth-first
145146
symex_eventt::resume(symex_eventt::enumt::NEXT, 6),
@@ -155,12 +156,15 @@ SCENARIO("path strategies")
155156
symex_eventt::resume(symex_eventt::enumt::NEXT, 14),
156157
symex_eventt::result(symex_eventt::enumt::SUCCESS),
157158
symex_eventt::resume(symex_eventt::enumt::JUMP, 16),
158-
symex_eventt::result(symex_eventt::enumt::SUCCESS)},
159-
unwind_limit);
159+
symex_eventt::result(symex_eventt::enumt::SUCCESS)});
160160
}
161161

162162
GIVEN("a loop program to test functional correctness")
163163
{
164+
std::function<void(optionst &)> opts_callback = [](optionst &opts) {
165+
opts.set_option("unwind", 2U);
166+
};
167+
164168
c =
165169
"/* 1 */ int main() \n"
166170
"/* 2 */ { \n"
@@ -173,10 +177,9 @@ SCENARIO("path strategies")
173177
"/* 9 */ assert(x); \n"
174178
"/* 10 */ } \n";
175179

176-
const unsigned unwind_limit = 2U;
177-
178180
check_with_strategy(
179181
"lifo",
182+
opts_callback,
180183
c,
181184
{
182185
// The path where we skip the loop body. Successful because the path is
@@ -194,11 +197,11 @@ SCENARIO("path strategies")
194197
// infeasible.
195198
symex_eventt::resume(symex_eventt::enumt::NEXT, 7),
196199
symex_eventt::result(symex_eventt::enumt::SUCCESS),
197-
},
198-
unwind_limit);
200+
});
199201

200202
check_with_strategy(
201203
"fifo",
204+
opts_callback,
202205
c,
203206
{
204207
// The path where we skip the loop body. Successful because the path is
@@ -219,8 +222,7 @@ SCENARIO("path strategies")
219222
// executing the loop once, decrementing x to 0; assert(x) should fail.
220223
symex_eventt::resume(symex_eventt::enumt::JUMP, 9),
221224
symex_eventt::result(symex_eventt::enumt::FAILURE),
222-
},
223-
unwind_limit);
225+
});
224226
}
225227
}
226228

@@ -286,7 +288,7 @@ void symex_eventt::validate_resume(
286288
void _check_with_strategy(
287289
const std::string &strategy,
288290
const std::string &program,
289-
const unsigned unwind_limit,
291+
std::function<void(optionst &)> opts_callback,
290292
symex_eventt::listt &events)
291293
{
292294
temporary_filet tmp("path-explore_", ".c");
@@ -307,11 +309,7 @@ void _check_with_strategy(
307309
opts.set_option("paths", true);
308310
opts.set_option("exploration-strategy", strategy);
309311

310-
if(unwind_limit)
311-
{
312-
opts.set_option("unwind", unwind_limit);
313-
cmdline.set("unwind", std::to_string(unwind_limit));
314-
}
312+
opts_callback(opts);
315313

316314
ui_message_handlert mh(cmdline, "path-explore");
317315
messaget log(mh);

unit/path_strategies.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ struct symex_eventt
4545
void _check_with_strategy(
4646
const std::string &strategy,
4747
const std::string &program,
48-
const unsigned unwind_limit,
48+
std::function<void(optionst &)>,
4949
symex_eventt::listt &events);
5050

5151
/// Call this one, not the underscore version
5252
void check_with_strategy(
5353
const std::string &strategy,
54+
std::function<void(optionst &)> opts_callback,
5455
const std::string &program,
55-
symex_eventt::listt events,
56-
const unsigned unwind_limit)
56+
symex_eventt::listt events)
5757
{
5858
WHEN("strategy is '" + strategy + "'")
59-
_check_with_strategy(strategy, program, unwind_limit, events);
59+
_check_with_strategy(strategy, program, opts_callback, events);
6060
}
6161

6262
#endif // CPROVER_PATH_STRATEGIES_H

0 commit comments

Comments
 (0)