[rtems commit] psxtmcond01: Fix bug where mutex not locked and add EPERM error check

Joel Sherrill joel at rtems.org
Tue Dec 10 23:50:52 UTC 2013


Module:    rtems
Branch:    master
Commit:    74c15fe6960a0db29d6d0bb1e2e9b4e80d92179a
Changeset: http://git.rtems.org/rtems/commit/?id=74c15fe6960a0db29d6d0bb1e2e9b4e80d92179a

Author:    Joel Sherrill <joel.sherrill at oarcorp.com>
Date:      Tue Dec 10 17:56:22 2013 -0600

psxtmcond01: Fix bug where mutex not locked and add EPERM error check

This test formerly had a bug in that it attempted to wait on a
condition variable with a Mutex that was not locked. This is
undefined by POSIX. But a recent change to match GNU/Linux behavior
resulted in finding a bug in the test.

---

 testsuites/psxtests/psxcond01/init.c        |   19 ++++++++++++++++---
 testsuites/psxtests/psxcond01/psxcond01.doc |    4 +++-
 testsuites/psxtests/psxcond01/psxcond01.scn |    1 +
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/testsuites/psxtests/psxcond01/init.c b/testsuites/psxtests/psxcond01/init.c
index f87eca2..ebf65f9 100644
--- a/testsuites/psxtests/psxcond01/init.c
+++ b/testsuites/psxtests/psxcond01/init.c
@@ -1,5 +1,5 @@
 /*
- *  COPYRIGHT (c) 1989-2012.
+ *  COPYRIGHT (c) 1989-2013.
  *  On-Line Applications Research Corporation (OAR).
  *
  *  The license and distribution terms for this file may be
@@ -27,10 +27,23 @@ void *BlockingThread(
   void *argument
 )
 {
+  int sc;
+
+  puts( "BlockingThread - pthread_cond_wait with mutex not locked - EPERM" );
+  sc = pthread_cond_wait( &Condition, &Mutex1 );
+  fatal_posix_service_status( sc, EPERM, "mutex1 not locked" );
+
+  sc = pthread_mutex_lock( &Mutex1 );
+  fatal_posix_service_status( sc, 0, "mutex1 lock" );
+  
   puts( "BlockingThread - pthread_cond_wait on Mutex1 - OK" );
-  (void) pthread_cond_wait( &Condition, &Mutex1 );
+  sc = pthread_cond_wait( &Condition, &Mutex1 );
 
-  puts( "ERROR - BlockingThread returned from pthread_cond_wait!" );
+  printf(
+    "ERROR - BlockingThread returned from pthread_cond_wait! (rc=%d/%s)\n",
+    sc,
+    strerror(sc)
+  );
   rtems_test_exit( 0 );
 
   return NULL;
diff --git a/testsuites/psxtests/psxcond01/psxcond01.doc b/testsuites/psxtests/psxcond01/psxcond01.doc
index 04c1847..3664278 100644
--- a/testsuites/psxtests/psxcond01/psxcond01.doc
+++ b/testsuites/psxtests/psxcond01/psxcond01.doc
@@ -1,4 +1,4 @@
-#  COPYRIGHT (c) 1989-2009.
+#  COPYRIGHT (c) 1989-2013.
 #  On-Line Applications Research Corporation (OAR).
 #
 #  The license and distribution terms for this file may be
@@ -23,6 +23,8 @@ concepts:
   to attempt to block on the same condition variable using a different
   mutex.
 
++ Verify EPERM is returned on pthread_cond_wait when mutex is not locked
+
 + Verify error conditions in pthread_mutexattr_settype
 
 + Verify normal paths through pthread_mutexattr_gettype
diff --git a/testsuites/psxtests/psxcond01/psxcond01.scn b/testsuites/psxtests/psxcond01/psxcond01.scn
index 18b4348..9e306cc 100644
--- a/testsuites/psxtests/psxcond01/psxcond01.scn
+++ b/testsuites/psxtests/psxcond01/psxcond01.scn
@@ -1,6 +1,7 @@
 *** POSIX TEST -- CONDITION VARIABLE 01 ***
 Init - pthread_mutex_init - Mutex1 - OK
 Init - pthread_mutex_init - Mutex2 - OK
+BlockingThread - pthread_cond_wait with mutex not locked - EPERM
 Init - pthread_cond_init - Condition - OK
 Init -  pthread_create - OK
 Init - sleep to let BlockingThread run




More information about the vc mailing list