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

4.104.11
Last change on this file since b84f1fdc was b84f1fdc, checked in by Joel Sherrill <joel.sherrill@…>, on May 10, 2009 at 2:39:46 PM

2009-05-10 Joel Sherrill <joel.sherrill@…>

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