OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [psxtests/] [psxsem01/] [init.c] - Blame information for rev 562

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
#define CONFIGURE_INIT
2
#include "system.h"
3
#include <sched.h>
4
#include <fcntl.h>
5
#include <time.h>
6
#include <tmacros.h>
7
 
8
void *POSIX_Init(
9
  void *argument
10
)
11
{
12
  int             status;
13
  int             value;
14
  int             i;
15
  sem_t           sems[CONFIGURE_MAXIMUM_POSIX_SEMAPHORES];
16
  sem_t           sem2;
17
  sem_t           *n_sem1;
18
  sem_t           *n_sem2;
19
  struct timespec waittime;
20
  char            failure_msg[80];
21
 
22
  puts( "\n\n*** POSIX SEMAPHORE MANAGER TEST 1 ***" );
23
 
24
  puts( "Init: sem_init - SUCCESSFUL" );
25
  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; i++) {
26
    status = sem_init(&sems[i], 0, i);
27
    sprintf(failure_msg, "sem_init %d", i );
28
    fatal_posix_service_status( status, 0, failure_msg);
29
  }
30
  puts( "Init: sem_init - UNSUCCESSFUL (ENOSPC)" );
31
  status = sem_init(&sem2, 0, 1);
32
  fatal_posix_service_status( status, -1, "sem_init error return status");
33
  fatal_posix_service_status( errno, ENOSPC, "sem_init errorno ENOSPC" );
34
 
35
  puts( "Init: sem_init - UNSUCCESSFUL (ENOSYS -- pshared not supported)" );
36
  status = sem_init(&sem2, 1, 1);
37
  fatal_posix_service_status( status, -1, "sem_init error return status");
38
  fatal_posix_service_status( errno, ENOSYS, "sem_init errno set to ENOSYS");
39
 
40
  puts( "Init: sem_getvalue - SUCCESSFUL ");
41
  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; i++) {
42
    status = sem_getvalue(&sems[i], &value);
43
    sprintf( failure_msg, "sem_getvalue %d", i );
44
    fatal_posix_service_status( status, 0, failure_msg );
45
    fatal_posix_service_status( value, i, "sem_getvalue correct value" );
46
  }
47
  puts( "Init: sem_getvalue - UNSUCCESSFUL ");
48
  status = sem_getvalue(&sem2, &value);
49
  fatal_posix_service_status( status, -1, "sem_getvalue error return status");
50
  fatal_posix_service_status( errno, EINVAL, "sem_getvalue errno EINVAL");
51
 
52
  puts( "Init: sem_destroy - SUCCESSFUL" );
53
  status = sem_destroy(&sems[0]);
54
  fatal_posix_service_status( status, 0, "sem_destroy semaphore 0");
55
 
56
  puts( "Init: sem_destroy - UNSUCCESSFUL (EINVAL)" );
57
  status = sem_destroy(&sem2);
58
  fatal_posix_service_status( status, -1, "sem_destroy error return status");
59
  fatal_posix_service_status( errno, EINVAL, "sem_destroy errno EINVAL");
60
 
61
  puts( "Init: sem_wait - SUCCESSFUL" );
62
  status = sem_wait(&sems[1]);
63
  fatal_posix_service_status( status, 0, "sem_wait semaphore 1");
64
 
65
  puts( "Init: sem_wait - UNSUCCESSFUL (EINVAL)" );
66
  status = sem_wait(&sem2);
67
  fatal_posix_service_status( status, -1, "sem_wait error return status");
68
  fatal_posix_service_status( errno, EINVAL, "sem_wait errno EINVAL");
69
 
70
  puts( "Init: sem_post - SUCCESSFUL" );
71
  status = sem_post(&sems[1]);
72
  fatal_posix_service_status( status, 0, "sem_post semaphore 1");
73
 
74
  puts( "Init: sem_wait - SUCCESSFUL (after a sem_post)" );
75
  status = sem_wait(&sems[1]);
76
  fatal_posix_service_status( status, 0, "sem_wait semaphore 1");
77
 
78
  puts( "Init: sem_trywait - SUCCESSFUL" );
79
  status = sem_trywait(&sems[2]);
80
  fatal_posix_service_status( status, 0, "sem_trywait semaphore 2");
81
 
82
  puts( "Init: sem_trywait - UNSUCCESSFUL (EAGAIN)" );
83
  status = sem_trywait(&sems[1]);
84
  fatal_posix_service_status( status, -1, "sem_trywait error return status");
85
  fatal_posix_service_status( errno, EAGAIN, "sem_trywait errno EAGAIN");
86
 
87
  puts( "Init: sem_trywait - UNSUCCESSFUL (EINVAL)" );
88
  status = sem_trywait(&sem2);
89
  fatal_posix_service_status( status, -1, "sem_trywait error return status");
90
  fatal_posix_service_status( errno, EINVAL, "sem_trywait errno EINVAL");
91
 
92
  puts( "Init: sem_timedwait - SUCCESSFUL" );
93
  waittime.tv_sec = 0;
94
  waittime.tv_nsec = 100;
95
  status = sem_timedwait(&sems[2], &waittime);
96
  fatal_posix_service_status( status, 0, "sem_timedwait semaphore 2");
97
 
98
  puts( "Init: sem_timedwait - UNSUCCESSFUL (ETIMEDOUT)" );
99
  status = sem_timedwait(&sems[1], &waittime);
100
  fatal_posix_service_status( status, -1, "sem_timedwait error return status");
101
  fatal_posix_service_status( errno, ETIMEDOUT, "sem_timedwait errno ETIMEDOUT");
102
 
103
  puts( "Init: sem_timedwait - UNSUCCESSFUL (EINVAL)" );
104
  status = sem_timedwait(&sem2, &waittime);
105
  fatal_posix_service_status( status, -1, "sem_timedwait error return status");
106
  fatal_posix_service_status( errno, EINVAL, "sem_init errno EINVAL");
107
 
108
  puts( "Init: sem_post - UNSUCCESSFUL (EINVAL)" );
109
  status = sem_post(&sem2);
110
  fatal_posix_service_status( status, -1, "sem_post error return status");
111
  fatal_posix_service_status( errno, EINVAL, "sem_post errno EINVAL");
112
 
113
  puts( "Init: sem_destroy - SUCCESSFUL" );
114
  for (i = 1; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; i++) {
115
    status = sem_destroy(&sems[i]);
116
    sprintf( failure_msg, "sem_destroy %d", i );
117
    fatal_posix_service_status( status, 0, failure_msg );
118
  }
119
 
120
  /* Modes are currently unsupported */
121
 
122
  /*
123
   * Validate all sem_open return paths.
124
   */
125
 
126
  puts( "Init: sem_open - sem1 SUCCESSFUL" );
127
  n_sem1 = sem_open( "sem1", O_CREAT, 00777, 1 );
128
  assert( n_sem1 != SEM_FAILED );
129
 
130
  puts( "Init: sem_open - Create an Existing sem (EEXIST)" );
131
  n_sem2 = sem_open("sem1", O_CREAT | O_EXCL, 00777, 1);
132
  fatal_posix_service_status(
133
    (int) n_sem2, (int ) SEM_FAILED, "sem_open error return status" );
134
  fatal_posix_service_status( errno, EEXIST,  "sem_open errno EEXIST");
135
 
136
  puts( "Init: sem_open - Open new sem without create flag (ENOENT)" );
137
  n_sem2 = sem_open("sem3", O_EXCL, 00777, 1);
138
  fatal_posix_service_status(
139
    (int) n_sem2, (int ) SEM_FAILED, "sem_open error return status" );
140
  fatal_posix_service_status( errno, ENOENT,  "sem_open errno EEXIST");
141
 
142
  /*
143
   * XXX - Could not hit the following errors:
144
   *   E_POSIX_Semaphore_Create_support only fails if
145
   *     ENOSYS - When semaphore is shared between processes.
146
   *     ENOSPC - When out of memory.
147
   */
148
 
149
  /*
150
   * Validate we can wait on a semaphore opened with sem_open.
151
   */
152
 
153
  puts( "Init: sem_wait on sem1" );
154
  status = sem_wait(n_sem1);
155
  fatal_posix_service_status( status, 0, "sem_wait opened semaphore");
156
 
157
  /*
158
   * Validate a second open returns the same semaphore.
159
   */
160
 
161
  puts( "Init: sem_open - Open an existing sem ( same id )" );
162
  n_sem2 = sem_open("sem1", 0 );
163
  fatal_posix_service_status(
164
    (int) n_sem2, (int ) n_sem1, "sem_open error return status" );
165
 
166
  /*
167
   * Unlink the semaphore, then verify an open of the same name produces a
168
   * different semaphore.
169
   */
170
 
171
  puts( "Init: sem_unlink - sem1 SUCCESSFUL" );
172
  status = sem_unlink( "sem1" );
173
  fatal_posix_service_status( status, 0, "sem_unlink locked semaphore");
174
 
175
  puts( "Init: sem_open - Reopen sem1 SUCCESSFUL with a different id" );
176
  n_sem2 = sem_open( "sem1", O_CREAT | O_EXCL, 00777, 1);
177
  assert( n_sem2 != SEM_FAILED );
178
  assert( n_sem2 != n_sem1 );
179
 
180
  /*
181
   * Validate we can call close on a semaphore opened with sem_open.
182
   */
183
 
184
  puts( "Init: sem_close (1) - SUCCESSFUL" );
185
  status = sem_close( n_sem1 );
186
  fatal_posix_service_status( status, 0, "sem_close semaphore");
187
 
188
 
189
  /*
190
   * Validate it n_sem2 (the last open for sem1 name can be
191
   * correctly closed and unlinked.
192
   */
193
 
194
  puts( "Init: sem_close (2) - SUCCESSFUL" );
195
  status = sem_close( n_sem2 );
196
  fatal_posix_service_status( status, 0, "sem_close semaphore");
197
 
198
  puts( "Init: sem_unlink - sem1 (2) SUCCESSFUL" );
199
  status = sem_unlink( "sem1" );
200
  fatal_posix_service_status( status, 0, "sem_unlink locked semaphore");
201
 
202
  puts( "Init: sem_close - UNSUCCESSFUL (EINVAL)" );
203
  status = sem_close(n_sem2);
204
  fatal_posix_service_status( status, -1, "sem_close error return status");
205
  fatal_posix_service_status( errno, EINVAL, "sem_close errno EINVAL");
206
 
207
  puts( "Init: sem_unlink - UNSUCCESSFUL (ENOENT)" );
208
  status = sem_unlink("sem1");
209
  fatal_posix_service_status( status, -1, "sem_unlink error return status");
210
  fatal_posix_service_status( errno, ENOENT, "sem_close errno EINVAL");
211
 
212
 
213
  /*
214
   * Validate we can unlink (2)
215
   */
216
 
217
  puts( "Init: sem_unlink (NULL) - EINVAL" );
218
  status = sem_unlink( NULL );
219
  fatal_posix_service_status( status, -1, "sem_unlink error return status");
220
  fatal_posix_service_status( errno, EINVAL, "sem_unlink errno value");
221
 
222
  puts( "Init: sem_unlink (\"\") - EINVAL" );
223
  status = sem_unlink( "" );
224
  fatal_posix_service_status( status, -1, "sem_unlink error return status");
225
  fatal_posix_service_status( errno, EINVAL, "sem_unlink errno value");
226
 
227
  /*
228
   * XXX - Cant' create location OBJECTS_ERROR or OBJECTS_REMOTE.
229
   *       sem_close and sem_unlink.
230
   */
231
 
232
  puts( "Init: sem_unlink - UNSUCCESSFUL (ENOENT)" );
233
  status = sem_unlink("sem2");
234
  fatal_posix_service_status( status, -1, "sem_unlink error return status");
235
  fatal_posix_service_status( errno, ENOENT, "sem_unlink errno ENOENT");
236
  assert( (status == -1) && (errno == ENOENT) );
237
 
238
 
239
  /* Try adding in unlinking before closing... (can we still open?) */
240
 
241
  puts( "*** POSIX SEMAPHORE MANAGER TEST 1 COMPLETED ***" );
242
  exit(0);
243
 
244
  return NULL; /* just so the compiler thinks we returned something */
245
}
246
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.