summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests/psx05/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/psxtests/psx05/init.c')
-rw-r--r--testsuites/psxtests/psx05/init.c193
1 files changed, 184 insertions, 9 deletions
diff --git a/testsuites/psxtests/psx05/init.c b/testsuites/psxtests/psx05/init.c
index e524d6f96f..4da2673857 100644
--- a/testsuites/psxtests/psx05/init.c
+++ b/testsuites/psxtests/psx05/init.c
@@ -239,6 +239,173 @@ static void test_errors_pthread_setschedprio( void )
rtems_test_assert( status == 0 );
}
+static void test_mutex_pshared_init(void)
+{
+ pthread_mutex_t mutex;
+ pthread_mutexattr_t attr;
+ int eno;
+
+ eno = pthread_mutexattr_init(&attr);
+ rtems_test_assert(eno == 0);
+
+ eno = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);
+ rtems_test_assert(eno == 0);
+
+ eno = pthread_mutex_init(&mutex, &attr);
+ rtems_test_assert(eno == 0);
+
+ eno = pthread_mutex_destroy(&mutex);
+ rtems_test_assert(eno == 0);
+
+ eno = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+ rtems_test_assert(eno == 0);
+
+ eno = pthread_mutex_init(&mutex, &attr);
+ rtems_test_assert(eno == 0);
+
+ eno = pthread_mutex_destroy(&mutex);
+ rtems_test_assert(eno == 0);
+
+ attr.process_shared = -1;
+
+ eno = pthread_mutex_init(&mutex, &attr);
+ rtems_test_assert(eno == EINVAL);
+
+ eno = pthread_mutexattr_destroy(&attr);
+ rtems_test_assert(eno == 0);
+}
+
+static void test_mutex_null( void )
+{
+ struct timespec to;
+ int eno;
+
+ eno = pthread_mutex_destroy( NULL );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_init( NULL, NULL );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_lock( NULL );
+ rtems_test_assert( eno == EINVAL );
+
+ to.tv_sec = 1;
+ to.tv_nsec = 1;
+ eno = pthread_mutex_timedlock( NULL, &to );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_trylock( NULL );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_unlock( NULL );
+ rtems_test_assert( eno == EINVAL );
+}
+
+static void test_mutex_not_initialized( void )
+{
+ pthread_mutex_t mutex;
+ struct timespec to;
+ int eno;
+
+ memset( &mutex, 0xff, sizeof( mutex ) );
+
+ eno = pthread_mutex_destroy( &mutex );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_lock( &mutex );
+ rtems_test_assert( eno == EINVAL );
+
+ to.tv_sec = 1;
+ to.tv_nsec = 1;
+ eno = pthread_mutex_timedlock( &mutex, &to );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_trylock( &mutex );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_unlock( &mutex );
+ rtems_test_assert( eno == EINVAL );
+}
+
+static void test_mutex_invalid_copy( void )
+{
+ pthread_mutex_t mutex;
+ pthread_mutex_t mutex2;
+ struct timespec to;
+ int eno;
+
+ eno = pthread_mutex_init( &mutex, NULL );
+ rtems_test_assert( eno == 0 );
+
+ memcpy( &mutex2, &mutex, sizeof( mutex2 ) );
+
+ eno = pthread_mutex_destroy( &mutex2 );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_lock( &mutex2 );
+ rtems_test_assert( eno == EINVAL );
+
+ to.tv_sec = 1;
+ to.tv_nsec = 1;
+ eno = pthread_mutex_timedlock( &mutex2, &to );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_trylock( &mutex2 );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_unlock( &mutex2 );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_mutex_destroy( &mutex );
+ rtems_test_assert( eno == 0 );
+}
+
+static void test_mutex_auto_initialization( void )
+{
+ struct timespec to;
+ int eno;
+
+ {
+ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+ eno = pthread_mutex_destroy( &mutex );
+ rtems_test_assert( eno == 0 );
+
+ eno = pthread_mutex_destroy( &mutex );
+ rtems_test_assert( eno == EINVAL );
+ }
+
+ {
+ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+ eno = pthread_mutex_lock( &mutex );
+ rtems_test_assert( eno == 0 );
+ }
+
+ {
+ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+ to.tv_sec = 1;
+ to.tv_nsec = 1;
+ eno = pthread_mutex_timedlock( &mutex, &to );
+ rtems_test_assert( eno == 0 );
+ }
+
+ {
+ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+ eno = pthread_mutex_trylock( &mutex );
+ rtems_test_assert( eno == 0 );
+ }
+
+ {
+ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+ eno = pthread_mutex_unlock( &mutex );
+ rtems_test_assert( eno == EPERM );
+ }
+}
+
void *POSIX_Init(
void *argument
)
@@ -255,11 +422,15 @@ void *POSIX_Init(
int old_ceiling;
int priority;
- rtems_test_assert( MUTEX_BAD_ID != PTHREAD_MUTEX_INITIALIZER );
- Mutex_bad_id = MUTEX_BAD_ID;
+ Mutex_bad_id = NULL;
TEST_BEGIN();
+ test_mutex_pshared_init();
+ test_mutex_null();
+ test_mutex_not_initialized();
+ test_mutex_invalid_copy();
+ test_mutex_auto_initialization();
test_get_priority();
test_set_priority();
test_errors_pthread_setschedprio();
@@ -504,7 +675,7 @@ void *POSIX_Init(
#endif
puts( "Init: pthread_mutex_trylock - EINVAL (illegal ID)" );
- status = pthread_mutex_trylock( &Mutex_bad_id );
+ status = pthread_mutex_trylock( Mutex_bad_id );
if ( status != EINVAL )
printf( "status = %d\n", status );
rtems_test_assert( status == EINVAL );
@@ -546,7 +717,7 @@ void *POSIX_Init(
/* switch to task 1 */
puts( "Init: pthread_mutex_unlock - EINVAL (invalid id)" );
- status = pthread_mutex_unlock( &Mutex_bad_id );
+ status = pthread_mutex_unlock( Mutex_bad_id );
if ( status != EINVAL )
printf( "status = %d\n", status );
rtems_test_assert( status == EINVAL );
@@ -593,20 +764,24 @@ void *POSIX_Init(
printf( "status = %d\n", status );
rtems_test_assert( !status );
- puts( "Init: pthread_mutex_init - EAGAIN (too many)" );
+ puts( "Init: pthread_mutex_init - SUCCESSFUL" );
status = pthread_mutex_init( &Mutex3_id, &attr );
- rtems_test_assert( status == EAGAIN );
+ rtems_test_assert( !status );
puts( "Init: pthread_mutexattr_destroy - SUCCESSFUL" );
status = pthread_mutexattr_destroy( &attr );
rtems_test_assert( !status );
puts( "Init: pthread_mutex_destroy - SUCCESSFUL" );
+ status = pthread_mutex_destroy( &Mutex3_id );
+ rtems_test_assert( !status );
+
+ puts( "Init: pthread_mutex_destroy - SUCCESSFUL" );
status = pthread_mutex_destroy( &Mutex2_id );
rtems_test_assert( !status );
puts( "Init: pthread_mutex_destroy - EINVAL (invalid id)" );
- status = pthread_mutex_destroy( &Mutex_bad_id );
+ status = pthread_mutex_destroy( Mutex_bad_id );
rtems_test_assert( status == EINVAL );
/* destroy a busy mutex */
@@ -713,7 +888,7 @@ void *POSIX_Init(
rtems_test_assert( !status );
puts( "Init: pthread_mutex_getprioceiling - EINVAL (invalid id)" );
- status = pthread_mutex_getprioceiling( &Mutex_bad_id, &ceiling );
+ status = pthread_mutex_getprioceiling( Mutex_bad_id, &ceiling );
rtems_test_assert( status == EINVAL );
puts( "Init: pthread_mutex_getprioceiling - EINVAL (NULL ceiling)" );
@@ -725,7 +900,7 @@ void *POSIX_Init(
printf( "Init: pthread_mutex_getprioceiling - %d\n", ceiling );
puts( "Init: pthread_mutex_setprioceiling - EINVAL (invalid id)" );
- status = pthread_mutex_setprioceiling( &Mutex_bad_id, 200, &old_ceiling );
+ status = pthread_mutex_setprioceiling( Mutex_bad_id, 200, &old_ceiling );
rtems_test_assert( status == EINVAL );
puts( "Init: pthread_mutex_setprioceiling - EINVAL (illegal priority)" );