Change-Id: I47cf9f3e347645fbd9ac4802ae978aba3ebb0107
This commit is contained in:
Harald Welte 2020-07-11 10:15:03 +02:00
parent e542b30f44
commit a94bb7761f
4 changed files with 86 additions and 0 deletions

View File

@ -5,6 +5,7 @@ SUBDIRS = \
doc \
src \
include \
tests \
$(NULL)
EXTRA_DIST = \

View File

@ -96,5 +96,6 @@ AC_OUTPUT(
doc/examples/Makefile
src/Makefile
include/Makefile
tests/Makefile
libosmo-e1d.pc
)

11
tests/Makefile.am Normal file
View File

@ -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)

73
tests/raw_test.c Normal file
View File

@ -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);
}
}