Skip to content

Commit 456a78b

Browse files
committed
Implemented timeout set via command line
1 parent 65d5eee commit 456a78b

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

src/api/Interpret.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,22 +1375,25 @@ void Interpret::getInterpolants(const ASTNode& n)
13751375
}
13761376

13771377
bool Interpret::setTimeLimit(ASTNode const & n) {
1378-
int64_t limit;
13791378
try {
1380-
limit = std::stoll(n.getValue());
1381-
if (limit <= 0) { throw std::out_of_range{"The value must be positive."}; }
1379+
int64_t limit = std::stoll(n.getValue());
1380+
setTimeLimit(limit);
13821381
} catch (std::out_of_range const & e) {
13831382
notify_formatted(true, "Invalid argument of set-time-limit: %s", e.what());
13841383
return false;
13851384
}
13861385

1386+
return true;
1387+
}
1388+
1389+
void Interpret::setTimeLimit(int64_t limit) {
1390+
if (limit <= 0) { throw std::out_of_range{"Time limit must be positive."}; }
1391+
13871392
if (main_solver) {
13881393
main_solver->setTimeLimit(std::chrono::milliseconds{limit});
13891394
} else {
13901395
optTimeLimit = limit;
13911396
}
1392-
1393-
return true;
13941397
}
13951398

13961399
bool Interpret::is_top_level_assertion(PTRef ref) {

src/api/Interpret.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ class Interpret {
196196

197197
~Interpret();
198198

199+
// may throw std::out_of_range
200+
void setTimeLimit(int64_t limit);
201+
199202
int interpFile(FILE* in);
200203
int interpFile(char *content);
201204
int interpPipe();

src/bin/opensmt.cc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3333
#include <getopt.h>
3434
#include <iostream>
3535
#include <unistd.h>
36+
#include <string>
3637

3738
#define opensmt_error_() { std::cerr << "# Error (triggered at " << __FILE__ << ", " << __LINE__ << ")" << std::endl; assert(false); ::exit( 1 ); }
3839
#define opensmt_error( S ) { std::cerr << "; Error: " << S << " (triggered at " << __FILE__ << ", " << __LINE__ << ")" << std::endl; ::exit( 1 ); }
@@ -49,7 +50,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4950

5051
namespace opensmt {
5152

52-
inline bool pipeExecution = false;
53+
using namespace std::string_literals;
54+
55+
namespace {
56+
std::optional<int64_t> optTimeLimit;
57+
58+
bool pipeExecution = false;
59+
}
5360

5461
SMTConfig parseCMDLineArgs(int argc, char * argv[ ]);
5562

@@ -85,8 +92,13 @@ int main( int argc, char * argv[] )
8592
FILE * fin = NULL;
8693

8794
SMTConfig c = parseCMDLineArgs(argc,argv);
95+
8896
Interpret interpreter(c);
8997

98+
if (optTimeLimit) {
99+
interpreter.setTimeLimit(*optTimeLimit);
100+
}
101+
90102
if (argc - optind == 0) {
91103
c.setInstanceName("stdin");
92104
if (pipeExecution) {
@@ -225,6 +237,7 @@ void printHelp()
225237
" --minimal-unsat-cores produced unsat cores must be irreducible\n"
226238
" --print-cores-full produced unsat cores are agnostic to the smt2 attribute ':named'\n"
227239
" --produce-interpolants [-i] enables interpolant computation\n"
240+
" --time-limit [-t] <ms> sets wall-clock time limit in milliseconds\n"
228241
" --pipe [-p] for execution within a pipe\n";
229242
std::cerr << help_string;
230243
}
@@ -247,14 +260,15 @@ SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
247260
{"minimal-unsat-cores", no_argument, &selectedLongOpt, minUcoreLongOpt},
248261
{"print-cores-full", no_argument, &selectedLongOpt, fullUcoreLongOpt},
249262
{"produce-interpolants", no_argument, nullptr, 'i'},
263+
{"time-limit", required_argument, nullptr, 't'},
250264
{"pipe", no_argument, nullptr, 'p'},
251265
{0, 0, 0, 0}
252266
};
253267

254268
const char* msg;
255269
while (true) {
256270
int option_index = 0;
257-
int c = getopt_long(argc, argv, "r:hdivp", long_options, &option_index);
271+
int c = getopt_long(argc, argv, "r:hdivpt:", long_options, &option_index);
258272
if (c == -1) { break; }
259273

260274
switch (c) {
@@ -289,6 +303,15 @@ SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
289303
case 'i':
290304
res.setOption(SMTConfig::o_produce_inter, SMTOption(true), msg);
291305
break;
306+
case 't': {
307+
try {
308+
optTimeLimit = std::stoll(optarg);
309+
} catch (std::out_of_range const & e) {
310+
throw std::invalid_argument{"Invalid argument of time-limit: "s + e.what()};
311+
}
312+
313+
break;
314+
}
292315
case 'p':
293316
pipeExecution = true;
294317
break;

0 commit comments

Comments
 (0)