source: rtems/testsuites/sptests/spfifo02/init.c @ 8ddd92d

5
Last change on this file since 8ddd92d was 8ddd92d, checked in by Sebastian Huber <sebastian.huber@…>, on 12/14/17 at 05:12:59

pipe: Use self-contained mutex

Update #2843.

  • Property mode set to 100644
File size: 3.7 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 delete_barrier(void);
30void create_fifo(void);
31void open_fifo(int expected, int flags);
32
33#define MAXIMUM 10
34#define NUM_OPEN_REQ 26
35
36rtems_id Barriers[MAXIMUM];
37int BarrierCount;
38
39rtems_id Semaphores[MAXIMUM];
40int SemaphoreCount;
41
42void create_all_barriers(void)
43{
44  rtems_status_code status;
45  int               i;
46
47  BarrierCount = 0;
48
49  memset( Barriers, 0, sizeof(Barriers) );
50  for ( i=0 ; i<MAXIMUM ; i++ ) {
51    status = rtems_barrier_create(
52      rtems_build_name( 'B', 'A', 'R', 0x30+i ),
53      RTEMS_BARRIER_MANUAL_RELEASE,
54      0,
55      &Barriers[i]
56    );
57    if ( status == RTEMS_TOO_MANY ) {
58      printf( "%d Barriers created\n", BarrierCount+1 );
59      return;
60    }
61
62    directive_failed( status, "barrier create" );
63    BarrierCount++;
64  }
65}
66
67void delete_barrier(void)
68{
69  rtems_status_code status;
70 
71  BarrierCount--;
72  printf( "Deleting barrier id=0x%08x\n",
73    (unsigned int)Barriers[BarrierCount] );
74  status = rtems_barrier_delete( Barriers[BarrierCount] );
75  directive_failed( status, "barrier delete" );
76}
77
78void create_fifo(void)
79{
80  int status;
81
82  status = mkfifo("/fifo01", 0777);
83  rtems_test_assert(status == 0);
84}
85
86void open_fifo(int expected, int flags)
87{
88  int fd;
89
90  fd = open("/fifo01", flags);
91  printf( "expect status=%d errno=%d/(%s)\n", fd, errno, strerror(errno) );
92  if ( expected ) {
93    rtems_test_assert(fd == -1);
94    rtems_test_assert(errno == expected);
95  } else {
96    rtems_test_assert(fd != -1);
97    close( fd );
98  }
99}
100
101rtems_task Init(
102  rtems_task_argument argument
103)
104{
105  void *alloc_ptr = (void *)0;
106  int num_opens = 0;
107  int index = 0;
108
109  TEST_BEGIN();
110
111  puts( "Creating all barriers" );
112  create_all_barriers();
113
114  puts( "Creating FIFO" );
115  create_fifo();
116
117  alloc_ptr = malloc( malloc_free_space() - 4 );
118  puts("Opening FIFO.. expect ENOMEM since no memory is available");
119  open_fifo(ENOMEM, O_RDWR);
120
121  free(alloc_ptr);
122  puts( "Opening FIFO.. expect ENOMEM (barrier-1 for pipe could not be created)" );
123  open_fifo(ENOMEM, O_RDWR);
124
125  delete_barrier();
126  puts( "Opening FIFO.. expect ENOMEM (barrier-2 for pipe could not be created" );
127  open_fifo(ENOMEM, O_RDWR);
128
129  delete_barrier();
130  puts( "Opening FIFO in RDWR mode. Expect OK" );
131  open_fifo(0, O_RDWR);
132  ++num_opens;
133
134  puts( "Opening FIFO in non blocking RDONLY mode. Expect OK");
135  open_fifo(0, O_RDONLY | O_NONBLOCK);
136  ++num_opens;
137
138  puts( "Opening FIFO in non blocking WRONLY mode. Expect ENXIO");
139  open_fifo(ENXIO, O_WRONLY | O_NONBLOCK);
140  ++num_opens;
141
142  puts("\nMultiple opens\n");
143  index = 0;
144  do {
145
146    printf("%d... ", index+1);
147    open_fifo(0, O_RDONLY | O_NONBLOCK);
148    ++index;
149  } while ( index < NUM_OPEN_REQ - num_opens );
150
151  TEST_END();
152
153  rtems_test_exit(0);
154}
155
156/* configuration information */
157
158#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
159#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
160
161#define CONFIGURE_MAXIMUM_TASKS             1
162#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
163
164#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
165
166#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
167#define CONFIGURE_MAXIMUM_FIFOS 1
168
169#define CONFIGURE_INIT
170
171#include <rtems/confdefs.h>
172/* end of file */
Note: See TracBrowser for help on using the repository browser.