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  * sem_post shall unlock the locked semaphore and increment the semaphore
     11  * value by one.
     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 "1-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 	int val;
     31 
     32 	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
     33 
     34 	/* Initial value of Semaphore is 0 */
     35 	mysemp = sem_open(semname, O_CREAT, 0777, 0);
     36 	if (mysemp == SEM_FAILED || mysemp == NULL) {
     37 		perror(ERROR_PREFIX "sem_open");
     38 		return PTS_UNRESOLVED;
     39 	}
     40 
     41 	if (sem_post(mysemp) == -1) {
     42 		perror(ERROR_PREFIX "sem_post");
     43 		return PTS_UNRESOLVED;
     44 	}
     45 
     46 	if (sem_getvalue(mysemp, &val) == -1) {
     47 		perror(ERROR_PREFIX "sem_getvalue");
     48 		return PTS_UNRESOLVED;
     49 
     50 		/* Checking if the value of the Semaphore incremented by one */
     51 	} else if (val == 1) {
     52 		puts("TEST PASSED");
     53 		sem_close(mysemp);
     54 		sem_unlink(semname);
     55 		return PTS_PASS;
     56 	} else {
     57 		puts("TEST FAILED");
     58 		return PTS_FAIL;
     59 	}
     60 }
     61