[ac7d5ef0] | 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 | * |
---|
[08311cc3] | 10 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
[98e4ebf5] | 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[d2b93bfd] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 16 | * |
---|
[3235ad9] | 17 | * $Id$ |
---|
[ac7d5ef0] | 18 | */ |
---|
| 19 | |
---|
| 20 | #include "system.h" |
---|
[4b374f36] | 21 | #include <string.h> /* for memcmp */ |
---|
[ac7d5ef0] | 22 | |
---|
[4b374f36] | 23 | char big_send_buffer[2048]; |
---|
| 24 | char big_receive_buffer[2048]; |
---|
| 25 | |
---|
[a841314] | 26 | long buffer[ MESSAGE_SIZE / sizeof(long) ]; |
---|
[df49c60] | 27 | |
---|
[4b374f36] | 28 | void dope_buffer(unsigned char *buff, |
---|
| 29 | int buff_size, |
---|
[c87608f] | 30 | uint32_t v) |
---|
[4b374f36] | 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 | |
---|
[ac7d5ef0] | 45 | rtems_task Task_1( |
---|
| 46 | rtems_task_argument argument |
---|
| 47 | ) |
---|
| 48 | { |
---|
| 49 | rtems_id qid; |
---|
[c87608f] | 50 | uint32_t index; |
---|
| 51 | uint32_t count; |
---|
[ac7d5ef0] | 52 | rtems_status_code status; |
---|
[c87608f] | 53 | uint32_t size; |
---|
| 54 | uint32_t queue_size; |
---|
[4b374f36] | 55 | char *cp; |
---|
| 56 | |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 67 | status = rtems_message_queue_send( Queue_id[ 1 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 72 | status = rtems_message_queue_send( Queue_id[ 1 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 81 | status = rtems_message_queue_send( Queue_id[ 1 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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 | |
---|
[ba39113] | 88 | rtems_test_pause(); |
---|
[ac7d5ef0] | 89 | |
---|
| 90 | Fill_buffer( "BUFFER 1 TO Q 2", buffer ); |
---|
| 91 | puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 2" ); |
---|
[df49c60] | 92 | status = rtems_message_queue_send( Queue_id[ 2 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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 ], |
---|
[4b374f36] | 99 | buffer, |
---|
| 100 | &size, |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 115 | status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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 | |
---|
[ba39113] | 122 | rtems_test_pause(); |
---|
[ac7d5ef0] | 123 | |
---|
| 124 | Fill_buffer( "BUFFER 2 TO Q 3", buffer ); |
---|
| 125 | puts( "TA1 - rtems_message_queue_send - BUFFER 2 TO Q 3" ); |
---|
[df49c60] | 126 | status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 131 | status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 136 | status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 141 | status = rtems_message_queue_urgent( Queue_id[ 3 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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 ], |
---|
[4b374f36] | 151 | buffer, |
---|
| 152 | &size, |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 164 | status = rtems_message_queue_urgent( Queue_id[ 2 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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 ], |
---|
[4b374f36] | 173 | buffer, |
---|
| 174 | &size, |
---|
[ac7d5ef0] | 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 | |
---|
[ba39113] | 183 | rtems_test_pause(); |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 191 | status = rtems_message_queue_urgent( Queue_id[ 2 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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 | |
---|
[13f09e6] | 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 | |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 208 | status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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" ); |
---|
[df49c60] | 213 | status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 214 | directive_failed( status, "rtems_message_queue_send" ); |
---|
| 215 | |
---|
[3e7a0fd] | 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 | |
---|
[13f09e6] | 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 | |
---|
[ac7d5ef0] | 232 | Fill_buffer( "BUFFER 3 TO Q 3", buffer ); |
---|
| 233 | puts( "TA1 - rtems_message_queue_send - BUFFER 3 TO Q 3" ); |
---|
[df49c60] | 234 | status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE ); |
---|
[ac7d5ef0] | 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 ) { |
---|
[df49c60] | 243 | status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE ); |
---|
[4b374f36] | 244 | if ( status == RTEMS_TOO_MANY ) break; |
---|
[ac7d5ef0] | 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 | |
---|
[ba39113] | 253 | rtems_test_pause(); |
---|
[ac7d5ef0] | 254 | |
---|
[4b374f36] | 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 | |
---|
[ba39113] | 271 | rtems_test_pause(); |
---|
[4b374f36] | 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 | { |
---|
[3a4ae6c] | 296 | /* printf("TA1 - message queue size: %d\n", queue_size); */ |
---|
[4b374f36] | 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"); |
---|
[3aa4c2e0] | 336 | rtems_test_exit(1); |
---|
[4b374f36] | 337 | } |
---|
| 338 | |
---|
| 339 | if (memcmp(big_send_buffer, big_receive_buffer, size) != 0) |
---|
| 340 | { |
---|
| 341 | puts("TA1 - exact size data match failed"); |
---|
[3aa4c2e0] | 342 | rtems_test_exit(1); |
---|
[4b374f36] | 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"); |
---|
[3aa4c2e0] | 351 | rtems_test_exit(1); |
---|
[4b374f36] | 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 | |
---|
[ac7d5ef0] | 359 | puts( "*** END OF TEST 13 ***" ); |
---|
[3aa4c2e0] | 360 | rtems_test_exit( 0 ); |
---|
[ac7d5ef0] | 361 | } |
---|