Home | History | Annotate | Download | only in pthread_sigmask
      1 /*
      2  * Copyright (c) 2003, Intel Corporation. All rights reserved.
      3  * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
      4  * This file is licensed under the GPL license.  For the full content
      5  * of this license, see the COPYING file at the top level of this
      6  * source tree.
      7 
      8  Steps:
      9  1. Call pthread_sigmask with a randomly generated
     10  value of  how that is checked to make sure it does not equal any of the three defined
     11  values of how which are SIG_SETMASK, SIG_BLOCK, or SIG_UNBLOCK. This should
     12  cause pthread_sigmask() to return EINVAL. If it doesn't, then fail, otherwise pass.
     13 
     14 */
     15 
     16 #include <pthread.h>
     17 #include <errno.h>
     18 #include <signal.h>
     19 #include <stdio.h>
     20 #include <stdlib.h>
     21 #include "posixtest.h"
     22 
     23 int get_rand()
     24 {
     25 
     26 	int r;
     27 	r = rand();
     28 	if ((r == SIG_BLOCK) || (r == SIG_SETMASK) || (r == SIG_UNBLOCK)) {
     29 		r = get_rand();
     30 	}
     31 	return r;
     32 }
     33 
     34 void *a_thread_func()
     35 {
     36 
     37 	int r = get_rand();
     38 	sigset_t actl;
     39 /*
     40 	printf("SIG_SETMASK=%d\n", SIG_SETMASK);
     41 	printf("SIG_BLOCK=%d\n", SIG_BLOCK);
     42 	printf("SIG_UNBLOCK=%d\n", SIG_UNBLOCK);
     43 	printf("r=%d\n", r);
     44 */
     45 	sigemptyset(&actl);
     46 	sigaddset(&actl, SIGABRT);
     47 
     48 	if (pthread_sigmask(r, &actl, NULL) != EINVAL) {
     49 		perror
     50 		    ("pthread_sigmask() did not fail even though invalid how parameter was passed to it.\n");
     51 		pthread_exit((void *)-1);
     52 	}
     53 
     54 	printf("PASS: pthread_sigmask returned the correct error value.\n");
     55 	pthread_exit(NULL);
     56 
     57 	/* To please some compilers */
     58 	return NULL;
     59 }
     60 
     61 int main(void)
     62 {
     63 
     64 	int *thread_return_value;
     65 
     66 	pthread_t new_thread;
     67 
     68 	if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
     69 		perror("Error creating new thread\n");
     70 		return PTS_UNRESOLVED;
     71 	}
     72 
     73 	if (pthread_join(new_thread, (void *)&thread_return_value) != 0) {
     74 		perror("Error in pthread_join()\n");
     75 		return PTS_UNRESOLVED;
     76 	}
     77 
     78 	if ((long)thread_return_value != 0) {
     79 		if ((long)thread_return_value == 1) {
     80 			printf("Test UNRESOLVED\n");
     81 			return PTS_UNRESOLVED;
     82 		} else if ((long)thread_return_value == -1) {
     83 			printf("Test FAILED\n");
     84 			return PTS_FAIL;
     85 		} else {
     86 			printf("Test UNRESOLVED\n");
     87 			return PTS_UNRESOLVED;
     88 		}
     89 	}
     90 	return PTS_PASS;
     91 }
     92