source: rtems/testsuites/sptests/spfifo03/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: 5.5 KB
Line 
1/*  Init
2 *
3 *  This routine is the initialization task for this test program.
4 *  It is a user initialization task and has the responsibility
5 *  of invoking the test routine
6 *
7 *  Input parameters:
8 *    not_used
9 *
10 *  Output parameters:  NONE
11 *
12 *  COPYRIGHT (c) 1989-1999.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.com/license/LICENSE.
18 *
19 *  $Id$
20 */
21
22/* Includes */
23#include <bsp.h>
24#include <tmacros.h>
25#include <stdio.h>
26#include <sys/types.h>
27#include <sys/stat.h>
28#include <fcntl.h>
29#include <unistd.h>
30#include <errno.h>
31
32#include <rtems.h>
33#include <rtems/libio.h>
34
35#define SEND_RCV_BUFSIZ 12
36rtems_id Barrier;
37
38rtems_task read_task(rtems_task_argument not_used)
39{
40  int fd = 0;
41  int status = -1;
42
43  char recvBuf_r1[SEND_RCV_BUFSIZ] = {0};
44  char recvBuf_r2[SEND_RCV_BUFSIZ] = {0};
45
46  puts("\nRead task activated, waiting till writer opens");
47
48  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
49  rtems_test_assert( status == RTEMS_SUCCESSFUL );
50
51  sleep(1);
52
53  puts("\nNow, reader opening file(1)"); 
54  fd = open("/tmp/fifo01", O_RDONLY);
55  if(fd <= 0) {
56    printf("Error opening file: (%d) :: %s", errno, strerror(errno));
57    rtems_test_assert(0);
58  }
59
60  status = read(fd, recvBuf_r1, sizeof(recvBuf_r1)-1);
61  rtems_test_assert(status == sizeof(recvBuf_r1)-1);
62
63  printf("\n@ receiver (being a unblocked reader): Got %s", recvBuf_r1);
64
65  status = close(fd);
66  rtems_test_assert(status == 0);
67
68  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
69  rtems_test_assert( status == RTEMS_SUCCESSFUL );
70 
71  puts("\nReader opening file(2)");
72  fd = open("/tmp/fifo01", O_RDONLY);
73  if(fd <= 0) {
74    printf("Error opening file: (%d) :: %s", errno, strerror(errno));
75    rtems_test_assert(0);
76  }
77
78  status = read(fd, recvBuf_r2, sizeof(recvBuf_r2)-1);
79  rtems_test_assert(status == sizeof(recvBuf_r2)-1);
80
81  printf("\n@ receiver (being a blocked reader): Got %s", recvBuf_r2);
82
83  status = close(fd);
84  rtems_test_assert(status == 0);
85 
86 
87  puts("\nReader done!");
88  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
89  rtems_test_assert( status == RTEMS_SUCCESSFUL );
90  rtems_task_delete( RTEMS_SELF );
91}
92
93
94void test_main(void) //Also acts as the write task
95{
96
97  rtems_id readTaskID;
98
99  rtems_name readTaskName;
100
101  char sendBuf_r1[SEND_RCV_BUFSIZ] = {0};
102  char sendBuf_r2[SEND_RCV_BUFSIZ] = {0};
103  int status = -1;
104  int fd = 0;
105
106
107  strcpy( sendBuf_r1, "SendBuffer1" );
108  strcpy( sendBuf_r2, "SendBuffer2" );
109
110  memset( &Barrier, 0, sizeof(Barrier) );
111  status = rtems_barrier_create (
112    rtems_build_name ( 'B', 'A', 'R', 't' ),
113    RTEMS_BARRIER_AUTOMATIC_RELEASE,
114    2,
115    &Barrier
116    );
117
118  rtems_test_assert( status == RTEMS_SUCCESSFUL );
119
120  puts("\n\n*** FIFO / PIPE OPEN TEST - 6 ***");
121
122  puts("\nCreating a task name and a task");
123  readTaskName = rtems_build_name('T','A','r',' ');
124
125  status = rtems_task_create(
126                             readTaskName,
127                             1,
128                             RTEMS_MINIMUM_STACK_SIZE * 2,
129                             RTEMS_INTERRUPT_LEVEL(31),
130                             RTEMS_DEFAULT_ATTRIBUTES,
131                             &readTaskID
132                             );
133 
134  rtems_test_assert( status == RTEMS_SUCCESSFUL );
135
136  puts("\ncreating directory /tmp");
137  status = mkdir("/tmp", 0777);
138  rtems_test_assert(status == 0);
139
140  puts("\ncreating fifo file /tmp/fifo01");
141  status = mkfifo("/tmp/fifo01", 0777);
142  rtems_test_assert(status == 0);
143
144  puts("\nStarting the read task");
145  status = rtems_task_start(readTaskID, read_task, 0);
146  rtems_test_assert(status == 0);
147
148  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
149  rtems_test_assert( status == RTEMS_SUCCESSFUL );
150
151  puts("\nWriter opening file(1)");
152  fd = open("/tmp/fifo01", O_WRONLY);
153  if(fd <= 0) {
154    printf("Error opening file: (%d) :: %s", errno, strerror(errno));
155    rtems_test_assert(0);
156  }
157
158 
159  printf("\n@ sender: %s", sendBuf_r1);
160  status = write(fd, sendBuf_r1, sizeof(sendBuf_r1)-1);
161  rtems_test_assert(status == sizeof(sendBuf_r1)-1);
162
163  status = close(fd);
164  rtems_test_assert(status == 0);
165 
166  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
167  rtems_test_assert( status == RTEMS_SUCCESSFUL );
168
169  sleep(1);
170
171  // Reader would have blocked by now
172  puts("\nWriter opening file(2)");
173  fd = open("/tmp/fifo01", O_WRONLY);
174  if(fd <= 0) {
175    printf("Error opening file: (%d) :: %s", errno, strerror(errno));
176    rtems_test_assert(0);
177  }
178
179  printf("\n@ sender: %s", sendBuf_r2);
180  status = write(fd, sendBuf_r2, sizeof(sendBuf_r2)-1);
181  rtems_test_assert(status == sizeof(sendBuf_r2)-1);
182
183  status = close(fd);
184  rtems_test_assert(status == 0);
185
186  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
187  rtems_test_assert( status == RTEMS_SUCCESSFUL );
188
189  puts( "Removing the fifo" );
190  status = unlink("/tmp/fifo01");
191  rtems_test_assert(status == 0);
192 
193  puts( "Removing /tmp" );
194  status = rmdir("/tmp");
195  rtems_test_assert(status == 0);
196 
197  puts("\n*** END OF FIFO / PIPE OPEN TEST - 6 ***");
198}
199
200rtems_task Init(
201  rtems_task_argument not_used
202)
203{
204  test_main();
205  rtems_test_exit(0);
206}
207
208#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
209#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
210
211#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
212#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
213
214#define CONFIGURE_MAXIMUM_TASKS 3
215
216#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
217
218#define CONFIGURE_MAXIMUM_BARRIERS 1
219
220#define CONFIGURE_INIT
221#define CONFIGURE_FIFOS_ENABLED
222#define CONFIGURE_MAXIMUM_FIFOS 1
223
224
225#define CONFIGURE_INIT
226#include <rtems/confdefs.h>
227
228/* end of file */
Note: See TracBrowser for help on using the repository browser.