From c0547b490171ad7b833ee91650ee5802b6ae79aa Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 4 Dec 2006 14:11:37 +0000 Subject: 2006-12-04 Joel Sherrill * psxrwlock01/main.c, psxrwlock01/test.c: Improve rwlock test to include normal blocking and unblocking on timeout. --- testsuites/psxtests/ChangeLog | 5 ++ testsuites/psxtests/psxrwlock01/main.c | 3 +- testsuites/psxtests/psxrwlock01/test.c | 100 ++++++++++++++++++++++++++++++--- 3 files changed, 100 insertions(+), 8 deletions(-) (limited to 'testsuites') diff --git a/testsuites/psxtests/ChangeLog b/testsuites/psxtests/ChangeLog index 02fd39947c..ff4747e224 100644 --- a/testsuites/psxtests/ChangeLog +++ b/testsuites/psxtests/ChangeLog @@ -1,3 +1,8 @@ +2006-12-04 Joel Sherrill + + * psxrwlock01/main.c, psxrwlock01/test.c: Improve rwlock test to + include normal blocking and unblocking on timeout. + 2006-12-02 Ralf Corsépius * configure.ac: New BUG-REPORT address. diff --git a/testsuites/psxtests/psxrwlock01/main.c b/testsuites/psxtests/psxrwlock01/main.c index adf3e32ec3..77d6970f7e 100644 --- a/testsuites/psxtests/psxrwlock01/main.c +++ b/testsuites/psxtests/psxrwlock01/main.c @@ -31,8 +31,9 @@ rtems_task Init( #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER -#define CONFIGURE_MAXIMUM_TASKS 2 +#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_MAXIMUM_POSIX_THREADS 2 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 1 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE diff --git a/testsuites/psxtests/psxrwlock01/test.c b/testsuites/psxtests/psxrwlock01/test.c index cbe80967bf..659f5c7777 100644 --- a/testsuites/psxtests/psxrwlock01/test.c +++ b/testsuites/psxtests/psxrwlock01/test.c @@ -23,8 +23,40 @@ pthread_t ThreadIds[NUMBER_THREADS]; pthread_rwlock_t RWLock; -void *RWLockThread(void *arg) +/* + * Test thread to block for read lock and unlock it + */ +void *ReadLockThread(void *arg) +{ + int status; + + puts( "ReadThread - pthread_rwlock_rdlock(RWLock) blocking -- OK" ); + status = pthread_rwlock_rdlock(&RWLock); + assert( !status ); + puts( "ReadThread - pthread_rwlock_rdlock(RWLock) unblocked -- OK" ); + + status = pthread_rwlock_unlock(&RWLock); + assert( !status ); + return NULL; +} + +/* + * Test thread to block for write lock and unlock it + */ +void *WriteLockThread(void *arg) { + int status; + + puts( "WriteThread - pthread_rwlock_wrlock(RWLock) blocking -- OK" ); + status = pthread_rwlock_wrlock(&RWLock); + assert( !status ); + puts( "WriteThread - pthread_rwlock_wrlock(RWLock) unblocked -- OK" ); + + sleep( 1 ); + + puts( "WriteThread - pthread_rwlock_unlock(RWLock) -- OK" ); + status = pthread_rwlock_unlock(&RWLock); + assert( !status ); return NULL; } @@ -246,21 +278,75 @@ int main( status = pthread_rwlock_destroy( &rwlock ); assert( status == 0 ); -#if 0 - /*************** CREATE TESTS AND LET THEM RELEASE *****************/ - puts( "pthread_rwlock_init( &RWLock, &attr, 2 ) -- OK" ); - status = pthread_rwlock_init( &RWLock, &attr, 2 ); + /*************** CREATE TESTS AND LET THEM OBTAIN READLOCK *****************/ + puts( "pthread_rwlock_init( &RWLock, &attr ) -- OK" ); + status = pthread_rwlock_init( &RWLock, &attr ); assert( status == 0 ); assert( rwlock != 0 ); + puts( "pthread_rwlock_trywrlock(RWLock) -- OK" ); + status = pthread_rwlock_trywrlock(&RWLock); + assert( !status ); + for (i=0 ; i