Commit 71d7db35 authored by Philippe Gerum's avatar Philippe Gerum

testsuite/smokey: cover RTIPC protocols

parent 8f879c17
......@@ -14227,7 +14227,7 @@ XENO_CONFIG_ARGS="$ac_configure_args"
ac_config_files="$ac_config_files Makefile config/Makefile scripts/Makefile scripts/xeno-config:scripts/xeno-config-$rtcore_type.in scripts/xeno lib/Makefile lib/boilerplate/Makefile lib/cobalt/Makefile lib/cobalt/arch/Makefile lib/cobalt/arch/arm/Makefile lib/cobalt/arch/arm/include/Makefile lib/cobalt/arch/arm/include/asm/Makefile lib/cobalt/arch/arm/include/asm/xenomai/Makefile lib/cobalt/arch/powerpc/Makefile lib/cobalt/arch/powerpc/include/Makefile lib/cobalt/arch/powerpc/include/asm/Makefile lib/cobalt/arch/powerpc/include/asm/xenomai/Makefile lib/cobalt/arch/blackfin/Makefile lib/cobalt/arch/blackfin/include/Makefile lib/cobalt/arch/blackfin/include/asm/Makefile lib/cobalt/arch/blackfin/include/asm/xenomai/Makefile lib/cobalt/arch/x86/Makefile lib/cobalt/arch/x86/include/Makefile lib/cobalt/arch/x86/include/asm/Makefile lib/cobalt/arch/x86/include/asm/xenomai/Makefile lib/cobalt/arch/nios2/Makefile lib/cobalt/arch/nios2/include/Makefile lib/cobalt/arch/nios2/include/asm/Makefile lib/cobalt/arch/nios2/include/asm/xenomai/Makefile lib/cobalt/arch/sh/Makefile lib/cobalt/arch/sh/include/Makefile lib/cobalt/arch/sh/include/asm/Makefile lib/cobalt/arch/sh/include/asm/xenomai/Makefile lib/copperplate/Makefile lib/copperplate/regd/Makefile lib/alchemy/Makefile lib/vxworks/Makefile lib/psos/Makefile lib/analogy/Makefile lib/smokey/Makefile lib/trank/Makefile testsuite/Makefile testsuite/latency/Makefile testsuite/switchtest/Makefile testsuite/smokey/Makefile testsuite/smokey/arith/Makefile testsuite/smokey/sched-quota/Makefile testsuite/smokey/sched-tp/Makefile testsuite/smokey/rtdm/Makefile testsuite/smokey/vdso-access/Makefile testsuite/smokey/cond-torture/Makefile testsuite/smokey/mutex-torture/Makefile testsuite/clocktest/Makefile testsuite/xeno-test/Makefile testsuite/regression/Makefile testsuite/regression/posix/Makefile utils/Makefile utils/can/Makefile utils/analogy/Makefile utils/ps/Makefile utils/slackspot/Makefile utils/autotune/Makefile demo/Makefile demo/posix/Makefile demo/posix/cobalt/Makefile demo/alchemy/Makefile demo/alchemy/cobalt/Makefile include/Makefile include/nocore/Makefile include/cobalt/uapi/Makefile include/cobalt/uapi/asm-generic/Makefile include/cobalt/uapi/kernel/Makefile include/cobalt/uapi/rtdm/Makefile include/cobalt/Makefile include/cobalt/sys/Makefile include/cobalt/kernel/Makefile include/cobalt/kernel/rtdm/Makefile include/cobalt/kernel/rtdm/analogy/Makefile include/cobalt/boilerplate/Makefile include/rtdm/Makefile include/rtdm/uapi/Makefile include/mercury/Makefile include/mercury/boilerplate/Makefile include/boilerplate/Makefile include/copperplate/Makefile include/alchemy/Makefile include/vxworks/Makefile include/psos/Makefile include/smokey/Makefile include/trank/Makefile include/trank/posix/Makefile include/trank/native/Makefile include/trank/rtdm/Makefile doc/Makefile doc/doxygen/Makefile doc/doxygen/xeno3prm-common.conf doc/doxygen/xeno3prm-html.conf doc/doxygen/xeno3prm-latex.conf doc/gitdoc/Makefile doc/asciidoc/Makefile"
ac_config_files="$ac_config_files Makefile config/Makefile scripts/Makefile scripts/xeno-config:scripts/xeno-config-$rtcore_type.in scripts/xeno lib/Makefile lib/boilerplate/Makefile lib/cobalt/Makefile lib/cobalt/arch/Makefile lib/cobalt/arch/arm/Makefile lib/cobalt/arch/arm/include/Makefile lib/cobalt/arch/arm/include/asm/Makefile lib/cobalt/arch/arm/include/asm/xenomai/Makefile lib/cobalt/arch/powerpc/Makefile lib/cobalt/arch/powerpc/include/Makefile lib/cobalt/arch/powerpc/include/asm/Makefile lib/cobalt/arch/powerpc/include/asm/xenomai/Makefile lib/cobalt/arch/blackfin/Makefile lib/cobalt/arch/blackfin/include/Makefile lib/cobalt/arch/blackfin/include/asm/Makefile lib/cobalt/arch/blackfin/include/asm/xenomai/Makefile lib/cobalt/arch/x86/Makefile lib/cobalt/arch/x86/include/Makefile lib/cobalt/arch/x86/include/asm/Makefile lib/cobalt/arch/x86/include/asm/xenomai/Makefile lib/cobalt/arch/nios2/Makefile lib/cobalt/arch/nios2/include/Makefile lib/cobalt/arch/nios2/include/asm/Makefile lib/cobalt/arch/nios2/include/asm/xenomai/Makefile lib/cobalt/arch/sh/Makefile lib/cobalt/arch/sh/include/Makefile lib/cobalt/arch/sh/include/asm/Makefile lib/cobalt/arch/sh/include/asm/xenomai/Makefile lib/copperplate/Makefile lib/copperplate/regd/Makefile lib/alchemy/Makefile lib/vxworks/Makefile lib/psos/Makefile lib/analogy/Makefile lib/smokey/Makefile lib/trank/Makefile testsuite/Makefile testsuite/latency/Makefile testsuite/switchtest/Makefile testsuite/smokey/Makefile testsuite/smokey/arith/Makefile testsuite/smokey/sched-quota/Makefile testsuite/smokey/sched-tp/Makefile testsuite/smokey/rtdm/Makefile testsuite/smokey/vdso-access/Makefile testsuite/smokey/cond-torture/Makefile testsuite/smokey/mutex-torture/Makefile testsuite/smokey/xddp/Makefile testsuite/smokey/iddp/Makefile testsuite/smokey/bufp/Makefile testsuite/clocktest/Makefile testsuite/xeno-test/Makefile testsuite/regression/Makefile testsuite/regression/posix/Makefile utils/Makefile utils/can/Makefile utils/analogy/Makefile utils/ps/Makefile utils/slackspot/Makefile utils/autotune/Makefile demo/Makefile demo/posix/Makefile demo/posix/cobalt/Makefile demo/alchemy/Makefile demo/alchemy/cobalt/Makefile include/Makefile include/nocore/Makefile include/cobalt/uapi/Makefile include/cobalt/uapi/asm-generic/Makefile include/cobalt/uapi/kernel/Makefile include/cobalt/uapi/rtdm/Makefile include/cobalt/Makefile include/cobalt/sys/Makefile include/cobalt/kernel/Makefile include/cobalt/kernel/rtdm/Makefile include/cobalt/kernel/rtdm/analogy/Makefile include/cobalt/boilerplate/Makefile include/rtdm/Makefile include/rtdm/uapi/Makefile include/mercury/Makefile include/mercury/boilerplate/Makefile include/boilerplate/Makefile include/copperplate/Makefile include/alchemy/Makefile include/vxworks/Makefile include/psos/Makefile include/smokey/Makefile include/trank/Makefile include/trank/posix/Makefile include/trank/native/Makefile include/trank/rtdm/Makefile doc/Makefile doc/doxygen/Makefile doc/doxygen/xeno3prm-common.conf doc/doxygen/xeno3prm-html.conf doc/doxygen/xeno3prm-latex.conf doc/gitdoc/Makefile doc/asciidoc/Makefile"
cat >confcache <<\_ACEOF
......@@ -15343,6 +15343,9 @@ do
"testsuite/smokey/vdso-access/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/smokey/vdso-access/Makefile" ;;
"testsuite/smokey/cond-torture/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/smokey/cond-torture/Makefile" ;;
"testsuite/smokey/mutex-torture/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/smokey/mutex-torture/Makefile" ;;
"testsuite/smokey/xddp/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/smokey/xddp/Makefile" ;;
"testsuite/smokey/iddp/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/smokey/iddp/Makefile" ;;
"testsuite/smokey/bufp/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/smokey/bufp/Makefile" ;;
"testsuite/clocktest/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/clocktest/Makefile" ;;
"testsuite/xeno-test/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/xeno-test/Makefile" ;;
"testsuite/regression/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/regression/Makefile" ;;
......
......@@ -850,6 +850,9 @@ AC_CONFIG_FILES([ \
testsuite/smokey/vdso-access/Makefile \
testsuite/smokey/cond-torture/Makefile \
testsuite/smokey/mutex-torture/Makefile \
testsuite/smokey/xddp/Makefile \
testsuite/smokey/iddp/Makefile \
testsuite/smokey/bufp/Makefile \
testsuite/clocktest/Makefile \
testsuite/xeno-test/Makefile \
testsuite/regression/Makefile \
......
......@@ -9,7 +9,17 @@ core_libs =
if XENO_COBALT
core_libs += ../../lib/cobalt/libcobalt.la
wrappers = $(XENO_POSIX_WRAPPERS)
SUBDIRS = arith sched-quota sched-tp cond-torture mutex-torture rtdm vdso-access
SUBDIRS = \
arith \
bufp \
cond-torture \
iddp \
mutex-torture \
rtdm \
sched-quota \
sched-tp \
vdso-access \
xddp
else
SUBDIRS =
wrappers =
......@@ -36,4 +46,14 @@ smokey_LDADD = \
@XENO_USER_LDADD@ \
-lpthread -lrt
DIST_SUBDIRS = arith sched-quota sched-tp cond-torture mutex-torture rtdm vdso-access
DIST_SUBDIRS = \
arith \
bufp \
cond-torture \
iddp \
mutex-torture \
rtdm \
sched-quota \
sched-tp \
vdso-access \
xddp
......@@ -384,7 +384,18 @@ core_libs = $(am__append_1)
@XENO_COBALT_FALSE@wrappers =
@XENO_COBALT_TRUE@wrappers = $(XENO_POSIX_WRAPPERS)
@XENO_COBALT_FALSE@SUBDIRS =
@XENO_COBALT_TRUE@SUBDIRS = arith sched-quota sched-tp cond-torture mutex-torture rtdm vdso-access
@XENO_COBALT_TRUE@SUBDIRS = \
@XENO_COBALT_TRUE@ arith \
@XENO_COBALT_TRUE@ bufp \
@XENO_COBALT_TRUE@ cond-torture \
@XENO_COBALT_TRUE@ iddp \
@XENO_COBALT_TRUE@ mutex-torture \
@XENO_COBALT_TRUE@ rtdm \
@XENO_COBALT_TRUE@ sched-quota \
@XENO_COBALT_TRUE@ sched-tp \
@XENO_COBALT_TRUE@ vdso-access \
@XENO_COBALT_TRUE@ xddp
plugin_list = $(foreach plugin,$(SUBDIRS),$(plugin)/lib$(plugin).a)
# wrap-link.sh is confused by -whole-archive, so work around
# this by forcing undefined references to symbols we expect the
......@@ -405,7 +416,18 @@ smokey_LDADD = \
@XENO_USER_LDADD@ \
-lpthread -lrt
DIST_SUBDIRS = arith sched-quota sched-tp cond-torture mutex-torture rtdm vdso-access
DIST_SUBDIRS = \
arith \
bufp \
cond-torture \
iddp \
mutex-torture \
rtdm \
sched-quota \
sched-tp \
vdso-access \
xddp
all: all-recursive
.SUFFIXES:
......
noinst_LIBRARIES = libbufp.a
libbufp_a_SOURCES = bufp.c
CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
libbufp_a_CPPFLAGS = \
@XENO_USER_CFLAGS@ \
-I$(top_srcdir)/include
This diff is collapsed.
/*
* RTIPC/BUFP test.
*
* Copyright (C) Philippe Gerum <rpm@xenomai.org>
*
* Released under the terms of GPLv2.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <pthread.h>
#include <fcntl.h>
#include <errno.h>
#include <smokey/smokey.h>
#include <rtdm/ipc.h>
smokey_test_plugin(bufp,
SMOKEY_NOARGS,
"Check RTIPC/BUFP protocol."
);
#define BUFP_SVPORT 12
static pthread_t svtid, cltid;
static void fail(const char *reason)
{
perror(reason);
exit(EXIT_FAILURE);
}
static void *server(void *arg)
{
struct sockaddr_ipc saddr, claddr;
long data, control = 0;
socklen_t addrlen;
size_t bufsz;
fd_set set;
int ret, s;
s = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_BUFP);
if (s < 0)
fail("socket");
bufsz = 32768; /* bytes */
ret = setsockopt(s, SOL_BUFP, BUFP_BUFSZ,
&bufsz, sizeof(bufsz));
if (ret)
fail("setsockopt");
memset(&saddr, 0, sizeof(saddr));
saddr.sipc_family = AF_RTIPC;
saddr.sipc_port = BUFP_SVPORT;
ret = bind(s, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret)
fail("bind");
FD_ZERO(&set);
FD_SET(s, &set);
for (;;) {
control++;
ret = select(s + 1, &set, NULL, NULL, NULL);
if (ret != 1 || !FD_ISSET(s, &set))
fail("select");
/*
* We can't race with any other reader in this setup,
* so recvfrom() shall confirm the select() result.
*/
addrlen = sizeof(saddr);
ret = recvfrom(s, &data, sizeof(data), MSG_DONTWAIT,
(struct sockaddr *)&claddr, &addrlen);
if (ret != sizeof(data)) {
close(s);
fail("recvfrom");
}
if (data != control) {
close(s);
smokey_note("data does not match control value");
errno = -EINVAL;
fail("recvfrom");
}
smokey_note("%s: received %d bytes, %ld from port %d\n",
__FUNCTION__, ret, data, claddr.sipc_port);
}
return NULL;
}
static void *client(void *arg)
{
struct sockaddr_ipc svsaddr;
int ret, s, loops = 30;
struct timespec ts;
long data = 0;
fd_set set;
s = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_BUFP);
if (s < 0)
fail("socket");
memset(&svsaddr, 0, sizeof(svsaddr));
svsaddr.sipc_family = AF_RTIPC;
svsaddr.sipc_port = BUFP_SVPORT;
ret = connect(s, (struct sockaddr *)&svsaddr, sizeof(svsaddr));
if (ret)
fail("connect");
FD_ZERO(&set);
FD_SET(s, &set);
while (--loops) {
#if 0
ret = select(s + 1, NULL, &set, NULL, NULL);
if (ret != 1 || !FD_ISSET(s, &set))
fail("select");
#endif
data++;
ret = sendto(s, &data, sizeof(data), MSG_DONTWAIT,
(struct sockaddr *)&svsaddr, sizeof(svsaddr));
if (ret != sizeof(data)) {
close(s);
fail("sendto");
}
smokey_note("%s: sent %d bytes, %ld\n", __FUNCTION__, ret, data);
ts.tv_sec = 0;
ts.tv_nsec = 100000000; /* 100 ms */
clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
}
return NULL;
}
static int run_bufp(struct smokey_test *t, int argc, char *const argv[])
{
struct sched_param svparam = {.sched_priority = 71 };
struct sched_param clparam = {.sched_priority = 70 };
pthread_attr_t svattr, clattr;
pthread_attr_init(&svattr);
pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
pthread_attr_setinheritsched(&svattr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&svattr, SCHED_FIFO);
pthread_attr_setschedparam(&svattr, &svparam);
errno = pthread_create(&svtid, &svattr, &server, NULL);
if (errno)
fail("pthread_create");
pthread_attr_init(&clattr);
pthread_attr_setdetachstate(&clattr, PTHREAD_CREATE_JOINABLE);
pthread_attr_setinheritsched(&clattr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&clattr, SCHED_FIFO);
pthread_attr_setschedparam(&clattr, &clparam);
errno = pthread_create(&cltid, &clattr, &client, NULL);
if (errno)
fail("pthread_create");
pthread_join(cltid, NULL);
pthread_cancel(svtid);
pthread_join(svtid, NULL);
return 0;
}
noinst_LIBRARIES = libiddp.a
libiddp_a_SOURCES = iddp.c
CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
libiddp_a_CPPFLAGS = \
@XENO_USER_CFLAGS@ \
-I$(top_srcdir)/include
This diff is collapsed.
/*
* RTIPC/IDDP test.
*
* Copyright (C) Philippe Gerum <rpm@xenomai.org>
*
* Released under the terms of GPLv2.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <pthread.h>
#include <fcntl.h>
#include <errno.h>
#include <smokey/smokey.h>
#include <rtdm/ipc.h>
smokey_test_plugin(iddp,
SMOKEY_NOARGS,
"Check RTIPC/IDDP protocol."
);
#define IDDP_SVPORT 12
#define IDDP_CLPORT 13
static pthread_t svtid, cltid;
static void fail(const char *reason)
{
perror(reason);
exit(EXIT_FAILURE);
}
static void *server(void *arg)
{
struct sockaddr_ipc saddr, claddr;
long data, control = 0;
socklen_t addrlen;
size_t poolsz;
fd_set set;
int ret, s;
s = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_IDDP);
if (s < 0)
fail("socket");
poolsz = 32768; /* bytes */
ret = setsockopt(s, SOL_IDDP, IDDP_POOLSZ,
&poolsz, sizeof(poolsz));
if (ret)
fail("setsockopt");
saddr.sipc_family = AF_RTIPC;
saddr.sipc_port = IDDP_SVPORT;
ret = bind(s, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret)
fail("bind");
FD_ZERO(&set);
FD_SET(s, &set);
for (;;) {
control++;
ret = select(s + 1, &set, NULL, NULL, NULL);
if (ret != 1 || !FD_ISSET(s, &set))
fail("select");
/*
* We can't race with any other reader in this setup,
* so recvfrom() shall confirm the select() result.
*/
addrlen = sizeof(saddr);
ret = recvfrom(s, &data, sizeof(data), MSG_DONTWAIT,
(struct sockaddr *)&claddr, &addrlen);
if (ret != sizeof(data)) {
close(s);
fail("recvfrom");
}
if (data != control) {
close(s);
smokey_note("data does not match control value");
errno = -EINVAL;
fail("recvfrom");
}
smokey_note("%s: received %d bytes, %ld from port %d\n",
__FUNCTION__, ret, data, claddr.sipc_port);
}
return NULL;
}
static void *client(void *arg)
{
struct sockaddr_ipc svsaddr, clsaddr;
int ret, s, loops = 30;
struct timespec ts;
long data = 0;
fd_set set;
s = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_IDDP);
if (s < 0)
fail("socket");
clsaddr.sipc_family = AF_RTIPC;
clsaddr.sipc_port = IDDP_CLPORT;
ret = bind(s, (struct sockaddr *)&clsaddr, sizeof(clsaddr));
if (ret)
fail("bind");
svsaddr.sipc_family = AF_RTIPC;
svsaddr.sipc_port = IDDP_SVPORT;
FD_ZERO(&set);
FD_SET(s, &set);
while (--loops) {
ret = select(s + 1, NULL, &set, NULL, NULL);
/* Should always be immediately writable. */
if (ret != 1 || !FD_ISSET(s, &set))
fail("select");
data++;
ret = sendto(s, &data, sizeof(data), MSG_DONTWAIT,
(struct sockaddr *)&svsaddr, sizeof(svsaddr));
if (ret != sizeof(data)) {
close(s);
fail("sendto");
}
smokey_note("%s: sent %d bytes, %ld\n", __FUNCTION__, ret, data);
ts.tv_sec = 0;
ts.tv_nsec = 100000000; /* 100 ms */
clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
}
return NULL;
}
static int run_iddp(struct smokey_test *t, int argc, char *const argv[])
{
struct sched_param svparam = {.sched_priority = 71 };
struct sched_param clparam = {.sched_priority = 70 };
pthread_attr_t svattr, clattr;
pthread_attr_init(&svattr);
pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
pthread_attr_setinheritsched(&svattr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&svattr, SCHED_FIFO);
pthread_attr_setschedparam(&svattr, &svparam);
errno = pthread_create(&svtid, &svattr, &server, NULL);
if (errno)
fail("pthread_create");
pthread_attr_init(&clattr);
pthread_attr_setdetachstate(&clattr, PTHREAD_CREATE_JOINABLE);
pthread_attr_setinheritsched(&clattr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&clattr, SCHED_FIFO);
pthread_attr_setschedparam(&clattr, &clparam);
errno = pthread_create(&cltid, &clattr, &client, NULL);
if (errno)
fail("pthread_create");
pthread_join(cltid, NULL);
pthread_cancel(svtid);
pthread_join(svtid, NULL);
return 0;
}
noinst_LIBRARIES = libxddp.a
libxddp_a_SOURCES = xddp.c
CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
libxddp_a_CPPFLAGS = \
@XENO_USER_CFLAGS@ \
-I$(top_srcdir)/include
This diff is collapsed.
/*
* RTIPC/XDDP test.
*
* Copyright (C) Philippe Gerum <rpm@xenomai.org>
*
* Released under the terms of GPLv2.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <pthread.h>
#include <fcntl.h>
#include <errno.h>
#include <smokey/smokey.h>
#include <rtdm/ipc.h>
smokey_test_plugin(xddp,
SMOKEY_NOARGS,
"Check RTIPC/XDDP protocol."
);
static pthread_t rt1, rt2, nrt;
#define XDDP_PORT_LABEL "xddp-smokey"
static void fail(const char *reason)
{
perror(reason);
exit(EXIT_FAILURE);
}
static void *realtime_thread1(void *arg)
{
struct rtipc_port_label plabel;
struct sockaddr_ipc saddr;
long control = 0, data;
fd_set set;
int ret, s;
s = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_XDDP);
if (s < 0) {
perror("socket");
exit(EXIT_FAILURE);
}
strcpy(plabel.label, XDDP_PORT_LABEL);
ret = setsockopt(s, SOL_XDDP, XDDP_LABEL, &plabel, sizeof(plabel));
if (ret)
fail("setsockopt");
memset(&saddr, 0, sizeof(saddr));
saddr.sipc_family = AF_RTIPC;
saddr.sipc_port = -1;
ret = bind(s, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret)
fail("bind");
FD_ZERO(&set);
FD_SET(s, &set);
for (;;) {
control++;
ret = select(s + 1, &set, NULL, NULL, NULL);
if (ret != 1 || !FD_ISSET(s, &set))
fail("select");
/*
* We can't race with any other reader in this setup,
* so recvfrom() shall confirm the select() result.
*/
ret = recvfrom(s, &data, sizeof(data), MSG_DONTWAIT, NULL, 0);
if (ret != sizeof(data)) {
close(s);
fail("recvfrom");
}
if (data != control) {
close(s);
smokey_note("data does not match control value");
errno = -EINVAL;
fail("recvfrom");
}
smokey_note("%s: %ld relayed by peer\n", __FUNCTION__, data);
}
return NULL;
}
static void *realtime_thread2(void *arg)
{
struct rtipc_port_label plabel;
struct sockaddr_ipc saddr;
int ret, s, loops = 30;
struct timespec ts;
struct timeval tv;
socklen_t addrlen;
long data = 0;
fd_set set;
s = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_XDDP);
if (s < 0) {
perror("socket");
exit(EXIT_FAILURE);
}
tv.tv_sec = 1;
tv.tv_usec = 0;
ret = setsockopt(s, SOL_SOCKET, SO_RCVTIMEO,
&tv, sizeof(tv));
if (ret)
fail("setsockopt");
strcpy(plabel.label, XDDP_PORT_LABEL);
ret = setsockopt(s, SOL_XDDP, XDDP_LABEL,
&plabel, sizeof(plabel));
if (ret)
fail("setsockopt");
memset(&saddr, 0, sizeof(saddr));
saddr.sipc_family = AF_RTIPC;
saddr.sipc_port = -1; /* Tell XDDP to search by label. */
ret = connect(s, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret)
fail("connect");
addrlen = sizeof(saddr);
ret = getpeername(s, (struct sockaddr *)&saddr, &addrlen);
if (ret || addrlen != sizeof(saddr))
fail("getpeername");
smokey_note("%s: NRT peer is reading from /dev/rtp%d\n",
__FUNCTION__, saddr.sipc_port);
FD_ZERO(&set);
FD_SET(s, &set);
while (--loops) {
ret = select(s + 1, NULL, &set, NULL, NULL);
/* Should always be immediately writable. */
if (ret != 1 || !FD_ISSET(s, &set))
fail("select");
/*
* Actually we might fail sending although select() on
* POLLOUT succeeded earlier, as the situation might
* have changed in the meantime due to a sudden
* pressure on the system heap. Pretend it did not.
*/
data++;
ret = sendto(s, &data, sizeof(data), MSG_DONTWAIT, NULL, 0);
if (ret != sizeof(data))
fail("sendto");
smokey_note("%s: sent %d bytes, %ld\n", __FUNCTION__, ret, data);
ts.tv_sec = 0;