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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Nov  5 18:59:32 2011 +0100

alchemy/testsuite: introduce unit tests

---

 lib/alchemy/testsuite/Makefile |   38 ++++++++++++++
 lib/alchemy/testsuite/task-1.c |   35 +++++++++++++
 lib/alchemy/testsuite/task-2.c |  109 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 182 insertions(+), 0 deletions(-)

diff --git a/lib/alchemy/testsuite/Makefile b/lib/alchemy/testsuite/Makefile
new file mode 100644
index 0000000..6880619
--- /dev/null
+++ b/lib/alchemy/testsuite/Makefile
@@ -0,0 +1,38 @@
+ifeq ($(DESTDIR),)
+XENO_CONFIG=xeno-config
+else
+XENO_CONFIG=$(DESTDIR)/bin/xeno-config
+endif
+
+prefix := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --prefix)
+solibs := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --libdir)
+
+ifeq ($(prefix),)
+$(error Please add <xenomai-install-path>/bin to your PATH variable or specify 
DESTDIR)
+endif
+
+TESTS :=       \
+       task-1  \
+       task-2
+
+CFLAGS := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --skin=alchemy --cflags) -g
+LDFLAGS := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --skin=alchemy --ldflags)
+CC = $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --cc)
+
+all: $(TESTS)
+
+%: %.c
+       $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)
+
+clean:
+       $(RM) $(TESTS) *~
+
+# Run the test suite. We pin all tests to CPU #0, so that SMP does not
+# alter the execution sequence we expect from them.
+test: all
+       @for t in $(TESTS); do \
+               echo -n $$t...; \
+               sudo LD_LIBRARY_PATH=$(solibs) ./$$t --cpu-affinity=0 && echo 
ok || echo BAD; \
+       done
+
+.PHONY: clean test
diff --git a/lib/alchemy/testsuite/task-1.c b/lib/alchemy/testsuite/task-1.c
new file mode 100644
index 0000000..3225cf9
--- /dev/null
+++ b/lib/alchemy/testsuite/task-1.c
@@ -0,0 +1,35 @@
+#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_main;
+
+static void main_task(void *arg)
+{
+       traceobj_enter(&trobj);
+       traceobj_assert(&trobj, arg == (void *)(long)0xdeadbeef);
+       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_main, "main", 0, 99, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_main, main_task, (void *)(long)0xdeadbeef);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_join(&trobj);
+
+       exit(0);
+}
diff --git a/lib/alchemy/testsuite/task-2.c b/lib/alchemy/testsuite/task-2.c
new file mode 100644
index 0000000..bb65c64
--- /dev/null
+++ b/lib/alchemy/testsuite/task-2.c
@@ -0,0 +1,109 @@
+#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[] = {
+       8, 1, 9, 4, 10, 5, 11, 2, 6, 7, 12
+};
+
+static RT_TASK t_bgnd, t_fgnd;
+
+static RT_SEM sem;
+
+static void background_task(void *arg)
+{
+       unsigned int safety = 100000000, count = 0;
+       int ret;
+
+       traceobj_enter(&trobj);
+
+       traceobj_mark(&trobj, 1);
+
+       ret = rt_sem_p(&sem, TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 2);
+
+       while (--safety > 0)
+               count++;
+
+       traceobj_mark(&trobj, 3);
+
+       traceobj_exit(&trobj);
+}
+
+static void foreground_task(void *arg)
+{
+       int ret;
+
+       traceobj_enter(&trobj);
+
+       traceobj_mark(&trobj, 4);
+
+       ret = rt_sem_p(&sem, TM_INFINITE);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 5);
+
+       rt_task_sleep(20000000);
+
+       traceobj_mark(&trobj, 6);
+
+       ret = rt_task_delete(&t_bgnd);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 7);
+
+       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_sem_create(&sem, "SEMA", 0, S_PRIO);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 8);
+
+       ret = rt_task_create(&t_bgnd, "BGND", 0,  20, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_bgnd, background_task, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 9);
+
+       ret = rt_task_create(&t_fgnd, "FGND", 0,  21, 0);
+       traceobj_assert(&trobj, ret == 0);
+
+       ret = rt_task_start(&t_fgnd, foreground_task, NULL);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 10);
+
+       ret = rt_sem_v(&sem);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 11);
+
+       ret = rt_sem_v(&sem);
+       traceobj_assert(&trobj, ret == 0);
+
+       traceobj_mark(&trobj, 12);
+
+       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