Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2009.
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 const char rtems_test_name[] = "SP 45";
0036 
0037 rtems_task Init(
0038   rtems_task_argument argument
0039 );
0040 rtems_timer_service_routine Malloc_From_TSR(
0041   rtems_id  ignored_id,
0042   void     *ignored_address
0043 );
0044 
0045 rtems_id   Timer_id[ 3 ];    /* array of timer ids */
0046 rtems_name Timer_name[ 3 ];  /* array of timer names */
0047 
0048 volatile int TSR_fired;
0049 volatile void *TSR_malloc_ptr;
0050 
0051 rtems_timer_service_routine Malloc_From_TSR(
0052   rtems_id  ignored_id,
0053   void     *ignored_address
0054 )
0055 {
0056   rtems_status_code  status;
0057 
0058   TSR_fired = 2;
0059   puts( "TSR: calling malloc" );
0060   TSR_malloc_ptr = malloc( 64 );
0061 
0062   puts( "TSR: calling free" );
0063   free( (void *) TSR_malloc_ptr );
0064 
0065   puts( "TSR: delaying with rtems_task_wake_after" );
0066   status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() / 2 );
0067   directive_failed( status, "rtems_task_wake_after" );
0068 }
0069 
0070 rtems_task Init(
0071   rtems_task_argument argument
0072 )
0073 {
0074   rtems_status_code  status;
0075 
0076   TEST_BEGIN();
0077 
0078   status = rtems_timer_initiate_server(
0079     RTEMS_TIMER_SERVER_DEFAULT_PRIORITY,
0080     RTEMS_MINIMUM_STACK_SIZE,
0081     RTEMS_DEFAULT_ATTRIBUTES
0082   );
0083   directive_failed( status, "rtems_timer_initiate_server" );
0084 
0085   /*
0086    * Initialize Timers
0087    */
0088 
0089   Timer_name[ 1 ] = rtems_build_name( 'T', 'M', '1', ' ' );
0090   Timer_name[ 2 ] = rtems_build_name( 'T', 'M', '2', ' ' );
0091 
0092   puts( "INIT - rtems_timer_create - creating timer 1" );
0093   status = rtems_timer_create( Timer_name[ 1 ], &Timer_id[ 1 ] );
0094   directive_failed( status, "rtems_timer_create" );
0095   printf( "INIT - timer 1 has id (0x%" PRIxrtems_id ")\n", Timer_id[ 1 ] );
0096 
0097   puts( "INIT - rtems_timer_create - creating timer 2" );
0098   status = rtems_timer_create( Timer_name[ 2 ], &Timer_id[ 2 ] );
0099   directive_failed( status, "rtems_timer_create" );
0100   printf( "INIT - timer 2 has id (0x%" PRIxrtems_id ")\n", Timer_id[ 2 ] );
0101 
0102   /*
0103    *  Schedule malloc TSR for 1 second from now
0104    */
0105 
0106   TSR_fired = 0;
0107   TSR_malloc_ptr = (void *) 0xa5a5a5;
0108   puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 1 seconds" );
0109   status = rtems_timer_server_fire_after(
0110     Timer_id[ 1 ],
0111     1 * rtems_clock_get_ticks_per_second(),
0112     Malloc_From_TSR,
0113     NULL
0114   );
0115   directive_failed( status, "rtems_timer_server_fire_after" );
0116 
0117   puts( "TA1 - rtems_task_wake_after - 2 second" );
0118   status = rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() );
0119   directive_failed( status, "rtems_task_wake_after" );
0120 
0121   if ( TSR_fired == 2 &&
0122        (TSR_malloc_ptr && TSR_malloc_ptr != (void *)0xa5a5a5) )
0123     puts( "TSR appears to have executed OK" );
0124   else {
0125     printf( "FAILURE ptr=%p TSR_fired=%d\n", TSR_malloc_ptr, TSR_fired );
0126     rtems_test_exit( 0 );
0127   }
0128 
0129   /*
0130    *  Delete timer and exit test
0131    */
0132   puts( "TA1 - timer_deleting - timer 1" );
0133   status = rtems_timer_delete( Timer_id[ 1 ] );
0134   directive_failed( status, "rtems_timer_delete" );
0135 
0136 
0137   TEST_END();
0138   rtems_test_exit( 0 );
0139 }
0140 
0141 #define CONFIGURE_INIT
0142 /* configuration information */
0143 
0144 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0145 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0146 
0147 /* Two Tasks: Init and Timer Server */
0148 #define CONFIGURE_MAXIMUM_TASKS           2
0149 #define CONFIGURE_MAXIMUM_TIMERS          2
0150 #define CONFIGURE_INIT_TASK_STACK_SIZE    (RTEMS_MINIMUM_STACK_SIZE * 2)
0151 
0152 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0153 
0154 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0155 
0156 #define CONFIGURE_EXTRA_TASK_STACKS       (1 * RTEMS_MINIMUM_STACK_SIZE)
0157 
0158 #include <rtems/confdefs.h>
0159