source: rtems/testsuites/sptests/sp13/task1.c @ 6a5990e

4.104.114.9
Last change on this file since 6a5990e was 6a5990e, checked in by Glenn Humphrey <glenn.humphrey@…>, on Oct 18, 2007 at 7:49:46 PM

2007-10-18 Glenn Humphrey <glenn.humphrey@…>

  • sp09/screen06.c, sp09/screen14.c, sp13/sp13.scn, sp13/task1.c, sp16/sp16.scn: Corrected some minor mistakes and regenerated some .scn files.
  • Property mode set to 100644
File size: 12.5 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-2007.
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
23unsigned char big_send_buffer[2048];
24unsigned char 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  size_t            size;
54  size_t            queue_size;
55  unsigned 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 - check Q 3" );
199  status = rtems_message_queue_get_number_pending( Queue_id[ 3 ], &count );
200  directive_failed( status, "rtems_message_queue_get_number_pending" );
201  printf( "TA1 - %d messages are pending on Q 3\n", count );
202
203  puts( "TA1 - rtems_message_queue_flush - empty Q 3" );
204  status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
205  directive_failed( status, "rtems_message_queue_flush" );
206  printf( "TA1 - %d messages were flushed from Q 3\n", count );
207
208  Fill_buffer( "BUFFER 1 TO Q 3", buffer );
209  puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 3" );
210  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
211  directive_failed( status, "rtems_message_queue_send" );
212
213  Fill_buffer( "BUFFER 2 TO Q 3", buffer );
214  puts( "TA1 - rtems_message_queue_send - BUFFER 2 TO Q 3" );
215  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
216  directive_failed( status, "rtems_message_queue_send" );
217
218  /* this broadcast should have no effect on the queue */
219  Fill_buffer( "NO BUFFER TO Q1", (long *)buffer );
220  puts( "TA1 - rtems_message_queue_broadcast - NO BUFFER TO Q1" );
221  status = rtems_message_queue_broadcast(
222    Queue_id[ 1 ],
223    (long (*)[4])buffer,
224    16,
225    &count
226  );
227  printf( "TA1 - number of tasks awakened = %d\n", count );
228
229  puts( "TA1 - rtems_message_queue_get_number_pending - check Q 3" );
230  status = rtems_message_queue_get_number_pending( Queue_id[ 3 ], &count );
231  directive_failed( status, "rtems_message_queue_get_number_pending" );
232  printf( "TA1 - %d messages are pending on Q 3\n", count );
233
234  Fill_buffer( "BUFFER 3 TO Q 3", buffer );
235  puts( "TA1 - rtems_message_queue_send - BUFFER 3 TO Q 3" );
236  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
237  directive_failed( status, "rtems_message_queue_send" );
238
239  puts( "TA1 - rtems_message_queue_flush - Q 3" );
240  status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
241  printf( "TA1 - %d messages were flushed from Q 3\n", count );
242
243  puts( "TA1 - rtems_message_queue_send until all message buffers consumed" );
244  while ( FOREVER ) {
245    status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
246    if ( status == RTEMS_TOO_MANY ) break;
247    directive_failed( status, "rtems_message_queue_send loop" );
248  }
249
250  puts( "TA1 - all message buffers consumed" );
251  puts( "TA1 - rtems_message_queue_flush - Q 3" );
252  status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
253  printf( "TA1 - %d messages were flushed from Q 3\n", count );
254
255rtems_test_pause();
256
257  puts( "TA1 - create message queue of 20 bytes on queue 1" );
258  status = rtems_message_queue_create(
259    Queue_name[ 1 ],
260    100,
261    20,
262    RTEMS_DEFAULT_ATTRIBUTES,
263    &Queue_id[ 1 ]
264  );
265  directive_failed( status, "rtems_message_queue_create of Q1; 20 bytes each" );
266  status = rtems_message_queue_send( Queue_id[ 1 ], big_send_buffer, 40 );
267  fatal_directive_status(status, RTEMS_INVALID_SIZE, "expected RTEMS_INVALID_SIZE");
268
269  puts( "TA1 - rtems_message_queue_delete - delete queue 1" );
270  status = rtems_message_queue_delete( Queue_id[ 1 ] );
271  directive_failed( status, "rtems_message_queue_delete" );
272
273rtems_test_pause();
274
275  puts( "TA1 - rtems_message_queue_create - variable sizes " );
276  for (queue_size = 1; queue_size < 1030; queue_size++)
277  {
278      status = rtems_message_queue_create(
279          Queue_name[ 1 ],
280          2,            /* just 2 msgs each */
281          queue_size,
282          RTEMS_DEFAULT_ATTRIBUTES,
283          &Queue_id[ 1 ]
284          );
285      if (status != RTEMS_SUCCESSFUL)
286      {
287          printf("TA1 - msq que size: %d\n", queue_size);
288          directive_failed( status, "rtems_message_queue_create of Q1" );
289      }
290
291      status = rtems_message_queue_delete( Queue_id[ 1 ] );
292      directive_failed( status, "rtems_message_queue_delete" );
293  }
294
295  puts( "TA1 - rtems_message_queue_create and send - variable sizes " );
296  for (queue_size = 1; queue_size < 1030; queue_size++)
297  {
298      /* printf("TA1 - message queue size: %d\n", queue_size); */
299
300      status = rtems_message_queue_create(
301          Queue_name[ 1 ],
302          2,            /* just 2 msgs each */
303          queue_size,
304          RTEMS_DEFAULT_ATTRIBUTES,
305          &Queue_id[ 1 ]
306          );
307
308      directive_failed( status, "rtems_message_queue_create of Q1" );
309
310      dope_buffer(big_send_buffer, sizeof(big_send_buffer), queue_size);
311      memset(big_receive_buffer, 'Z', sizeof(big_receive_buffer));
312
313      /* send a msg too big */
314      status = rtems_message_queue_send( Queue_id[ 1 ],
315                                         big_send_buffer,
316                                         queue_size + 1 );
317
318      fatal_directive_status(status,
319                             RTEMS_INVALID_SIZE,
320                             "rtems_message_queue_send too large");
321
322      /* send a msg that is just right */
323      status = rtems_message_queue_send(Queue_id[ 1 ],
324                                        big_send_buffer,
325                                        queue_size);
326      directive_failed(status, "rtems_message_queue_send exact size");
327
328      /* now read and verify the message just sent */
329      status = rtems_message_queue_receive(Queue_id[ 1 ],
330                                           big_receive_buffer,
331                                           &size,
332                                           RTEMS_DEFAULT_OPTIONS,
333                                           1 * TICKS_PER_SECOND);
334      directive_failed(status, "rtems_message_queue_receive exact size");
335      if (size != queue_size)
336      {
337          puts("TA1 - exact size size match failed");
338          rtems_test_exit(1);
339      }
340
341      if (memcmp(big_send_buffer, big_receive_buffer, size) != 0)
342      {
343          puts("TA1 - exact size data match failed");
344          rtems_test_exit(1);
345      }
346
347      for (cp = (big_receive_buffer + size);
348           cp < (big_receive_buffer + sizeof(big_receive_buffer));
349           cp++)
350          if (*cp != 'Z')
351          {
352              puts("TA1 - exact size overrun match failed");
353              rtems_test_exit(1);
354          }
355
356      /* all done with this one; delete it */
357      status = rtems_message_queue_delete( Queue_id[ 1 ] );
358      directive_failed( status, "rtems_message_queue_delete" );
359  }
360
361  puts( "*** END OF TEST 13 ***" );
362  rtems_test_exit( 0 );
363}
Note: See TracBrowser for help on using the repository browser.