Module: xenomai-3
Branch: wip/handover
Commit: 92644e7468953c3a034657ae6ec35ac2732cfd43
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=92644e7468953c3a034657ae6ec35ac2732cfd43

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Jul  8 10:03:19 2016 +0200

smokey/rtdm: test mode switch handover

---

 testsuite/smokey/rtdm/rtdm.c |   99 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)

diff --git a/testsuite/smokey/rtdm/rtdm.c b/testsuite/smokey/rtdm/rtdm.c
index 2c035c0..643bc4f 100644
--- a/testsuite/smokey/rtdm/rtdm.c
+++ b/testsuite/smokey/rtdm/rtdm.c
@@ -73,6 +73,102 @@ static void check_sleep_inner(const char *fn, int line,
 static const char *devname = "/dev/rtdm/rtdm0";
 static const char *devname2 = "/dev/rtdm/rtdm1";
 
+static int do_handover(int fd)
+{
+       struct sched_param param;
+       int ret, magic = 0;
+
+       if (!__F(ret, ioctl(fd, RTTST_RTIOC_RTDM_PING_PRIMARY, &magic)))
+               return ret;
+
+       smokey_trace("PING_PRIMARY over regular => ret=%d, errno=%d",
+                    ret, errno);
+
+       if (!__Tassert(magic == 0))
+               return -EINVAL;
+
+       if (!__F(ret, ioctl(fd, RTTST_RTIOC_RTDM_PING_SECONDARY, &magic)))
+               return ret;
+
+       smokey_trace("PING_SECONDARY over regular => ret=%d, errno=%d",
+                    ret, errno);
+
+       if (!__Tassert(magic == 0))
+               return -EINVAL;
+
+       /* Switch to Cobalt's SCHED_FIFO[1] */
+       
+       param.sched_priority = 1;
+       if (!__T(ret, pthread_setschedparam(pthread_self(),
+                                           SCHED_FIFO, &param)))
+               return ret;
+       
+       if (!__T(ret, ioctl(fd, RTTST_RTIOC_RTDM_PING_PRIMARY, &magic)))
+               return ret;
+
+       if (!__Tassert(magic == RTTST_RTDM_MAGIC_PRIMARY))
+               return -EINVAL;
+
+       if (!__T(ret, ioctl(fd, RTTST_RTIOC_RTDM_PING_SECONDARY, &magic)))
+               return ret;
+
+       if (!__Tassert(magic == RTTST_RTDM_MAGIC_SECONDARY))
+               return -EINVAL;
+
+       /* Switch to Cobalt's SCHED_WEAK[1] */
+       
+       param.sched_priority = 1;
+       if (!__T(ret, pthread_setschedparam(pthread_self(),
+                                           SCHED_WEAK, &param)))
+               return ret;
+       
+       if (!__T(ret, ioctl(fd, RTTST_RTIOC_RTDM_PING_PRIMARY, &magic)))
+               return ret;
+
+       if (!__Tassert(magic == RTTST_RTDM_MAGIC_PRIMARY))
+               return -EINVAL;
+
+       if (!__T(ret, ioctl(fd, RTTST_RTIOC_RTDM_PING_SECONDARY, &magic)))
+               return ret;
+
+       if (!__Tassert(magic == RTTST_RTDM_MAGIC_SECONDARY))
+               return -EINVAL;
+
+       return 0;
+}
+
+static void *__test_handover(void *arg)
+{
+       int fd = *(int *)arg;
+
+       return (void *)(long)do_handover(fd);
+}
+
+static int test_handover(int fd)
+{
+       struct sched_param param;
+       pthread_attr_t attr;
+       pthread_t tid;
+       void *p;
+       int ret;
+
+       pthread_attr_init(&attr);
+       param.sched_priority = 0;
+       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+       pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
+       pthread_attr_setschedparam(&attr, &param);
+       pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+
+       if (!__T(ret, __STD(pthread_create(&tid, &attr,
+                          __test_handover, &fd))))
+               return ret;
+
+       if (!__T(ret, pthread_join(tid, &p)))
+               return ret;
+
+       return (int)(long)p;
+}
+
 static int run_rtdm(struct smokey_test *t, int argc, char *const argv[])
 {
        unsigned long long start;
@@ -95,6 +191,9 @@ static int run_rtdm(struct smokey_test *t, int argc, char 
*const argv[])
        dev2 = check("open", open(devname2, O_RDWR), dev + 1);
        check("close", close(dev2), 0);
 
+       smokey_trace("Handover mode");
+       check("handover", test_handover(dev), 0);
+
        smokey_trace("Defer close by pending reference");
        check("ioctl", ioctl(dev, RTTST_RTIOC_RTDM_DEFER_CLOSE,
                             RTTST_RTDM_DEFER_CLOSE_CONTEXT), 0);


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

Reply via email to