source: rtems/testsuites/sptests/spfifo05/init.c @ feddcde0

5
Last change on this file since feddcde0 was feddcde0, checked in by Sebastian Huber <sebastian.huber@…>, on 01/08/19 at 08:08:27

tests: Remove bogus RTEMS_INTERRUPT_LEVEL(31)

It is unnecessary to run these test cases with interrupts disabled.

  • Property mode set to 100644
File size: 7.7 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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 <bsp.h>
15#include <tmacros.h>
16#include <stdio.h>
17#include <sys/types.h>
18#include <sys/stat.h>
19#include <sys/ioctl.h>
20#include <fcntl.h>
21#include <unistd.h>
22#include <errno.h>
23#include <limits.h>
24
25#include <rtems.h>
26#include <rtems/libio.h>
27
28const char rtems_test_name[] = "SPFIFO 5";
29
30/* forward declarations to avoid warnings */
31rtems_task Init(rtems_task_argument argument);
32rtems_task read_task(rtems_task_argument not_used);
33
34#define SEND_RCV_BUFSIZ       (PIPE_BUF+20)
35
36rtems_id rBarrier;
37rtems_id wBarrier;
38
39char recvBuf[SEND_RCV_BUFSIZ] = {0};
40char sendBuf[SEND_RCV_BUFSIZ] = {0};
41
42rtems_task read_task(rtems_task_argument not_used)
43{
44  int fd = 0;
45  int status = -1;
46  uint32_t released = 0;
47
48  puts( "read_task - opening /fifo in non-blocking mode" );
49
50  fd = open( "/fifo", O_RDONLY | O_NONBLOCK );
51  if( fd <= 0 ) {
52    printf( "Error opening file: (%d) :: %s\n", errno, strerror( errno ) );
53    rtems_test_assert( 0 );
54  }
55
56  puts( "read_task - attempt to read with number of writers = 0" );
57  status = read( fd, recvBuf, SEND_RCV_BUFSIZ );
58  rtems_test_assert( status == 0 );
59
60  puts( "read_task - releasing the write task" );
61  status = rtems_barrier_release( wBarrier, &released );
62  rtems_test_assert( status == 0 );
63
64  puts( "read_task - waiting at a barrier" );
65  status = rtems_barrier_wait( rBarrier, RTEMS_NO_TIMEOUT );
66  rtems_test_assert( status == RTEMS_SUCCESSFUL );
67
68  puts( "read_task - attempting to read from the fifo -- Expect EAGAIN" );
69  status = read( fd, recvBuf, SEND_RCV_BUFSIZ );
70  rtems_test_assert( status == -1 );
71  rtems_test_assert( errno == EAGAIN );
72
73  puts( "read_task - closing /fifo" );
74  status = close( fd );
75  rtems_test_assert( status == 0 );
76
77  puts("read_task - opening /fifo in read-only mode");
78  fd = open( "/fifo", O_RDONLY );
79  if( fd <= 0 ) {
80    printf( "Error opening file: (%d) :: %s\n", errno, strerror( errno ) );
81    rtems_test_assert( 0 );
82  }
83
84  puts( "read_task - releasing the write task" );
85  status = rtems_barrier_release( wBarrier, &released );
86  rtems_test_assert( status == 0 );
87
88  puts( "read_task - reading from /fifo - OK" );
89  status = read( fd, recvBuf, 10 );
90  rtems_test_assert( status == 10 );
91
92  puts( "read_task - reading from /fifo - OK" );
93  status = read( fd, recvBuf+10, 10 );
94  rtems_test_assert( status == 10 );
95
96  puts( "read_task - waiting at a barrier" );
97  status = rtems_barrier_wait( rBarrier, RTEMS_NO_TIMEOUT );
98  rtems_test_assert( status == RTEMS_SUCCESSFUL );
99
100  puts( "read_task - reading from /fifo - OK" );
101  status = read( fd, recvBuf+20, SEND_RCV_BUFSIZ - 20 );
102  rtems_test_assert( status == SEND_RCV_BUFSIZ - 20 );
103
104  if( strcmp( sendBuf, recvBuf ) ) {
105    puts( "Sent, received buffer do not match" );
106    rtems_test_assert( 0 );
107  }
108
109  puts( "read_task - releasing the write task" );
110  status = rtems_barrier_release( wBarrier, &released );
111  rtems_test_assert( status == 0 );
112
113  puts( "read_task - waiting at a barrier" );
114  status = rtems_barrier_wait( rBarrier, RTEMS_NO_TIMEOUT );
115  rtems_test_assert( status == RTEMS_SUCCESSFUL );
116
117  status = close( fd );
118  rtems_test_assert( status == 0 );
119
120  puts( "read_task - releasing the write task" );
121  status = rtems_barrier_release( wBarrier, &released );
122  rtems_test_assert( status == 0 );
123
124  rtems_task_exit();
125}
126
127rtems_task Init(
128  rtems_task_argument not_used
129)
130{
131  rtems_id readTaskID;
132
133  rtems_name readTaskName;
134
135  int status = -1;
136  int fd = 0;
137  uint32_t released = 0;
138  int flag = 1;
139
140  TEST_BEGIN();
141
142  memset( sendBuf, '1', SEND_RCV_BUFSIZ - 30 );
143  memset( sendBuf, '2', 29 );
144  sendBuf[SEND_RCV_BUFSIZ-1] = 0;
145
146  memset( &rBarrier, 0, sizeof(rBarrier) );
147  status = rtems_barrier_create (
148    rtems_build_name ( 'B', 'A', 'R', 'r' ),
149    RTEMS_BARRIER_MANUAL_RELEASE,
150    2,
151    &rBarrier
152    );
153
154  rtems_test_assert( status == RTEMS_SUCCESSFUL );
155
156  memset( &wBarrier, 0, sizeof( wBarrier ) );
157  status = rtems_barrier_create (
158    rtems_build_name ( 'B', 'A', 'R', 'w' ),
159    RTEMS_BARRIER_MANUAL_RELEASE,
160    2,
161    &wBarrier
162    );
163  rtems_test_assert( status == RTEMS_SUCCESSFUL );
164
165  readTaskName = rtems_build_name( 'T','A','r',' ' );
166  status = rtems_task_create(
167                             readTaskName,
168                             1,
169                             RTEMS_MINIMUM_STACK_SIZE * 2,
170                             RTEMS_DEFAULT_MODES,
171                             RTEMS_DEFAULT_ATTRIBUTES,
172                             &readTaskID
173                             );
174 
175  rtems_test_assert( status == RTEMS_SUCCESSFUL );
176
177  puts( "Init - Creating fifo file /fifo" );
178  status = mkfifo( "/fifo", 0777 );
179  rtems_test_assert( status == 0 );
180
181  puts( "Init - starting the read task" );
182  status = rtems_task_start( readTaskID, read_task, 0 );
183  rtems_test_assert( status == 0 );
184
185  puts( "Init - waiting at a barrier" );
186  status = rtems_barrier_wait( wBarrier, RTEMS_NO_TIMEOUT );
187  rtems_test_assert( status == RTEMS_SUCCESSFUL );
188
189  puts("Init - opening the fifo in write only mode -- OK");
190  fd = open("/fifo", O_WRONLY);
191  if(fd <= 0) {
192    printf("Error opening file: (%d) :: %s\n", errno, strerror(errno));
193    rtems_test_assert(0);
194  }
195
196  puts( "Init - writing to /fifo" );
197  status = write(fd, sendBuf, 0 );
198  rtems_test_assert( status == 0 );
199
200  puts( "Init - releasing the read_task" );
201  status = rtems_barrier_release( rBarrier, &released );
202  rtems_test_assert( status == 0 );
203
204  puts( "Init - waiting at a barrier" );
205  status = rtems_barrier_wait( wBarrier, RTEMS_NO_TIMEOUT );
206  rtems_test_assert( status == RTEMS_SUCCESSFUL );
207 
208  puts( "Init - writing to /fifo - OK" );
209  status = write(fd, sendBuf, SEND_RCV_BUFSIZ - 30 );
210  rtems_test_assert( status == SEND_RCV_BUFSIZ - 30 );
211
212  puts( "Init - writing to /fifo - OK" );
213  status = write(fd, sendBuf+SEND_RCV_BUFSIZ - 30, 30 );
214  rtems_test_assert( status == 30 );
215
216  puts( "Init - releasing the read_task" );
217  status = rtems_barrier_release( rBarrier, &released );
218  rtems_test_assert( status == 0 );
219
220  puts( "Init - waiting at a barrier" );
221  status = rtems_barrier_wait( wBarrier, RTEMS_NO_TIMEOUT );
222  rtems_test_assert( status == RTEMS_SUCCESSFUL ); 
223
224  puts( "Init - converting the write-mode to non-block" );
225  status = ioctl( fd, FIONBIO, &flag );
226  rtems_test_assert( status == 0 );
227
228  puts( "Init - writing to /fifo - OK" );
229  status = write(fd, sendBuf, SEND_RCV_BUFSIZ - 30 );
230  rtems_test_assert( status == SEND_RCV_BUFSIZ - 30 );
231 
232  puts( "Init - writing to /fifo - Expect EAGAIN" );
233  status = write(fd, sendBuf, SEND_RCV_BUFSIZ - 30 );
234  rtems_test_assert( status == -1 );
235  rtems_test_assert( errno == EAGAIN );
236
237  puts( "Init - releasing the read_task" );
238  status = rtems_barrier_release( rBarrier, &released );
239  rtems_test_assert( status == 0 );
240
241  puts( "Init - waiting at a barrier" );
242  status = rtems_barrier_wait( wBarrier, RTEMS_NO_TIMEOUT );
243  rtems_test_assert( status == RTEMS_SUCCESSFUL ); 
244
245  puts( "Init - writing to /fifo - Expect EPIPE" );
246  status = write(fd, sendBuf, SEND_RCV_BUFSIZ - 30 );
247  rtems_test_assert( status == -1 );
248  rtems_test_assert( errno == EPIPE );
249
250  status = close( fd );
251  rtems_test_assert( status == 0 );
252
253  puts( "Removing the fifo" );
254  status = unlink("/fifo");
255  rtems_test_assert(status == 0);
256 
257  TEST_END();
258  rtems_test_exit(0);
259}
260
261#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
262#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
263
264#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
265
266#define CONFIGURE_MAXIMUM_TASKS 3
267
268#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
269
270#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
271
272#define CONFIGURE_MAXIMUM_BARRIERS 2
273
274#define CONFIGURE_MAXIMUM_FIFOS 1
275
276#define CONFIGURE_DISABLE_SMP_CONFIGURATION
277
278#define CONFIGURE_INIT
279#include <rtems/confdefs.h>
280
281/* end of file */
Note: See TracBrowser for help on using the repository browser.