Home | History | Annotate | Download | only in pthread_rwlock_unlock
      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 that pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
      8  *
      9  *	It 'may' fail if:
     10  *	[EINVAL]  rwlock doesn't refer to an intialized read-write lock
     11  *	[EPERM]  the current thread doesn't hold the lock on the rwlock
     12  *
     13  *	Testing EINVAL in this test.
     14  *
     15  * Steps:
     16  *  1. Call pthread_rwlock_unlock with an uninitialized rwlock
     17  *  2. The test will pass even if it returns 0, but with a note stating that the standard
     18  *     states it 'may' fail.
     19  *
     20  */
     21 
     22 #define _XOPEN_SOURCE 600
     23 #include <pthread.h>
     24 #include <stdio.h>
     25 #include <stdlib.h>
     26 #include <unistd.h>
     27 #include <errno.h>
     28 #include "posixtest.h"
     29 
     30 int main(void)
     31 {
     32 	static pthread_rwlock_t rwlock;
     33 	int rc;
     34 
     35 #ifdef __linux__
     36 	printf("Unlocking uninitialized rwlock is undefined on Linux\n");
     37 	return PTS_UNSUPPORTED;
     38 #endif
     39 
     40 	rc = pthread_rwlock_unlock(&rwlock);
     41 	if (rc != 0) {
     42 		if (rc == EINVAL) {
     43 			printf("Test PASSED\n");
     44 			return PTS_PASS;
     45 		}
     46 
     47 		printf
     48 		    ("Test FAILED: Incorrect error code, expected 0 or EINVAL, got %d\n",
     49 		     rc);
     50 		return PTS_FAIL;
     51 	}
     52 
     53 	printf
     54 	    ("Test PASSED: Note*: Returned 0 instead of EINVAL, but standard specified _may_ fail.\n");
     55 	return PTS_PASS;
     56 }
     57