Home | History | Annotate | Download | only in pthread_mutex_destroy
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Created by:  bing.wei.liu 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 pthread_mutex_destroy()
      9  *   Upon succesful completion, it shall return a 0
     10  *
     11  */
     12 
     13 #include <pthread.h>
     14 #include <stdio.h>
     15 #include <errno.h>
     16 #include "posixtest.h"
     17 
     18 int main(void)
     19 {
     20 	pthread_mutex_t mutex;
     21 	int rc;
     22 
     23 	/* Initialize a mutex object */
     24 	if ((rc = pthread_mutex_init(&mutex, NULL)) != 0) {
     25 		fprintf(stderr, "Fail to initialize mutex, rc=%d\n", rc);
     26 		return PTS_UNRESOLVED;
     27 	}
     28 
     29 	if ((rc = pthread_mutex_destroy(&mutex)) == 0) {
     30 		printf("Test PASSED\n");
     31 		return PTS_PASS;
     32 	}
     33 
     34 	/* The following error codes are possible, but against assertion 5 */
     35 	else if (rc == EBUSY) {
     36 		fprintf(stderr,
     37 			"Detected an attempt to destroy a mutex in use\n");
     38 	} else if (rc == EINVAL) {
     39 		fprintf(stderr, "The value specified by 'mutex' is invalid\n");
     40 	}
     41 
     42 	/* Any other returned value means the test failed */
     43 	else {
     44 		printf("Test FAILED (error: %i)\n", rc);
     45 	}
     46 	return PTS_FAIL;
     47 }
     48