source: rtems/testsuites/sptests/spfifo03/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: 5.4 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 <fcntl.h>
20#include <unistd.h>
21#include <errno.h>
22
23#include <rtems.h>
24#include <rtems/libio.h>
25
26const char rtems_test_name[] = "SPFIFO 3";
27
28/* forward declarations to avoid warnings */
29rtems_task Init(rtems_task_argument argument);
30rtems_task read_task(rtems_task_argument not_used);
31void test_main(void);
32
33#define SEND_RCV_BUFSIZ 12
34rtems_id Barrier;
35
36rtems_task read_task(rtems_task_argument not_used)
37{
38  int fd = 0;
39  int status = -1;
40
41  char recvBuf_r1[SEND_RCV_BUFSIZ] = {0};
42  char recvBuf_r2[SEND_RCV_BUFSIZ] = {0};
43
44  puts("\nRead task activated, waiting till writer opens");
45
46  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
47  rtems_test_assert( status == RTEMS_SUCCESSFUL );
48
49  sleep(1);
50
51  puts("\nNow, reader opening file(1)"); 
52  fd = open("/tmp/fifo01", O_RDONLY);
53  if(fd <= 0) {
54    printf("Error opening file: (%d) :: %s", errno, strerror(errno));
55    rtems_test_assert(0);
56  }
57
58  status = read(fd, recvBuf_r1, sizeof(recvBuf_r1)-1);
59  rtems_test_assert(status == sizeof(recvBuf_r1)-1);
60
61  printf("\n@ receiver (being a unblocked reader): Got %s", recvBuf_r1);
62
63  status = close(fd);
64  rtems_test_assert(status == 0);
65
66  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
67  rtems_test_assert( status == RTEMS_SUCCESSFUL );
68 
69  puts("\nReader opening file(2)");
70  fd = open("/tmp/fifo01", O_RDONLY);
71  if(fd <= 0) {
72    printf("Error opening file: (%d) :: %s", errno, strerror(errno));
73    rtems_test_assert(0);
74  }
75
76  status = read(fd, recvBuf_r2, sizeof(recvBuf_r2)-1);
77  rtems_test_assert(status == sizeof(recvBuf_r2)-1);
78
79  printf("\n@ receiver (being a blocked reader): Got %s", recvBuf_r2);
80
81  status = close(fd);
82  rtems_test_assert(status == 0);
83 
84 
85  puts("\nReader done!");
86  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
87  rtems_test_assert( status == RTEMS_SUCCESSFUL );
88  rtems_task_exit();
89}
90
91void test_main(void) /* Also acts as the write task */
92{
93
94  rtems_id readTaskID;
95
96  rtems_name readTaskName;
97
98  char sendBuf_r1[SEND_RCV_BUFSIZ] = {0};
99  char sendBuf_r2[SEND_RCV_BUFSIZ] = {0};
100  int status = -1;
101  int fd = 0;
102
103
104  strcpy( sendBuf_r1, "SendBuffer1" );
105  strcpy( sendBuf_r2, "SendBuffer2" );
106
107  memset( &Barrier, 0, sizeof(Barrier) );
108  status = rtems_barrier_create (
109    rtems_build_name ( 'B', 'A', 'R', 't' ),
110    RTEMS_BARRIER_AUTOMATIC_RELEASE,
111    2,
112    &Barrier
113    );
114
115  rtems_test_assert( status == RTEMS_SUCCESSFUL );
116
117  TEST_BEGIN();
118
119  puts("\nCreating a task name and a task");
120  readTaskName = rtems_build_name('T','A','r',' ');
121
122  status = rtems_task_create(
123                             readTaskName,
124                             1,
125                             RTEMS_MINIMUM_STACK_SIZE * 2,
126                             RTEMS_DEFAULT_MODES,
127                             RTEMS_DEFAULT_ATTRIBUTES,
128                             &readTaskID
129                             );
130 
131  rtems_test_assert( status == RTEMS_SUCCESSFUL );
132
133  puts("\ncreating directory /tmp");
134  status = mkdir("/tmp", 0777);
135  rtems_test_assert(status == 0);
136
137  puts("\ncreating fifo file /tmp/fifo01");
138  status = mkfifo("/tmp/fifo01", 0777);
139  rtems_test_assert(status == 0);
140
141  puts("\nStarting the read task");
142  status = rtems_task_start(readTaskID, read_task, 0);
143  rtems_test_assert(status == 0);
144
145  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
146  rtems_test_assert( status == RTEMS_SUCCESSFUL );
147
148  puts("\nWriter opening file(1)");
149  fd = open("/tmp/fifo01", O_WRONLY);
150  if(fd <= 0) {
151    printf("Error opening file: (%d) :: %s", errno, strerror(errno));
152    rtems_test_assert(0);
153  }
154
155 
156  printf("\n@ sender: %s", sendBuf_r1);
157  status = write(fd, sendBuf_r1, sizeof(sendBuf_r1)-1);
158  rtems_test_assert(status == sizeof(sendBuf_r1)-1);
159
160  status = close(fd);
161  rtems_test_assert(status == 0);
162 
163  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
164  rtems_test_assert( status == RTEMS_SUCCESSFUL );
165
166  sleep(1);
167
168  // Reader would have blocked by now
169  puts("\nWriter opening file(2)");
170  fd = open("/tmp/fifo01", O_WRONLY);
171  if(fd <= 0) {
172    printf("Error opening file: (%d) :: %s", errno, strerror(errno));
173    rtems_test_assert(0);
174  }
175
176  printf("\n@ sender: %s", sendBuf_r2);
177  status = write(fd, sendBuf_r2, sizeof(sendBuf_r2)-1);
178  rtems_test_assert(status == sizeof(sendBuf_r2)-1);
179
180  status = close(fd);
181  rtems_test_assert(status == 0);
182
183  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
184  rtems_test_assert( status == RTEMS_SUCCESSFUL );
185
186  puts( "Removing the fifo" );
187  status = unlink("/tmp/fifo01");
188  rtems_test_assert(status == 0);
189 
190  puts( "Removing /tmp" );
191  status = rmdir("/tmp");
192  rtems_test_assert(status == 0);
193 
194  TEST_END();
195}
196
197rtems_task Init(
198  rtems_task_argument not_used
199)
200{
201  test_main();
202  rtems_test_exit(0);
203}
204
205#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
206#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
207
208#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
209
210#define CONFIGURE_MAXIMUM_TASKS 3
211
212#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
213
214#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
215
216#define CONFIGURE_MAXIMUM_BARRIERS 1
217
218#define CONFIGURE_MAXIMUM_FIFOS 1
219
220#define CONFIGURE_DISABLE_SMP_CONFIGURATION
221
222#define CONFIGURE_INIT
223#include <rtems/confdefs.h>
224
225/* end of file */
Note: See TracBrowser for help on using the repository browser.