From 2e503dccd889a3f83951830fda18c9357377693d Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 8 Aug 2014 09:11:52 +0200 Subject: common: Allow specifying which tests to run on command line This modifies our common unit test code so we can specify full test paths on the command line, and restrict the run tests to the ones specified. Order is not respected at this time. --- common/test.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/test.c b/common/test.c index a006f74..c619b7d 100644 --- a/common/test.c +++ b/common/test.c @@ -206,6 +206,22 @@ p11_fixture (void (* setup) (void *), test_push (&item); } +static int +should_run_test (int argc, + char **argv, + test_item *item) +{ + int i; + if (argc == 0) + return 1; + for (i = 0; i < argc; i++) { + if (strcmp (argv[i], item->x.test.name) == 0) + return 1; + } + + return 0; +} + int p11_test_run (int argc, char **argv) @@ -216,16 +232,28 @@ p11_test_run (int argc, int count; int ret = 0; int setup; + int opt; /* p11-kit specific stuff */ putenv ("P11_KIT_STRICT=1"); p11_debug_init (); + while ((opt = getopt (argc, argv, "")) != -1) { + switch (opt) { + default: + fprintf (stderr, "specify only test names on the command line\n"); + return 2; + } + } + + argc -= optind; + argv += optind; + assert (gl.number == 0); gl.last = NULL; for (item = gl.suite, count = 0; item != NULL; item = item->next) { - if (item->type == TEST) + if (item->type == TEST && should_run_test (argc, argv, item)) count++; } @@ -243,6 +271,10 @@ p11_test_run (int argc, } assert (item->type == TEST); + + if (!should_run_test (argc, argv, item)) + continue; + gl.last = item; gl.number++; setup = 0; -- cgit v1.2.3