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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Nov 13 18:37:41 2011 +0100

alchemy/testsuite: introduce mutex test

---

 lib/alchemy/testsuite/Makefile  |    3 +-
 lib/alchemy/testsuite/mutex-1.c |  151 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 1 deletions(-)

diff --git a/lib/alchemy/testsuite/Makefile b/lib/alchemy/testsuite/Makefile
index d9f1f38..03c0823 100644
--- a/lib/alchemy/testsuite/Makefile
+++ b/lib/alchemy/testsuite/Makefile
@@ -23,8 +23,9 @@ TESTS :=      \
        mq-2    \
        mq-3    \
        alarm-1 \
+       sem-1   \
        sem-2   \
-       sem-1
+       mutex-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/mutex-1.c b/lib/alchemy/testsuite/mutex-1.c
new file mode 100644
index 0000000..17f111e
--- /dev/null
+++ b/lib/alchemy/testsuite/mutex-1.c
@@ -0,0 +1,151 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <copperplate/init.h>
+#include <copperplate/traceobj.h>
+#include <alchemy/task.h>
+#include <alchemy/mutex.h>
+
+static struct traceobj trobj;
+
+static int tseq[] = {
+       6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+       18, 1, 2, 3, 19, 4, 5, 16, 6, 17
+};
+
+static RT_TASK t_a, t_b;
+
+static RT_MUTEX mutex;
+
+static void task_a(void *arg)
+{
+       RT_TASK t;
+       int ret;
+
+       traceobj_enter(&trobj);
+
+       traceobj_mark(&trobj, 1);
+
+       ret = rt_task_bind(&t, "taskB", TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0 && rt_task_same(&t, &t_b));
+
+       traceobj_mark(&trobj, 2);
+
+       ret = rt_mutex_acquire(&mutex, TM_NONBLOCK);
+       traceobj_assert(&trobj, ret == -EWOULDBLOCK);
+
+       traceobj_mark(&trobj, 3);
+
+       ret = rt_mutex_acquire(&mutex, 100000000);
+       traceobj_assert(&trobj, ret == -ETIMEDOUT);
+
+       traceobj_mark(&trobj, 4);
+
+       ret = rt_task_resume(&t);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 5);
+
+       ret = rt_mutex_acquire(&mutex, TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 6);
+
+       traceobj_exit(&trobj);
+}
+
+static void task_b(void *arg)
+{
+       int ret;
+
+       traceobj_enter(&trobj);
+
+       traceobj_mark(&trobj, 6);
+
+       ret = rt_task_set_priority(NULL, 19);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 7);
+
+       ret = rt_mutex_create(&mutex, "MUTEX");
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 8);
+
+       ret = rt_mutex_create(&mutex, "MUTEX");
+       traceobj_assert(&trobj, ret == -EEXIST);
+
+       traceobj_mark(&trobj, 9);
+
+       ret = rt_mutex_acquire(&mutex, TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 10);
+
+       ret = rt_mutex_acquire(&mutex, TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 11);
+
+       ret = rt_mutex_release(&mutex);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 12);
+
+       ret = rt_mutex_release(&mutex);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 13);
+
+       ret = rt_mutex_release(&mutex);
+       traceobj_assert(&trobj, ret == -EPERM);
+
+       traceobj_mark(&trobj, 14);
+
+       ret = rt_mutex_acquire(&mutex, TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 15);
+
+       ret = rt_task_suspend(rt_task_self());
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 16);
+
+       ret = rt_mutex_release(&mutex);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 17);
+
+       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_b, "taskB", 0, 21, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_b, task_b, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 18);
+
+       ret = rt_task_create(&t_a, "taskA", 0, 20, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_a, task_a, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 19);
+
+       traceobj_join(&trobj);
+
+       traceobj_verify(&trobj, tseq, sizeof(tseq) / sizeof(int));
+
+       exit(0);
+}


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

Reply via email to