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.
This commit is contained in:
Joel Sherrill
2013-12-10 17:56:22 -06:00
parent 0f01de2b96
commit 74c15fe696
3 changed files with 21 additions and 5 deletions

View File

@@ -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
)
{
puts( "BlockingThread - pthread_cond_wait on Mutex1 - OK" );
(void) pthread_cond_wait( &Condition, &Mutex1 );
int sc;
puts( "ERROR - BlockingThread returned from pthread_cond_wait!" );
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" );
sc = pthread_cond_wait( &Condition, &Mutex1 );
printf(
"ERROR - BlockingThread returned from pthread_cond_wait! (rc=%d/%s)\n",
sc,
strerror(sc)
);
rtems_test_exit( 0 );
return NULL;

View File

@@ -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

View File

@@ -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