aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2020-07-11 10:15:03 +0200
committerHarald Welte <laforge@osmocom.org>2020-11-09 13:37:54 +0100
commita94bb7761f04c6f8cc8ed672c0c37f83e768e133 (patch)
tree0e22890127961181481da09f239a73a97e8d4ef5
parente542b30f447a4349a16189919c067c1c777cf1ac (diff)
raw_test
-rw-r--r--Makefile.am1
-rw-r--r--configure.ac1
-rw-r--r--tests/Makefile.am11
-rw-r--r--tests/raw_test.c73
4 files changed, 86 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 3f87824..e623296 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,6 +5,7 @@ SUBDIRS = \
doc \
src \
include \
+ tests \
$(NULL)
EXTRA_DIST = \
diff --git a/configure.ac b/configure.ac
index 548cc68..7a1a2da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -96,5 +96,6 @@ AC_OUTPUT(
doc/examples/Makefile
src/Makefile
include/Makefile
+ tests/Makefile
libosmo-e1d.pc
)
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..66248a0
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,11 @@
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)
+AM_CFLAGS=-Wall -Wno-unused-result $(LIBOSMOCORE_CFLAGS)
+LDADD = $(LIBOSMOCORE_LIBS) ../src/libosmo-e1d.la
+
+bin_PROGRAMS = \
+ raw_test \
+ $(NULL)
+
+raw_test_SOURCES = \
+ raw_test.c \
+ $(NULL)
diff --git a/tests/raw_test.c b/tests/raw_test.c
new file mode 100644
index 0000000..bfaa019
--- /dev/null
+++ b/tests/raw_test.c
@@ -0,0 +1,73 @@
+
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <osmocom/core/utils.h>
+#include <osmocom/core/application.h>
+#include <osmocom/core/select.h>
+#include <osmocom/e1d/proto_clnt.h>
+
+static struct osmo_e1dp_client *g_client;
+static struct osmo_fd g_ts_ofd[2];
+static uint8_t g_counter;
+
+
+static int ts_fd_read_cb(struct osmo_fd *ofd, unsigned int what)
+{
+ uint8_t buf[4096];
+ int rc, nbytes;
+
+ if (!(what & OSMO_FD_READ))
+ return 0;
+
+ /* read + print */
+ rc = read(ofd->fd, buf, sizeof(buf));
+ OSMO_ASSERT(rc > 0);
+ nbytes = rc;
+ printf("%u: %s\n", ofd->priv_nr, osmo_hexdump_nospc(buf, nbytes));
+
+#if 0
+ /* write just as many bytes back */
+ memset(buf, g_counter, nbytes);
+ rc = write(ofd->fd, buf, nbytes);
+ OSMO_ASSERT(rc == nbytes);
+#else
+ /* write twice as many bytes on every 2nd frame */
+ if (g_counter % 2 == 0) {
+ memset(buf, g_counter, nbytes);
+ memset(buf+nbytes, g_counter+1, nbytes);
+ rc = write(ofd->fd, buf, nbytes*2);
+ OSMO_ASSERT(rc == nbytes*2);
+ }
+#endif
+ g_counter++;
+
+ return 0;
+}
+
+
+int main(int argc, char **argv)
+{
+ int ts_fd;
+
+ osmo_init_logging2(NULL, NULL);
+
+ g_client = osmo_e1dp_client_create(NULL, E1DP_DEFAULT_SOCKET);
+ OSMO_ASSERT(g_client);
+
+ /* open two file descriptors of a vpair */
+ ts_fd = osmo_e1dp_client_ts_open(g_client, 0, 0, 10, E1DP_TSMODE_RAW, 160);
+ OSMO_ASSERT(ts_fd >= 0);
+ osmo_fd_setup(&g_ts_ofd[0], ts_fd, OSMO_FD_READ, ts_fd_read_cb, NULL, 0);
+ osmo_fd_register(&g_ts_ofd[0]);
+
+ ts_fd = osmo_e1dp_client_ts_open(g_client, 1, 0, 10, E1DP_TSMODE_RAW, 160);
+ OSMO_ASSERT(ts_fd >= 0);
+ osmo_fd_setup(&g_ts_ofd[1], ts_fd, OSMO_FD_READ, ts_fd_read_cb, NULL, 1);
+ osmo_fd_register(&g_ts_ofd[1]);
+
+ while (1) {
+ osmo_select_main(0);
+ }
+}