Module: xenomai-2.6
Branch: master
Commit: e4acba44732c12ec1914748030408ec78bf03b5b
URL:    
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=e4acba44732c12ec1914748030408ec78bf03b5b

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Wed Sep 19 00:28:01 2012 +0200

testsuite: add xddp crash regression test

---

 src/testsuite/regression/posix/Makefile.am       |    2 +-
 src/testsuite/regression/posix/Makefile.in       |   15 ++-
 src/testsuite/regression/posix/check.h           |    6 +-
 src/testsuite/regression/posix/xddp_test.c       |  171 ++++++++++++++++++++++
 src/testsuite/regression/xeno-regression-test.in |    1 +
 5 files changed, 188 insertions(+), 7 deletions(-)

diff --git a/src/testsuite/regression/posix/Makefile.am 
b/src/testsuite/regression/posix/Makefile.am
index 2107482..bd3c1cf 100644
--- a/src/testsuite/regression/posix/Makefile.am
+++ b/src/testsuite/regression/posix/Makefile.am
@@ -4,7 +4,7 @@ noinst_HEADERS = check.h
 
 CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 
-tst_PROGRAMS = leaks shm mprotect nano_test
+tst_PROGRAMS = leaks shm mprotect nano_test xddp_test
 
 CPPFLAGS = $(XENO_USER_CFLAGS) \
        -I$(top_srcdir)/include/posix \
diff --git a/src/testsuite/regression/posix/Makefile.in 
b/src/testsuite/regression/posix/Makefile.in
index 9f77e38..da24e2f 100644
--- a/src/testsuite/regression/posix/Makefile.in
+++ b/src/testsuite/regression/posix/Makefile.in
@@ -37,7 +37,7 @@ build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
 tst_PROGRAMS = leaks$(EXEEXT) shm$(EXEEXT) mprotect$(EXEEXT) \
-       nano_test$(EXEEXT)
+       nano_test$(EXEEXT) xddp_test$(EXEEXT)
 subdir = src/testsuite/regression/posix
 DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
        $(srcdir)/Makefile.in
@@ -78,6 +78,11 @@ shm_OBJECTS = shm.$(OBJEXT)
 shm_LDADD = $(LDADD)
 shm_DEPENDENCIES = ../../../skins/posix/libpthread_rt.la \
        ../../../skins/common/libxenomai.la
+xddp_test_SOURCES = xddp_test.c
+xddp_test_OBJECTS = xddp_test.$(OBJEXT)
+xddp_test_LDADD = $(LDADD)
+xddp_test_DEPENDENCIES = ../../../skins/posix/libpthread_rt.la \
+       ../../../skins/common/libxenomai.la
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src/include
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 am__depfiles_maybe = depfiles
@@ -90,8 +95,8 @@ LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) 
$(LIBTOOLFLAGS) \
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
        $(LDFLAGS) -o $@
-SOURCES = leaks.c mprotect.c nano_test.c shm.c
-DIST_SOURCES = leaks.c mprotect.c nano_test.c shm.c
+SOURCES = leaks.c mprotect.c nano_test.c shm.c xddp_test.c
+DIST_SOURCES = leaks.c mprotect.c nano_test.c shm.c xddp_test.c
 HEADERS = $(noinst_HEADERS)
 ETAGS = etags
 CTAGS = ctags
@@ -358,6 +363,9 @@ nano_test$(EXEEXT): $(nano_test_OBJECTS) 
$(nano_test_DEPENDENCIES)
 shm$(EXEEXT): $(shm_OBJECTS) $(shm_DEPENDENCIES) 
        @rm -f shm$(EXEEXT)
        $(LINK) $(shm_OBJECTS) $(shm_LDADD) $(LIBS)
+xddp_test$(EXEEXT): $(xddp_test_OBJECTS) $(xddp_test_DEPENDENCIES) 
+       @rm -f xddp_test$(EXEEXT)
+       $(LINK) $(xddp_test_OBJECTS) $(xddp_test_LDADD) $(LIBS)
 
 mostlyclean-compile:
        -rm -f *.$(OBJEXT)
@@ -369,6 +377,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mprotect.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nano_test.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shm.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xddp_test.Po@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ 
$<
diff --git a/src/testsuite/regression/posix/check.h 
b/src/testsuite/regression/posix/check.h
index 63dc4a3..5530e8a 100644
--- a/src/testsuite/regression/posix/check.h
+++ b/src/testsuite/regression/posix/check.h
@@ -10,7 +10,7 @@
        ({                                                              \
                int rc = (expr);                                        \
                if (rc > 0) {                                           \
-                       fprintf(stderr, "FAILURE %s:%d: "#expr ": %s\n", 
__FILE__, __LINE__, strerror(rc)); \
+                       fprintf(stderr, "FAILURE %s:%d: %s: %s\n", __FILE__, 
__LINE__, #expr, strerror(rc)); \
                        exit(EXIT_FAILURE);                             \
                }                                                       \
                rc;                                                     \
@@ -20,7 +20,7 @@
        ({                                                              \
                int rc = (expr);                                        \
                if (rc < 0) {                                           \
-                       fprintf(stderr, "FAILURE %s:%d: "#expr ": %s\n", 
__FILE__, __LINE__, strerror(errno)); \
+                       fprintf(stderr, "FAILURE %s:%d: %s: %s\n", __FILE__, 
__LINE__, #expr, strerror(errno)); \
                        exit(EXIT_FAILURE);                             \
                }                                                       \
                rc;                                                     \
@@ -30,7 +30,7 @@
        ({                                                              \
                void *rc = (expr);                                      \
                if (rc == MAP_FAILED) {                                 \
-                       fprintf(stderr, "FAILURE %s:%d: "#expr ": %s\n", 
__FILE__, __LINE__, strerror(errno)); \
+                       fprintf(stderr, "FAILURE %s:%d: %s: %s\n", __FILE__, 
__LINE__, #expr, strerror(errno)); \
                        exit(EXIT_FAILURE);                             \
                }                                                       \
                rc;                                                     \
diff --git a/src/testsuite/regression/posix/xddp_test.c 
b/src/testsuite/regression/posix/xddp_test.c
new file mode 100644
index 0000000..30b95bb
--- /dev/null
+++ b/src/testsuite/regression/posix/xddp_test.c
@@ -0,0 +1,171 @@
+/*
+ * XDDP-based RT/NRT threads regression test.
+ *
+ * Original author: Doug Brunner
+ *
+ * This test causes a crash with Xenomai 2.6.1 and earlier versions.
+ */
+#include <sys/mman.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+#include <malloc.h>
+#include <pthread.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <rtdk.h>
+#include <rtdm/rtipc.h>
+#include "check.h"
+
+static pthread_t rt, nrt;
+
+#define XDDP_PORT 0    /* [0..CONFIG-XENO_OPT_PIPE_NRDEV - 1] */
+
+static void *realtime_thread(void *arg)
+{
+       unsigned long count = (unsigned long)arg;
+       struct sockaddr_ipc saddr;
+       struct timespec ts;
+       size_t poolsz;
+       int ret, s;
+
+       /*
+        * Get a datagram socket to bind to the RT endpoint. Each
+        * endpoint is represented by a port number within the XDDP
+        * protocol namespace.
+        */
+       s = check_unix(socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_XDDP));
+
+       /*
+        * Set a local 16k pool for the RT endpoint. Memory needed to
+        * convey datagrams will be pulled from this pool, instead of
+        * Xenomai's system pool.
+        */
+       poolsz = 16384; /* bytes */
+       ret = check_unix(setsockopt(s, SOL_XDDP, XDDP_POOLSZ,
+                                   &poolsz, sizeof(poolsz)));
+
+       /*
+        * Bind the socket to the port, to setup a proxy to channel
+        * traffic to/from the Linux domain.
+        *
+        * saddr.sipc_port specifies the port number to use.
+        */
+       memset(&saddr, 0, sizeof(saddr));
+       saddr.sipc_family = AF_RTIPC;
+       saddr.sipc_port = XDDP_PORT;
+       ret = bind(s, (struct sockaddr *)&saddr, sizeof(saddr));
+       if (count == 1) {
+               if (ret < 0 && errno == EADDRINUSE) {
+                       fprintf(stderr, "Test OK\n");
+                       exit(EXIT_SUCCESS);
+               }
+               if (ret < 0) {
+                       fprintf(stderr, "FAILURE: bind: %m\n");
+                       exit(EXIT_FAILURE);
+               }
+               fprintf(stderr, "FAILURE: bind returned %d\n", ret);
+       }
+       if (ret < 0) {
+               fprintf(stderr, "FAILURE bind: %m\n");
+               exit(EXIT_FAILURE);
+       }
+
+       ts.tv_sec = 0;
+       ts.tv_nsec = 500000000; /* 500 ms */
+       check_unix(clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL));
+       check_unix(close(s));
+
+       return NULL;
+}
+
+static void *regular_thread(void *arg)
+{
+       char buf[128], *devname;
+       int fd, ret;
+
+       check_unix(asprintf(&devname, "/dev/rtp%d", XDDP_PORT));
+
+       fd = check_unix(open(devname, O_RDWR));
+       free(devname);
+
+       for (;;) {
+               /* Get the next message from realtime_thread. */
+               ret = read(fd, buf, sizeof(buf));
+
+               usleep(10000);
+       }
+
+       return NULL;
+}
+
+static void cleanup_upon_sig(int sig)
+{
+       pthread_cancel(rt);
+       pthread_cancel(nrt);
+       signal(sig, SIG_DFL);
+       pthread_join(rt, NULL);
+       pthread_join(nrt, NULL);
+       raise(sig);
+}
+
+int main(int argc, char **argv)
+{
+       struct sched_param rtparam = { .sched_priority = 42 };
+       pthread_attr_t rtattr, regattr;
+       sigset_t mask, oldmask;
+
+       check_unix(mlockall(MCL_CURRENT | MCL_FUTURE));
+
+       check_unix(sigemptyset(&mask));
+       check_unix(sigaddset(&mask, SIGINT));
+       check_unix(signal(SIGINT, cleanup_upon_sig) == SIG_ERR ? -1 : 0);
+       check_unix(sigaddset(&mask, SIGTERM));
+       check_unix(signal(SIGTERM, cleanup_upon_sig) == SIG_ERR ? -1 : 0);
+       check_unix(sigaddset(&mask, SIGHUP));
+       check_unix(signal(SIGHUP, cleanup_upon_sig) == SIG_ERR ? -1 : 0);
+       check_pthread(pthread_sigmask(SIG_BLOCK, &mask, &oldmask));
+
+       check_pthread(pthread_attr_init(&rtattr));
+       check_pthread(pthread_attr_setdetachstate(&rtattr,
+                                                 PTHREAD_CREATE_JOINABLE));
+       check_pthread(pthread_attr_setinheritsched(&rtattr,
+                                                  PTHREAD_EXPLICIT_SCHED));
+       check_pthread(pthread_attr_setschedpolicy(&rtattr, SCHED_FIFO));
+       check_pthread(pthread_attr_setschedparam(&rtattr, &rtparam));
+
+       check_pthread(pthread_create(&rt, &rtattr, &realtime_thread, NULL));
+       check_pthread(pthread_attr_destroy(&rtattr));
+
+       check_pthread(pthread_attr_init(&regattr));
+       check_pthread(pthread_attr_setdetachstate(&regattr,
+                                                 PTHREAD_CREATE_JOINABLE));
+       check_pthread(pthread_attr_setinheritsched(&regattr,
+                                                  PTHREAD_EXPLICIT_SCHED));
+       check_pthread(pthread_attr_setschedpolicy(&regattr, SCHED_OTHER));
+
+       check_pthread(pthread_create(&nrt, &regattr, &regular_thread, NULL));
+       check_pthread(pthread_attr_destroy(&regattr));
+
+       /* after this call returns the RT thread will have ended */
+       sleep(1);
+
+       /* start another RT thread to cause the crash */
+       check_pthread(pthread_attr_init(&rtattr));
+       check_pthread(pthread_attr_setdetachstate(&rtattr,
+                                                 PTHREAD_CREATE_JOINABLE));
+       check_pthread(pthread_attr_setinheritsched(&rtattr,
+                                                  PTHREAD_EXPLICIT_SCHED));
+       check_pthread(pthread_attr_setschedpolicy(&rtattr, SCHED_FIFO));
+       check_pthread(pthread_attr_setschedparam(&rtattr, &rtparam));
+
+       check_pthread(pthread_create(&rt, &rtattr,
+                                    &realtime_thread, (void *)1UL));
+       check_pthread(pthread_attr_destroy(&rtattr));
+
+       check_unix(sigsuspend(&oldmask));
+
+       return 0;
+}
diff --git a/src/testsuite/regression/xeno-regression-test.in 
b/src/testsuite/regression/xeno-regression-test.in
index 738d661..6fa81f0 100644
--- a/src/testsuite/regression/xeno-regression-test.in
+++ b/src/testsuite/regression/xeno-regression-test.in
@@ -48,6 +48,7 @@ echo 0 > /proc/xenomai/latency || :
 @testdir@/regression/posix/mprotect
 @testdir@/regression/posix/nano_test
 @testdir@/regression/posix/shm
+@testdir@/regression/posix/xddp_test
 @testdir@/regression/native/heap
 @testdir@/regression/native/leaks
 @testdir@/regression/native/sigdebug


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to