1 /* 2 * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. 3 * Created by: abisain REMOVE-THIS AT qualcomm 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 when a pthread_mutex_destroy is called on a 9 * locked mutex, it fails and returns EBUSY 10 11 * Steps: 12 * 1. Create a mutex 13 * 2. Lock the mutex 14 * 3. Try to destroy the mutex 15 * 4. Check that this may fail with EBUSY 16 */ 17 18 #include <pthread.h> 19 #include <stdio.h> 20 #include <stdlib.h> 21 #include <errno.h> 22 #include <unistd.h> 23 #include "posixtest.h" 24 25 #define TEST "4-2" 26 #define FUNCTION "pthread_mutex_destroy" 27 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 28 29 int main(void) 30 { 31 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 32 int rc = 0; 33 34 /* Lock the mutex */ 35 rc = pthread_mutex_lock(&mutex); 36 if (rc != 0) { 37 perror(ERROR_PREFIX "pthread_mutex_lock\n"); 38 exit(PTS_UNRESOLVED); 39 } 40 41 /* Try to destroy the locked mutex */ 42 rc = pthread_mutex_destroy(&mutex); 43 if (rc != EBUSY) { 44 printf(ERROR_PREFIX "Test PASS: Expected %d(EBUSY) got %d, " 45 "though the standard states 'may' fail\n", EBUSY, rc); 46 exit(PTS_PASS); 47 } 48 printf("Test PASSED\n"); 49 exit(PTS_PASS); 50 } 51