[Xenomai-git] Jan Kiszka : Add sigdebug unit test

2012-01-27 Thread GIT version control
Module: xenomai-jki
Branch: for-upstream
Commit: 8379db1cce25db428ebd2e2b46bdeafd2260c29a
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=8379db1cce25db428ebd2e2b46bdeafd2260c29a

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Wed Jan 25 14:58:52 2012 +0100

Add sigdebug unit test

We had two regressions in this code recently. So test all 6 possible
SIGDEBUG reasons, or 5 if the watchdog is not available.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 src/testsuite/regression/native/Makefile.am |2 +-
 src/testsuite/regression/native/sigdebug.c  |  264 +++
 2 files changed, 265 insertions(+), 1 deletions(-)

diff --git a/src/testsuite/regression/native/Makefile.am 
b/src/testsuite/regression/native/Makefile.am
index 8f19c11..e9ca148 100644
--- a/src/testsuite/regression/native/Makefile.am
+++ b/src/testsuite/regression/native/Makefile.am
@@ -2,7 +2,7 @@ tstdir = $(pkgdatadir)/regression/native
 
 noinst_HEADERS = check.h
 
-tst_PROGRAMS = leaks tsc mayday heap
+tst_PROGRAMS = leaks tsc mayday heap sigdebug
 
 CPPFLAGS = $(XENO_USER_CFLAGS) \
-I$(top_srcdir)/include
diff --git a/src/testsuite/regression/native/sigdebug.c 
b/src/testsuite/regression/native/sigdebug.c
new file mode 100644
index 000..786501f
--- /dev/null
+++ b/src/testsuite/regression/native/sigdebug.c
@@ -0,0 +1,264 @@
+/*
+ * Functional testing of unwanted domain switch debugging mechanism.
+ *
+ * Copyright (C) Jan Kiszka  jan.kis...@siemens.com
+ *
+ * Released under the terms of GPLv2.
+ */
+
+#include unistd.h
+#include stdlib.h
+#include stdio.h
+#include stdbool.h
+#include string.h
+#include signal.h
+#include fcntl.h
+#include sys/mman.h
+#include pthread.h
+#include rtdk.h
+#include native/task.h
+#include native/mutex.h
+#include native/sem.h
+#include native/timer.h
+
+#define WRITE_TEST_SIZE(4*1024)
+
+unsigned int expected_reason;
+bool sigdebug_received;
+pthread_t rt_task_thread;
+RT_MUTEX prio_invert;
+RT_SEM send_signal;
+char *mem;
+FILE *wd;
+
+static void setup_checkdebug(unsigned int reason)
+{
+   sigdebug_received = false;
+   expected_reason = reason;
+}
+
+static void check_inner(const char *fn, int line, const char *msg,
+   int status, int expected)
+{
+   if (status == expected)
+   return;
+
+   rt_task_set_mode(T_WARNSW, 0, NULL);
+   rt_print_flush_buffers();
+   fprintf(stderr, FAILURE %s:%d: %s returned %d instead of %d - %s\n,
+   fn, line, msg, status, expected, strerror(-status));
+   exit(EXIT_FAILURE);
+}
+
+static void check_sigdebug_inner(const char *fn, int line, const char *reason)
+{
+   if (sigdebug_received)
+   return;
+
+   rt_task_set_mode(T_WARNSW, 0, NULL);
+   rt_print_flush_buffers();
+   fprintf(stderr, FAILURE %s:%d: no %s received\n, fn, line, reason);
+   exit(EXIT_FAILURE);
+}
+
+#define check(msg, status, expected) ({
\
+   int __status = status;  \
+   check_inner(__FUNCTION__, __LINE__, msg, __status, expected);   \
+   __status;   \
+})
+
+#define check_no_error(msg, status) ({ \
+   int __status = status;  \
+   check_inner(__FUNCTION__, __LINE__, msg,\
+   __status  0 ? __status : 0, 0);\
+   __status;   \
+})
+
+#define check_sigdebug_received(reason) do {   \
+   const char *__reason = reason;  \
+   check_sigdebug_inner(__FUNCTION__, __LINE__, __reason); \
+} while (0)
+
+void rt_task_body(void *cookie)
+{
+   RTIME end;
+   int err;
+
+   rt_task_thread = pthread_self();
+
+   rt_printf(syscall\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_SYSCALL);
+   syscall(-1);
+   check_sigdebug_received(SIGDEBUG_MIGRATE_SYSCALL);
+
+   rt_printf(signal\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_SIGNAL);
+   err = rt_sem_v(send_signal);
+   check_no_error(rt_sem_v, err);
+   rt_task_sleep(1000LL);
+   check_sigdebug_received(SIGDEBUG_MIGRATE_SIGNAL);
+
+   rt_printf(relaxed mutex owner\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_PRIOINV);
+   err = rt_mutex_acquire(prio_invert, TM_INFINITE);
+   check(rt_mutex_acquire, err, -EINTR);
+   check_sigdebug_received(SIGDEBUG_MIGRATE_PRIOINV);
+
+
+   rt_printf(page fault\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_FAULT);
+   rt_task_sleep(0);
+   *mem ^= 0xFF;
+   check_sigdebug_received(SIGDEBUG_MIGRATE_FAULT);
+
+   if (wd) {
+   rt_printf(watchdog\n);
+   rt_print_flush_buffers();
+   setup_checkdebug(SIGDEBUG_WATCHDOG);
+

[Xenomai-git] Jan Kiszka : Add sigdebug unit test

2012-01-27 Thread GIT version control
Module: xenomai-2.6
Branch: master
Commit: e710958719746c96756be09fd260547f2bdd36d2
URL:
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=e710958719746c96756be09fd260547f2bdd36d2

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Wed Jan 25 14:58:52 2012 +0100

Add sigdebug unit test

We had two regressions in this code recently. So test all 6 possible
SIGDEBUG reasons, or 5 if the watchdog is not available.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 src/testsuite/regression/native/Makefile.am |2 +-
 src/testsuite/regression/native/sigdebug.c  |  264 +++
 2 files changed, 265 insertions(+), 1 deletions(-)

diff --git a/src/testsuite/regression/native/Makefile.am 
b/src/testsuite/regression/native/Makefile.am
index bb783d2..7f9f001 100644
--- a/src/testsuite/regression/native/Makefile.am
+++ b/src/testsuite/regression/native/Makefile.am
@@ -2,7 +2,7 @@ tstdir = @XENO_TEST_DIR@/regression/native
 
 noinst_HEADERS = check.h
 
-tst_PROGRAMS = leaks tsc mayday heap
+tst_PROGRAMS = leaks tsc mayday heap sigdebug
 
 CPPFLAGS = $(XENO_USER_CFLAGS) \
-I$(top_srcdir)/include
diff --git a/src/testsuite/regression/native/sigdebug.c 
b/src/testsuite/regression/native/sigdebug.c
new file mode 100644
index 000..786501f
--- /dev/null
+++ b/src/testsuite/regression/native/sigdebug.c
@@ -0,0 +1,264 @@
+/*
+ * Functional testing of unwanted domain switch debugging mechanism.
+ *
+ * Copyright (C) Jan Kiszka  jan.kis...@siemens.com
+ *
+ * Released under the terms of GPLv2.
+ */
+
+#include unistd.h
+#include stdlib.h
+#include stdio.h
+#include stdbool.h
+#include string.h
+#include signal.h
+#include fcntl.h
+#include sys/mman.h
+#include pthread.h
+#include rtdk.h
+#include native/task.h
+#include native/mutex.h
+#include native/sem.h
+#include native/timer.h
+
+#define WRITE_TEST_SIZE(4*1024)
+
+unsigned int expected_reason;
+bool sigdebug_received;
+pthread_t rt_task_thread;
+RT_MUTEX prio_invert;
+RT_SEM send_signal;
+char *mem;
+FILE *wd;
+
+static void setup_checkdebug(unsigned int reason)
+{
+   sigdebug_received = false;
+   expected_reason = reason;
+}
+
+static void check_inner(const char *fn, int line, const char *msg,
+   int status, int expected)
+{
+   if (status == expected)
+   return;
+
+   rt_task_set_mode(T_WARNSW, 0, NULL);
+   rt_print_flush_buffers();
+   fprintf(stderr, FAILURE %s:%d: %s returned %d instead of %d - %s\n,
+   fn, line, msg, status, expected, strerror(-status));
+   exit(EXIT_FAILURE);
+}
+
+static void check_sigdebug_inner(const char *fn, int line, const char *reason)
+{
+   if (sigdebug_received)
+   return;
+
+   rt_task_set_mode(T_WARNSW, 0, NULL);
+   rt_print_flush_buffers();
+   fprintf(stderr, FAILURE %s:%d: no %s received\n, fn, line, reason);
+   exit(EXIT_FAILURE);
+}
+
+#define check(msg, status, expected) ({
\
+   int __status = status;  \
+   check_inner(__FUNCTION__, __LINE__, msg, __status, expected);   \
+   __status;   \
+})
+
+#define check_no_error(msg, status) ({ \
+   int __status = status;  \
+   check_inner(__FUNCTION__, __LINE__, msg,\
+   __status  0 ? __status : 0, 0);\
+   __status;   \
+})
+
+#define check_sigdebug_received(reason) do {   \
+   const char *__reason = reason;  \
+   check_sigdebug_inner(__FUNCTION__, __LINE__, __reason); \
+} while (0)
+
+void rt_task_body(void *cookie)
+{
+   RTIME end;
+   int err;
+
+   rt_task_thread = pthread_self();
+
+   rt_printf(syscall\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_SYSCALL);
+   syscall(-1);
+   check_sigdebug_received(SIGDEBUG_MIGRATE_SYSCALL);
+
+   rt_printf(signal\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_SIGNAL);
+   err = rt_sem_v(send_signal);
+   check_no_error(rt_sem_v, err);
+   rt_task_sleep(1000LL);
+   check_sigdebug_received(SIGDEBUG_MIGRATE_SIGNAL);
+
+   rt_printf(relaxed mutex owner\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_PRIOINV);
+   err = rt_mutex_acquire(prio_invert, TM_INFINITE);
+   check(rt_mutex_acquire, err, -EINTR);
+   check_sigdebug_received(SIGDEBUG_MIGRATE_PRIOINV);
+
+
+   rt_printf(page fault\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_FAULT);
+   rt_task_sleep(0);
+   *mem ^= 0xFF;
+   check_sigdebug_received(SIGDEBUG_MIGRATE_FAULT);
+
+   if (wd) {
+   rt_printf(watchdog\n);
+   rt_print_flush_buffers();
+   setup_checkdebug(SIGDEBUG_WATCHDOG);
+

[Xenomai-git] Jan Kiszka : Add sigdebug unit test

2012-01-25 Thread GIT version control
Module: xenomai-jki
Branch: for-upstream
Commit: 937aa4814c37ca985bc273186130057e04735bfb
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=937aa4814c37ca985bc273186130057e04735bfb

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Wed Jan 25 14:58:52 2012 +0100

Add sigdebug unit test

We had two regressions in this code recently. So test all 6 possible
SIGDEBUG reasons, or 5 if the watchdog is not available.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 src/testsuite/unit/Makefile.am |   16 +++-
 src/testsuite/unit/sigdebug.c  |  233 
 2 files changed, 248 insertions(+), 1 deletions(-)

diff --git a/src/testsuite/unit/Makefile.am b/src/testsuite/unit/Makefile.am
index 1bf5d8d..6e8203d 100644
--- a/src/testsuite/unit/Makefile.am
+++ b/src/testsuite/unit/Makefile.am
@@ -11,7 +11,8 @@ test_PROGRAMS = \
cond-torture-posix \
cond-torture-native \
check-vdso \
-   rtdm
+   rtdm \
+   sigdebug
 
 arith_SOURCES = arith.c arith-noinline.c arith-noinline.h
 
@@ -119,3 +120,16 @@ rtdm_LDADD = \
../../skins/native/libnative.la \
../../skins/common/libxenomai.la \
-lpthread -lrt -lm
+
+sigdebug_SOURCES = sigdebug.c
+
+sigdebug_CPPFLAGS = \
+   @XENO_USER_CFLAGS@ \
+   -I$(top_srcdir)/include
+
+sigdebug_LDFLAGS = @XENO_USER_LDFLAGS@
+
+sigdebug_LDADD = \
+   ../../skins/native/libnative.la \
+   ../../skins/common/libxenomai.la \
+   -lpthread -lm
diff --git a/src/testsuite/unit/sigdebug.c b/src/testsuite/unit/sigdebug.c
new file mode 100644
index 000..57d9beb
--- /dev/null
+++ b/src/testsuite/unit/sigdebug.c
@@ -0,0 +1,233 @@
+/*
+ * Functional testing of unwanted domain switch debugging mechanism.
+ *
+ * Copyright (C) Jan Kiszka  jan.kis...@siemens.com
+ *
+ * Released under the terms of GPLv2.
+ */
+
+#include unistd.h
+#include stdlib.h
+#include stdio.h
+#include stdbool.h
+#include string.h
+#include signal.h
+#include fcntl.h
+#include sys/mman.h
+#include pthread.h
+#include rtdk.h
+#include native/task.h
+#include native/mutex.h
+#include native/sem.h
+#include native/timer.h
+
+#define WRITE_TEST_SIZE(4*1024)
+
+unsigned int expected_reason;
+bool sigdebug_received;
+pthread_t rt_task_thread;
+RT_MUTEX prio_invert;
+RT_SEM send_signal;
+char *mem;
+FILE *wd;
+
+static void setup_checkdebug(unsigned int reason)
+{
+   sigdebug_received = false;
+   expected_reason = reason;
+}
+
+static void check_inner(const char *fn, int line, const char *msg,
+   int status, int expected)
+{
+   if (status == expected)
+   return;
+
+   rt_task_set_mode(T_WARNSW, 0, NULL);
+   rt_print_flush_buffers();
+   fprintf(stderr, FAILURE %s:%d: %s returned %d instead of %d - %s\n,
+   fn, line, msg, status, expected, strerror(-status));
+   exit(EXIT_FAILURE);
+}
+
+static void check_sigdebug_inner(const char *fn, int line, const char *reason)
+{
+   if (sigdebug_received)
+   return;
+
+   rt_task_set_mode(T_WARNSW, 0, NULL);
+   rt_print_flush_buffers();
+   fprintf(stderr, FAILURE %s:%d: no %s received\n, fn, line, reason);
+   exit(EXIT_FAILURE);
+}
+
+#define check(msg, status, expected) ({
\
+   int __status = status;  \
+   check_inner(__FUNCTION__, __LINE__, msg, __status, expected);   \
+   __status;   \
+})
+
+#define check_no_error(msg, status) ({ \
+   int __status = status;  \
+   check_inner(__FUNCTION__, __LINE__, msg,\
+   __status  0 ? __status : 0, 0);\
+   __status;   \
+})
+
+#define check_sigdebug_received(reason) do {   \
+   const char *__reason = reason;  \
+   check_sigdebug_inner(__FUNCTION__, __LINE__, __reason); \
+} while (0)
+
+void rt_task_body(void *cookie)
+{
+   RTIME end;
+   int err;
+
+   rt_task_thread = pthread_self();
+
+   rt_printf(syscall\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_SYSCALL);
+   syscall(-1);
+   check_sigdebug_received(SIGDEBUG_MIGRATE_SYSCALL);
+
+   rt_printf(signal\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_SIGNAL);
+   err = rt_sem_v(send_signal);
+   check_no_error(rt_sem_v, err);
+   rt_task_sleep(1000LL);
+   check_sigdebug_received(SIGDEBUG_MIGRATE_SIGNAL);
+
+   rt_printf(relaxed mutex owner\n);
+   setup_checkdebug(SIGDEBUG_MIGRATE_PRIOINV);
+   err = rt_mutex_acquire(prio_invert, TM_INFINITE);
+   check(rt_mutex_acquire, err, -EINTR);
+   check_sigdebug_received(SIGDEBUG_MIGRATE_PRIOINV);
+
+
+   rt_printf(page