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 26int rc; 27 28static void sig_handler() 29{ 30 printf("main: interrupted by SIGALARM\n"); 31 if(rc == EINVAL) 32 { 33 printf("main: correctly got EINVAL\n"); 34 printf("Test PASSED\n"); 35 } 36 else 37 { 38 printf("main: get return code: %d, %s\n", rc, strerror(rc)); 39 printf("Test PASSED: *Note: Did not return EINVAL when attempting to lock an uninitialized spinlock, but standard says 'may' fail\n"); 40 } 41 42 exit(PTS_PASS); 43} 44 45int main() 46{ 47 pthread_spinlock_t spinlock; 48 struct sigaction act; 49 50 /* Set up child thread to handle SIGALRM */ 51 act.sa_flags = 0; 52 act.sa_handler = sig_handler; 53 sigfillset(&act.sa_mask); 54 sigaction(SIGALRM, &act, 0); 55 56 printf("main: attemp to lock an un-initialized spin lock\n"); 57 58 printf("main: Send SIGALRM to me after 5 secs\n"); 59 alarm(5); 60 61 /* Attempt to lock an uninitialized spinlock */ 62 rc = pthread_spin_lock(&spinlock); 63 64 /* If we get here, call sig_handler() to check the return code of 65 * pthread_spin_lock() */ 66 sig_handler(); 67 68 /* Unlock spinlock */ 69 pthread_spin_unlock(&spinlock); 70 71 /* Destroy spinlock */ 72 pthread_spin_destroy(&spinlock); 73 74 return PTS_PASS; 75} 76