Home | History | Annotate | Download | only in sem_post
      1 /*
      2     Copyright (c) 2003, Intel Corporation. All rights reserved.
      3     Created by:  majid.awad 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 
      9 /*
     10  * This test case verifies the semaphore value is 0, then shows a successful
     11  * call to release the unlock from mysemp.
     12  */
     13 
     14 #include <stdio.h>
     15 #include <errno.h>
     16 #include <unistd.h>
     17 #include <semaphore.h>
     18 #include <sys/stat.h>
     19 #include <fcntl.h>
     20 #include "posixtest.h"
     21 
     22 #define TEST "2-1"
     23 #define FUNCTION "sem_post"
     24 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
     25 
     26 int main(void)
     27 {
     28 	sem_t *mysemp;
     29 	char semname[28];
     30 
     31 	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
     32 
     33 	/* Initial value of Semaphore is 0 */
     34 	mysemp = sem_open(semname, O_CREAT, 0777, 1);
     35 	if (mysemp == SEM_FAILED || mysemp == NULL) {
     36 		perror(ERROR_PREFIX "sem_open");
     37 		return PTS_UNRESOLVED;
     38 	}
     39 
     40 	if (sem_wait(mysemp) == -1) {
     41 		perror(ERROR_PREFIX "sem_post");
     42 		return PTS_UNRESOLVED;
     43 	}
     44 
     45 	if (sem_post(mysemp) == 0) {
     46 		puts("TEST PASSED");
     47 		sem_close(mysemp);
     48 		sem_unlink(semname);
     49 		return PTS_PASS;
     50 	} else {
     51 		puts("TEST FAILED: value of sem_post is not zero");
     52 		return PTS_FAIL;
     53 	}
     54 
     55 }
     56