Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Test_task
0004  *
0005  *  This task tests global message queue operations.  It also generates
0006  *  an error condition.
0007  *
0008  *  Input parameters:
0009  *    argument - task argument
0010  *
0011  *  Output parameters:  NONE
0012  *
0013  *  COPYRIGHT (c) 1989-2009.
0014  *  On-Line Applications Research Corporation (OAR).
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #ifdef HAVE_CONFIG_H
0039 #include "config.h"
0040 #endif
0041 
0042 #include "system.h"
0043 
0044 char buffer1[16] = "123456789012345";
0045 char buffer2[16] = "abcdefghijklmno";
0046 char buffer3[16] = "ABCDEFGHIJKLMNO";
0047 char buffer4[16] = "PQRSTUVWXYZ(){}";
0048 
0049 rtems_task Test_task(
0050   rtems_task_argument argument
0051 )
0052 {
0053   rtems_status_code status;
0054   uint32_t          count;
0055   size_t            size;
0056   char              receive_buffer[16];
0057 
0058   status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
0059   directive_failed( status, "rtems_task_wake_after" );
0060 
0061   puts( "Getting QID of message queue" );
0062 
0063   do {
0064     status = rtems_message_queue_ident(
0065       Queue_name[ 1 ],
0066       RTEMS_SEARCH_ALL_NODES,
0067       &Queue_id[ 1 ]
0068     );
0069   } while ( !rtems_is_status_successful( status ) );
0070 
0071   status = rtems_message_queue_ident(
0072     Queue_name[ 2 ],
0073     RTEMS_SEARCH_ALL_NODES,
0074     &Queue_id[ 2 ]
0075   );
0076   directive_failed( status, "rtems_message_queue_ident" );
0077 
0078   if ( rtems_object_get_local_node() == 2 ) {
0079     status = rtems_message_queue_delete( Queue_id[ 2 ] );
0080     fatal_directive_status(
0081       status,
0082       RTEMS_ILLEGAL_ON_REMOTE_OBJECT,
0083       "rtems_message_queue_delete"
0084     );
0085     status = rtems_message_queue_delete( Queue_id[ 1 ] );
0086     fatal_directive_status(
0087       status,
0088       RTEMS_ILLEGAL_ON_REMOTE_OBJECT,
0089       "rtems_message_queue_delete"
0090     );
0091     puts(
0092   "rtems_message_queue_delete correctly returned RTEMS_ILLEGAL_ON_REMOTE_OBJECT"
0093     );
0094 
0095     Send_messages();
0096     Receive_messages();
0097 
0098     puts( "Flushing remote empty queue" );
0099     status = rtems_message_queue_flush( Queue_id[ 1 ], &count );
0100     directive_failed( status, "rtems_message_queue_flush" );
0101     printf( "%" PRIu32 " messages were flushed on the remote queue\n", count );
0102 
0103     puts( "Send messages to be flushed from remote queue" );
0104     status = rtems_message_queue_send( Queue_id[ 1 ], buffer1, 16 );
0105     directive_failed( status, "rtems_message_queue_send" );
0106 
0107     puts( "Flushing remote queue" );
0108     status = rtems_message_queue_flush( Queue_id[ 1 ], &count );
0109     directive_failed( status, "rtems_message_queue_flush" );
0110     printf( "%" PRIu32 " messages were flushed on the remote queue\n", count );
0111 
0112     puts( "Waiting for message queue to be deleted" );
0113     status = rtems_message_queue_receive(
0114       Queue_id[ 1 ],
0115       receive_buffer,
0116       &size,
0117       RTEMS_DEFAULT_OPTIONS,
0118       RTEMS_NO_TIMEOUT
0119     );
0120     fatal_directive_status(
0121       status,
0122       RTEMS_OBJECT_WAS_DELETED,
0123       "rtems_message_queue_receive"
0124     );
0125     puts( "\nGlobal message queue deleted" );
0126   }
0127   else {                   /* node == 1 */
0128     Receive_messages();
0129     Send_messages();
0130 
0131     puts( "Delaying for 5 seconds" );
0132     status = rtems_task_wake_after( 5*rtems_clock_get_ticks_per_second() );
0133     directive_failed( status, "rtems_task_wake_after" );
0134 
0135     puts( "Deleting Message queue" );
0136     status = rtems_message_queue_delete( Queue_id[ 1 ] );
0137     directive_failed( status, "rtems_message_queue_delete" );
0138 
0139     status = rtems_message_queue_delete( Queue_id[ 2 ] );
0140     directive_failed( status, "rtems_message_queue_delete" );
0141   }
0142 
0143   puts( "*** END OF TEST 9 ***" );
0144   rtems_test_exit( 0 );
0145 }