summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests/psx05
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-09-27 15:08:33 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-05 14:29:02 +0200
commitde59c065c57cb8526662ee6da28a57ad16fdde66 (patch)
tree21f4a2adbd58f65f722051bca435572fbf5dcf05 /testsuites/psxtests/psx05
parent5222488573e3ba8c2eceffe29f878a73a3a81694 (diff)
downloadrtems-de59c065c57cb8526662ee6da28a57ad16fdde66.tar.bz2
posix: Implement self-contained POSIX mutex
POSIX mutexes are now available in all configurations and no longer depend on --enable-posix. Update #2514. Update #3112.
Diffstat (limited to 'testsuites/psxtests/psx05')
-rw-r--r--testsuites/psxtests/psx05/init.c193
-rw-r--r--testsuites/psxtests/psx05/psx05.scn7
-rw-r--r--testsuites/psxtests/psx05/system.h3
3 files changed, 188 insertions, 15 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)" );
diff --git a/testsuites/psxtests/psx05/psx05.scn b/testsuites/psxtests/psx05/psx05.scn
index 0315eee562..700f3bfb4f 100644
--- a/testsuites/psxtests/psx05/psx05.scn
+++ b/testsuites/psxtests/psx05/psx05.scn
@@ -3,7 +3,7 @@ Init's ID is 0x0b010001
Init: pthread_mutexattr_init - EINVAL (NULL attr)
Init: pthread_mutexattr_init - SUCCESSFUL
Init: mutex protocol is (0) -- PTHREAD_PRIO_NONE
-Init: mutex priority ceiling is 254
+Init: mutex priority ceiling is 2147483647
Init: mutex process shared is (0) -- PTHREAD_PROCESS_PRIVATE
Init: pthread_mutexattr_destroy - SUCCESSFUL
Init: pthread_mutexattr_destroy - EINVAL (NULL attr)
@@ -67,9 +67,10 @@ Init: pthread_mutex_timedlock - time out in the past
Init: pthread_mutex_timedlock - EAGAIN (timeout)
Init: pthread_mutex_init - SUCCESSFUL
-Init: pthread_mutex_init - EAGAIN (too many)
+Init: pthread_mutex_init - SUCCESSFUL
Init: pthread_mutexattr_destroy - SUCCESSFUL
Init: pthread_mutex_destroy - SUCCESSFUL
+Init: pthread_mutex_destroy - SUCCESSFUL
Init: pthread_mutex_destroy - EINVAL (invalid id)
Init: pthread_mutexattr_init - SUCCESSFUL
@@ -113,8 +114,6 @@ Task 3: pthread_mutex_lock unavailable (inherit case)
Init: pthread_mutex_unlock - SUCCESSFUL
Task 3: mutex acquired
Task 3: unlock Mutex 2
-Task 3: pthread_getschedparam priority = 199
-Task 3: exit
Init: pthread_mutex_getprioceiling- ceiling = 200
Init: pthread_setschedparam - set Init priority to highest
Init: pthread_mutex_lock - EINVAL (priority ceiling violation)
diff --git a/testsuites/psxtests/psx05/system.h b/testsuites/psxtests/psx05/system.h
index a3615d49c3..a4d128d6f6 100644
--- a/testsuites/psxtests/psx05/system.h
+++ b/testsuites/psxtests/psx05/system.h
@@ -39,7 +39,6 @@ void *Task_3(
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_MAXIMUM_POSIX_THREADS 4
-#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 2
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
@@ -62,6 +61,6 @@ TEST_EXTERN pthread_t Task3_id;
TEST_EXTERN pthread_mutex_t Mutex_id;
TEST_EXTERN pthread_mutex_t Mutex2_id;
TEST_EXTERN pthread_mutex_t Mutex3_id;
-TEST_EXTERN pthread_mutex_t Mutex_bad_id;
+TEST_EXTERN pthread_mutex_t *Mutex_bad_id;
/* end of include file */