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 The following test case initializes an unnamed semaphore with a value of 1, 11 and then check the value of the semaphore. 12 */ 13 14 #include <sys/types.h> 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 #define TEST "1-1" 24 #define FUNCTION "sem_init" 25 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 26 27 int main(void) 28 { 29 sem_t mysemp; 30 int sts; 31 int val; 32 33 sts = sem_init(&mysemp, 0, 1); 34 35 if (sem_getvalue(&mysemp, &val) == -1) { 36 perror(ERROR_PREFIX "sem_getvalue"); 37 return PTS_UNRESOLVED; 38 } 39 40 if ((sts == -1) && (val != 1)) { 41 puts("TEST FAILED"); 42 return PTS_FAIL; 43 } else { 44 puts("TEST PASSED"); 45 sem_destroy(&mysemp); 46 return PTS_PASS; 47 } 48 } 49