Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 2011.
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 <tmacros.h>
0034 
0035 #include <rtems/score/threadimpl.h>
0036 
0037 const char rtems_test_name[] = "SPSIMPLESCHED 2";
0038 
0039 /* forward declarations to avoid warnings */
0040 rtems_task Init(rtems_task_argument argument);
0041 rtems_task Test_task(rtems_task_argument argument);
0042 void ObtainRelease(bool suspendIdle);
0043 
0044 /*
0045  *  Keep the names and IDs in global variables so another task can use them.
0046  */
0047 rtems_id   Idle_id;
0048 rtems_id   Task_id[ 3 ];         /* array of task ids */
0049 rtems_name Task_name[ 3 ];       /* array of task names */
0050 rtems_name Semaphore_name[ 2 ];
0051 rtems_id   Semaphore_id[ 2 ];
0052 
0053 rtems_task Test_task(
0054   rtems_task_argument unused
0055 )
0056 {
0057   rtems_id          tid;
0058   rtems_status_code status;
0059 
0060   status = rtems_task_ident( RTEMS_WHO_AM_I, RTEMS_SEARCH_ALL_NODES, &tid );
0061   directive_failed( status, "wake after" );
0062 
0063   for ( ; ; ) {
0064     status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0065     directive_failed( status, "yield" );
0066   }
0067 }
0068 
0069 void ObtainRelease( bool suspendIdle )
0070 {
0071   rtems_status_code   status;
0072 
0073   if (suspendIdle) {
0074     puts( "INIT - Suspend Idle Task");
0075     status = rtems_task_suspend( Idle_id );
0076     directive_failed( status, "rtems_task_suspend idle" );
0077   }
0078 
0079   puts( "INIT - Obtain priority ceiling semaphore - priority increases" );
0080   status= rtems_semaphore_obtain( Semaphore_id[1], RTEMS_DEFAULT_OPTIONS, 0 );
0081   directive_failed( status, "rtems_semaphore_obtain" );
0082 
0083   puts( "INIT - Obtain priority ceiling semaphore - priority decreases" );
0084   status = rtems_semaphore_release( Semaphore_id[1] );
0085   directive_failed( status, "rtems_semaphore_release" );
0086 
0087   if (suspendIdle) {
0088     puts( "INIT - Resume Idle Task");
0089     status = rtems_task_resume( Idle_id );
0090     directive_failed( status, "rtems_task_resume idle" );
0091   }
0092 }
0093 
0094 rtems_task Init(
0095   rtems_task_argument argument
0096 )
0097 {
0098   rtems_status_code   status;
0099 
0100   TEST_BEGIN();
0101 
0102   status = _Objects_Name_to_id_u32(
0103     rtems_build_name( 'I', 'D', 'L', 'E' ),
0104     RTEMS_SEARCH_LOCAL_NODE,
0105     &Idle_id,
0106     &_Thread_Information.Objects
0107   );
0108   rtems_test_assert( status == RTEMS_SUCCESSFUL );
0109 
0110   /*
0111    * Create the semaphore. Then obtain and release the
0112    * semaphore with no other tasks running.
0113    */
0114   puts( "INIT - Create priority ceiling semaphore" );
0115   Semaphore_name[ 1 ] = rtems_build_name( 'S', 'M', '1', ' ' );
0116   status = rtems_semaphore_create(
0117     Semaphore_name[ 1 ],
0118     1,
0119     RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY,
0120     2,
0121     &Semaphore_id[ 1 ]
0122   );
0123   directive_failed( status, "rtems_semaphore_create of SM1" );
0124   ObtainRelease( false );
0125 
0126   /*
0127    * Create test task and obtain release the semaphore with
0128    * one other task running.
0129    */
0130   puts( "INIT - create task 1" );
0131   Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
0132   status = rtems_task_create(
0133     Task_name[ 1 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
0134     RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ]
0135   );
0136   status = rtems_task_start( Task_id[ 1 ], Test_task, 1 );
0137   ObtainRelease( false );
0138 
0139   /*
0140    * Create a a second test task and obtain release the semaphore
0141    * with both tasks running.
0142    */
0143   puts( "INIT - create task 2" );
0144   Task_name[ 1 ] = rtems_build_name( 'T', 'A', '2', ' ' );
0145   status = rtems_task_create(
0146     Task_name[ 2 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
0147     RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ]
0148   );
0149   status = rtems_task_start( Task_id[ 2 ], Test_task, 1 );
0150   ObtainRelease( false );
0151 
0152   /*
0153    * Obtain and release the semaphore with the idle task suspended.
0154    */
0155   ObtainRelease( true );
0156 
0157   /*  End the Test */
0158   TEST_END();
0159   rtems_test_exit(0);
0160 }
0161 
0162 /* configuration information */
0163 
0164 #define CONFIGURE_SCHEDULER_SIMPLE
0165 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0166 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0167 
0168 #define CONFIGURE_MAXIMUM_TASKS             3
0169 #define CONFIGURE_MAXIMUM_SEMAPHORES        2
0170 
0171 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0172 
0173 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0174 
0175 #define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)
0176 
0177 #define CONFIGURE_INIT_TASK_INITIAL_MODES   RTEMS_NO_PREEMPT
0178 #define CONFIGURE_INIT_TASK_PRIORITY        4
0179 
0180 #define CONFIGURE_INIT
0181 #include <rtems/confdefs.h>
0182 /* end of include file */