Module: xenomai-3
Branch: next
Commit: f0bd2f6242890800b2ca1441f0daeeb6ce21ef7f
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=f0bd2f6242890800b2ca1441f0daeeb6ce21ef7f

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Oct 30 14:34:15 2014 +0100

alchemy/testsuite: test pipe basics

---

 lib/alchemy/testsuite/Makefile |   48 ++++++++++--------
 lib/alchemy/testsuite/pipe-1.c |  105 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+), 21 deletions(-)

diff --git a/lib/alchemy/testsuite/Makefile b/lib/alchemy/testsuite/Makefile
index 1014741..e3804a0 100644
--- a/lib/alchemy/testsuite/Makefile
+++ b/lib/alchemy/testsuite/Makefile
@@ -6,32 +6,38 @@ endif
 
 prefix := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --prefix)
 solibs := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --libdir)
+core := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --core)
 
 ifeq ($(prefix),)
 $(error Please add <xenomai-install-path>/bin to your PATH variable or specify 
DESTDIR)
 endif
 
-TESTS :=       \
-       task-1  \
-       task-2  \
-       task-3  \
-       task-4  \
-       task-5  \
-       task-6  \
-       task-7  \
-       task-8  \
-       task-9  \
-       task-10 \
-       mq-1    \
-       mq-2    \
-       mq-3    \
-       alarm-1 \
-       sem-1   \
-       sem-2   \
-       mutex-1 \
-       event-1 \
-       heap-1  \
-       buffer-1
+cobalt-only := pipe-1
+mercury-only :=
+core-specific = $($(core)-only)
+
+TESTS :=               \
+       task-1          \
+       task-2          \
+       task-3          \
+       task-4          \
+       task-5          \
+       task-6          \
+       task-7          \
+       task-8          \
+       task-9          \
+       task-10         \
+       mq-1            \
+       mq-2            \
+       mq-3            \
+       alarm-1         \
+       sem-1           \
+       sem-2           \
+       mutex-1         \
+       event-1         \
+       heap-1          \
+       buffer-1        \
+       $(core-specific)
 
 CFLAGS := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --skin=alchemy --cflags) -g
 LDFLAGS := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --skin=alchemy --ldflags)
diff --git a/lib/alchemy/testsuite/pipe-1.c b/lib/alchemy/testsuite/pipe-1.c
new file mode 100644
index 0000000..99cf1fa
--- /dev/null
+++ b/lib/alchemy/testsuite/pipe-1.c
@@ -0,0 +1,105 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <copperplate/traceobj.h>
+#include <alchemy/task.h>
+#include <alchemy/pipe.h>
+
+static struct traceobj trobj;
+
+static RT_TASK t_real;
+
+static RT_PIPE pipe;
+
+static pthread_t t_reg;
+
+static int minor;
+
+struct pipe_message {
+       int value;
+};
+
+static void realtime_task(void *arg)
+{
+       struct pipe_message m;
+       int ret, seq;
+
+       traceobj_enter(&trobj);
+
+       ret = rt_pipe_bind(&pipe, "pipe", TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       while (seq < 8192) {
+               ret = rt_pipe_read(&pipe, &m, sizeof(m), TM_INFINITE);
+               traceobj_assert(&trobj, ret == sizeof(m));
+               traceobj_assert(&trobj, m.value == seq);
+               ret = rt_pipe_write(&pipe, &m, sizeof(m),
+                                   (seq & 1) ? P_URGENT : P_NORMAL);
+               traceobj_assert(&trobj, ret == sizeof(m));
+               seq++;
+       }
+
+       pthread_cancel(t_reg);
+
+       traceobj_exit(&trobj);
+}
+
+static void *regular_thread(void *arg)
+{
+       struct pipe_message m;
+       int fd, seq = 0;
+       ssize_t ret;
+       char *rtp;
+
+       asprintf(&rtp, "/dev/rtp%d", minor);
+
+       fd = open(rtp, O_RDWR);
+       free(rtp);
+       traceobj_assert(&trobj, fd >= 0);
+
+       for (;;) {
+               m.value = seq;
+               ret = write(fd, &m, sizeof(m));
+               traceobj_assert(&trobj, ret == sizeof(m));
+               ret = read(fd, &m, sizeof(m));
+               traceobj_assert(&trobj, ret == sizeof(m));
+               traceobj_assert(&trobj, m.value == seq);
+               seq++;
+       }
+
+       return NULL;
+}
+
+int main(int argc, char *const argv[])
+{
+       struct pipe_message m;
+       int ret;
+
+       traceobj_init(&trobj, argv[0], 0);
+
+       ret = rt_pipe_create(&pipe, "pipe", P_MINOR_AUTO, 0);
+       traceobj_assert(&trobj, ret >= 0);
+
+       ret = rt_pipe_delete(&pipe);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_create(&t_real, "realtime", 0,  10, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_real, realtime_task, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_pipe_create(&pipe, "pipe", P_MINOR_AUTO, 16384);
+       traceobj_assert(&trobj, ret >= 0);
+       minor = ret;
+
+       ret = rt_pipe_read(&pipe, &m, sizeof(m), TM_NONBLOCK);
+       traceobj_assert(&trobj, ret == -EWOULDBLOCK);
+
+       ret = pthread_create(&t_reg, NULL, regular_thread, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_join(&trobj);
+
+       exit(0);
+}


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

Reply via email to