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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu May 31 16:44:46 2012 +0200

alchemy: introduce test for rt_task_slice()

---

 lib/alchemy/testsuite/Makefile |    3 +-
 lib/alchemy/testsuite/task-8.c |   69 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/lib/alchemy/testsuite/Makefile b/lib/alchemy/testsuite/Makefile
index ef08a45..a24cdeb 100644
--- a/lib/alchemy/testsuite/Makefile
+++ b/lib/alchemy/testsuite/Makefile
@@ -19,6 +19,7 @@ TESTS :=      \
        task-5  \
        task-6  \
        task-7  \
+       task-8  \
        mq-1    \
        mq-2    \
        mq-3    \
@@ -28,7 +29,7 @@ TESTS :=      \
        mutex-1 \
        event-1 \
        heap-1  \
-       buffer-1 \
+       buffer-1
 
 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/task-8.c b/lib/alchemy/testsuite/task-8.c
new file mode 100644
index 0000000..4e0360e
--- /dev/null
+++ b/lib/alchemy/testsuite/task-8.c
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <copperplate/init.h>
+#include <copperplate/traceobj.h>
+#include <alchemy/task.h>
+#include <alchemy/sem.h>
+
+static struct traceobj trobj;
+
+static RT_TASK t_rr1, t_rr2;
+
+static RT_SEM sem;
+
+#define RR_QUANTUM  500000ULL
+
+double d = 0.7;
+
+double f = 1.7;
+
+static void rr_task(void *arg)
+{
+       int ret, n;
+
+       traceobj_enter(&trobj);
+
+       ret = rt_task_slice(NULL, RR_QUANTUM);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_sem_p(&sem, TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       for (n = 0; n < 1000000; n++) {
+               d *= 0.99;
+               f = d / 16;
+       }
+
+       traceobj_exit(&trobj);
+}
+
+int main(int argc, char *const argv[])
+{
+       int ret;
+
+       copperplate_init(&argc, &argv);
+
+       traceobj_init(&trobj, argv[0], 0);
+
+       ret = rt_sem_create(&sem, "SEMA", 0, S_FIFO);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_create(&t_rr1, "rr_task_1", 0, 10, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_rr1, rr_task, "t1");
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_create(&t_rr2, "rr_task_2", 0, 10, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_rr2, rr_task, "t2");
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_sem_broadcast(&sem);
+       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