From 73dfaf83a11177c1b5c7740acae406d226a02bae Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 23 Jul 2009 13:29:49 +0000 Subject: 2009-07-23 Santosh G Vattam * psxcancel/Makefile.am, psxcancel/init.c, psxcancel/psxcancel.scn: Add multiple cases which complete coverage of thread cancellation. * psxcancel/psxcancel.doc: New file. --- testsuites/psxtests/psxcancel/Makefile.am | 1 + testsuites/psxtests/psxcancel/init.c | 55 ++++++++++++++++++++++------- testsuites/psxtests/psxcancel/psxcancel.doc | 46 ++++++++++++++++++++++++ testsuites/psxtests/psxcancel/psxcancel.scn | 6 ++-- 4 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 testsuites/psxtests/psxcancel/psxcancel.doc (limited to 'testsuites/psxtests/psxcancel') diff --git a/testsuites/psxtests/psxcancel/Makefile.am b/testsuites/psxtests/psxcancel/Makefile.am index 4a7fb9b1a1..caab977476 100644 --- a/testsuites/psxtests/psxcancel/Makefile.am +++ b/testsuites/psxtests/psxcancel/Makefile.am @@ -8,6 +8,7 @@ rtems_tests_PROGRAMS = psxcancel psxcancel_SOURCES = init.c ../include/pmacros.h dist_rtems_tests_DATA = psxcancel.scn +dist_rtems_tests_DATA += psxcancel.doc include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg include $(top_srcdir)/../automake/compile.am diff --git a/testsuites/psxtests/psxcancel/init.c b/testsuites/psxtests/psxcancel/init.c index a2f691fa9a..72e6ea99c5 100644 --- a/testsuites/psxtests/psxcancel/init.c +++ b/testsuites/psxtests/psxcancel/init.c @@ -6,7 +6,6 @@ * $Id$ */ - #include #include #include @@ -15,18 +14,24 @@ #include #include - #if defined(__rtems__) -#include -#include -#include + #include + #include + #include #endif +volatile bool countTask_handler; + +void countTask_cancel_handler(void *ignored) +{ + countTask_handler = true; +} + void *countTaskDeferred(void *ignored) { int i=0; int type,state; - + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &type); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &state); while (1) { @@ -43,10 +48,17 @@ void *countTaskAsync(void *ignored) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &type); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &state); + pthread_cleanup_push(countTask_cancel_handler, NULL); while (1) { printf("countTaskAsync: elapsed time (second): %2d\n", i++ ); sleep(1); } + countTask_handler = false; + pthread_cleanup_pop(1); + if ( countTask_handler == false ){ + puts("countTask_cancel_handler not executed"); + rtems_test_exit(0); + } } #if defined(__rtems__) @@ -56,15 +68,33 @@ void *countTaskAsync(void *ignored) #endif { pthread_t task; - int taskparameter = 0; + int taskparameter = 0; + int sc; + int old; puts( "\n\n*** POSIX CANCEL TEST ***" ); + /* generate some error conditions */ + puts( "Init - pthread_setcancelstate - NULL oldstate - EINVAL" ); + sc = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + fatal_posix_service_status( sc, EINVAL, "cancel state EINVAL" ); + + puts( "Init - pthread_setcancelstate - bad state - EINVAL" ); + sc = pthread_setcancelstate(12, &old); + fatal_posix_service_status( sc, EINVAL, "cancel state EINVAL" ); + + puts( "Init - pthread_setcanceltype - NULL oldtype - EINVAL" ); + sc = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); + fatal_posix_service_status( sc, EINVAL, "cancel type EINVAL" ); + + puts( "Init - pthread_setcanceltype - bad type - EINVAL" ); + sc = pthread_setcanceltype(12, &old); + fatal_posix_service_status( sc, EINVAL, "cancel type EINVAL" ); + /* Start countTask deferred */ { - int task_ret; - task_ret = pthread_create(&task, NULL, countTaskDeferred, &taskparameter); - if (task_ret) { + sc = pthread_create(&task, NULL, countTaskDeferred, &taskparameter); + if (sc) { perror("pthread_create: countTask"); rtems_test_exit(EXIT_FAILURE); } @@ -76,9 +106,8 @@ void *countTaskAsync(void *ignored) /* Start countTask asynchronous */ { - int task_ret; - task_ret = pthread_create(&task, NULL, countTaskAsync, &taskparameter); - if (task_ret) { + sc = pthread_create(&task, NULL, countTaskAsync, &taskparameter); + if (sc) { perror("pthread_create: countTask"); rtems_test_exit(EXIT_FAILURE); } diff --git a/testsuites/psxtests/psxcancel/psxcancel.doc b/testsuites/psxtests/psxcancel/psxcancel.doc new file mode 100644 index 0000000000..07dbc62a69 --- /dev/null +++ b/testsuites/psxtests/psxcancel/psxcancel.doc @@ -0,0 +1,46 @@ +# +# $Id$ +# +# COPYRIGHT (c) 1989-2009. +# On-Line Applications Research Corporation (OAR). +# +# The license and distribution terms for this file may be +# found in the file LICENSE in this distribution or at +# http://www.rtems.com/license/LICENSE. +# + +This file describes the directives and concepts tested by this test set. + +test set name: psxcancel + +directives: + + pthread_setcancelstate + pthread_setcanceltype + pthread_testcancel + pthread_cleanup_push + pthread_cleanup_pop + pthread_create + pthread_cancel + pthread_join + +concepts: + ++ Verify that setting cancellation state and type to various + combinations of enable/disable and deferred/asynchronous works + as expected. + ++ Verify that cleanup handlers that have been pushed do indeed run + as expected at at cancellation point. + ++ Exercise argument checking error cases in pthread_setcancelstate and + pthread_setcanceltype. + associated one mutex instance that it is an error for another task + to attempt to block on the same condition variable using a different + mutex. + ++ Verify error conditions in pthread_mutexattr_settype + ++ Verify normal paths through pthread_mutexattr_gettype + ++ Verify normal paths through pthread_mutexattr_settype diff --git a/testsuites/psxtests/psxcancel/psxcancel.scn b/testsuites/psxtests/psxcancel/psxcancel.scn index bb5c7d58e0..255e9242ce 100644 --- a/testsuites/psxtests/psxcancel/psxcancel.scn +++ b/testsuites/psxtests/psxcancel/psxcancel.scn @@ -1,6 +1,8 @@ - - *** POSIX CANCEL TEST *** +Init - pthread_setcancelstate - NULL oldstate - EINVAL +Init - pthread_setcancelstate - bad state - EINVAL +Init - pthread_setcanceltype - NULL oldtype - EINVAL +Init - pthread_setcanceltype - bad type - EINVAL countTaskDeferred: elapsed time (second): 0 countTaskDeferred: elapsed time (second): 1 countTaskDeferred: elapsed time (second): 2 -- cgit v1.2.3