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 will call sem_getvalue to update the location referenced
11 * by the semaphpre without effecting the state of the semaphore.  The
12 * updated value represents the actual semaphore value when it was called.
13*/
14
15
16
17#include <stdio.h>
18#include <errno.h>
19#include <unistd.h>
20#include <semaphore.h>
21#include <sys/stat.h>
22#include <fcntl.h>
23#include "posixtest.h"
24
25#define TEST "1-1"
26#define FUNCTION "sem_getvalue"
27#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
28
29
30int main() {
31
32	char semname[50];
33	sem_t *mysemp;
34	int val;
35
36	sprintf(semname, "/" FUNCTION "_" TEST "_%ld", (long)getpid());
37
38	mysemp = sem_open(semname, O_CREAT, 0777, 1);
39
40	if( mysemp == SEM_FAILED || mysemp == NULL ) {
41		perror(ERROR_PREFIX "sem_open");
42		return PTS_UNRESOLVED;
43	}
44
45	if( sem_getvalue(mysemp, &val) == -1 ) {
46		perror(ERROR_PREFIX "sem_getvalue");
47		return PTS_UNRESOLVED;
48	}
49
50	/*
51	printf("Current value is: %d\n", val);
52	*/
53	if (val == 1 ) {
54		puts("TEST PASSED");
55		sem_close(mysemp);
56		sem_unlink(semname);
57		return PTS_PASS;
58	} else {
59		puts("TEST FAILED");
60		return PTS_FAIL;
61	}
62}
63
64