source: rtems/testsuites/sptests/spfifo08/init.c @ b34685f4

4.11
Last change on this file since b34685f4 was b34685f4, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 20, 2010 at 10:16:25 PM

2010-06-20 Joel Sherrill <joel.sherrill@…>

  • spfifo08/init.c: Catch more cases but discussion on errors and proper behaviour remain.
  • Property mode set to 100644
File size: 3.9 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
21#define MAXIMUM 10
22rtems_id Barriers[MAXIMUM];
23int BarrierCount;
24
25rtems_id Semaphores[MAXIMUM];
26int SemaphoreCount;
27
28void create_all_barriers(void)
29{
30  rtems_status_code status;
31  int               i;
32
33  BarrierCount = 0;
34
35  memset( Barriers, 0, sizeof(Barriers) );
36  for ( i=0 ; i<MAXIMUM ; i++ ) {
37    status = rtems_barrier_create(
38      rtems_build_name( 'B', 'A', 'R', 0x30+i ),
39      RTEMS_BARRIER_MANUAL_RELEASE,
40      0,
41      &Barriers[i]
42    );
43    if ( status == RTEMS_TOO_MANY ) {
44      printf( "%d Barriers created\n", BarrierCount+1 );
45      return;
46    } 
47
48    directive_failed( status, "barrier create" );
49    BarrierCount++;
50  }
51}
52
53void create_all_semaphores(void)
54{
55  rtems_status_code status;
56  int               i;
57
58  SemaphoreCount = 0;
59
60  for ( i=0 ; i<MAXIMUM ; i++ ) {
61    status = rtems_semaphore_create(
62      rtems_build_name( 'S', 'E', 'M', 0x30+i ),
63      0,
64      RTEMS_DEFAULT_ATTRIBUTES,
65      0,
66      &Semaphores[i]
67    );
68    if ( status == RTEMS_TOO_MANY ) {
69      printf( "%d Semaphores created\n", SemaphoreCount+1 );
70      return;
71    } 
72
73    directive_failed( status, "semaphore create" );
74    SemaphoreCount++;
75  }
76}
77
78void delete_barrier(void)
79{
80  rtems_status_code status;
81 
82  BarrierCount--;
83  printf( "Deleting barrier id=0x%08x\n",
84    (unsigned int)Barriers[BarrierCount] );
85  status = rtems_barrier_delete( Barriers[BarrierCount] );
86  directive_failed( status, "barrier delete" );
87}
88
89void delete_semaphore(void)
90{
91  rtems_status_code status;
92 
93  SemaphoreCount--;
94  printf( "Deleting semaphore id=0x%08x\n",
95    (unsigned int) Semaphores[SemaphoreCount] );
96  status = rtems_semaphore_delete( Semaphores[SemaphoreCount] );
97  directive_failed( status, "semaphore delete" );
98}
99
100void create_fifo(void)
101{
102  int status;
103
104  status = mkfifo("/fifo01", 0777);
105  rtems_test_assert(status == 0);
106}
107
108void open_fifo(int expected)
109{
110  int fd;
111
112  fd = open("/fifo01", O_RDONLY);
113  printf( "status=%d errno=%d/(%s)\n", fd, errno, strerror(errno) );
114  if ( expected ) {
115    rtems_test_assert(fd == -1);
116    rtems_test_assert(errno == expected); 
117  } else {
118    rtems_test_assert(fd != -1);
119    close( fd );
120  }
121}
122
123rtems_task Init(
124  rtems_task_argument argument
125)
126{
127  puts( "\n\n*** TEST FIFO 08 ***" );
128
129  puts( "Creating all barriers" );
130  create_all_barriers();
131
132  puts( "Creating all semaphores" );
133  create_all_semaphores();
134
135  puts( "Creating FIFO" );
136  create_fifo();
137 
138  puts( "Opening FIFO.. expect ENFILE (barrier - case 1)" );
139  open_fifo(ENFILE); /* XXX ENOMEM */
140
141  delete_barrier();
142  puts( "Opening FIFO.. expect ENFILE (barrier - case 2)" );
143  open_fifo(ENFILE); /* XXX ENOMEM */
144
145  delete_barrier();
146  puts( "Opening FIFO.. expect ENFILE (semaphore - case 1)" );
147  open_fifo(ENFILE); /* XXX ENOMEM */
148
149  delete_semaphore();
150  puts( "Opening FIFO.. expect ERROR ???" );
151  open_fifo(EINTR); /* XXX ENOMEM */
152
153  delete_semaphore();
154  puts( "Opening FIFO.. expect ENOSPC???" );
155  open_fifo(ENOMEM);
156 
157  delete_semaphore();
158  puts( "Opening FIFO.. expect OK???" );
159  open_fifo(0);
160
161  puts( "*** END OF TEST FIFO 08 ***" );
162
163  rtems_test_exit(0);
164}
165
166/* configuration information */
167
168#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
169#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
170
171#define CONFIGURE_MAXIMUM_TASKS             1
172#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
173
174#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
175#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
176#define CONFIGURE_FIFOS_ENABLED
177#define CONFIGURE_MAXIMUM_FIFOS 1
178
179#define CONFIGURE_INIT
180
181#include <rtems/confdefs.h>
182/* end of file */
Note: See TracBrowser for help on using the repository browser.