1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Created by: rolla.n.selbak 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 * Test pthread_create() 9 * 10 * The signal state of the new thread will be initialized as so: 11 * 12 * - The signal mask shall be inherited from the created thread 13 * - The set of signals pending for the new thread shall be empty. 14 * 15 * Steps: 16 * 1. In main(), create a signal mask with a few signals in the set (SIGUSR1 and SIGUSR2). 17 * 2. Raise those signals in main. These signals now should be pending. 18 * 3. Create a thread using pthread_create(). 19 * 4. The thread should have the same signal mask, but no signals should be pending. 20 * 21 */ 22 23 #include <pthread.h> 24 #include <stdio.h> 25 #include <signal.h> 26 #include <string.h> 27 #include <stdlib.h> 28 #include "posixtest.h" 29 30 static sigset_t th_pendingset, th_sigmask; 31 32 static void *a_thread_func() 33 { 34 pthread_sigmask(SIG_SETMASK, NULL, &th_sigmask); 35 36 if (sigpending(&th_pendingset) != 0) { 37 printf("Error calling sigpending()\n"); 38 exit(PTS_UNRESOLVED); 39 } 40 41 return NULL; 42 } 43 44 int main(void) 45 { 46 pthread_t new_th; 47 sigset_t main_sigmask, main_pendingset; 48 int ret; 49 50 if ((sigemptyset(&main_sigmask) != 0) || 51 (sigemptyset(&main_pendingset) != 0)) { 52 perror("sigemptyset()"); 53 return PTS_UNRESOLVED; 54 } 55 56 if (sigaddset(&main_sigmask, SIGUSR1) != 0) { 57 perror("sigaddset(SIGUSR1)"); 58 return PTS_UNRESOLVED; 59 } 60 61 if (sigaddset(&main_sigmask, SIGUSR2) != 0) { 62 perror("sigaddset(SIGUSR2)"); 63 return PTS_UNRESOLVED; 64 } 65 66 ret = pthread_sigmask(SIG_SETMASK, &main_sigmask, NULL); 67 if (ret) { 68 fprintf(stderr, "pthread_sigmask(): %s\n", strerror(ret)); 69 return PTS_UNRESOLVED; 70 } 71 72 if (raise(SIGUSR1) != 0) { 73 printf("Could not raise SIGALRM\n"); 74 return PTS_UNRESOLVED; 75 } 76 if (raise(SIGUSR2) != 0) { 77 printf("Could not raise SIGALRM\n"); 78 return PTS_UNRESOLVED; 79 } 80 81 ret = pthread_create(&new_th, NULL, a_thread_func, NULL); 82 if (ret) { 83 fprintf(stderr, "pthread_create(): %s\n", strerror(ret)); 84 return PTS_UNRESOLVED; 85 } 86 87 ret = pthread_join(new_th, NULL); 88 if (ret) { 89 fprintf(stderr, "pthread_join(): %s\n", strerror(ret)); 90 return PTS_UNRESOLVED; 91 } 92 93 ret = sigismember(&th_sigmask, SIGUSR1); 94 if (ret == 0) { 95 printf("FAIL: SIGUSR1 not a member of new thread sigmask.\n"); 96 return PTS_FAIL; 97 } 98 if (ret != 1) { 99 perror("sigismember(sigmask, SIGUSR1)"); 100 return PTS_UNRESOLVED; 101 } 102 103 ret = sigismember(&th_sigmask, SIGUSR2); 104 if (ret == 0) { 105 printf("FAIL: SIGUSR2 not a member of new thread sigmask.\n"); 106 return PTS_FAIL; 107 } 108 if (ret != 1) { 109 perror("sigismember(sigmask, SIGUSR2)"); 110 return PTS_UNRESOLVED; 111 } 112 113 ret = sigismember(&th_pendingset, SIGUSR1); 114 if (ret == 1) { 115 printf("FAIL: SIGUSR1 is member of new thread pendingset.\n"); 116 return PTS_FAIL; 117 } 118 if (ret != 0) { 119 perror("sigismember(pendingset, SIGUSR1)"); 120 return PTS_UNRESOLVED; 121 } 122 123 ret = sigismember(&th_pendingset, SIGUSR2); 124 if (ret == 1) { 125 printf("FAIL: SIGUSR1 is member of new thread pendingset.\n"); 126 return PTS_FAIL; 127 } 128 if (ret != 0) { 129 perror("sigismember(pendingset, SIGUSR2)"); 130 return PTS_UNRESOLVED; 131 } 132 133 printf("Test PASSED\n"); 134 return PTS_PASS; 135 } 136