diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 30 | ||||
-rw-r--r-- | mk/modules.mk | 1 | ||||
-rw-r--r-- | modules/selftest/module.mk | 11 | ||||
-rw-r--r-- | modules/selftest/selftest.c | 75 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | test/cmd.c (renamed from modules/selftest/cmd.c) | 4 | ||||
-rw-r--r-- | test/main.c | 86 | ||||
-rw-r--r-- | test/sip_server.c (renamed from modules/selftest/sip_server.c) | 28 | ||||
-rw-r--r-- | test/srcs.mk | 13 | ||||
-rw-r--r-- | test/test.c | 30 | ||||
-rw-r--r-- | test/test.h (renamed from modules/selftest/selftest.h) | 2 | ||||
-rw-r--r-- | test/ua.c (renamed from modules/selftest/ua.c) | 8 |
13 files changed, 188 insertions, 105 deletions
@@ -17,6 +17,7 @@ *.out *.app baresip +selftest # Generated files src/static.c @@ -84,12 +84,14 @@ endif BINDIR := $(PREFIX)/bin INCDIR := $(PREFIX)/include BIN := $(PROJECT)$(BIN_SUFFIX) +TEST_BIN := selftest$(BIN_SUFFIX) SHARED := lib$(PROJECT)$(LIB_SUFFIX) STATICLIB := libbaresip.a ifeq ($(STATIC),) MOD_BINS:= $(patsubst %,%$(MOD_SUFFIX),$(MODULES)) endif APP_MK := src/srcs.mk +TEST_MK := test/srcs.mk MOD_MK := $(patsubst %,modules/%/module.mk,$(MODULES)) MOD_BLD := $(patsubst %,$(BUILD)/modules/%,$(MODULES)) LIBDIR := $(PREFIX)/lib @@ -104,6 +106,7 @@ all: sanity $(MOD_BINS) $(BIN) modules: $(MOD_BINS) include $(APP_MK) +include $(TEST_MK) include $(MOD_MK) OBJS := $(patsubst %.c,$(BUILD)/src/%.o,$(filter %.c,$(SRCS))) @@ -112,6 +115,10 @@ OBJS += $(patsubst %.S,$(BUILD)/src/%.o,$(filter %.S,$(SRCS))) APP_OBJS := $(OBJS) $(patsubst %.c,$(BUILD)/src/%.o,$(APP_SRCS)) $(MOD_OBJS) +LIB_OBJS := $(OBJS) $(MOD_OBJS) + +TEST_OBJS := $(patsubst %.c,$(BUILD)/test/%.o,$(filter %.c,$(TEST_SRCS))) + ifneq ($(LIBREM_PATH),) LIBS += -L$(LIBREM_PATH) endif @@ -129,6 +136,9 @@ LIBS += -L$(SYSROOT)/lib -include $(APP_OBJS:.o=.d) +-include $(TEST_OBJS:.o=.d) + + sanity: ifeq ($(LIBRE_MK),) @echo "ERROR: Missing common makefile for libre. Check LIBRE_MK" @@ -146,11 +156,11 @@ endif Makefile: mk/*.mk $(MOD_MK) $(LIBRE_MK) -$(SHARED): $(APP_OBJS) +$(SHARED): $(LIB_OBJS) @echo " LD $@" @$(LD) $(LFLAGS) $(SH_LFLAGS) $^ -L$(LIBRE_SO) -lre $(LIBS) -o $@ -$(STATICLIB): $(APP_OBJS) +$(STATICLIB): $(LIB_OBJS) @echo " AR $@" @rm -f $@; $(AR) $(AFLAGS) $@ $^ ifneq ($(RANLIB),) @@ -167,6 +177,16 @@ else @$(LD) $(LFLAGS) $(APP_LFLAGS) $^ -L$(LIBRE_SO) -lre $(LIBS) -o $@ endif + +.PHONY: test +test: $(TEST_BIN) + +$(TEST_BIN): $(STATICLIB) $(TEST_OBJS) + @echo " LD $@" + @$(LD) $(LFLAGS) $(TEST_OBJS) \ + -L$(LIBRE_SO) -L. \ + -l$(PROJECT) -lre $(LIBS) -o $@ + $(BUILD)/%.o: %.c $(BUILD) Makefile $(APP_MK) @echo " CC $@" @$(CC) $(CFLAGS) -c $< -o $@ $(DFLAGS) @@ -180,7 +200,7 @@ $(BUILD)/%.o: %.S $(BUILD) Makefile $(APP_MK) @$(CC) $(CFLAGS) -c $< -o $@ $(DFLAGS) $(BUILD): Makefile - @mkdir -p $(BUILD)/src $(MOD_BLD) + @mkdir -p $(BUILD)/src $(MOD_BLD) $(BUILD)/test @touch $@ install: $(BIN) $(MOD_BINS) @@ -208,10 +228,12 @@ install-static: $(STATICLIB) uninstall: @rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN) @rm -rf $(DESTDIR)$(MOD_PATH) + @rm -f $(DESTDIR)$(PREFIX)/lib/$(SHARED) + @rm -f $(DESTDIR)$(PREFIX)/lib/$(STATICLIB) .PHONY: clean clean: - @rm -rf $(BIN) $(MOD_BINS) $(SHARED) $(BUILD) + @rm -rf $(BIN) $(MOD_BINS) $(SHARED) $(BUILD) $(TEST_BIN) @rm -f *stamp \ `find . -name "*.[od]"` \ `find . -name "*~"` \ diff --git a/mk/modules.mk b/mk/modules.mk index dc93491..085a8c5 100644 --- a/mk/modules.mk +++ b/mk/modules.mk @@ -232,7 +232,6 @@ endif MODULES += $(EXTRA_MODULES) MODULES += stun turn ice natbd auloop presence MODULES += menu contact vumeter mwi account natpmp httpd -MODULES += selftest MODULES += srtp MODULES += uuid diff --git a/modules/selftest/module.mk b/modules/selftest/module.mk deleted file mode 100644 index d47f2fe..0000000 --- a/modules/selftest/module.mk +++ /dev/null @@ -1,11 +0,0 @@ -# -# module.mk -# -# Copyright (C) 2010 Creytiv.com -# - -MOD := selftest -$(MOD)_SRCS += selftest.c cmd.c ua.c -$(MOD)_SRCS += sip_server.c - -include mk/mod.mk diff --git a/modules/selftest/selftest.c b/modules/selftest/selftest.c deleted file mode 100644 index 87e89d3..0000000 --- a/modules/selftest/selftest.c +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file selftest.c Selftest for Baresip core - * - * Copyright (C) 2010 Creytiv.com - */ -#include <re.h> -#include <baresip.h> -#include "selftest.h" - - -static void timeout_handler(void *arg) -{ - int *err = arg; - - warning("selftest: re_main() loop timed out -- test hung..\n"); - - *err = ETIMEDOUT; - - re_cancel(); -} - - -int re_main_timeout(uint32_t timeout) -{ - struct tmr tmr; - int err = 0; - - tmr_init(&tmr); - - tmr_start(&tmr, timeout * 1000, timeout_handler, &err); - re_main(NULL); - - tmr_cancel(&tmr); - return err; -} - - -static int module_init(void) -{ - int err; - - err = test_cmd(); - if (err) - return err; - - err = test_ua_alloc(); - if (err) - return err; - - err = test_uag_find_param(); - if (err) - return err; - - err = test_ua_register(); - if (err) - return err; - - re_printf("\x1b[32mselftest passed successfully\x1b[;m\n"); - - return 0; -} - - -static int module_close(void) -{ - return 0; -} - - -const struct mod_export DECL_EXPORTS(selftest) = { - "selftest", - "application", - module_init, - module_close -}; @@ -1,7 +1,7 @@ /** - * @file main.c Main application code + * @file src/main.c Main application code * - * Copyright (C) 2010 - 2011 Creytiv.com + * Copyright (C) 2010 - 2015 Creytiv.com */ #ifdef SOLARIS #define __EXTENSIONS__ 1 diff --git a/modules/selftest/cmd.c b/test/cmd.c index a0e5e2c..dfd42fa 100644 --- a/modules/selftest/cmd.c +++ b/test/cmd.c @@ -1,11 +1,11 @@ /** - * @file selftest/cmd.c Baresip selftest -- cmd + * @file test/cmd.c Baresip selftest -- cmd * * Copyright (C) 2010 Creytiv.com */ #include <re.h> #include <baresip.h> -#include "selftest.h" +#include "test.h" static bool cmd_called; diff --git a/test/main.c b/test/main.c new file mode 100644 index 0000000..c32cd4b --- /dev/null +++ b/test/main.c @@ -0,0 +1,86 @@ +/** + * @file test/main.c Selftest for Baresip core + * + * Copyright (C) 2010 Creytiv.com + */ +#include <re.h> +#include <baresip.h> +#include "test.h" + + +static int run_tests(void) +{ + int err; + + err = test_cmd(); + if (err) + return err; + + err = test_ua_alloc(); + if (err) + return err; + + err = test_uag_find_param(); + if (err) + return err; + + err = test_ua_register(); + if (err) + return err; + + return 0; +} + + +int main(void) +{ + struct config *config; + int err; + + err = libre_init(); + if (err) + return err; + + re_printf("running test..\n"); + + /* note: run SIP-traffic on localhost */ + config = conf_config(); + if (!config) { + err = ENOENT; + goto out; + } + str_ncpy(config->sip.local, "127.0.0.1:0", sizeof(config->sip.local)); + + /* XXX: needed for ua tests */ + err = ua_init("test", true, true, false, false); + if (err) + goto out; + + err = run_tests(); + if (err) + goto out; + +#if 1 + ua_stop_all(false); + err = re_main_timeout(5); + if (err) + goto out; +#endif + + re_printf("\x1b[32mOK. selftest passed successfully\x1b[;m\n"); + + out: + if (err) { + warning("test failed (%m)\n", err); + re_printf("%H\n", re_debug, 0); + } + ua_stop_all(true); + ua_close(); + + libre_close(); + + tmr_debug(); + mem_debug(); + + return err; +} diff --git a/modules/selftest/sip_server.c b/test/sip_server.c index 1962c3c..0e637de 100644 --- a/modules/selftest/sip_server.c +++ b/test/sip_server.c @@ -6,7 +6,7 @@ #include <string.h> #include <re.h> #include <baresip.h> -#include "selftest.h" +#include "test.h" static void udp_recv(const struct sa *src, struct mbuf *mb, void *arg) @@ -16,6 +16,7 @@ static void udp_recv(const struct sa *src, struct mbuf *mb, void *arg) int err; #if 0 + re_printf("sip: %zu bytes from %J\n", mbuf_get_left(mb), src); re_printf("%b\n", mb->buf, mb->end); #endif @@ -62,30 +63,45 @@ static void destructor(void *arg) int sip_server_create(struct sip_server **srvp) { struct sip_server *srv; + struct sa laddr_tp; int err; srv = mem_zalloc(sizeof *srv, destructor); if (!srv) return ENOMEM; - sa_set_str(&srv->laddr, "127.0.0.1", 0); + err = sa_set_str(&laddr_tp, "127.0.0.1", 0); + err |= sa_set_str(&srv->laddr, "127.0.0.1", 0); + if (err) + goto out; err = sip_alloc(&srv->sip, NULL, 16, 16, 16, "dummy SIP registrar", NULL, NULL); if (err) goto out; - err = sip_transp_add(srv->sip, SIP_TRANSP_UDP, &srv->laddr); - if (err) + err = sip_transp_add(srv->sip, SIP_TRANSP_UDP, &laddr_tp); + if (err) { + warning("failed to add sip transport (%m)\n", err); goto out; + } err = udp_listen(&srv->us, &srv->laddr, udp_recv, srv); - if (err) + if (err) { + warning("sip: udp_listen on '%J' failed (%d/%m)\n", + &srv->laddr, err, err); goto out; + } err = udp_local_get(srv->us, &srv->laddr); - if (err) + if (err) { + warning("sip: udp_local_get\n"); goto out; + } + +#if 0 + re_printf("sip: listen on %J\n", &srv->laddr); +#endif out: if (err) diff --git a/test/srcs.mk b/test/srcs.mk new file mode 100644 index 0000000..df16f8b --- /dev/null +++ b/test/srcs.mk @@ -0,0 +1,13 @@ +# +# srcs.mk All application source files. +# +# Copyright (C) 2010 Creytiv.com +# + +TEST_SRCS += cmd.c +TEST_SRCS += ua.c + +TEST_SRCS += sip_server.c +TEST_SRCS += test.c + +TEST_SRCS += main.c diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..ec6f6fb --- /dev/null +++ b/test/test.c @@ -0,0 +1,30 @@ +#include <re.h> +#include <baresip.h> +#include "test.h" + + +static void timeout_handler(void *arg) +{ + int *err = arg; + + warning("selftest: re_main() loop timed out -- test hung..\n"); + + *err = ETIMEDOUT; + + re_cancel(); +} + + +int re_main_timeout(uint32_t timeout) +{ + struct tmr tmr; + int err = 0; + + tmr_init(&tmr); + + tmr_start(&tmr, timeout * 1000, timeout_handler, &err); + re_main(NULL); + + tmr_cancel(&tmr); + return err; +} diff --git a/modules/selftest/selftest.h b/test/test.h index f460b3f..20807b6 100644 --- a/modules/selftest/selftest.h +++ b/test/test.h @@ -1,5 +1,5 @@ /** - * @file selftest.h Selftest for Baresip core -- internal API + * @file test.h Selftest for Baresip core -- internal API * * Copyright (C) 2010 Creytiv.com */ diff --git a/modules/selftest/ua.c b/test/ua.c index 0117867..ddfa76e 100644 --- a/modules/selftest/ua.c +++ b/test/ua.c @@ -1,12 +1,12 @@ /** - * @file selftest/ua.c Baresip selftest -- User-Agent (UA) + * @file test/ua.c Baresip selftest -- User-Agent (UA) * * Copyright (C) 2010 Creytiv.com */ #include <string.h> #include <re.h> #include <baresip.h> -#include "selftest.h" +#include "test.h" struct test { @@ -59,8 +59,10 @@ int test_ua_register(void) memset(&t, 0, sizeof t); err = sip_server_create(&t.srv); - if (err) + if (err) { + warning("failed to create sip server (%d/%m)\n", err, err); goto out; + } re_snprintf(aor, sizeof(aor), "sip:x:x@%J", &t.srv->laddr); |