Module: xenomai-3
Branch: wip/drivers
Commit: 7d55b32cc287dbf47fca5f1eeeb5e70690c83915
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7d55b32cc287dbf47fca5f1eeeb5e70690c83915

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Jul 10 10:07:24 2016 +0200

testsuite/smokey: rtdm: add handover test

---

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

diff --git a/testsuite/smokey/rtdm/rtdm.c b/testsuite/smokey/rtdm/rtdm.c
index 2c035c0..c41daa7 100644
--- a/testsuite/smokey/rtdm/rtdm.c
+++ b/testsuite/smokey/rtdm/rtdm.c
@@ -73,6 +73,97 @@ 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)) ||
+           errno != ENOTTY)
+               return ret ? -ENOTTY : -EINVAL;
+
+       if (!__Tassert(magic == 0))
+               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_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[0] */
+       
+       param.sched_priority = 0;
+       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 +186,11 @@ 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");
+       status = test_handover(dev);
+       if (status)
+               return status;
+
        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