summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2016-02-14 13:27:47 +0100
committerAlfred E. Heggestad <aeh@db.org>2016-02-14 13:27:47 +0100
commit50a10f5cf062b7dcd3780983b035cc7ffe06778e (patch)
tree3a0959282822ae737c1aa3e51815c9b98fe251d2 /test
parent1f1b7e8e0dba873aaeedbdaf8d78914501e6de1b (diff)
test: add option to specify which testcase(s) to run
Diffstat (limited to 'test')
-rw-r--r--test/main.c74
1 files changed, 68 insertions, 6 deletions
diff --git a/test/main.c b/test/main.c
index 90f67d7..de46b11 100644
--- a/test/main.c
+++ b/test/main.c
@@ -30,6 +30,25 @@ static const struct test tests[] = {
};
+static int run_one_test(const struct test *test)
+{
+ int err;
+
+ re_printf("[ RUN ] %s\n", test->name);
+
+ err = test->exec();
+ if (err) {
+ warning("%s: test failed (%m)\n",
+ test->name, err);
+ return err;
+ }
+
+ re_printf("[ OK ]\n");
+
+ return 0;
+}
+
+
static int run_tests(void)
{
size_t i;
@@ -72,10 +91,24 @@ static void test_listcases(void)
}
+static const struct test *find_test(const char *name)
+{
+ size_t i;
+
+ for (i=0; i<ARRAY_SIZE(tests); i++) {
+
+ if (0 == str_casecmp(name, tests[i].name))
+ return &tests[i];
+ }
+
+ return NULL;
+}
+
+
static void usage(void)
{
(void)re_fprintf(stderr,
- "Usage: selftest [options]\n"
+ "Usage: selftest [options] <testcases..>\n"
"options:\n"
"\t-l List all testcases and exit\n"
"\t-v Verbose output (INFO level)\n"
@@ -86,6 +119,7 @@ static void usage(void)
int main(int argc, char *argv[])
{
struct config *config;
+ size_t i, ntests;
int err;
err = libre_init();
@@ -119,8 +153,13 @@ int main(int argc, char *argv[])
}
}
+ if (argc >= (optind + 1))
+ ntests = argc - optind;
+ else
+ ntests = ARRAY_SIZE(tests);
+
re_printf("running baresip selftest version %s with %zu tests\n",
- BARESIP_VERSION, ARRAY_SIZE(tests));
+ BARESIP_VERSION, ntests);
/* note: run SIP-traffic on localhost */
config = conf_config();
@@ -135,16 +174,39 @@ int main(int argc, char *argv[])
if (err)
goto out;
- err = run_tests();
- if (err)
- goto out;
+ if (argc >= (optind + 1)) {
+
+ for (i=0; i<ntests; i++) {
+ const char *name = argv[optind + i];
+ const struct test *test;
+
+ test = find_test(name);
+ if (test) {
+ err = run_one_test(test);
+ if (err)
+ goto out;
+ }
+ else {
+ re_fprintf(stderr,
+ "testcase not found: `%s'\n",
+ name);
+ err = ENOENT;
+ goto out;
+ }
+ }
+ }
+ else {
+ err = run_tests();
+ if (err)
+ goto out;
+ }
#if 1
ua_stop_all(true);
#endif
re_printf("\x1b[32mOK. %zu tests passed successfully\x1b[;m\n",
- ARRAY_SIZE(tests));
+ ntests);
out:
if (err) {