1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * This file is licensed under the GPL license. For the full content 4 * of this license, see the COPYING file at the top level of this 5 * source tree. 6 7 * Test pthread_spin_lock(pthread_spinlock_t *lock) 8 * 9 * 35543 These functions may fail if: 10 * 35544 [EINVAL] The value specified by lock does not 11 * refer to an initialized spin lock object. 12 * 13 * This case will always pass. 14 */ 15 16 #define _XOPEN_SOURCE 600 17 #include <pthread.h> 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <unistd.h> 21 #include <signal.h> 22 #include <errno.h> 23 #include <string.h> 24 #include "posixtest.h" 25 26 int rc; 27 28 static void sig_handler() 29 { 30 printf("main: interrupted by SIGALARM\n"); 31 if (rc == EINVAL) { 32 printf("main: correctly got EINVAL\n"); 33 printf("Test PASSED\n"); 34 } else { 35 printf("main: get return code: %d, %s\n", rc, strerror(rc)); 36 printf 37 ("Test PASSED: *Note: Did not return EINVAL when attempting to lock an uninitialized spinlock, but standard says 'may' fail\n"); 38 } 39 40 exit(PTS_PASS); 41 } 42 43 int main(void) 44 { 45 pthread_spinlock_t spinlock; 46 struct sigaction act; 47 48 /* Set up child thread to handle SIGALRM */ 49 act.sa_flags = 0; 50 act.sa_handler = sig_handler; 51 sigfillset(&act.sa_mask); 52 sigaction(SIGALRM, &act, 0); 53 54 printf("main: attemp to lock an un-initialized spin lock\n"); 55 56 printf("main: Send SIGALRM to me after 5 secs\n"); 57 alarm(5); 58 59 /* Attempt to lock an uninitialized spinlock */ 60 rc = pthread_spin_lock(&spinlock); 61 62 /* If we get here, call sig_handler() to check the return code of 63 * pthread_spin_lock() */ 64 sig_handler(); 65 66 /* Unlock spinlock */ 67 pthread_spin_unlock(&spinlock); 68 69 /* Destroy spinlock */ 70 pthread_spin_destroy(&spinlock); 71 72 return PTS_PASS; 73 } 74