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
15#include <stdio.h>
16#include <errno.h>
17#include <unistd.h>
18#include <semaphore.h>
19#include <sys/stat.h>
20#include <fcntl.h>
21#include "posixtest.h"
22
23
24#define TEST "2-1"
25#define FUNCTION "sem_post"
26#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
27
28
29
30int main() {
31	sem_t *mysemp;
32	char semname[50];
33
34	sprintf(semname, "/" FUNCTION "_" TEST "_%ld", (long)getpid());
35
36	/* Initial value of Semaphore is 0 */
37	mysemp = sem_open(semname, O_CREAT, 0777, 1);
38	if( mysemp == SEM_FAILED || mysemp == NULL ) {
39		perror(ERROR_PREFIX "sem_open");
40		return PTS_UNRESOLVED;
41	}
42
43	if( sem_wait(mysemp) == -1 ) {
44		perror(ERROR_PREFIX "sem_post");
45		return PTS_UNRESOLVED;
46	}
47
48	if((  sem_post(mysemp)) == 0 ) {
49		puts("TEST PASSED");
50		sem_close(mysemp);
51		sem_unlink(semname);
52		return PTS_PASS;
53	} else {
54		puts("TEST FAILED: value of sem_post is not zero");
55		return PTS_FAIL;
56	}
57
58}
59
60