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 for this test program.
0006  *  Other than creating all objects needed by this test, if this routine
0007  *  is running on node one, it acquires a global semaphore to
0008  *  force all other tasks to pend.  If running on node two, this task
0009  *  sleeps for a while, and then deletes two local tasks which are
0010  *  waiting on a remote message queue or a semaphore.
0011  *  This routine is the initialization task for this test program.
0012  *  It is a user initialization task and has the responsibility for creating
0013  *  and starting the tasks that make up the test.  If the time of day
0014  *  clock is required for the test, it should also be set to a known
0015  *  value by this function.
0016  *
0017  *  Input parameters:
0018  *    argument - task argument
0019  *
0020  *  Output parameters:  NONE
0021  *
0022  *  COPYRIGHT (c) 1989-2009.
0023  *  On-Line Applications Research Corporation (OAR).
0024  *
0025  * Redistribution and use in source and binary forms, with or without
0026  * modification, are permitted provided that the following conditions
0027  * are met:
0028  * 1. Redistributions of source code must retain the above copyright
0029  *    notice, this list of conditions and the following disclaimer.
0030  * 2. Redistributions in binary form must reproduce the above copyright
0031  *    notice, this list of conditions and the following disclaimer in the
0032  *    documentation and/or other materials provided with the distribution.
0033  *
0034  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0035  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0036  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0037  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0038  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0039  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0040  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0041  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0042  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0043  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0044  * POSSIBILITY OF SUCH DAMAGE.
0045  */
0046 
0047 #ifdef HAVE_CONFIG_H
0048 #include "config.h"
0049 #endif
0050 
0051 #define CONFIGURE_INIT
0052 #include "system.h"
0053 
0054 rtems_task Init(
0055   rtems_task_argument argument
0056 )
0057 {
0058   rtems_status_code status;
0059 
0060   printf(
0061    "\n\n*** TEST 10 -- NODE %" PRIu32 " ***\n",
0062    rtems_object_get_local_node()
0063   );
0064 
0065   Task_name[ 1 ] =  rtems_build_name( 'T', 'A', '1', ' ' );
0066   Task_name[ 2 ] =  rtems_build_name( 'T', 'A', '2', ' ' );
0067   Task_name[ 3 ] =  rtems_build_name( 'S', 'A', '3', ' ' );
0068 
0069   Queue_name[ 1 ] = rtems_build_name( 'M', 'S', 'G', ' ' );
0070 
0071   Semaphore_name[ 1 ] = rtems_build_name( 'S', 'E', 'M', ' ' );
0072 
0073   if ( rtems_object_get_local_node() == 1 ) {
0074     puts( "Creating Message Queue (Global)" );
0075     status = rtems_message_queue_create(
0076       Queue_name[ 1 ],
0077       3,
0078       16,
0079       RTEMS_GLOBAL,
0080       &Queue_id[ 1 ]
0081     );
0082     directive_failed( status, "rtems_message_queue_create" );
0083 
0084     puts( "Creating Semaphore (Global)" );
0085     status = rtems_semaphore_create(
0086       Semaphore_name[ 1 ],
0087       0,
0088       RTEMS_GLOBAL | RTEMS_PRIORITY,
0089       RTEMS_NO_PRIORITY,
0090       &Semaphore_id[ 1 ]
0091     );
0092     directive_failed( status, "rtems_semaphore_create" );
0093 
0094     status = rtems_task_wake_after( 10 * rtems_clock_get_ticks_per_second() );
0095     directive_failed( status, "rtems_task_wake_after" );
0096 
0097   } else {
0098 
0099     puts( "Creating Test_task 1 (local)" );
0100     status = rtems_task_create(
0101       Task_name[ 1 ],
0102       1,
0103       RTEMS_MINIMUM_STACK_SIZE,
0104       RTEMS_TIMESLICE,
0105       RTEMS_DEFAULT_ATTRIBUTES,
0106       &Task_id[ 1 ]
0107     );
0108     directive_failed( status, "rtems_task_create" );
0109 
0110     puts( "Starting Test_task 1 (local)" );
0111     status = rtems_task_start( Task_id[ 1 ], Test_task1, 0 );
0112     directive_failed( status, "rtems_task_start" );
0113 
0114     puts( "Creating Test_task 2 (local)" );
0115     status = rtems_task_create(
0116       Task_name[ 2 ],
0117       1,
0118       RTEMS_MINIMUM_STACK_SIZE,
0119       RTEMS_TIMESLICE,
0120       RTEMS_DEFAULT_ATTRIBUTES,
0121       &Task_id[ 2 ]
0122     );
0123     directive_failed( status, "rtems_task_create" );
0124 
0125     puts( "Starting Test_task 2 (local)" );
0126     status = rtems_task_start( Task_id[ 2 ], Test_task2, 0 );
0127     directive_failed( status, "rtems_task_start" );
0128 
0129     puts( "Creating Test_task 3 (local)" );
0130     status = rtems_task_create(
0131       Task_name[ 3 ],
0132       1,
0133       RTEMS_MINIMUM_STACK_SIZE,
0134       RTEMS_TIMESLICE,
0135       RTEMS_DEFAULT_ATTRIBUTES,
0136       &Task_id[ 3 ]
0137     );
0138     directive_failed( status, "rtems_task_create" );
0139 
0140     puts( "Starting Test_task 3 (local)" );
0141     status = rtems_task_start( Task_id[ 3 ], Test_task2, 0 );
0142     directive_failed( status, "rtems_task_start" );
0143 
0144     puts( "Sleeping for 1 seconds ..." );
0145     status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
0146     directive_failed( status, "rtems_task_wake_after" );
0147 
0148     puts( "Deleting Test_task2" );
0149     status = rtems_task_delete( Task_id[ 2 ] );
0150     directive_failed( status, "rtems_task_delete of Task 2" );
0151 
0152     puts( "Deleting Test_task1" );
0153     status = rtems_task_delete( Task_id[ 1 ] );
0154     directive_failed( status, "rtems_task_delete of Task 1" );
0155 
0156     puts( "Restarting Test_task3" );
0157     status = rtems_task_restart( Task_id[ 3 ], 1 );
0158     directive_failed( status, "rtems_task_restart of Task 3" );
0159 
0160   }
0161   puts( "*** END OF TEST 10 ***" );
0162   rtems_test_exit( 0 );
0163 }