source: rtems/testsuites/sptests/sp13/task1.c @ 13f09e6

4.104.114.84.95
Last change on this file since 13f09e6 was 13f09e6, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 31, 1997 at 7:48:23 PM

Added support for rtems_message_queue_get_number_pending.

  • Property mode set to 100644
File size: 11.8 KB
Line 
1/*  Task_1
2 *
3 *  This routine serves as a test task.  It verifies the message manager.
4 *
5 *  Input parameters:
6 *    argument - task argument
7 *
8 *  Output parameters:  NONE
9 *
10 *  COPYRIGHT (c) 1989-1997.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may in
15 *  the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#include "system.h"
22#include <string.h>             /* for memcmp */
23
24extern rtems_configuration_table BSP_Configuration;
25
26char    big_send_buffer[2048];
27char    big_receive_buffer[2048];
28
29long    buffer[ 4 ];
30
31void dope_buffer(unsigned char *buff,
32                 int   buff_size,
33                 unsigned32 v)
34{
35    int i;
36    unsigned char ch;
37
38    ch = (' ' + (v % (0x7f - ' ')));
39   
40    for (i=0; i<buff_size; i++)
41    {
42        *buff++ = ch++;
43        if (ch >= 0x7f)
44            ch = ' ';
45    }
46}
47
48rtems_task Task_1(
49  rtems_task_argument argument
50)
51{
52  rtems_id          qid;
53  rtems_unsigned32  index;
54  rtems_unsigned32  count;
55  rtems_status_code status;
56  rtems_unsigned32  size;
57  rtems_unsigned32  queue_size;
58  char             *cp;
59 
60  status = rtems_message_queue_ident(
61    Queue_name[ 1 ],
62    RTEMS_SEARCH_ALL_NODES,
63    &qid
64  );
65  printf( "TA1 - rtems_message_queue_ident - qid => %08x\n", qid );
66  directive_failed( status, "rtems_message_queue_ident" );
67
68  Fill_buffer( "BUFFER 1 TO Q 1", buffer );
69  puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 1" );
70  status = rtems_message_queue_send( Queue_id[ 1 ], buffer, 16 );
71  directive_failed( status, "rtems_message_queue_send" );
72
73  Fill_buffer( "BUFFER 2 TO Q 1", buffer );
74  puts( "TA1 - rtems_message_queue_send - BUFFER 2 TO Q 1" );
75  status = rtems_message_queue_send( Queue_id[ 1 ], buffer, 16 );
76  directive_failed( status, "rtems_message_queue_send" );
77
78  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
79  status = rtems_task_wake_after( 5*TICKS_PER_SECOND );
80  directive_failed( status, "rtems_task_wake_after" );
81
82  Fill_buffer( "BUFFER 3 TO Q 1", buffer );
83  puts( "TA1 - rtems_message_queue_send - BUFFER 3 TO Q 1" );
84  status = rtems_message_queue_send( Queue_id[ 1 ], buffer, 16 );
85  directive_failed( status, "rtems_message_queue_send" );
86
87  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
88  status = rtems_task_wake_after( 5*TICKS_PER_SECOND );
89  directive_failed( status, "rtems_task_wake_after" );
90
91rtems_test_pause();
92
93  Fill_buffer( "BUFFER 1 TO Q 2", buffer );
94  puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 2" );
95  status = rtems_message_queue_send( Queue_id[ 2 ], buffer, 16 );
96  directive_failed( status, "rtems_message_queue_send" );
97
98  puts_nocr( "TA1 - rtems_message_queue_receive - receive from queue 1 - " );
99  puts     ( "10 second timeout" );
100  status = rtems_message_queue_receive(
101    Queue_id[ 1 ],
102    buffer,
103    &size,
104    RTEMS_DEFAULT_OPTIONS,
105    10 * TICKS_PER_SECOND
106  );
107  directive_failed( status, "rtems_message_queue_receive" );
108  puts_nocr( "TA1 - buffer received: " );
109  Put_buffer( buffer );
110  new_line;
111
112  puts( "TA1 - rtems_task_delete - delete TA2" );
113  status = rtems_task_delete( Task_id[ 2 ] );
114  directive_failed( status, "rtems_task_delete" );
115
116  Fill_buffer( "BUFFER 1 TO Q 3", buffer );
117  puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 3" );
118  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, 16 );
119  directive_failed( status, "rtems_message_queue_send" );
120
121  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
122  status = rtems_task_wake_after( 5*TICKS_PER_SECOND );
123  directive_failed( status, "rtems_task_wake_after" );
124
125rtems_test_pause();
126
127  Fill_buffer( "BUFFER 2 TO Q 3", buffer );
128  puts( "TA1 - rtems_message_queue_send - BUFFER 2 TO Q 3" );
129  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, 16 );
130  directive_failed( status, "rtems_message_queue_send" );
131
132  Fill_buffer( "BUFFER 3 TO Q 3", buffer );
133  puts( "TA1 - rtems_message_queue_send - BUFFER 3 TO Q 3" );
134  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, 16 );
135  directive_failed( status, "rtems_message_queue_send" );
136
137  Fill_buffer( "BUFFER 4 TO Q 3", buffer );
138  puts( "TA1 - rtems_message_queue_send - BUFFER 4 TO Q 3" );
139  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, 16 );
140  directive_failed( status, "rtems_message_queue_send" );
141
142  Fill_buffer( "BUFFER 5 TO Q 3", buffer );
143  puts( "TA1 - rtems_message_queue_urgent - BUFFER 5 TO Q 3" );
144  status = rtems_message_queue_urgent( Queue_id[ 3 ], buffer, 16 );
145  directive_failed( status, "rtems_message_queue_urgent" );
146
147  for ( index = 1 ; index <= 4 ; index++ ) {
148    puts(
149      "TA1 - rtems_message_queue_receive - receive from queue 3 - "
150        "RTEMS_WAIT FOREVER"
151    );
152    status = rtems_message_queue_receive(
153      Queue_id[ 3 ],
154      buffer,
155      &size,
156      RTEMS_DEFAULT_OPTIONS,
157      RTEMS_NO_TIMEOUT
158    );
159    directive_failed( status, "rtems_message_queue_receive" );
160    puts_nocr( "TA1 - buffer received: " );
161    Put_buffer( buffer );
162    new_line;
163  }
164
165  Fill_buffer( "BUFFER 3 TO Q 2", buffer );
166  puts( "TA1 - rtems_message_queue_urgent - BUFFER 3 TO Q 2" );
167  status = rtems_message_queue_urgent( Queue_id[ 2 ], buffer, 16 );
168  directive_failed( status, "rtems_message_queue_urgent" );
169
170  puts(
171    "TA1 - rtems_message_queue_receive - receive from queue 2 - "
172      "RTEMS_WAIT FOREVER"
173  );
174  status = rtems_message_queue_receive(
175    Queue_id[ 2 ],
176    buffer,
177    &size,
178    RTEMS_DEFAULT_OPTIONS,
179    RTEMS_NO_TIMEOUT
180  );
181  directive_failed( status, "rtems_message_queue_receive" );
182  puts_nocr( "TA1 - buffer received: " );
183  Put_buffer( buffer );
184  new_line;
185
186rtems_test_pause();
187
188  puts( "TA1 - rtems_message_queue_delete - delete queue 1" );
189  status = rtems_message_queue_delete( Queue_id[ 1 ] );
190  directive_failed( status, "rtems_message_queue_delete" );
191
192  Fill_buffer( "BUFFER 3 TO Q 2", buffer );
193  puts( "TA1 - rtems_message_queue_urgent - BUFFER 3 TO Q 2" );
194  status = rtems_message_queue_urgent( Queue_id[ 2 ], buffer, 16 );
195  directive_failed( status, "rtems_message_queue_urgent" );
196
197  puts( "TA1 - rtems_message_queue_delete - delete queue 2" );
198  status = rtems_message_queue_delete( Queue_id[ 2 ] );
199  directive_failed( status, "rtems_message_queue_delete" );
200
201  puts( "TA1 - rtems_message_queue_get_number_pending - SUCCESSFUL\n" );
202  status = rtems_message_queue_get_number_pending( Queue_id[ 3 ], &count );
203  printf( "TA1 - %d messages are pending on Q 3\n", count );
204
205  puts( "TA1 - rtems_message_queue_flush - empty Q 3" );
206  status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
207  printf( "TA1 - %d messages were flushed from Q 3\n", count );
208
209  Fill_buffer( "BUFFER 1 TO Q 3", buffer );
210  puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 3" );
211  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, 16 );
212  directive_failed( status, "rtems_message_queue_send" );
213
214  Fill_buffer( "BUFFER 2 TO Q 3", buffer );
215  puts( "TA1 - rtems_message_queue_send - BUFFER 2 TO Q 3" );
216  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, 16 );
217  directive_failed( status, "rtems_message_queue_send" );
218
219  puts( "TA1 - rtems_message_queue_get_number_pending - SUCCESSFUL\n" );
220  status = rtems_message_queue_get_number_pending( Queue_id[ 3 ], &count );
221  printf( "TA1 - %d messages are pending on Q 3\n", count );
222
223  Fill_buffer( "BUFFER 3 TO Q 3", buffer );
224  puts( "TA1 - rtems_message_queue_send - BUFFER 3 TO Q 3" );
225  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, 16 );
226  directive_failed( status, "rtems_message_queue_send" );
227
228  puts( "TA1 - rtems_message_queue_flush - Q 3" );
229  status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
230  printf( "TA1 - %d messages were flushed from Q 3\n", count );
231
232  puts( "TA1 - rtems_message_queue_send until all message buffers consumed" );
233  while ( FOREVER ) {
234    status = rtems_message_queue_send( Queue_id[ 3 ], buffer, 16 );
235    if ( status == RTEMS_TOO_MANY ) break;
236    directive_failed( status, "rtems_message_queue_send loop" );
237  }
238
239  puts( "TA1 - all message buffers consumed" );
240  puts( "TA1 - rtems_message_queue_flush - Q 3" );
241  status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
242  printf( "TA1 - %d messages were flushed from Q 3\n", count );
243
244rtems_test_pause();
245
246  puts( "TA1 - create message queue of 20 bytes on queue 1" );
247  status = rtems_message_queue_create(
248    Queue_name[ 1 ],
249    100,
250    20,
251    RTEMS_DEFAULT_ATTRIBUTES,
252    &Queue_id[ 1 ]
253  );
254  directive_failed( status, "rtems_message_queue_create of Q1; 20 bytes each" );
255  status = rtems_message_queue_send( Queue_id[ 3 ], big_send_buffer, 40 );
256  fatal_directive_status(status, RTEMS_INVALID_SIZE, "expected RTEMS_INVALID_SIZE");
257 
258  puts( "TA1 - rtems_message_queue_delete - delete queue 1" );
259  status = rtems_message_queue_delete( Queue_id[ 1 ] );
260  directive_failed( status, "rtems_message_queue_delete" );
261
262rtems_test_pause();
263 
264  puts( "TA1 - rtems_message_queue_create - variable sizes " );
265  for (queue_size = 1; queue_size < 1030; queue_size++)
266  {
267      status = rtems_message_queue_create(
268          Queue_name[ 1 ],
269          2,            /* just 2 msgs each */
270          queue_size,
271          RTEMS_DEFAULT_ATTRIBUTES,
272          &Queue_id[ 1 ]
273          );
274      if (status != RTEMS_SUCCESSFUL)
275      {
276          printf("TA1 - msq que size: %d\n", queue_size);
277          directive_failed( status, "rtems_message_queue_create of Q1" );
278      }
279
280      status = rtems_message_queue_delete( Queue_id[ 1 ] );
281      directive_failed( status, "rtems_message_queue_delete" );
282  }
283 
284  puts( "TA1 - rtems_message_queue_create and send - variable sizes " );
285  for (queue_size = 1; queue_size < 1030; queue_size++)
286  {
287      /* printf("TA1 - message queue size: %d\n", queue_size); */
288
289      status = rtems_message_queue_create(
290          Queue_name[ 1 ],
291          2,            /* just 2 msgs each */
292          queue_size,
293          RTEMS_DEFAULT_ATTRIBUTES,
294          &Queue_id[ 1 ]
295          );
296
297      directive_failed( status, "rtems_message_queue_create of Q1" );
298
299      dope_buffer(big_send_buffer, sizeof(big_send_buffer), queue_size);
300      memset(big_receive_buffer, 'Z', sizeof(big_receive_buffer));
301
302      /* send a msg too big */
303      status = rtems_message_queue_send( Queue_id[ 1 ],
304                                         big_send_buffer,
305                                         queue_size + 1 );
306
307      fatal_directive_status(status,
308                             RTEMS_INVALID_SIZE,
309                             "rtems_message_queue_send too large");
310
311      /* send a msg that is just right */
312      status = rtems_message_queue_send(Queue_id[ 1 ],
313                                        big_send_buffer,
314                                        queue_size);
315      directive_failed(status, "rtems_message_queue_send exact size");
316
317      /* now read and verify the message just sent */
318      status = rtems_message_queue_receive(Queue_id[ 1 ],
319                                           big_receive_buffer,
320                                           &size,
321                                           RTEMS_DEFAULT_OPTIONS,
322                                           1 * TICKS_PER_SECOND);
323      directive_failed(status, "rtems_message_queue_receive exact size");
324      if (size != queue_size)
325      {
326          puts("TA1 - exact size size match failed");
327          exit(1);
328      }
329
330      if (memcmp(big_send_buffer, big_receive_buffer, size) != 0)
331      {
332          puts("TA1 - exact size data match failed");
333          exit(1);
334      }
335
336      for (cp = (big_receive_buffer + size);
337           cp < (big_receive_buffer + sizeof(big_receive_buffer));
338           cp++)
339          if (*cp != 'Z')
340          {
341              puts("TA1 - exact size overrun match failed");
342              exit(1);
343          }
344         
345      /* all done with this one; delete it */
346      status = rtems_message_queue_delete( Queue_id[ 1 ] );
347      directive_failed( status, "rtems_message_queue_delete" );
348  }
349 
350  puts( "*** END OF TEST 13 ***" );
351  exit( 0 );
352}
Note: See TracBrowser for help on using the repository browser.