cli: Added --timeout flag
This commit is contained in:
parent
e7ab23d67a
commit
4e1a877c66
4 changed files with 27 additions and 10 deletions
|
@ -165,6 +165,15 @@ struct criterion_options {
|
||||||
* default: 1234
|
* default: 1234
|
||||||
*/
|
*/
|
||||||
unsigned debug_port;
|
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
|
CR_BEGIN_C_API
|
||||||
|
|
|
@ -339,9 +339,7 @@ bool handle_timeout(struct server_ctx *sctx, struct client_ctx *ctx, const crite
|
||||||
|
|
||||||
if (ctx->state < CS_MAX_CLIENT_STATES) {
|
if (ctx->state < CS_MAX_CLIENT_STATES) {
|
||||||
ctx->tstats->timed_out = true;
|
ctx->tstats->timed_out = true;
|
||||||
double elapsed_time = ctx->test->data->timeout;
|
double elapsed_time = ctx->instance->time.elapsed / 1000000000.;
|
||||||
if (elapsed_time == 0 && ctx->suite->data)
|
|
||||||
elapsed_time = ctx->suite->data->timeout;
|
|
||||||
push_event(POST_TEST, .data = &elapsed_time);
|
push_event(POST_TEST, .data = &elapsed_time);
|
||||||
push_event(POST_FINI);
|
push_event(POST_FINI);
|
||||||
log(test_timeout, ctx->tstats);
|
log(test_timeout, ctx->tstats);
|
||||||
|
|
|
@ -308,10 +308,15 @@ static bxf_instance *run_test(struct run_next_context *ctx,
|
||||||
sp.debug.tcp = criterion_options.debug_port;
|
sp.debug.tcp = criterion_options.debug_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->suite_set->suite.data && ctx->suite_set->suite.data->timeout != 0)
|
double timeout = 0;
|
||||||
sp.quotas.runtime = ctx->suite_set->suite.data->timeout;
|
if (ctx->suite_set->suite.data && ctx->suite_set->suite.data->timeout > 0)
|
||||||
if (ctx->test->data->timeout != 0)
|
timeout = ctx->suite_set->suite.data->timeout;
|
||||||
sp.iquotas.runtime = ctx->test->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;
|
bxf_instance *instance;
|
||||||
rc = bxf_spawn_struct(&instance, &sp);
|
rc = bxf_spawn_struct(&instance, &sp);
|
||||||
|
|
|
@ -60,6 +60,8 @@
|
||||||
"name of the source file on a failure\n" \
|
"name of the source file on a failure\n" \
|
||||||
" --filter [PATTERN]: run tests matching the " \
|
" --filter [PATTERN]: run tests matching the " \
|
||||||
"given pattern\n" \
|
"given pattern\n" \
|
||||||
|
" --timeout [TIMEOUT]: set a timeout (in seconds) " \
|
||||||
|
"for all tests\n" \
|
||||||
" --tap[=FILE]: writes TAP report in FILE " \
|
" --tap[=FILE]: writes TAP report in FILE " \
|
||||||
"(no file or \"-\" means stderr)\n" \
|
"(no file or \"-\" means stderr)\n" \
|
||||||
" --xml[=FILE]: writes XML report in FILE " \
|
" --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'},
|
{"verbose", optional_argument, 0, 'b'},
|
||||||
{"quiet", no_argument, 0, 'q'},
|
{"quiet", no_argument, 0, 'q'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, 0, 'v'},
|
||||||
{"tap", optional_argument, 0, 't'},
|
{"tap", optional_argument, 0, 'T'},
|
||||||
{"xml", optional_argument, 0, 'x'},
|
{"xml", optional_argument, 0, 'x'},
|
||||||
{"json", optional_argument, 0, 'n'},
|
{"json", optional_argument, 0, 'n'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"list", no_argument, 0, 'l'},
|
{"list", no_argument, 0, 'l'},
|
||||||
{"ascii", no_argument, 0, 'k'},
|
{"ascii", no_argument, 0, 'k'},
|
||||||
{"jobs", required_argument, 0, 'j'},
|
{"jobs", required_argument, 0, 'j'},
|
||||||
|
{"timeout", required_argument, 0, 't'},
|
||||||
{"fail-fast", no_argument, 0, 'f'},
|
{"fail-fast", no_argument, 0, 'f'},
|
||||||
{"short-filename", no_argument, 0, 'S'},
|
{"short-filename", no_argument, 0, 'S'},
|
||||||
{"single", required_argument, 0, 's'},
|
{"single", required_argument, 0, 's'},
|
||||||
|
@ -278,7 +281,7 @@ CR_API int criterion_handle_args(int argc, char *argv[],
|
||||||
free(out);
|
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) {
|
switch (c) {
|
||||||
case 'b': criterion_options.logging_threshold = (enum criterion_logging_level) atou(DEF(optarg, "1")); break;
|
case 'b': criterion_options.logging_threshold = (enum criterion_logging_level) atou(DEF(optarg, "1")); break;
|
||||||
case 'y': criterion_options.always_succeed = true; 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 'F': criterion_options.pattern = optarg; break;
|
||||||
case 'q': quiet = true; break;
|
case 'q': quiet = true; break;
|
||||||
|
|
||||||
|
case 't': criterion_options.timeout = atof(optarg); break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
if (!parse_dbg(optarg))
|
if (!parse_dbg(optarg))
|
||||||
exit(3);
|
exit(3);
|
||||||
|
@ -303,7 +308,7 @@ CR_API int criterion_handle_args(int argc, char *argv[],
|
||||||
|
|
||||||
{
|
{
|
||||||
const char *provider;
|
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 'x': provider = "xml"; goto provider_def;
|
||||||
case 'n': provider = "json"; goto provider_def;
|
case 'n': provider = "json"; goto provider_def;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue