1 /* 2 * Copyright (c) 2002-3, 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 * Test that the pthread_kill() function shall return ESRCH when no 9 * thread could be found corresponding to that specified by the given 10 * thread ID. 11 * 12 * NOTE: Cannot find 6-1.c in PTS cvs. So write this one. 13 */ 14 15 #include <pthread.h> 16 #include <signal.h> 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <unistd.h> 20 #include <errno.h> 21 #include <string.h> 22 #include "posixtest.h" 23 24 void *thread_function(void *arg) 25 { 26 /* Does nothing */ 27 pthread_exit(NULL); 28 29 /* To please some compilers */ 30 return NULL; 31 } 32 33 int main(void) 34 { 35 pthread_t child_thread; 36 pthread_t invalid_tid; 37 38 int rc; 39 40 rc = pthread_create(&child_thread, NULL, thread_function, NULL); 41 if (rc != 0) { 42 printf("Error at pthread_create()\n"); 43 return PTS_UNRESOLVED; 44 } 45 46 rc = pthread_join(child_thread, NULL); 47 if (rc != 0) { 48 printf("Error at pthread_join()\n"); 49 return PTS_UNRESOLVED; 50 } 51 52 /* Now the child_thread exited, it is an invalid tid */ 53 memcpy(&invalid_tid, &child_thread, sizeof(pthread_t)); 54 55 if (pthread_kill(invalid_tid, 0) == ESRCH) { 56 printf("pthread_kill() returns ESRCH.\n"); 57 return PTS_PASS; 58 } 59 60 printf("Test Fail\n"); 61 return PTS_FAIL; 62 } 63