OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [sptests/] [sp13/] [task1.c] - Blame information for rev 587

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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.OARcorp.com/rtems/license.html.
16
 *
17
 *  $Id: task1.c,v 1.2 2001-09-27 12:02:32 chris Exp $
18
 */
19
 
20
#include "system.h"
21
#include <string.h>             /* for memcmp */
22
 
23
char    big_send_buffer[2048];
24
char    big_receive_buffer[2048];
25
 
26
long    buffer[ 4 ];
27
 
28
#define MESSAGE_SIZE (sizeof(long) * 4)
29
 
30
void dope_buffer(unsigned char *buff,
31
                 int   buff_size,
32
                 unsigned32 v)
33
{
34
    int i;
35
    unsigned char ch;
36
 
37
    ch = (' ' + (v % (0x7f - ' ')));
38
 
39
    for (i=0; i<buff_size; i++)
40
    {
41
        *buff++ = ch++;
42
        if (ch >= 0x7f)
43
            ch = ' ';
44
    }
45
}
46
 
47
rtems_task Task_1(
48
  rtems_task_argument argument
49
)
50
{
51
  rtems_id          qid;
52
  rtems_unsigned32  index;
53
  rtems_unsigned32  count;
54
  rtems_status_code status;
55
  rtems_unsigned32  size;
56
  rtems_unsigned32  queue_size;
57
  char             *cp;
58
 
59
  status = rtems_message_queue_ident(
60
    Queue_name[ 1 ],
61
    RTEMS_SEARCH_ALL_NODES,
62
    &qid
63
  );
64
  printf( "TA1 - rtems_message_queue_ident - qid => %08x\n", qid );
65
  directive_failed( status, "rtems_message_queue_ident" );
66
 
67
  Fill_buffer( "BUFFER 1 TO Q 1", buffer );
68
  puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 1" );
69
  status = rtems_message_queue_send( Queue_id[ 1 ], buffer, MESSAGE_SIZE );
70
  directive_failed( status, "rtems_message_queue_send" );
71
 
72
  Fill_buffer( "BUFFER 2 TO Q 1", buffer );
73
  puts( "TA1 - rtems_message_queue_send - BUFFER 2 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
  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
78
  status = rtems_task_wake_after( 5*TICKS_PER_SECOND );
79
  directive_failed( status, "rtems_task_wake_after" );
80
 
81
  Fill_buffer( "BUFFER 3 TO Q 1", buffer );
82
  puts( "TA1 - rtems_message_queue_send - BUFFER 3 TO Q 1" );
83
  status = rtems_message_queue_send( Queue_id[ 1 ], buffer, MESSAGE_SIZE );
84
  directive_failed( status, "rtems_message_queue_send" );
85
 
86
  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
87
  status = rtems_task_wake_after( 5*TICKS_PER_SECOND );
88
  directive_failed( status, "rtems_task_wake_after" );
89
 
90
rtems_test_pause();
91
 
92
  Fill_buffer( "BUFFER 1 TO Q 2", buffer );
93
  puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 2" );
94
  status = rtems_message_queue_send( Queue_id[ 2 ], buffer, MESSAGE_SIZE );
95
  directive_failed( status, "rtems_message_queue_send" );
96
 
97
  puts_nocr( "TA1 - rtems_message_queue_receive - receive from queue 1 - " );
98
  puts     ( "10 second timeout" );
99
  status = rtems_message_queue_receive(
100
    Queue_id[ 1 ],
101
    buffer,
102
    &size,
103
    RTEMS_DEFAULT_OPTIONS,
104
    10 * TICKS_PER_SECOND
105
  );
106
  directive_failed( status, "rtems_message_queue_receive" );
107
  puts_nocr( "TA1 - buffer received: " );
108
  Put_buffer( buffer );
109
  new_line;
110
 
111
  puts( "TA1 - rtems_task_delete - delete TA2" );
112
  status = rtems_task_delete( Task_id[ 2 ] );
113
  directive_failed( status, "rtems_task_delete" );
114
 
115
  Fill_buffer( "BUFFER 1 TO Q 3", buffer );
116
  puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 3" );
117
  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
118
  directive_failed( status, "rtems_message_queue_send" );
119
 
120
  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
121
  status = rtems_task_wake_after( 5*TICKS_PER_SECOND );
122
  directive_failed( status, "rtems_task_wake_after" );
123
 
124
rtems_test_pause();
125
 
126
  Fill_buffer( "BUFFER 2 TO Q 3", buffer );
127
  puts( "TA1 - rtems_message_queue_send - BUFFER 2 TO Q 3" );
128
  status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
129
  directive_failed( status, "rtems_message_queue_send" );
130
 
131
  Fill_buffer( "BUFFER 3 TO Q 3", buffer );
132
  puts( "TA1 - rtems_message_queue_send - BUFFER 3 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 4 TO Q 3", buffer );
137
  puts( "TA1 - rtems_message_queue_send - BUFFER 4 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 5 TO Q 3", buffer );
142
  puts( "TA1 - rtems_message_queue_urgent - BUFFER 5 TO Q 3" );
143
  status = rtems_message_queue_urgent( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
144
  directive_failed( status, "rtems_message_queue_urgent" );
145
 
146
  for ( index = 1 ; index <= 4 ; index++ ) {
147
    puts(
148
      "TA1 - rtems_message_queue_receive - receive from queue 3 - "
149
        "RTEMS_WAIT FOREVER"
150
    );
151
    status = rtems_message_queue_receive(
152
      Queue_id[ 3 ],
153
      buffer,
154
      &size,
155
      RTEMS_DEFAULT_OPTIONS,
156
      RTEMS_NO_TIMEOUT
157
    );
158
    directive_failed( status, "rtems_message_queue_receive" );
159
    puts_nocr( "TA1 - buffer received: " );
160
    Put_buffer( buffer );
161
    new_line;
162
  }
163
 
164
  Fill_buffer( "BUFFER 3 TO Q 2", buffer );
165
  puts( "TA1 - rtems_message_queue_urgent - BUFFER 3 TO Q 2" );
166
  status = rtems_message_queue_urgent( Queue_id[ 2 ], buffer, MESSAGE_SIZE );
167
  directive_failed( status, "rtems_message_queue_urgent" );
168
 
169
  puts(
170
    "TA1 - rtems_message_queue_receive - receive from queue 2 - "
171
      "RTEMS_WAIT FOREVER"
172
  );
173
  status = rtems_message_queue_receive(
174
    Queue_id[ 2 ],
175
    buffer,
176
    &size,
177
    RTEMS_DEFAULT_OPTIONS,
178
    RTEMS_NO_TIMEOUT
179
  );
180
  directive_failed( status, "rtems_message_queue_receive" );
181
  puts_nocr( "TA1 - buffer received: " );
182
  Put_buffer( buffer );
183
  new_line;
184
 
185
rtems_test_pause();
186
 
187
  puts( "TA1 - rtems_message_queue_delete - delete queue 1" );
188
  status = rtems_message_queue_delete( Queue_id[ 1 ] );
189
  directive_failed( status, "rtems_message_queue_delete" );
190
 
191
  Fill_buffer( "BUFFER 3 TO Q 2", buffer );
192
  puts( "TA1 - rtems_message_queue_urgent - BUFFER 3 TO Q 2" );
193
  status = rtems_message_queue_urgent( Queue_id[ 2 ], buffer, MESSAGE_SIZE );
194
  directive_failed( status, "rtems_message_queue_urgent" );
195
 
196
  puts( "TA1 - rtems_message_queue_delete - delete queue 2" );
197
  status = rtems_message_queue_delete( Queue_id[ 2 ] );
198
  directive_failed( status, "rtems_message_queue_delete" );
199
 
200
  puts( "TA1 - rtems_message_queue_get_number_pending - SUCCESSFUL\n" );
201
  status = rtems_message_queue_get_number_pending( Queue_id[ 3 ], &count );
202
  printf( "TA1 - %d messages are pending on Q 3\n", count );
203
 
204
  puts( "TA1 - rtems_message_queue_flush - empty Q 3" );
205
  status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
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( "TA3 - 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( "TA3 - number of tasks awakened = %d\n", count );
228
 
229
 
230
  puts( "TA1 - rtems_message_queue_get_number_pending - SUCCESSFUL\n" );
231
  status = rtems_message_queue_get_number_pending( Queue_id[ 3 ], &count );
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
 
255
rtems_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[ 3 ], 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
 
273
rtems_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
          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
          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
              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
  exit( 0 );
363
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.