From 0c07f6950ffe764f3c4ec37924a9921638a7079a Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 28 Sep 2009 23:52:46 +0000 Subject: 2009-09-28 Joel Sherrill * psxcancel/init.c, psxcancel/psxcancel.scn, psxcancel01/init.c, psxcancel01/psxcancel01.scn: Add missing pthread cancellation test cases. --- testsuites/psxtests/ChangeLog | 6 ++ testsuites/psxtests/psxcancel/init.c | 4 ++ testsuites/psxtests/psxcancel/psxcancel.scn | 1 + testsuites/psxtests/psxcancel01/init.c | 89 +++++++++++++++++-------- testsuites/psxtests/psxcancel01/psxcancel01.scn | 4 ++ 5 files changed, 76 insertions(+), 28 deletions(-) (limited to 'testsuites') diff --git a/testsuites/psxtests/ChangeLog b/testsuites/psxtests/ChangeLog index aae293f998..04ce75b669 100644 --- a/testsuites/psxtests/ChangeLog +++ b/testsuites/psxtests/ChangeLog @@ -1,3 +1,9 @@ +2009-09-28 Joel Sherrill + + * psxcancel/init.c, psxcancel/psxcancel.scn, psxcancel01/init.c, + psxcancel01/psxcancel01.scn: Add missing pthread cancellation test + cases. + 2009-09-28 Joel Sherrill * Makefile.am, configure.ac: Add new test for calling pthread_cancel() diff --git a/testsuites/psxtests/psxcancel/init.c b/testsuites/psxtests/psxcancel/init.c index 72e6ea99c5..7c75a7f4bf 100644 --- a/testsuites/psxtests/psxcancel/init.c +++ b/testsuites/psxtests/psxcancel/init.c @@ -91,6 +91,10 @@ void *countTaskAsync(void *ignored) sc = pthread_setcanceltype(12, &old); fatal_posix_service_status( sc, EINVAL, "cancel type EINVAL" ); + puts( "Init - pthread_cancel - bad ID - EINVAL" ); + sc = pthread_cancel(0x100); + fatal_posix_service_status( sc, EINVAL, "cancel bad Id" ); + /* Start countTask deferred */ { sc = pthread_create(&task, NULL, countTaskDeferred, &taskparameter); diff --git a/testsuites/psxtests/psxcancel/psxcancel.scn b/testsuites/psxtests/psxcancel/psxcancel.scn index 255e9242ce..b51dd73f5f 100644 --- a/testsuites/psxtests/psxcancel/psxcancel.scn +++ b/testsuites/psxtests/psxcancel/psxcancel.scn @@ -3,6 +3,7 @@ Init - pthread_setcancelstate - NULL oldstate - EINVAL Init - pthread_setcancelstate - bad state - EINVAL Init - pthread_setcanceltype - NULL oldtype - EINVAL Init - pthread_setcanceltype - bad type - EINVAL +Init - pthread_cancel - bad ID - EINVAL countTaskDeferred: elapsed time (second): 0 countTaskDeferred: elapsed time (second): 1 countTaskDeferred: elapsed time (second): 2 diff --git a/testsuites/psxtests/psxcancel01/init.c b/testsuites/psxtests/psxcancel01/init.c index 437fd93588..72f95b1c10 100644 --- a/testsuites/psxtests/psxcancel01/init.c +++ b/testsuites/psxtests/psxcancel01/init.c @@ -12,59 +12,92 @@ #include #include -volatile int Cancel_occurred; -volatile int Cancel_status; +volatile int TSR_occurred; +volatile int TSR_status; + +rtems_id timer_id; rtems_timer_service_routine Cancel_duringISR_TSR( rtems_id ignored_id, void *ignored_address ) { - Cancel_status = pthread_cancel( pthread_self() ); - Cancel_occurred = 1; + TSR_status = pthread_cancel( pthread_self() ); + TSR_occurred = 1; } +rtems_timer_service_routine SetState_duringISR_TSR( + rtems_id ignored_id, + void *ignored_address +) +{ + int oldstate; + + TSR_status = pthread_setcancelstate( 0, &oldstate ); + TSR_occurred = 1; +} -void *POSIX_Init( - void *argument +rtems_timer_service_routine SetType_duringISR_TSR( + rtems_id ignored_id, + void *ignored_address ) { - int status; - rtems_interval start; - rtems_interval end; - rtems_id timer_id; + int oldtype; - puts( "\n\n*** POSIX TEST CANCEL 01 ***" ); + TSR_status = pthread_setcanceltype( 0, &oldtype ); + TSR_occurred = 1; +} - status = rtems_timer_create( - rtems_build_name( 'T', 'M', '1', ' ' ), - &timer_id - ); - assert( !status ); +void doit( + rtems_timer_service_routine (*TSR)(rtems_id, void *), + const char *method +) +{ + rtems_interval start; + rtems_interval end; + rtems_status_code status; - Cancel_occurred = 0; - Cancel_status = 0; + printf( "Init: schedule %s from a TSR\n", method ); - puts( "Init: schedule pthread_cancel from a TSR" ); - status = rtems_timer_fire_after( timer_id, 10, Cancel_duringISR_TSR, NULL ); - assert( !status ); + TSR_occurred = 0; + TSR_status = 0; - /* cancel occurs during sleep */ + status = rtems_timer_fire_after( timer_id, 10, TSR, NULL ); + assert( !status ); do { end = rtems_clock_get_ticks_since_boot(); - } while ( !Cancel_occurred && ((end - start) <= 800)); + } while ( !TSR_occurred && ((end - start) <= 800)); - if ( !Cancel_occurred ) { - puts( "Cancel did not occur" ); + if ( !TSR_occurred ) { + printf( "%s did not occur\n", method ); rtems_test_exit(0); } - if ( Cancel_status != EPROTO ) { - printf( "Cancel returned %s\n", strerror(Cancel_status) ); + if ( TSR_status != EPROTO ) { + printf( "%s returned %s\n", method, strerror(TSR_status) ); rtems_test_exit(0); } - puts( "pthread_cancel - from ISR returns EPROTO - OK" ); + printf( "%s - from ISR returns EPROTO - OK\n", method ); + +} + +void *POSIX_Init( + void *argument +) +{ + rtems_status_code status; + + puts( "\n\n*** POSIX TEST CANCEL 01 ***" ); + + status = rtems_timer_create( + rtems_build_name( 'T', 'M', '1', ' ' ), + &timer_id + ); + assert( !status ); + doit( Cancel_duringISR_TSR, "pthread_cancel" ); + doit( SetState_duringISR_TSR, "pthread_setcancelstate" ); + doit( SetType_duringISR_TSR, "pthread_setcanceltype" ); puts( "*** END OF POSIX TEST CANCEL 01 ***" ); rtems_test_exit(0); diff --git a/testsuites/psxtests/psxcancel01/psxcancel01.scn b/testsuites/psxtests/psxcancel01/psxcancel01.scn index ad1dae753e..80e93440c1 100644 --- a/testsuites/psxtests/psxcancel01/psxcancel01.scn +++ b/testsuites/psxtests/psxcancel01/psxcancel01.scn @@ -1,4 +1,8 @@ *** POSIX TEST CANCEL 01 *** Init: schedule pthread_cancel from a TSR pthread_cancel - from ISR returns EPROTO - OK +Init: schedule pthread_setcancelstate from a TSR +pthread_setcancelstate - from ISR returns EPROTO - OK +Init: schedule pthread_setcanceltype from a TSR +pthread_setcanceltype - from ISR returns EPROTO - OK *** END OF POSIX TEST CANCEL 01 *** -- cgit v1.2.3