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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Nov 13 16:35:35 2011 +0100

alchemy: add more tests

---

 lib/alchemy/testsuite/Makefile  |    6 +-
 lib/alchemy/testsuite/alarm-1.c |   93 +++++++++++++++++++++++
 lib/alchemy/testsuite/sem-1.c   |  154 +++++++++++++++++++++++++++++++++++++++
 lib/alchemy/testsuite/sem-2.c   |   69 +++++++++++++++++
 lib/alchemy/testsuite/task-7.c  |  119 ++++++++++++++++++++++++++++++
 5 files changed, 440 insertions(+), 1 deletions(-)

diff --git a/lib/alchemy/testsuite/Makefile b/lib/alchemy/testsuite/Makefile
index 3048581..d9f1f38 100644
--- a/lib/alchemy/testsuite/Makefile
+++ b/lib/alchemy/testsuite/Makefile
@@ -18,9 +18,13 @@ TESTS :=     \
        task-4  \
        task-5  \
        task-6  \
+       task-7  \
        mq-1    \
        mq-2    \
-       mq-3
+       mq-3    \
+       alarm-1 \
+       sem-2   \
+       sem-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/alarm-1.c b/lib/alchemy/testsuite/alarm-1.c
new file mode 100644
index 0000000..22ea19d
--- /dev/null
+++ b/lib/alchemy/testsuite/alarm-1.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <copperplate/init.h>
+#include <copperplate/traceobj.h>
+#include <alchemy/task.h>
+#include <alchemy/alarm.h>
+
+static struct traceobj trobj;
+
+static int tseq[] = {
+       5, 6, 8,
+       1, 4, 1, 4, 1,
+       2, 3, 7
+};
+
+static RT_TASK t_main;
+
+static RT_ALARM alrm;
+
+static void alarm_handler(void *arg)
+{
+       static int hits;
+       int ret;
+
+       traceobj_assert(&trobj, arg == &alrm);
+
+       traceobj_mark(&trobj, 1);
+
+       if (++hits >= 3) {
+               ret = rt_alarm_stop(&alrm);
+               traceobj_assert(&trobj, ret == 0);
+               traceobj_mark(&trobj, 2);
+               ret = rt_task_resume(&t_main);
+               traceobj_assert(&trobj, ret == 0);
+               traceobj_mark(&trobj, 3);
+               return;
+       }
+
+       traceobj_mark(&trobj, 4);
+       ret = rt_alarm_start(&alrm, 200000000, 200000000);
+       traceobj_assert(&trobj, ret == 0);
+}
+
+static void main_task(void *arg)
+{
+       RT_TASK *p;
+       int ret;
+
+       traceobj_enter(&trobj);
+
+       p = rt_task_self();
+       traceobj_assert(&trobj, p != NULL && rt_task_same(p, &t_main));
+
+       traceobj_mark(&trobj, 5);
+
+       ret = rt_alarm_create(&alrm, "ALARM", alarm_handler, &alrm);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_alarm_start(&alrm, 200000000, 200000000);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 6);
+
+       ret = rt_task_suspend(&t_main);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 7);
+
+       ret = rt_alarm_delete(&alrm);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_exit(&trobj);
+}
+
+int main(int argc, char *argv[])
+{
+       int ret;
+
+       copperplate_init(argc, argv);
+
+       traceobj_init(&trobj, argv[0], sizeof(tseq) / sizeof(int));
+
+       ret = rt_task_spawn(&t_main, "main_task", 0,  50, 0, main_task, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 8);
+
+       traceobj_join(&trobj);
+
+       traceobj_verify(&trobj, tseq, sizeof(tseq) / sizeof(int));
+
+       exit(0);
+}
diff --git a/lib/alchemy/testsuite/sem-1.c b/lib/alchemy/testsuite/sem-1.c
new file mode 100644
index 0000000..8155652
--- /dev/null
+++ b/lib/alchemy/testsuite/sem-1.c
@@ -0,0 +1,154 @@
+#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 int tseq[] = {
+       10, 13,
+       1, 14, 15, 2, 3, 4,
+       5, 6, 7, 8, 16, 17, 18,
+       9, 19
+};
+
+static RT_TASK t_a, t_b;
+
+static RT_SEM sem;
+
+static void task_a(void *arg)
+{
+       int ret, oldmode;
+       RT_TASK t;
+
+       traceobj_enter(&trobj);
+
+       traceobj_mark(&trobj, 1);
+
+       ret = rt_sem_v(&sem);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 2);
+
+       ret = rt_sem_p(&sem, TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 3);
+
+       ret = rt_task_set_mode(T_LOCK, T_LOCK, &oldmode);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 4);
+
+       ret = rt_task_bind(&t, "taskB", TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0 && rt_task_same(&t, &t_b));
+
+       traceobj_mark(&trobj, 5);
+
+       ret = rt_task_resume(&t);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 6);
+
+       ret = rt_sem_v(&sem);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 7);
+
+       ret = rt_sem_v(&sem);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 8);
+
+       ret = rt_task_set_mode(T_LOCK, 0, &oldmode);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 9);
+
+       ret = rt_task_suspend(NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_exit(&trobj);
+}
+
+static void task_b(void *arg)
+{
+       RT_TASK t;
+       int ret;
+
+       traceobj_enter(&trobj);
+
+       traceobj_mark(&trobj, 10);
+
+       ret = rt_sem_create(&sem, "SEMA", 0, S_FIFO);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 13);
+
+       ret = rt_sem_p(&sem, TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_bind(&t, "taskA", TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0 && rt_task_same(&t, &t_a));
+
+       traceobj_mark(&trobj, 14);
+
+       ret = rt_sem_v(&sem);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 15);
+
+       ret = rt_task_suspend(NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 16);
+
+       ret = rt_sem_p(&sem, 10000000);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 17);
+
+       ret = rt_sem_p(&sem, TM_NONBLOCK);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 18);
+
+       ret = rt_sem_p(&sem, 100000000);
+       traceobj_assert(&trobj, ret == -ETIMEDOUT);
+
+       traceobj_mark(&trobj, 19);
+
+       ret = rt_task_resume(&t);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_exit(&trobj);
+}
+
+int main(int argc, char *argv[])
+{
+       int ret;
+
+       copperplate_init(argc, argv);
+
+       traceobj_init(&trobj, argv[0], sizeof(tseq) / sizeof(int));
+
+       ret = rt_task_create(&t_a, "taskA", 0, 20, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_create(&t_b, "taskB", 0, 21, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_b, task_b, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_a, task_a, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_join(&trobj);
+
+       traceobj_verify(&trobj, tseq, sizeof(tseq) / sizeof(int));
+
+       exit(0);
+}
diff --git a/lib/alchemy/testsuite/sem-2.c b/lib/alchemy/testsuite/sem-2.c
new file mode 100644
index 0000000..ae52e58
--- /dev/null
+++ b/lib/alchemy/testsuite/sem-2.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 int tseq[] = {
+       1, 2, 3, 5, 4, 6
+};
+
+static RT_TASK t_main;
+
+static RT_SEM sem;
+
+static void main_task(void *arg)
+{
+       int ret;
+
+       traceobj_enter(&trobj);
+
+       traceobj_mark(&trobj, 1);
+
+       ret = rt_sem_create(&sem, "SEMA", 1, S_FIFO);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 2);
+
+       ret = rt_sem_p(&sem, TM_NONBLOCK);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 3);
+
+       ret = rt_sem_p(&sem, TM_INFINITE);
+       traceobj_assert(&trobj, ret == -EIDRM || ret == -EINVAL);
+
+       traceobj_mark(&trobj, 4);
+
+       traceobj_exit(&trobj);
+}
+
+int main(int argc, char *argv[])
+{
+       int ret;
+
+       copperplate_init(argc, argv);
+
+       traceobj_init(&trobj, argv[0], sizeof(tseq) / sizeof(int));
+
+       ret = rt_task_create(&t_main, "main_task", 0, 20, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_main, main_task, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 5);
+
+       ret = rt_sem_delete(&sem);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 6);
+
+       traceobj_join(&trobj);
+
+       traceobj_verify(&trobj, tseq, sizeof(tseq) / sizeof(int));
+
+       exit(0);
+}
diff --git a/lib/alchemy/testsuite/task-7.c b/lib/alchemy/testsuite/task-7.c
new file mode 100644
index 0000000..f71e089
--- /dev/null
+++ b/lib/alchemy/testsuite/task-7.c
@@ -0,0 +1,119 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <copperplate/init.h>
+#include <copperplate/traceobj.h>
+#include <alchemy/task.h>
+
+static struct traceobj trobj;
+
+static RT_TASK t_bgnd, t_fgnda, t_fgndb;
+
+static void background_task(void *arg)
+{
+       int msg, ret, flowid, n;
+       RT_TASK_MCB mcb;
+
+       traceobj_enter(&trobj);
+
+       ret = rt_task_reply(-1, &mcb);
+       traceobj_assert(&trobj, ret == -EINVAL);
+
+       ret = rt_task_reply(999, &mcb);
+       traceobj_assert(&trobj, ret == -ENXIO);
+
+       for (n = 0; n < 20; n++) {
+               mcb.data = &msg;
+               mcb.size = sizeof(msg);
+               flowid = rt_task_receive(&mcb, TM_NONBLOCK);
+               traceobj_assert(&trobj, flowid > 0);
+               traceobj_assert(&trobj, mcb.size == sizeof(msg));
+               switch (mcb.opcode) {
+               case 0x77:
+                       msg = ~msg;
+                       ret = rt_task_reply(flowid, &mcb);
+                       traceobj_assert(&trobj, ret == 0);
+                       break;
+               case 0x78:
+                       ret = rt_task_reply(flowid, &mcb);
+                       traceobj_assert(&trobj, ret == -ENOBUFS);
+                       break;
+               default:
+                       traceobj_assert(&trobj, 0);
+               }
+       }
+
+       traceobj_exit(&trobj);
+}
+
+static void foreground_task_a(void *arg)
+{
+       RT_TASK_MCB mcb, mcb_r;
+       int ret, msg, notmsg;
+
+       traceobj_enter(&trobj);
+
+       for (msg = 0; msg < 10; msg++) {
+               mcb.opcode = 0x77;
+               mcb.data = &msg;
+               mcb.size = sizeof(msg);
+               mcb_r.data = &notmsg;
+               mcb_r.size = sizeof(notmsg);
+               notmsg = msg;
+               ret = rt_task_send(&t_bgnd, &mcb, &mcb_r, TM_INFINITE);
+               traceobj_assert(&trobj, ret == sizeof(msg));
+               traceobj_assert(&trobj, notmsg == ~msg);
+       }
+
+       traceobj_exit(&trobj);
+}
+
+static void foreground_task_b(void *arg)
+{
+       RT_TASK_MCB mcb, mcb_r;
+       int ret, msg;
+
+       traceobj_enter(&trobj);
+
+       for (msg = 0; msg < 10; msg++) {
+               mcb.opcode = 0x78;
+               mcb.data = &msg;
+               mcb.size = sizeof(msg);
+               mcb_r.data = NULL;
+               mcb_r.size = 0;
+               ret = rt_task_send(&t_bgnd, &mcb, &mcb_r, TM_INFINITE);
+               traceobj_assert(&trobj, ret == -ENOBUFS);
+       }
+
+       traceobj_exit(&trobj);
+}
+
+int main(int argc, char *argv[])
+{
+       int ret;
+
+       copperplate_init(argc, argv);
+
+       traceobj_init(&trobj, argv[0], 0);
+
+       ret = rt_task_create(&t_bgnd, "BGND", 0,  20, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_create(&t_fgnda, "FGND-A", 0,  21, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_fgnda, foreground_task_a, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_create(&t_fgndb, "FGND-B", 0,  21, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_fgndb, foreground_task_b, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_bgnd, background_task, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_join(&trobj);
+
+       exit(0);
+}


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

Reply via email to