source: rtems/testsuites/sptests/spfifo02/init.c @ a0b1b5ed

4.115
Last change on this file since a0b1b5ed was a0b1b5ed, checked in by Sebastian Huber <sebastian.huber@…>, on 12/15/14 at 13:19:43

Delete CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM

This define was superfluous, undocumented and used inconsistently.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2014.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15#include "test_support.h"
16
17#include <sys/types.h>
18#include <sys/stat.h>
19#include <fcntl.h>
20#include <unistd.h>
21#include <errno.h>
22#include <rtems/libcsupport.h>
23
24const char rtems_test_name[] = "SPFIFO 2";
25
26/* forward declarations to avoid warnings */
27rtems_task Init(rtems_task_argument argument);
28void create_all_barriers(void);
29void create_all_semaphores(void);
30void delete_barrier(void);
31void delete_semaphore(void);
32void create_fifo(void);
33void open_fifo(int expected, int flags);
34
35#define MAXIMUM 10
36#define NUM_OPEN_REQ 26
37
38rtems_id Barriers[MAXIMUM];
39int BarrierCount;
40
41rtems_id Semaphores[MAXIMUM];
42int SemaphoreCount;
43
44void create_all_barriers(void)
45{
46  rtems_status_code status;
47  int               i;
48
49  BarrierCount = 0;
50
51  memset( Barriers, 0, sizeof(Barriers) );
52  for ( i=0 ; i<MAXIMUM ; i++ ) {
53    status = rtems_barrier_create(
54      rtems_build_name( 'B', 'A', 'R', 0x30+i ),
55      RTEMS_BARRIER_MANUAL_RELEASE,
56      0,
57      &Barriers[i]
58    );
59    if ( status == RTEMS_TOO_MANY ) {
60      printf( "%d Barriers created\n", BarrierCount+1 );
61      return;
62    }
63
64    directive_failed( status, "barrier create" );
65    BarrierCount++;
66  }
67}
68
69void create_all_semaphores(void)
70{
71  rtems_status_code status;
72  int               i;
73
74  SemaphoreCount = 0;
75
76  for ( i=0 ; i<MAXIMUM ; i++ ) {
77    status = rtems_semaphore_create(
78      rtems_build_name( 'S', 'E', 'M', 0x30+i ),
79      0,
80      RTEMS_DEFAULT_ATTRIBUTES,
81      0,
82      &Semaphores[i]
83    );
84    if ( status == RTEMS_TOO_MANY ) {
85      printf( "%d Semaphores created\n", SemaphoreCount+1 );
86      return;
87    }
88
89    directive_failed( status, "semaphore create" );
90    SemaphoreCount++;
91  }
92}
93
94void delete_barrier(void)
95{
96  rtems_status_code status;
97 
98  BarrierCount--;
99  printf( "Deleting barrier id=0x%08x\n",
100    (unsigned int)Barriers[BarrierCount] );
101  status = rtems_barrier_delete( Barriers[BarrierCount] );
102  directive_failed( status, "barrier delete" );
103}
104
105void delete_semaphore(void)
106{
107  rtems_status_code status;
108 
109  SemaphoreCount--;
110  printf( "Deleting semaphore id=0x%08x\n",
111    (unsigned int) Semaphores[SemaphoreCount] );
112  status = rtems_semaphore_delete( Semaphores[SemaphoreCount] );
113  directive_failed( status, "semaphore delete" );
114}
115
116void create_fifo(void)
117{
118  int status;
119
120  status = mkfifo("/fifo01", 0777);
121  rtems_test_assert(status == 0);
122}
123
124void open_fifo(int expected, int flags)
125{
126  int fd;
127
128  fd = open("/fifo01", flags);
129  printf( "expect status=%d errno=%d/(%s)\n", fd, errno, strerror(errno) );
130  if ( expected ) {
131    rtems_test_assert(fd == -1);
132    rtems_test_assert(errno == expected);
133  } else {
134    rtems_test_assert(fd != -1);
135    close( fd );
136  }
137}
138
139rtems_task Init(
140  rtems_task_argument argument
141)
142{
143  void *alloc_ptr = (void *)0;
144  int num_opens = 0;
145  int index = 0;
146
147  TEST_BEGIN();
148
149  puts( "Creating all barriers" );
150  create_all_barriers();
151
152  puts( "Creating all semaphores" );
153  create_all_semaphores();
154
155  puts( "Creating FIFO" );
156  create_fifo();
157
158  puts( "Opening FIFO.. expect ENOMEM (semaphore for pipe could not be created)" );
159  open_fifo(ENOMEM, O_RDWR);
160
161  delete_semaphore();
162
163  alloc_ptr = malloc( malloc_free_space() - 4 );
164  puts("Opening FIFO.. expect ENOMEM since no memory is available");
165  open_fifo(ENOMEM, O_RDWR);
166
167  free(alloc_ptr);
168  puts( "Opening FIFO.. expect ENOMEM (barrier-1 for pipe could not be created)" );
169  open_fifo(ENOMEM, O_RDWR);
170
171  delete_barrier();
172  puts( "Opening FIFO.. expect ENOMEM (barrier-2 for pipe could not be created" );
173  open_fifo(ENOMEM, O_RDWR);
174
175  delete_barrier();
176  puts( "Opening FIFO.. expect ENOMEM (semaphore-1 for pipe could not be created" );
177  open_fifo(ENOMEM, O_RDWR);
178
179  delete_semaphore();
180  puts( "Opening FIFO in RDWR mode. Expect OK" );
181  open_fifo(0, O_RDWR);
182  ++num_opens;
183
184  puts( "Opening FIFO in non blocking RDONLY mode. Expect OK");
185  open_fifo(0, O_RDONLY | O_NONBLOCK);
186  ++num_opens;
187
188  puts( "Opening FIFO in non blocking WRONLY mode. Expect ENXIO");
189  open_fifo(ENXIO, O_WRONLY | O_NONBLOCK);
190  ++num_opens;
191
192  puts("\nMultiple opens\n");
193  index = 0;
194  do {
195
196    printf("%d... ", index+1);
197    open_fifo(0, O_RDONLY | O_NONBLOCK);
198    ++index;
199  } while ( index < NUM_OPEN_REQ - num_opens );
200
201  TEST_END();
202
203  rtems_test_exit(0);
204}
205
206/* configuration information */
207
208#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
209#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
210
211#define CONFIGURE_MAXIMUM_TASKS             1
212#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
213
214#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
215
216#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
217#define CONFIGURE_FIFOS_ENABLED
218#define CONFIGURE_MAXIMUM_FIFOS 1
219
220#define CONFIGURE_INIT
221
222#include <rtems/confdefs.h>
223/* end of file */
Note: See TracBrowser for help on using the repository browser.