summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
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) {