source: rtems/testsuites/psxtests/psxsem01/init.c @ 27eb3ec

4.104.114.84.95
Last change on this file since 27eb3ec was 27eb3ec, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 9, 1999 at 1:36:26 PM

New files.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1#define CONFIGURE_INIT
2#include "system.h"
3#include <sched.h>
4#include <fcntl.h>
5#include <time.h>
6
7void *POSIX_Init(
8  void *argument
9)
10{
11  int             status;
12  int             value;
13  int             i;
14  sem_t           sems[CONFIGURE_MAXIMUM_POSIX_SEMAPHORES];
15  sem_t           sem2;
16  sem_t           *n_sem1;
17  sem_t           *n_sem2;
18  sem_t           testsem;
19  struct timespec waittime;
20
21  puts( "\n\n*** POSIX SEMAPHORE MANAGER TEST 1 ***" );
22
23  puts( "Init: sem_init - SUCCESSFUL" );
24  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; i++) {
25    status = sem_init(&sems[i], 0, i);
26    assert( status == 0 );
27  }
28  puts( "Init: sem_init - UNSUCCESSFUL (ENOSPC)" );
29  status = sem_init(&sem2, 0, 1);
30  assert( (status == -1) && (errno == ENOSPC) );
31 
32  puts( "Init: sem_init - UNSUCCESSFUL (ENOSYS -- pshared not supported)" );
33  status = sem_init(&sem2, 1, 1);
34  assert( (status == -1) && (errno == ENOSYS) );
35 
36  puts( "Init: sem_getvalue - SUCCESSFUL ");
37  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; i++) {
38    status = sem_getvalue(&sems[i], &value);
39    assert( (status == 0) && (value == i) );
40  }
41  puts( "Init: sem_getvalue - UNSUCCESSFUL ");
42  status = sem_getvalue(&sem2, &value);
43  assert( (status == -1) && (errno == EINVAL) );
44
45  puts( "Init: sem_destroy - SUCCESSFUL" );
46  status = sem_destroy(&sems[0]);
47  assert( status == 0 );
48
49  puts( "Init: sem_destroy - UNSUCCESSFUL (EINVAL)" );
50  status = sem_destroy(&sem2);
51  assert( (status == -1) && (errno == EINVAL) );
52
53  puts( "Init: sem_wait - SUCCESSFUL" );
54  status = sem_wait(&sems[1]);
55  assert( status == 0);
56
57  puts( "Init: sem_wait - UNSUCCESSFUL (EINVAL)" );
58  status = sem_wait(&sem2);
59  assert( (status == -1) && (errno == EINVAL) );
60
61  puts( "Init: sem_post - SUCCESSFUL" );
62  status = sem_post(&sems[1]);
63  assert( status == 0 );
64
65  puts( "Init: sem_wait - SUCCESSFUL (after a sem_post)" );
66  status = sem_wait(&sems[1]);
67  assert( status == 0 );
68
69  puts( "Init: sem_trywait - SUCCESSFUL" );
70  status = sem_trywait(&sems[2]);
71  assert( status == 0 );
72
73  puts( "Init: sem_trywait - UNSUCCESSFUL (EAGAIN)" );
74  status = sem_trywait(&sems[1]);
75  assert( (status == -1) && (errno == EAGAIN) );
76
77  puts( "Init: sem_trywait - UNSUCCESSFUL (EINVAL)" );
78  status = sem_trywait(&sem2);
79  assert( (status == -1) && (errno == EINVAL) );
80
81  puts( "Init: sem_timedwait - SUCCESSFUL" );
82  waittime.tv_sec = 0;
83  waittime.tv_nsec = 100;
84  status = sem_timedwait(&sems[2], &waittime);
85  assert( status == 0 );
86
87  puts( "Init: sem_timedwait - UNSUCCESSFUL (ETIMEDOUT)" );
88  status = sem_timedwait(&sems[1], &waittime);
89  assert( (status == -1) && (errno == ETIMEDOUT) );
90
91  puts( "Init: sem_timedwait - UNSUCCESSFUL (EINVAL)" );
92  status = sem_timedwait(&sem2, &waittime);
93  assert( (status == -1) && (errno == EINVAL) );
94
95  puts( "Init: sem_post - UNSUCCESSFUL (EINVAL)" );
96  status = sem_post(&sem2);
97  assert( (status == -1) && (errno == EINVAL) );
98
99  puts( "Init: sem_destroy - SUCCESSFUL" );
100  for (i = 1; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; i++) {
101    status = sem_destroy(&sems[i]);
102    assert( status == 0);
103  }
104
105  /* Modes are currently unsupported */
106
107  puts( "Init: sem_open - SUCCESSFUL" );
108  n_sem1 = sem_open("sem1", O_CREAT, 00777, 1);
109  assert( n_sem1 != SEM_FAILED );
110
111  puts( "Init: sem_open - UNSUCCESSFUL (EEXIST)" );
112  n_sem2 = sem_open("sem1", O_CREAT | O_EXCL, 00777, 1);
113  assert( (n_sem2 == SEM_FAILED) && (errno == EEXIST) );
114
115  puts( "Init: sem_close - SUCCESSFUL" );
116  status = sem_close(n_sem1);
117  assert( status == 0);
118
119  /*
120  puts( "Init: sem_close - UNSUCCESSFUL (EINVAL)" );
121  status = sem_close(n_sem2);
122  assert( (status == -1) && (errno == EINVAL) );
123
124  puts( "Init: sem_unlink - SUCCESSFUL" );
125  status = sem_unlink("sem1");
126  assert( status == 0 );
127
128  puts( "Init: sem_unlink - UNSUCCESSFUL (ENOENT)" );
129  status = sem_unlink("sem2");
130  assert( (status == -1) && (errno == ENOENT) );
131  */
132
133  /* Try adding in unlinking before closing... (can we still open?) */
134
135  puts( "*** POSIX SEMAPHORE MANAGER TEST 1 COMPLETED ***" );
136  exit(0);
137
138  return NULL; /* just so the compiler thinks we returned something */
139}
Note: See TracBrowser for help on using the repository browser.