Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:44

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2011, 2016.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include "system.h"
0034 #include <string.h>             /* for memcmp */
0035 
0036 void dope_buffer(
0037   unsigned char *buff,
0038   int            buff_size,
0039   unsigned char  v
0040 );
0041 
0042 unsigned char big_send_buffer[2048];
0043 unsigned char big_receive_buffer[2048];
0044 
0045 long buffer[ MESSAGE_SIZE / sizeof(long) ];
0046 
0047 void dope_buffer(
0048   unsigned char *buff,
0049   int            buff_size,
0050   unsigned char  v
0051 )
0052 {
0053   int           i;
0054   unsigned char ch;
0055 
0056   ch = (' ' + (v % (0x7f - ' ')));
0057 
0058   for (i=0; i<buff_size; i++) {
0059     *buff++ = ch++;
0060     if (ch >= 0x7f)
0061       ch = ' ';
0062   }
0063 }
0064 
0065 rtems_task Task_1(
0066   rtems_task_argument argument
0067 )
0068 {
0069   rtems_id          qid;
0070   uint32_t          index;
0071   uint32_t          count;
0072   rtems_status_code status;
0073   size_t            size;
0074   size_t            queue_size;
0075   unsigned char    *cp;
0076 
0077   status = rtems_message_queue_ident(
0078     Queue_name[ 1 ],
0079     RTEMS_SEARCH_ALL_NODES,
0080     &qid
0081   );
0082   printf(
0083     "TA1 - rtems_message_queue_ident - qid => %08" PRIxrtems_id "\n",
0084      qid
0085   );
0086   directive_failed( status, "rtems_message_queue_ident" );
0087 
0088   Fill_buffer( "BUFFER 1 TO Q 1", buffer );
0089   puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 1" );
0090   status = rtems_message_queue_send( Queue_id[ 1 ], buffer, MESSAGE_SIZE );
0091   directive_failed( status, "rtems_message_queue_send" );
0092 
0093   Fill_buffer( "BUFFER 2 TO Q 1", buffer );
0094   puts( "TA1 - rtems_message_queue_send - BUFFER 2 TO Q 1" );
0095   status = rtems_message_queue_send( Queue_id[ 1 ], buffer, MESSAGE_SIZE );
0096   directive_failed( status, "rtems_message_queue_send" );
0097 
0098   puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
0099   status = rtems_task_wake_after( 5*rtems_clock_get_ticks_per_second() );
0100   directive_failed( status, "rtems_task_wake_after" );
0101 
0102   Fill_buffer( "BUFFER 3 TO Q 1", buffer );
0103   puts( "TA1 - rtems_message_queue_send - BUFFER 3 TO Q 1" );
0104   status = rtems_message_queue_send( Queue_id[ 1 ], buffer, MESSAGE_SIZE );
0105   directive_failed( status, "rtems_message_queue_send" );
0106 
0107   puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
0108   status = rtems_task_wake_after( 5*rtems_clock_get_ticks_per_second() );
0109   directive_failed( status, "rtems_task_wake_after" );
0110 
0111   Fill_buffer( "BUFFER 1 TO Q 2", buffer );
0112   puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 2" );
0113   status = rtems_message_queue_send( Queue_id[ 2 ], buffer, MESSAGE_SIZE );
0114   directive_failed( status, "rtems_message_queue_send" );
0115 
0116   puts_nocr( "TA1 - rtems_message_queue_receive - receive from queue 1 - " );
0117   puts     ( "10 second timeout" );
0118   status = rtems_message_queue_receive(
0119     Queue_id[ 1 ],
0120     buffer,
0121     &size,
0122     RTEMS_DEFAULT_OPTIONS,
0123     10 * rtems_clock_get_ticks_per_second()
0124   );
0125   directive_failed( status, "rtems_message_queue_receive" );
0126   puts_nocr( "TA1 - buffer received: " );
0127   Put_buffer( buffer );
0128   new_line;
0129 
0130   puts( "TA1 - rtems_task_delete - delete TA2" );
0131   status = rtems_task_delete( Task_id[ 2 ] );
0132   directive_failed( status, "rtems_task_delete" );
0133 
0134   Fill_buffer( "BUFFER 1 TO Q 3", buffer );
0135   puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 3" );
0136   status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
0137   directive_failed( status, "rtems_message_queue_send" );
0138 
0139   puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
0140   status = rtems_task_wake_after( 5*rtems_clock_get_ticks_per_second() );
0141   directive_failed( status, "rtems_task_wake_after" );
0142 
0143   Fill_buffer( "BUFFER 2 TO Q 3", buffer );
0144   puts( "TA1 - rtems_message_queue_send - BUFFER 2 TO Q 3" );
0145   status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
0146   directive_failed( status, "rtems_message_queue_send" );
0147 
0148   Fill_buffer( "BUFFER 3 TO Q 3", buffer );
0149   puts( "TA1 - rtems_message_queue_send - BUFFER 3 TO Q 3" );
0150   status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
0151   directive_failed( status, "rtems_message_queue_send" );
0152 
0153   Fill_buffer( "BUFFER 4 TO Q 3", buffer );
0154   puts( "TA1 - rtems_message_queue_send - BUFFER 4 TO Q 3" );
0155   status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
0156   directive_failed( status, "rtems_message_queue_send" );
0157 
0158   Fill_buffer( "BUFFER 5 TO Q 3", buffer );
0159   puts( "TA1 - rtems_message_queue_urgent - BUFFER 5 TO Q 3" );
0160   status = rtems_message_queue_urgent( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
0161   directive_failed( status, "rtems_message_queue_urgent" );
0162 
0163   for ( index = 1 ; index <= 4 ; index++ ) {
0164     puts(
0165       "TA1 - rtems_message_queue_receive - receive from queue 3 - "
0166         "RTEMS_WAIT FOREVER"
0167     );
0168     status = rtems_message_queue_receive(
0169       Queue_id[ 3 ],
0170       buffer,
0171       &size,
0172       RTEMS_DEFAULT_OPTIONS,
0173       RTEMS_NO_TIMEOUT
0174     );
0175     directive_failed( status, "rtems_message_queue_receive" );
0176     puts_nocr( "TA1 - buffer received: " );
0177     Put_buffer( buffer );
0178     new_line;
0179   }
0180 
0181   Fill_buffer( "BUFFER 3 TO Q 2", buffer );
0182   puts( "TA1 - rtems_message_queue_urgent - BUFFER 3 TO Q 2" );
0183   status = rtems_message_queue_urgent( Queue_id[ 2 ], buffer, MESSAGE_SIZE );
0184   directive_failed( status, "rtems_message_queue_urgent" );
0185 
0186   puts(
0187     "TA1 - rtems_message_queue_receive - receive from queue 2 - "
0188       "RTEMS_WAIT FOREVER"
0189   );
0190   status = rtems_message_queue_receive(
0191     Queue_id[ 2 ],
0192     buffer,
0193     &size,
0194     RTEMS_DEFAULT_OPTIONS,
0195     RTEMS_NO_TIMEOUT
0196   );
0197   directive_failed( status, "rtems_message_queue_receive" );
0198   puts_nocr( "TA1 - buffer received: " );
0199   Put_buffer( buffer );
0200   new_line;
0201 
0202   puts( "TA1 - rtems_message_queue_delete - delete queue 1" );
0203   status = rtems_message_queue_delete( Queue_id[ 1 ] );
0204   directive_failed( status, "rtems_message_queue_delete" );
0205 
0206   Fill_buffer( "BUFFER 3 TO Q 2", buffer );
0207   puts( "TA1 - rtems_message_queue_urgent - BUFFER 3 TO Q 2" );
0208   status = rtems_message_queue_urgent( Queue_id[ 2 ], buffer, MESSAGE_SIZE );
0209   directive_failed( status, "rtems_message_queue_urgent" );
0210 
0211   puts( "TA1 - rtems_message_queue_delete - delete queue 2" );
0212   status = rtems_message_queue_delete( Queue_id[ 2 ] );
0213   directive_failed( status, "rtems_message_queue_delete" );
0214 
0215   puts( "TA1 - rtems_message_queue_get_number_pending - check Q 3" );
0216   status = rtems_message_queue_get_number_pending( Queue_id[ 3 ], &count );
0217   directive_failed( status, "rtems_message_queue_get_number_pending" );
0218   printf( "TA1 - %" PRIu32 " messages are pending on Q 3\n", count );
0219 
0220   puts( "TA1 - rtems_message_queue_flush - empty Q 3" );
0221   status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
0222   directive_failed( status, "rtems_message_queue_flush" );
0223   printf( "TA1 - %" PRIu32 " messages were flushed from Q 3\n", count );
0224 
0225   Fill_buffer( "BUFFER 1 TO Q 3", buffer );
0226   puts( "TA1 - rtems_message_queue_send - BUFFER 1 TO Q 3" );
0227   status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
0228   directive_failed( status, "rtems_message_queue_send" );
0229 
0230   Fill_buffer( "BUFFER 2 TO Q 3", buffer );
0231   puts( "TA1 - rtems_message_queue_send - BUFFER 2 TO Q 3" );
0232   status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
0233   directive_failed( status, "rtems_message_queue_send" );
0234 
0235   /* this broadcast should have no effect on the queue */
0236   Fill_buffer( "NO BUFFER TO Q1", (long *)buffer );
0237   puts( "TA1 - rtems_message_queue_broadcast - NO BUFFER TO Q1" );
0238   status = rtems_message_queue_broadcast(
0239     Queue_id[ 1 ],
0240     (long (*)[4])buffer,
0241     16,
0242     &count
0243   );
0244   printf( "TA1 - number of tasks awakened = %" PRIu32 "\n", count );
0245 
0246   puts( "TA1 - rtems_message_queue_get_number_pending - check Q 3" );
0247   status = rtems_message_queue_get_number_pending( Queue_id[ 3 ], &count );
0248   directive_failed( status, "rtems_message_queue_get_number_pending" );
0249   printf( "TA1 - %" PRIu32 " messages are pending on Q 3\n", count );
0250 
0251   Fill_buffer( "BUFFER 3 TO Q 3", buffer );
0252   puts( "TA1 - rtems_message_queue_send - BUFFER 3 TO Q 3" );
0253   status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
0254   directive_failed( status, "rtems_message_queue_send" );
0255 
0256   puts( "TA1 - rtems_message_queue_flush - Q 3" );
0257   status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
0258   printf( "TA1 - %" PRIu32 " messages were flushed from Q 3\n", count );
0259 
0260   puts( "TA1 - rtems_message_queue_send until all message buffers consumed" );
0261   while ( FOREVER ) {
0262     status = rtems_message_queue_send( Queue_id[ 3 ], buffer, MESSAGE_SIZE );
0263     if ( status == RTEMS_TOO_MANY ) break;
0264     directive_failed( status, "rtems_message_queue_send loop" );
0265   }
0266 
0267   puts( "TA1 - all message buffers consumed" );
0268   puts( "TA1 - rtems_message_queue_flush - Q 3" );
0269   status = rtems_message_queue_flush( Queue_id[ 3 ], &count );
0270   printf( "TA1 - %" PRIu32 " messages were flushed from Q 3\n", count );
0271 
0272   puts( "TA1 - create message queue of 20 bytes on queue 1" );
0273   status = rtems_message_queue_create(
0274     Queue_name[ 1 ],
0275     100,
0276     20,
0277     RTEMS_DEFAULT_ATTRIBUTES,
0278     &Queue_id[ 1 ]
0279   );
0280   directive_failed( status, "rtems_message_queue_create of Q1; 20 bytes each" );
0281 
0282   status = rtems_message_queue_send( Queue_id[ 1 ], big_send_buffer, 40 );
0283   fatal_directive_status(status,
0284     RTEMS_INVALID_SIZE,
0285     "expected RTEMS_INVALID_SIZE"
0286   );
0287 
0288   puts( "TA1 - rtems_message_queue_delete - delete queue 1" );
0289   status = rtems_message_queue_delete( Queue_id[ 1 ] );
0290   directive_failed( status, "rtems_message_queue_delete" );
0291 
0292   puts( "TA1 - rtems_message_queue_create - variable sizes " );
0293   for (queue_size = 1; queue_size < 1030; queue_size++) {
0294     status = rtems_message_queue_create(
0295       Queue_name[ 1 ],
0296       2,            /* just 2 msgs each */
0297       queue_size,
0298       RTEMS_DEFAULT_ATTRIBUTES,
0299       &Queue_id[ 1 ]
0300     );
0301     if (status != RTEMS_SUCCESSFUL) {
0302       printf("TA1 - msq que size: %zu\n", queue_size);
0303       directive_failed( status, "rtems_message_queue_create of Q1" );
0304     }
0305 
0306     status = rtems_message_queue_delete( Queue_id[ 1 ] );
0307     directive_failed( status, "rtems_message_queue_delete" );
0308   }
0309 
0310   puts( "TA1 - rtems_message_queue_create and send - variable sizes " );
0311   for (queue_size = 1; queue_size < 1030; queue_size++) {
0312     status = rtems_message_queue_create(
0313       Queue_name[ 1 ],
0314       2,            /* just 2 msgs each */
0315       queue_size,
0316       RTEMS_DEFAULT_ATTRIBUTES,
0317       &Queue_id[ 1 ]
0318     );
0319     directive_failed( status, "rtems_message_queue_create of Q1" );
0320 
0321     dope_buffer(big_send_buffer, sizeof(big_send_buffer), queue_size);
0322     memset(big_receive_buffer, 'Z', sizeof(big_receive_buffer));
0323 
0324     /* send a msg too big */
0325     status = rtems_message_queue_send(
0326       Queue_id[ 1 ],
0327       big_send_buffer,
0328       queue_size + 1
0329     );
0330     fatal_directive_status(
0331       status,
0332       RTEMS_INVALID_SIZE,
0333       "rtems_message_queue_send too large"
0334     );
0335 
0336     /* send a msg that is just right */
0337     status = rtems_message_queue_send(
0338       Queue_id[ 1 ],
0339       big_send_buffer,
0340       queue_size);
0341     directive_failed(status, "rtems_message_queue_send exact size");
0342 
0343     /* now read and verify the message just sent */
0344     status = rtems_message_queue_receive(
0345       Queue_id[ 1 ],
0346       big_receive_buffer,
0347       &size,
0348       RTEMS_DEFAULT_OPTIONS,
0349       1 * rtems_clock_get_ticks_per_second()
0350     );
0351     directive_failed(status, "rtems_message_queue_receive exact size");
0352     if (size != queue_size) {
0353       puts("TA1 - exact size size match failed");
0354       rtems_test_exit(1);
0355     }
0356 
0357     if (memcmp(big_send_buffer, big_receive_buffer, size) != 0) {
0358       puts("TA1 - exact size data match failed");
0359       rtems_test_exit(1);
0360     }
0361 
0362     for (cp = (big_receive_buffer + size);
0363          cp < (big_receive_buffer + sizeof(big_receive_buffer));
0364          cp++) {
0365      if (*cp != 'Z') {
0366        puts("TA1 - exact size overrun match failed");
0367        rtems_test_exit(1);
0368      }
0369    }
0370 
0371    /* all done with this one; delete it */
0372    status = rtems_message_queue_delete( Queue_id[ 1 ] );
0373    directive_failed( status, "rtems_message_queue_delete" );
0374   }
0375 
0376   TEST_END();
0377   rtems_test_exit( 0 );
0378 }