[Xenomai-git] Jan Kiszka : testsuite/smokey: Add cond + pp-mutex test

2018-05-16 Thread git repository hosting
Module: xenomai-3
Branch: wip/heapmem
Commit: 410a4cc1109ba4e0d05b7ece7b4a5210287e1183
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=410a4cc1109ba4e0d05b7ece7b4a5210287e1183

Author: Jan Kiszka 
Date:   Wed May  2 18:33:00 2018 +0200

testsuite/smokey: Add cond + pp-mutex test

This stresses the case of fast-path mutex acquire plus pthread_cond_wait
with that mutex, which currently triggers a bug in xnsynch_release.

Along this, drop the HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL conditional -
libboilerplate takes care of that.

Signed-off-by: Jan Kiszka 

---

 testsuite/smokey/posix-cond/posix-cond.c |   96 ++
 1 file changed, 72 insertions(+), 24 deletions(-)

diff --git a/testsuite/smokey/posix-cond/posix-cond.c 
b/testsuite/smokey/posix-cond/posix-cond.c
index 6c9a458..153c645 100644
--- a/testsuite/smokey/posix-cond/posix-cond.c
+++ b/testsuite/smokey/posix-cond/posix-cond.c
@@ -42,27 +42,21 @@ static inline unsigned long long timer_tsc2ns(unsigned long 
long tsc)
return clockobj_tsc_to_ns(tsc);
 }
 
-static int mutex_init(pthread_mutex_t *mutex, int type, int pi)
+static int mutex_init(pthread_mutex_t *mutex, int type, int proto)
 {
pthread_mutexattr_t mattr;
int err;
 
pthread_mutexattr_init();
pthread_mutexattr_settype(, type);
-#ifdef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
-   if (pi != 0)
-   pthread_mutexattr_setprotocol(, PTHREAD_PRIO_INHERIT);
-
-   err = pthread_mutex_init(mutex, );
-#else
-   if (pi != 0) {
-   err = ENOSYS;
+   err = pthread_mutexattr_setprotocol(, proto);
+   if (err)
goto out;
-   }
-   err = pthread_mutex_init(mutex, );
+   if (proto == PTHREAD_PRIO_PROTECT)
+   pthread_mutexattr_setprioceiling(, 3);
 
+   err = pthread_mutex_init(mutex, );
   out:
-#endif
pthread_mutexattr_destroy();
 
return -err;
@@ -217,7 +211,8 @@ static void autoinit_simple_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("mutex_lock", mutex_lock(), 0);
check("thread_spawn",
  thread_spawn(_signaler_tid, 2, cond_signaler, ), 0);
@@ -246,7 +241,8 @@ static void simple_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 0), 0);
check("mutex_lock", mutex_lock(), 0);
check("thread_spawn",
@@ -271,7 +267,8 @@ static void relative_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 0), 0);
check("mutex_lock", mutex_lock(), 0);
 
@@ -294,7 +291,8 @@ static void autoinit_absolute_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("mutex_lock", mutex_lock(), 0);
 
start = timer_get_tsc();
@@ -316,7 +314,8 @@ static void absolute_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 1), 0);
check("mutex_lock", mutex_lock(), 0);
 
@@ -373,7 +372,8 @@ static void sig_norestart_condwait(void)
smokey_trace("%s", __func__);
 
check_unix("sigaction", sigaction(SIGRTMIN, , NULL), 0);
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 0), 0);
check("mutex_lock", mutex_lock(), 0);
check("thread_spawn",
@@ -411,7 +411,8 @@ static void sig_restart_condwait(void)
smokey_trace("%s", __func__);
 
check_unix("sigaction", sigaction(SIGRTMIN, , NULL), 0);
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 0), 0);
check("mutex_lock", mutex_lock(), 0);
check("thread_spawn",

[Xenomai-git] Jan Kiszka : testsuite/smokey: Add cond + pp-mutex test

2018-05-12 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 410a4cc1109ba4e0d05b7ece7b4a5210287e1183
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=410a4cc1109ba4e0d05b7ece7b4a5210287e1183

Author: Jan Kiszka 
Date:   Wed May  2 18:33:00 2018 +0200

testsuite/smokey: Add cond + pp-mutex test

This stresses the case of fast-path mutex acquire plus pthread_cond_wait
with that mutex, which currently triggers a bug in xnsynch_release.

Along this, drop the HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL conditional -
libboilerplate takes care of that.

Signed-off-by: Jan Kiszka 

---

 testsuite/smokey/posix-cond/posix-cond.c |   96 ++
 1 file changed, 72 insertions(+), 24 deletions(-)

diff --git a/testsuite/smokey/posix-cond/posix-cond.c 
b/testsuite/smokey/posix-cond/posix-cond.c
index 6c9a458..153c645 100644
--- a/testsuite/smokey/posix-cond/posix-cond.c
+++ b/testsuite/smokey/posix-cond/posix-cond.c
@@ -42,27 +42,21 @@ static inline unsigned long long timer_tsc2ns(unsigned long 
long tsc)
return clockobj_tsc_to_ns(tsc);
 }
 
-static int mutex_init(pthread_mutex_t *mutex, int type, int pi)
+static int mutex_init(pthread_mutex_t *mutex, int type, int proto)
 {
pthread_mutexattr_t mattr;
int err;
 
pthread_mutexattr_init();
pthread_mutexattr_settype(, type);
-#ifdef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
-   if (pi != 0)
-   pthread_mutexattr_setprotocol(, PTHREAD_PRIO_INHERIT);
-
-   err = pthread_mutex_init(mutex, );
-#else
-   if (pi != 0) {
-   err = ENOSYS;
+   err = pthread_mutexattr_setprotocol(, proto);
+   if (err)
goto out;
-   }
-   err = pthread_mutex_init(mutex, );
+   if (proto == PTHREAD_PRIO_PROTECT)
+   pthread_mutexattr_setprioceiling(, 3);
 
+   err = pthread_mutex_init(mutex, );
   out:
-#endif
pthread_mutexattr_destroy();
 
return -err;
@@ -217,7 +211,8 @@ static void autoinit_simple_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("mutex_lock", mutex_lock(), 0);
check("thread_spawn",
  thread_spawn(_signaler_tid, 2, cond_signaler, ), 0);
@@ -246,7 +241,8 @@ static void simple_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 0), 0);
check("mutex_lock", mutex_lock(), 0);
check("thread_spawn",
@@ -271,7 +267,8 @@ static void relative_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 0), 0);
check("mutex_lock", mutex_lock(), 0);
 
@@ -294,7 +291,8 @@ static void autoinit_absolute_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("mutex_lock", mutex_lock(), 0);
 
start = timer_get_tsc();
@@ -316,7 +314,8 @@ static void absolute_condwait(void)
 
smokey_trace("%s", __func__);
 
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 1), 0);
check("mutex_lock", mutex_lock(), 0);
 
@@ -373,7 +372,8 @@ static void sig_norestart_condwait(void)
smokey_trace("%s", __func__);
 
check_unix("sigaction", sigaction(SIGRTMIN, , NULL), 0);
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 0), 0);
check("mutex_lock", mutex_lock(), 0);
check("thread_spawn",
@@ -411,7 +411,8 @@ static void sig_restart_condwait(void)
smokey_trace("%s", __func__);
 
check_unix("sigaction", sigaction(SIGRTMIN, , NULL), 0);
-   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT, 0), 0);
+   check("mutex_init", mutex_init(, PTHREAD_MUTEX_DEFAULT,
+  PTHREAD_PRIO_NONE), 0);
check("cond_init", cond_init(, 0), 0);
check("mutex_lock", mutex_lock(), 0);
check("thread_spawn",
@@