source: rtems/testsuites/sptests/spfifo02/init.c @ 287febb5

4.11
Last change on this file since 287febb5 was 287febb5, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 24, 2010 at 7:46:40 PM

2010-06-24 Bharath Suri <bharath.s.jois@…>

  • Makefile.am, configure.ac: Removed some fifo tests.
  • spfifo01/Makefile.am, spfifo01/init.c: Minor changes to avoid excessive new lines in the output.

spfifo02/Makefile.am, spfifo02/init.c, spfifo02/spfifo02.doc,
spfifo02/spfifo02.scn, spfifo03/Makefile.am: Merge from spfifo08.
Also added a few more cases, mostly from spfifo04/init.c.

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