Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-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 #include "test_support.h"
0035 
0036 const char rtems_test_name[] = "SMP 7";
0037 
0038 volatile bool TaskRan = false;
0039 volatile bool TSRFired = false;
0040 rtems_id      Semaphore;
0041 
0042 rtems_task Init(
0043   rtems_task_argument argument
0044 );
0045 
0046 rtems_task Test_task(
0047   rtems_task_argument argument
0048 );
0049 
0050 static void success(void)
0051 {
0052   TEST_END( );
0053   rtems_test_exit( 0 );
0054 }
0055 
0056 rtems_task Test_task(
0057   rtems_task_argument argument
0058 )
0059 {
0060   uint32_t          cpu_num;
0061   rtems_status_code sc;
0062   char              name[5];
0063   char             *p;
0064 
0065   /* Get the task name */
0066   p = rtems_object_get_name( RTEMS_SELF, 5, name );
0067   rtems_test_assert( p != NULL );
0068 
0069    /* Get the CPU Number */
0070   cpu_num = rtems_scheduler_get_processor();
0071 
0072   /* Print that the task is up and running. */
0073   locked_printf(" CPU %" PRIu32 " runnng Task %s and blocking\n", cpu_num, name);
0074 
0075   sc = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
0076   directive_failed( sc,"obtain in test task");
0077 
0078   if ( !TSRFired )
0079     locked_printf( "*** ERROR TSR DID NOT FIRE BUT TEST TASK AWAKE***" );
0080 
0081   /* Print that the task is up and running. */
0082   locked_printf(
0083     " CPU %" PRIu32 " running Task %s after semaphore release\n",
0084     cpu_num,
0085     name
0086   );
0087 
0088   TaskRan = true;
0089 
0090   rtems_task_exit();
0091 }
0092 
0093 
0094 static rtems_timer_service_routine TimerMethod(
0095   rtems_id  timer,
0096   void     *arg
0097 )
0098 {
0099   /*
0100    * Set flag and release the semaphore, allowing the blocked tasks to start.
0101    */
0102   TSRFired = true;
0103 
0104   rtems_semaphore_release( Semaphore );
0105 }
0106 
0107 rtems_task Init(
0108   rtems_task_argument argument
0109 )
0110 {
0111   int                cpu_num;
0112   rtems_id           id;
0113   rtems_status_code  status;
0114   rtems_interval     per_second;
0115   rtems_interval     then;
0116   rtems_id           Timer;
0117 
0118   locked_print_initialize();
0119   TEST_BEGIN();
0120 
0121   if ( rtems_scheduler_get_processor_maximum() == 1 ) {
0122     success();
0123   }
0124 
0125   /* Create/verify semaphore */
0126   status = rtems_semaphore_create(
0127     rtems_build_name ('S', 'E', 'M', '1'),
0128     1,
0129     RTEMS_LOCAL                   |
0130     RTEMS_SIMPLE_BINARY_SEMAPHORE |
0131     RTEMS_PRIORITY,
0132     1,
0133     &Semaphore
0134   );
0135   directive_failed( status, "rtems_semaphore_create" );
0136 
0137   /* Lock semaphore */
0138   status = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, 0);
0139   directive_failed( status,"rtems_semaphore_obtain of SEM1\n");
0140 
0141   /* Create and Start test task. */
0142   status = rtems_task_create(
0143     rtems_build_name( 'T', 'A', '1', ' ' ),
0144     1,
0145     RTEMS_MINIMUM_STACK_SIZE,
0146     RTEMS_DEFAULT_MODES,
0147     RTEMS_DEFAULT_ATTRIBUTES,
0148     &id
0149   );
0150   directive_failed( status, "task create" );
0151 
0152   cpu_num = rtems_scheduler_get_processor();
0153   locked_printf(" CPU %d start task TA1\n", cpu_num );
0154   status = rtems_task_start( id, Test_task, 1 );
0155   directive_failed( status, "task start" );
0156 
0157   /* Create and start TSR */
0158   locked_printf(" CPU %d create and start timer\n", cpu_num );
0159   status = rtems_timer_create( rtems_build_name( 'T', 'M', 'R', '1' ), &Timer);
0160   directive_failed( status, "rtems_timer_create" );
0161 
0162   per_second = rtems_clock_get_ticks_per_second();
0163   status = rtems_timer_fire_after( Timer, 2 * per_second, TimerMethod, NULL );
0164   directive_failed( status, "rtems_timer_fire_after");
0165 
0166   /*
0167    *  Wait long enough that TSR should have fired.
0168    *
0169    *  Spin so CPU 0 is consumed.  This forces task to run on CPU 1.
0170    */
0171   then = rtems_clock_get_ticks_since_boot() + 4 * per_second;
0172   while (1) {
0173     if ( rtems_clock_get_ticks_since_boot() > then )
0174       break;
0175     if ( TSRFired && TaskRan )
0176       break;
0177   };
0178 
0179   /* Validate the timer fired and that the task ran */
0180   if ( !TSRFired )
0181     locked_printf( "*** ERROR TSR DID NOT FIRE ***" );
0182 
0183   if ( !TaskRan ) {
0184     locked_printf( "*** ERROR TASK DID NOT RUN ***" );
0185     rtems_test_exit(0);
0186   }
0187 
0188   /* End the program */
0189   success();
0190 }
0191 
0192 /* configuration information */
0193 
0194 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0195 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0196 
0197 #define CONFIGURE_MAXIMUM_PROCESSORS   2
0198 #define CONFIGURE_MAXIMUM_TIMERS           1
0199 
0200 #define CONFIGURE_MAXIMUM_TASKS            2
0201 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0202 
0203 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0204 #define CONFIGURE_MAXIMUM_SEMAPHORES       2
0205 
0206 #define CONFIGURE_INIT
0207 
0208 #include <rtems/confdefs.h>
0209 /* end of file */