test: add a filter for iteration

Debugging is easier if we can explicitly run a single iteration only.
This filter could be a range but for now it's sufficient to be able to
run a single test only.
This commit is contained in:
Peter Hutterer 2021-10-07 13:49:28 +10:00 committed by Wim Taymans
parent 82de0613d6
commit 3f6521819f
2 changed files with 16 additions and 0 deletions

View file

@ -130,6 +130,8 @@ struct pwtest_context {
bool no_fork;
const char *test_filter;
bool has_iteration_filter;
int iteration_filter;
char *xdg_dir;
};
@ -1109,6 +1111,10 @@ static int run_tests(struct pwtest_context *ctx)
bool have_range = min != 0 || max != 1;
for (int iteration = min; iteration < max; iteration++) {
if (ctx->has_iteration_filter &&
ctx->iteration_filter != iteration)
continue;
fprintf(stderr, " - name: \"%s\"\n", t->name);
if (have_range)
fprintf(stderr, " iteration: %d # %d - %d\n",
@ -1192,6 +1198,7 @@ static void usage(FILE *fp, const char *progname)
" --timeout=N Set the test timeout to N seconds (default: 30)\n"
" --filter-test=glob Run only tests matching the given glob\n"
" --filter-suites=glob Run only suites matching the given glob\n"
" --filter-iteration=N Run only iteration N\n"
" --no-fork Do not fork for the test (see note below)\n"
"\n"
"Using --no-fork allows for easy debugging of tests but should only be used.\n"
@ -1209,6 +1216,7 @@ int main(int argc, char **argv)
OPT_VERBOSE,
OPT_FILTER_TEST,
OPT_FILTER_SUITE,
OPT_FILTER_ITERATION,
OPT_NOFORK,
};
static const struct option opts[] = {
@ -1217,6 +1225,7 @@ int main(int argc, char **argv)
{ "list", no_argument, 0, OPT_LIST },
{ "filter-test", required_argument, 0, OPT_FILTER_TEST },
{ "filter-suite", required_argument, 0, OPT_FILTER_SUITE },
{ "filter-iteration", required_argument, 0, OPT_FILTER_ITERATION },
{ "list", no_argument, 0, OPT_LIST },
{ "verbose", no_argument, 0, OPT_VERBOSE },
{ "no-fork", no_argument, 0, OPT_NOFORK },
@ -1225,6 +1234,7 @@ int main(int argc, char **argv)
struct pwtest_context test_ctx = {
.suites = SPA_LIST_INIT(&test_ctx.suites),
.timeout = 30,
.has_iteration_filter = false,
};
enum {
MODE_TEST,
@ -1260,6 +1270,9 @@ int main(int argc, char **argv)
case OPT_FILTER_SUITE:
suite_filter= optarg;
break;
case OPT_FILTER_ITERATION:
ctx->has_iteration_filter = spa_atoi32(optarg, &ctx->iteration_filter, 10);
break;
case OPT_NOFORK:
ctx->no_fork = true;
break;

View file

@ -141,6 +141,9 @@ extern "C" {
* Disabling forking makes it easy to debug but should always be used with
* `--filter-test`. Any test that modifies its environment will affect
* subsequent tests and may invalidate the test results.
*
* Where a test has multiple iterations, use `--filter-iteration` to only run
* one single iteration.
*/
/**