summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2016-01-09 20:48:07 +0100
committerAlfred E. Heggestad <aeh@db.org>2016-01-09 20:48:07 +0100
commitfba45710a563c655b56379b86d8577fdd96a302a (patch)
tree00adc8895434953e8295edb01a0608cebfef9b07
parent4d8a30e750cfcbb6de91b1a4ee9c55411a146821 (diff)
selftest: silent output, add optional verbose -v
-rw-r--r--include/baresip.h1
-rw-r--r--src/log.c14
-rw-r--r--test/call.c2
-rw-r--r--test/cplusplus.cpp2
-rw-r--r--test/main.c50
5 files changed, 58 insertions, 11 deletions
diff --git a/include/baresip.h b/include/baresip.h
index 2369915..d9d1013 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -405,6 +405,7 @@ struct log {
void log_register_handler(struct log *log);
void log_unregister_handler(struct log *log);
void log_enable_debug(bool enable);
+void log_enable_info(bool enable);
void log_enable_stderr(bool enable);
void vlog(enum log_level level, const char *fmt, va_list ap);
void loglv(enum log_level level, const char *fmt, ...);
diff --git a/src/log.c b/src/log.c
index 793305e..666f963 100644
--- a/src/log.c
+++ b/src/log.c
@@ -11,10 +11,12 @@
static struct {
struct list logl;
bool debug;
+ bool info;
bool stder;
} lg = {
LIST_INIT,
false,
+ true,
true
};
@@ -43,6 +45,12 @@ void log_enable_debug(bool enable)
}
+void log_enable_info(bool enable)
+{
+ lg.info = enable;
+}
+
+
void log_enable_stderr(bool enable)
{
lg.stder = enable;
@@ -90,6 +98,9 @@ void loglv(enum log_level level, const char *fmt, ...)
if ((LEVEL_DEBUG == level) && !lg.debug)
return;
+ if ((LEVEL_INFO == level) && !lg.info)
+ return;
+
va_start(ap, fmt);
vlog(level, fmt, ap);
va_end(ap);
@@ -113,6 +124,9 @@ void info(const char *fmt, ...)
{
va_list ap;
+ if (!lg.info)
+ return;
+
va_start(ap, fmt);
vlog(LEVEL_INFO, fmt, ap);
va_end(ap);
diff --git a/test/call.c b/test/call.c
index dfb39dd..7ca1815 100644
--- a/test/call.c
+++ b/test/call.c
@@ -134,7 +134,6 @@ static void event_handler(struct ua *ua, enum ua_event ev,
++ag->n_established;
if (ag->peer->n_established) {
- re_printf("@@@ test complete\n");
re_cancel();
}
break;
@@ -146,7 +145,6 @@ static void event_handler(struct ua *ua, enum ua_event ev,
ag->close_scode = call_scode(call);
if (ag->peer->n_closed) {
- re_printf("@@@ test complete\n");
re_cancel();
}
break;
diff --git a/test/cplusplus.cpp b/test/cplusplus.cpp
index 7d2b208..e6ec89f 100644
--- a/test/cplusplus.cpp
+++ b/test/cplusplus.cpp
@@ -15,7 +15,7 @@ int test_cplusplus(void)
int err = 0;
ASSERT_TRUE(str_isset(version));
- re_printf("c++ ok\n");
+ info("c++ ok\n");
out:
return err;
diff --git a/test/main.c b/test/main.c
index 8215ed4..4fe93a0 100644
--- a/test/main.c
+++ b/test/main.c
@@ -3,6 +3,7 @@
*
* Copyright (C) 2010 Creytiv.com
*/
+#include <getopt.h>
#include <re.h>
#include <baresip.h>
#include "test.h"
@@ -29,17 +30,14 @@ static const struct test tests[] = {
};
-static int run_tests(bool verbose)
+static int run_tests(void)
{
size_t i;
int err;
for (i=0; i<ARRAY_SIZE(tests); i++) {
- if (verbose) {
- re_printf("test %u -- %s\n",
- i, tests[i].name);
- }
+ re_printf("[ RUN ] %s\n", tests[i].name);
err = tests[i].exec();
if (err) {
@@ -47,13 +45,25 @@ static int run_tests(bool verbose)
tests[i].name, err);
return err;
}
+
+ re_printf("[ OK ]\n");
}
return 0;
}
-int main(void)
+static void usage(void)
+{
+ (void)re_fprintf(stderr,
+ "Usage: selftest [options]\n"
+ "options:\n"
+ "\t-v Verbose output (INFO level)\n"
+ );
+}
+
+
+int main(int argc, char *argv[])
{
struct config *config;
int err;
@@ -62,7 +72,31 @@ int main(void)
if (err)
return err;
- re_printf("running test version %s\n", BARESIP_VERSION);
+ log_enable_info(false);
+
+ for (;;) {
+ const int c = getopt(argc, argv, "v");
+ if (0 > c)
+ break;
+
+ switch (c) {
+
+ case '?':
+ case 'h':
+ usage();
+ return -2;
+
+ case 'v':
+ log_enable_info(true);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ re_printf("running baresip selftest version %s with %zu tests\n",
+ BARESIP_VERSION, ARRAY_SIZE(tests));
/* note: run SIP-traffic on localhost */
config = conf_config();
@@ -77,7 +111,7 @@ int main(void)
if (err)
goto out;
- err = run_tests(false);
+ err = run_tests();
if (err)
goto out;