source: rtems/testsuites/sptests/sp13/task1.c @ a841314

4.104.114.84.95
Last change on this file since a841314 was a841314, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 30, 2004 at 7:46:38 PM

2004-03-30 David Querbach <querbach@…>

PR 595/tests

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