cli: Added --timeout flag

This commit is contained in:
Snaipe 2016-09-04 21:06:25 +02:00
parent e7ab23d67a
commit 4e1a877c66
4 changed files with 27 additions and 10 deletions

View file

@ -165,6 +165,15 @@ struct criterion_options {
* default: 1234
*/
unsigned debug_port;
/**
* The default timeout for each test when none is specified, in seconds.
*
* If the value is non-positive, no timeout is applied.
*
* default: 0
*/
double timeout;
};
CR_BEGIN_C_API

View file

@ -339,9 +339,7 @@ bool handle_timeout(struct server_ctx *sctx, struct client_ctx *ctx, const crite
if (ctx->state < CS_MAX_CLIENT_STATES) {
ctx->tstats->timed_out = true;
double elapsed_time = ctx->test->data->timeout;
if (elapsed_time == 0 && ctx->suite->data)
elapsed_time = ctx->suite->data->timeout;
double elapsed_time = ctx->instance->time.elapsed / 1000000000.;
push_event(POST_TEST, .data = &elapsed_time);
push_event(POST_FINI);
log(test_timeout, ctx->tstats);

View file

@ -308,10 +308,15 @@ static bxf_instance *run_test(struct run_next_context *ctx,
sp.debug.tcp = criterion_options.debug_port;
}
if (ctx->suite_set->suite.data && ctx->suite_set->suite.data->timeout != 0)
sp.quotas.runtime = ctx->suite_set->suite.data->timeout;
if (ctx->test->data->timeout != 0)
sp.iquotas.runtime = ctx->test->data->timeout;
double timeout = 0;
if (ctx->suite_set->suite.data && ctx->suite_set->suite.data->timeout > 0)
timeout = ctx->suite_set->suite.data->timeout;
if (ctx->test->data->timeout > 0)
timeout = ctx->test->data->timeout;
if (timeout > criterion_options.timeout)
timeout = criterion_options.timeout;
sp.iquotas.runtime = timeout;
bxf_instance *instance;
rc = bxf_spawn_struct(&instance, &sp);

View file

@ -60,6 +60,8 @@
"name of the source file on a failure\n" \
" --filter [PATTERN]: run tests matching the " \
"given pattern\n" \
" --timeout [TIMEOUT]: set a timeout (in seconds) " \
"for all tests\n" \
" --tap[=FILE]: writes TAP report in FILE " \
"(no file or \"-\" means stderr)\n" \
" --xml[=FILE]: writes XML report in FILE " \
@ -183,13 +185,14 @@ CR_API int criterion_handle_args(int argc, char *argv[],
{"verbose", optional_argument, 0, 'b'},
{"quiet", no_argument, 0, 'q'},
{"version", no_argument, 0, 'v'},
{"tap", optional_argument, 0, 't'},
{"tap", optional_argument, 0, 'T'},
{"xml", optional_argument, 0, 'x'},
{"json", optional_argument, 0, 'n'},
{"help", no_argument, 0, 'h'},
{"list", no_argument, 0, 'l'},
{"ascii", no_argument, 0, 'k'},
{"jobs", required_argument, 0, 'j'},
{"timeout", required_argument, 0, 't'},
{"fail-fast", no_argument, 0, 'f'},
{"short-filename", no_argument, 0, 'S'},
{"single", required_argument, 0, 's'},
@ -278,7 +281,7 @@ CR_API int criterion_handle_args(int argc, char *argv[],
free(out);
}
for (int c; (c = getopt_long(argc, argv, "hvlfj:SqO:w", opts, NULL)) != -1;) {
for (int c; (c = getopt_long(argc, argv, "hvlfj:SqO:wt:", opts, NULL)) != -1;) {
switch (c) {
case 'b': criterion_options.logging_threshold = (enum criterion_logging_level) atou(DEF(optarg, "1")); break;
case 'y': criterion_options.always_succeed = true; break;
@ -292,6 +295,8 @@ CR_API int criterion_handle_args(int argc, char *argv[],
case 'F': criterion_options.pattern = optarg; break;
case 'q': quiet = true; break;
case 't': criterion_options.timeout = atof(optarg); break;
case 'd':
if (!parse_dbg(optarg))
exit(3);
@ -303,7 +308,7 @@ CR_API int criterion_handle_args(int argc, char *argv[],
{
const char *provider;
case 't': provider = "tap"; goto provider_def;
case 'T': provider = "tap"; goto provider_def;
case 'x': provider = "xml"; goto provider_def;
case 'n': provider = "json"; goto provider_def;