Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Init
0004  *
0005  *  This routine is the initialization routine and test code for
0006  *  global partitions.  It creates a global partition, obtains and
0007  *  releases a buffer, and deletes the partition.  The partition
0008  *  is created on node one, and an attempt is made to delete it
0009  *  by node two.
0010  *  This routine is the initialization task for this test program.
0011  *  It is a user initialization task and has the responsibility for creating
0012  *  and starting the tasks that make up the test.  If the time of day
0013  *  clock is required for the test, it should also be set to a known
0014  *  value by this function.
0015  *
0016  *  Input parameters:
0017  *    argument - task argument
0018  *
0019  *  Output parameters:  NONE
0020  *
0021  *  COPYRIGHT (c) 1989-2009.
0022  *  On-Line Applications Research Corporation (OAR).
0023  *
0024  * Redistribution and use in source and binary forms, with or without
0025  * modification, are permitted provided that the following conditions
0026  * are met:
0027  * 1. Redistributions of source code must retain the above copyright
0028  *    notice, this list of conditions and the following disclaimer.
0029  * 2. Redistributions in binary form must reproduce the above copyright
0030  *    notice, this list of conditions and the following disclaimer in the
0031  *    documentation and/or other materials provided with the distribution.
0032  *
0033  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0034  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0035  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0036  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0037  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0038  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0039  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0040  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0041  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0042  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0043  * POSSIBILITY OF SUCH DAMAGE.
0044  */
0045 
0046 #ifdef HAVE_CONFIG_H
0047 #include "config.h"
0048 #endif
0049 
0050 #define CONFIGURE_INIT
0051 #include "system.h"
0052 
0053 uint8_t   Partition_area[ 1024 ] CPU_STRUCTURE_ALIGNMENT;
0054 
0055 rtems_task Init(
0056   rtems_task_argument argument
0057 )
0058 {
0059   rtems_status_code  status;
0060   void              *bufaddr;
0061 
0062   printf(
0063     "\n\n*** TEST 12 -- NODE %" PRId32 " ***\n",
0064     rtems_object_get_local_node()
0065    );
0066 
0067   Task_name[ 1 ] = rtems_build_name( '1', '1', '1', ' ' );
0068   Task_name[ 2 ] = rtems_build_name( '2', '2', '2', ' ' );
0069 
0070   Partition_name[ 1 ] = rtems_build_name( 'P', 'A', 'R', ' ' );
0071 
0072   puts( "Got to initialization task" );
0073 
0074   if ( rtems_object_get_local_node() == 2 )  {
0075     status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
0076     directive_failed( status, "rtems_task_wake_after" );
0077 
0078     puts( "Getting ID of remote Partition (Global)" );
0079 
0080     do {
0081       status = rtems_partition_ident(
0082         Partition_name[ 1 ],
0083         RTEMS_SEARCH_ALL_NODES,
0084         &Partition_id[ 1 ]
0085       );
0086     } while ( !rtems_is_status_successful( status ) );
0087 
0088     puts( "Attempting to delete remote Partition (Global)" );
0089     status = rtems_partition_delete( Partition_id[ 1 ] );
0090     fatal_directive_status(
0091       status,
0092       RTEMS_ILLEGAL_ON_REMOTE_OBJECT,
0093       "rtems_partition_delete"
0094     );
0095     puts(
0096      "rtems_partition_delete correctly returned RTEMS_ILLEGAL_ON_REMOTE_OBJECT"
0097     );
0098 
0099     puts( "Obtaining a buffer from the global partition" );
0100     status = rtems_partition_get_buffer( Partition_id[ 1 ], &bufaddr );
0101     directive_failed( status, "rtems_partition_get_buffer" );
0102     printf( "Address returned was : 0x%p\n", bufaddr );
0103 
0104     puts( "Releasing a buffer to the global partition" );
0105     status = rtems_partition_return_buffer( Partition_id[ 1 ], bufaddr );
0106     directive_failed( status, "rtems_partition_return_buffer" );
0107 
0108     status = rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() );
0109     directive_failed( status, "rtems_task_wake_after" );
0110   }
0111   else {
0112     puts( "Creating Partition (Global)" );
0113     status = rtems_partition_create(
0114       Partition_name[ 1 ],
0115       Partition_area,
0116       128,
0117       64,
0118       RTEMS_GLOBAL,
0119       &Partition_id[ 1 ]
0120     );
0121     directive_failed( status, "rtems_partition_create" );
0122 
0123     puts( "Sleeping for two seconds" );
0124     status = rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() );
0125     directive_failed( status, "rtems_task_wake_after" );
0126 
0127     puts( "Deleting Partition (Global)" );
0128     status = rtems_partition_delete( Partition_id[ 1 ] );
0129     directive_failed( status, "rtems_partition_delete" );
0130  }
0131  puts( "*** END OF TEST 12 ***" );
0132  rtems_test_exit( 0 );
0133 }