aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac2
-rw-r--r--tests/Makefile.am48
-rw-r--r--tests/osmux/osmux-test.ok1
-rw-r--r--tests/osmux/osmux_test.c159
-rw-r--r--tests/testsuite.at8
6 files changed, 219 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 24feaca..91abed1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = foreign dist-bzip2 1.6
ACLOCAL_AMFLAGS = -I m4
INCLUDES = $(all_includes) -I$(top_srcdir)/include
-SUBDIRS = include src examples
+SUBDIRS = include src examples tests
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libosmo-netif.pc
diff --git a/configure.ac b/configure.ac
index 411eec9..28dde0c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,6 +3,7 @@ AC_INIT([libosmo-netif],
[openbsc-devel@lists.openbsc.org])
AM_INIT_AUTOMAKE([dist-bzip2])
+AC_CONFIG_TESTDIR(tests)
dnl kernel style compile messages
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -56,4 +57,5 @@ AC_OUTPUT(
src/channel/abis/Makefile
examples/Makefile
examples/channel/Makefile
+ tests/Makefile
Makefile)
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..7189324
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,48 @@
+AM_CFLAGS = -Wall $(all_includes) -I$(top_srcdir)/include
+
+check_PROGRAMS = osmux/osmux_test
+
+osmux_osmux_test_SOURCES = osmux/osmux_test.c
+osmux_osmux_test_LDADD = -losmocore -losmonetif
+
+# The `:;' works around a Bash 3.2 bug when the output is not writeable.
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac
+ :;{ \
+ echo '# Signature of the current package.' && \
+ echo 'm4_define([AT_PACKAGE_NAME],' && \
+ echo ' [$(PACKAGE_NAME)])' && \
+ echo 'm4_define([AT_PACKAGE_TARNAME],' && \
+ echo ' [$(PACKAGE_TARNAME)])' && \
+ echo 'm4_define([AT_PACKAGE_VERSION],' && \
+ echo ' [$(PACKAGE_VERSION)])' && \
+ echo 'm4_define([AT_PACKAGE_STRING],' && \
+ echo ' [$(PACKAGE_STRING)])' && \
+ echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \
+ echo ' [$(PACKAGE_BUGREPORT)])'; \
+ echo 'm4_define([AT_PACKAGE_URL],' && \
+ echo ' [$(PACKAGE_URL)])'; \
+ } >'$(srcdir)/package.m4'
+
+EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \
+ osmux_test.ok
+
+DISTCLEANFILES = atconfig
+
+TESTSUITE = $(srcdir)/testsuite
+
+check-local: atconfig $(TESTSUITE)
+ $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
+
+installcheck-local: atconfig $(TESTSUITE)
+ $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \
+ $(TESTSUITEFLAGS)
+
+clean-local:
+ test ! -f '$(TESTSUITE)' || \
+ $(SHELL) '$(TESTSUITE)' --clean
+
+AUTOM4TE = $(SHELL) $(top_srcdir)/missing --run autom4te
+AUTOTEST = $(AUTOM4TE) --language=autotest
+$(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4
+ $(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at
+ mv $@.tmp $@
diff --git a/tests/osmux/osmux-test.ok b/tests/osmux/osmux-test.ok
new file mode 100644
index 0000000..0f65527
--- /dev/null
+++ b/tests/osmux/osmux-test.ok
@@ -0,0 +1 @@
+OK: Test passed
diff --git a/tests/osmux/osmux_test.c b/tests/osmux/osmux_test.c
new file mode 100644
index 0000000..3f01d6e
--- /dev/null
+++ b/tests/osmux/osmux_test.c
@@ -0,0 +1,159 @@
+/*
+ * (C) 2013 by Pablo Neira Ayuso <pablo@gnumonks.org>
+ * (C) 2013 by On Waves ehf <http://www.on-waves.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+#include <signal.h>
+#include <arpa/inet.h>
+#include <sys/time.h>
+
+#include <osmocom/core/select.h>
+#include <osmocom/core/application.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/netif/osmux.h>
+#include <osmocom/netif/rtp.h>
+
+#define DOSMUX_TEST 0
+
+struct log_info_cat osmux_test_cat[] = {
+ [DOSMUX_TEST] = {
+ .name = "DOSMUX_TEST",
+ .description = "osmux test",
+ .color = "\033[1;35m",
+ .enabled = 1, .loglevel = LOGL_DEBUG,
+ },
+};
+
+const struct log_info osmux_test_log_info = {
+ .filter_fn = NULL,
+ .cat = osmux_test_cat,
+ .num_cat = ARRAY_SIZE(osmux_test_cat),
+};
+
+/* RTP packet with AMR payload */
+static uint8_t rtp_pkt[] = {
+ 0x80, 0x62, 0x3f, 0xcc, 0x00, 0x01, 0xa7, 0x6f, /* RTP */
+ 0x07, 0x09, 0x00, 0x62, 0x20, 0x14, 0xff, 0xd4, /* AMR */
+ 0xf9, 0xff, 0xfb, 0xe7, 0xeb, 0xf9, 0x9f, 0xf8,
+ 0xf2, 0x26, 0x33, 0x65, 0x54,
+};
+
+static int rtp_pkts;
+static struct timeval last;
+
+static void tx_cb(struct msgb *msg, void *data)
+{
+ char buf[4096];
+ struct timeval now, diff;
+
+ gettimeofday(&now, NULL);
+ timersub(&now, &last, &diff);
+ last = now;
+
+ if (diff.tv_usec > 17000) {
+ fprintf(stdout, "lagging to deliver reconstructed RTP\n");
+ exit(EXIT_FAILURE);
+ }
+
+ osmo_rtp_snprintf(buf, sizeof(buf), msg);
+ fprintf(stderr, "extracted packet: %s\n", buf);
+
+ if (memcmp(msg->data + sizeof(struct rtp_hdr),
+ rtp_pkt + sizeof(struct rtp_hdr),
+ sizeof(rtp_pkt) - sizeof(struct rtp_hdr)) != 0) {
+ fprintf(stdout, "payload mismatch!\n");
+ exit(EXIT_FAILURE);
+ }
+
+ rtp_pkts--;
+}
+
+static struct osmux_out_handle h_output;
+
+static void osmux_deliver(struct msgb *batch_msg, void *data)
+{
+ char buf[1024];
+ struct osmux_hdr *osmuxh;
+ LLIST_HEAD(list);
+
+ osmux_snprintf(buf, sizeof(buf), batch_msg);
+ fprintf(stderr, "OSMUX message (len=%d) %s\n", batch_msg->len, buf);
+
+ /* For each OSMUX message, extract the RTP messages and put them
+ * in a list. Then, reconstruct transmission timing.
+ */
+ while((osmuxh = osmux_xfrm_output_pull(batch_msg)) != NULL) {
+ osmux_xfrm_output(osmuxh, &h_output, &list);
+ osmux_tx_sched(&list, tx_cb, NULL);
+ }
+}
+
+struct osmux_in_handle h_input = {
+ .osmux_seq = 0, /* sequence number to start OSmux message from */
+ .batch_factor = 4, /* batch up to 4 RTP messages */
+ .deliver = osmux_deliver,
+};
+
+int main(void)
+{
+ struct msgb *msg;
+ char buf[1024];
+ struct rtp_hdr *rtph = (struct rtp_hdr *)rtp_pkt;
+ uint16_t seq;
+ int i, j;
+
+ /* This test doesn't use it, but osmux requires it internally. */
+ osmo_init_logging(&osmux_test_log_info);
+ log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
+
+ osmux_xfrm_input_init(&h_input);
+ osmux_xfrm_output_init(&h_output, 0x7000000);
+
+ for (i=1; i<64; i++) {
+ msg = msgb_alloc(1500, "test");
+ if (!msg)
+ return 0;
+
+ memcpy(msg->data, rtp_pkt, sizeof(rtp_pkt));
+ msgb_put(msg, sizeof(rtp_pkt));
+
+ seq = ntohs(rtph->sequence);
+ seq++;
+ rtph->sequence = htons(seq);
+
+ osmo_rtp_snprintf(buf, sizeof(buf), msg);
+ fprintf(stderr, "adding %s\n", buf);
+ rtp_pkts++;
+
+ osmux_xfrm_input(&h_input, msg, 0);
+ if (i % 4 == 0) {
+ gettimeofday(&last, NULL);
+
+ /* After four RTP messages, squash them into the OSMUX
+ * batch and call the routine to deliver it.
+ */
+ osmux_xfrm_input_deliver(&h_input);
+
+ /* The first RTP message that is delivered immediately,
+ * wait until the three RTP messages that are extracted
+ * from OSMUX has been delivered.
+ */
+ for (j=0; j<3; j++)
+ osmo_select_main(0);
+ }
+ }
+ fprintf(stdout, "OK: Test passed\n");
+ return EXIT_SUCCESS;
+}
diff --git a/tests/testsuite.at b/tests/testsuite.at
new file mode 100644
index 0000000..b3bc50f
--- /dev/null
+++ b/tests/testsuite.at
@@ -0,0 +1,8 @@
+AT_INIT
+AT_BANNER([Regression tests.])
+
+AT_SETUP([osmux_test])
+AT_KEYWORDS([osmux_test])
+cat $abs_srcdir/osmux/osmux-test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/osmux/osmux_test], [0], [expout], [ignore])
+AT_CLEANUP