summaryrefslogtreecommitdiffstats
path: root/testsuites
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2006-12-04 14:11:37 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2006-12-04 14:11:37 +0000
commitc0547b490171ad7b833ee91650ee5802b6ae79aa (patch)
tree54414e0ce0b6c32d0407fb121d0bfa95f52fabad /testsuites
parent2006-12-04 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-c0547b490171ad7b833ee91650ee5802b6ae79aa.tar.bz2
2006-12-04 Joel Sherrill <joel.sherrill@oarcorp.com>
* psxrwlock01/main.c, psxrwlock01/test.c: Improve rwlock test to include normal blocking and unblocking on timeout.
Diffstat (limited to 'testsuites')
-rw-r--r--testsuites/psxtests/ChangeLog5
-rw-r--r--testsuites/psxtests/psxrwlock01/main.c3
-rw-r--r--testsuites/psxtests/psxrwlock01/test.c100
3 files changed, 100 insertions, 8 deletions
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 <joel.sherrill@oarcorp.com>
+
+ * psxrwlock01/main.c, psxrwlock01/test.c: Improve rwlock test to
+ include normal blocking and unblocking on timeout.
+
2006-12-02 Ralf Corsépius <ralf.corsepius@rtems.org>
* 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<NUMBER_THREADS ; i++ ) {
printf( "Init: pthread_create - thread %d OK\n", i+1 );
- status = pthread_create(&ThreadIds[i], NULL, RWLockThread, &ThreadIds[i]);
+ status = pthread_create(&ThreadIds[i], NULL, ReadLockThread, &ThreadIds[i]);
assert( !status );
sleep(1);
}
-#endif
+
+ puts( "pthread_rwlock_unlock(RWLock) -- OK" );
+ status = pthread_rwlock_unlock(&RWLock);
+ assert( !status );
+
+ sleep(1);
+
+
+ /*************** CREATE TESTS AND LET THEM OBTAIN WRITE LOCK ***************/
+ puts( "pthread_rwlock_trywrlock(RWLock) -- OK" );
+ status = pthread_rwlock_trywrlock(&RWLock);
+ assert( !status );
+
+ for (i=0 ; i<NUMBER_THREADS ; i++ ) {
+ printf( "Init: pthread_create - thread %d OK\n", i+1 );
+ status =
+ pthread_create(&ThreadIds[i], NULL, WriteLockThread, &ThreadIds[i]);
+ assert( !status );
+
+ sleep(1);
+ }
+
+ puts( "pthread_rwlock_unlock(RWLock) -- OK" );
+ status = pthread_rwlock_unlock(&RWLock);
+ assert( !status );
+
+ sleep( 3 );
+ puts( "pthread_rwlock_trywrlock(RWLock) -- OK" );
+ status = pthread_rwlock_trywrlock(&RWLock);
+ assert( !status );
+
+ /*************** TIMEOUT ON RWLOCK ***************/
+
+ puts( "clock_gettime(CLOCK_REALTIME, &abstime) -- OK" );
+ status = clock_gettime( CLOCK_REALTIME, &abstime );
+ assert( !status );
+
+ abstime.tv_sec += 1;
+ puts( "pthread_rwlock_timedwrlock( &RWLock, &abstime) -- OK" );
+ status = pthread_rwlock_timedwrlock( &RWLock, &abstime );
+ assert( !status );
+
+ abstime.tv_sec += 1;
+ puts( "pthread_rwlock_timedrdlock( &RWLock, &abstime) -- OK" );
+ status = pthread_rwlock_timedrdlock( &RWLock, &abstime );
+ assert( !status );
+
+ /*************** DESTROY RWLOCK ***************/
+ puts( "pthread_rwlock_destroy( &rwlock ) -- OK" );
+ status = pthread_rwlock_destroy( &rwlock );
+ assert( status == 0 );
+
/*************** END OF TEST *****************/
puts( "*** END OF POSIX RWLOCK TEST 01 ***" );