summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests/psxcancel/init.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-23 13:29:49 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-23 13:29:49 +0000
commit73dfaf83a11177c1b5c7740acae406d226a02bae (patch)
tree97cc851bae9283cf0235e10580a280c768da9994 /testsuites/psxtests/psxcancel/init.c
parent2009-07-22 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-73dfaf83a11177c1b5c7740acae406d226a02bae.tar.bz2
2009-07-23 Santosh G Vattam <vattam.santosh@gmail.com>
* psxcancel/Makefile.am, psxcancel/init.c, psxcancel/psxcancel.scn: Add multiple cases which complete coverage of thread cancellation. * psxcancel/psxcancel.doc: New file.
Diffstat (limited to '')
-rw-r--r--testsuites/psxtests/psxcancel/init.c55
1 files changed, 42 insertions, 13 deletions
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 <stdio.h>
#include <stdlib.h>
#include <pthread.h>
@@ -15,18 +14,24 @@
#include <errno.h>
#include <sched.h>
-
#if defined(__rtems__)
-#include <rtems.h>
-#include <bsp.h>
-#include <pmacros.h>
+ #include <rtems.h>
+ #include <bsp.h>
+ #include <pmacros.h>
#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);
}