Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2013.
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[] = "SPTIMER_ERR 2";
0037 
0038 /* forward declarations to avoid warnings */
0039 rtems_task Init(rtems_task_argument argument);
0040 rtems_timer_service_routine Delayed_routine(
0041   rtems_id  ignored_id,
0042   void     *ignored_address
0043 );
0044 
0045 rtems_task Init(
0046   rtems_task_argument argument
0047 )
0048 {
0049   TEST_BEGIN();
0050 
0051   rtems_status_code        status;
0052   rtems_time_of_day        time;
0053   rtems_id                 timer_id;
0054   rtems_name               timer_name;
0055 
0056   /* Set System time */
0057   build_time( &time, 12, 31, 1992, 9, 0, 0, 0 );
0058   status = rtems_clock_set( &time );
0059   directive_failed( status, "rtems_clock_set" );
0060 
0061   timer_name =  rtems_build_name( 'T', 'M', '1', ' ' );
0062 
0063   /* OK */
0064   status = rtems_timer_create( timer_name, &timer_id );
0065   directive_failed( status, "rtems_timer_create" );
0066   puts( "TA1 - rtems_timer_create - 1 - RTEMS_SUCCESSFUL" );
0067 
0068   /* incorrect state */
0069   status = rtems_timer_server_fire_after( 0, 5, NULL, NULL );
0070   fatal_directive_status(
0071     status,
0072     RTEMS_INCORRECT_STATE,
0073     "rtems_timer_server_fire_after incorrect state"
0074   );
0075   puts( "TA1 - rtems_timer_server_fire_after - RTEMS_INCORRECT_STATE" );
0076 
0077   /* incorrect state */
0078   status = rtems_timer_server_fire_when( 0, &time, NULL, NULL );
0079   fatal_directive_status(
0080     status,
0081     RTEMS_INCORRECT_STATE,
0082     "rtems_timer_server_fire_when incorrect state"
0083   );
0084   puts( "TA1 - rtems_timer_server_fire_when - RTEMS_INCORRECT_STATE" );
0085 
0086   /* invalid priority */
0087   status = rtems_timer_initiate_server( UINT32_MAX - 1, 0, 0 );
0088   fatal_directive_status(
0089     status,
0090     RTEMS_INVALID_PRIORITY,
0091     "rtems_timer_initiate_server invalid priority"
0092   );
0093   puts( "TA1 - rtems_timer_initiate_server - RTEMS_INVALID_PRIORITY" );
0094 
0095   status = rtems_timer_initiate_server(
0096     RTEMS_TIMER_SERVER_DEFAULT_PRIORITY,
0097     0x10000000,
0098     0
0099   );
0100   fatal_directive_status(
0101     status,
0102     RTEMS_UNSATISFIED,
0103     "rtems_timer_initiate_server too much stack "
0104   );
0105   puts( "TA1 - rtems_timer_initiate_server - RTEMS_UNSATISFIED" );
0106 
0107   status =
0108     rtems_timer_initiate_server( RTEMS_TIMER_SERVER_DEFAULT_PRIORITY, 0, 0 );
0109   directive_failed( status, "rtems_timer_initiate_server" );
0110   puts( "TA1 - rtems_timer_initiate_server - SUCCESSFUL" );
0111 
0112   /* NULL routine */
0113   status = rtems_timer_server_fire_after( timer_id, 1, NULL, NULL );
0114   fatal_directive_status(
0115     status,
0116     RTEMS_INVALID_ADDRESS,
0117     "rtems_timer_server_fire_after NULL routine"
0118   );
0119   puts( "TA1 - rtems_timer_server_fire_after - RTEMS_INVALID_ADDRESS" );
0120 
0121   /* bad Id */
0122   status = rtems_timer_server_fire_after(
0123     rtems_build_id( 1, 1, 1, 256 ),
0124     5 * rtems_clock_get_ticks_per_second(),
0125     Delayed_routine,
0126     NULL
0127   );
0128   fatal_directive_status(
0129     status,
0130     RTEMS_INVALID_ID,
0131     "rtems_timer_server_fire_after illegal id"
0132   );
0133   puts( "TA1 - rtems_timer_server_fire_after - RTEMS_INVALID_ID" );
0134 
0135   /* bad id */
0136   build_time( &time, 12, 31, 1994, 9, 0, 0, 0 );
0137   status = rtems_timer_server_fire_when(
0138     rtems_build_id( 1, 1, 1, 256 ),
0139     &time,
0140     Delayed_routine,
0141     NULL
0142   );
0143   fatal_directive_status(
0144     status,
0145     RTEMS_INVALID_ID,
0146     "rtems_timer_server_fire_when with illegal id"
0147   );
0148   puts( "TA1 - rtems_timer_server_fire_when - RTEMS_INVALID_ID" );
0149 
0150   /* NULL routine */
0151   status = rtems_timer_server_fire_after( timer_id, 1, NULL, NULL );
0152   fatal_directive_status(
0153     status,
0154     RTEMS_INVALID_ADDRESS,
0155     "rtems_timer_server_fire_after NULL routine"
0156   );
0157   puts( "TA1 - rtems_timer_server_fire_after - RTEMS_INVALID_ADDRESS" );
0158 
0159   /* 0 ticks */
0160   status = rtems_timer_server_fire_after(
0161     timer_id, 0, Delayed_routine, NULL );
0162   fatal_directive_status(
0163     status,
0164     RTEMS_INVALID_NUMBER,
0165     "rtems_timer_server_fire_after with 0 ticks"
0166   );
0167   puts( "TA1 - rtems_timer_server_fire_after - RTEMS_INVALID_NUMBER" );
0168 
0169   /* illegal time */
0170   build_time( &time, 2, 5, 1987, 8, 30, 45, 0 );
0171   status = rtems_timer_server_fire_when(
0172     timer_id, &time, Delayed_routine, NULL );
0173   fatal_directive_status(
0174     status,
0175     RTEMS_INVALID_CLOCK,
0176     "rtems_timer_server_fire_when with illegal time"
0177   );
0178   print_time(
0179     "TA1 - rtems_timer_server_fire_when - ",
0180     &time,
0181     " - RTEMS_INVALID_CLOCK\n"
0182   );
0183 
0184   status = rtems_clock_get_tod( &time );
0185   directive_failed( status, "rtems_clock_get_tod" );
0186   print_time( "TA1 - rtems_clock_get_tod       - ", &time, "\n" );
0187 
0188   /* when NULL routine */
0189   status = rtems_timer_server_fire_when( timer_id, &time, NULL, NULL );
0190   fatal_directive_status(
0191     status,
0192     RTEMS_INVALID_ADDRESS,
0193     "rtems_timer_server_fire_when NULL routine"
0194   );
0195   puts( "TA1 - rtems_timer_server_fire_when - RTEMS_INVALID_ADDRESS" );
0196 
0197   /* before current time */
0198   build_time( &time, 2, 5, 1990, 8, 30, 45, 0 );
0199   status = rtems_timer_server_fire_when(
0200     timer_id, &time, Delayed_routine, NULL );
0201   fatal_directive_status(
0202     status,
0203     RTEMS_INVALID_CLOCK,
0204     "rtems_timer_server_fire_when before current time"
0205   );
0206   print_time(
0207     "TA1 - rtems_timer_server_fire_when - ",
0208     &time,
0209     " - before RTEMS_INVALID_CLOCK\n"
0210   );
0211 
0212   TEST_END();
0213 
0214   rtems_test_exit(0);
0215 }
0216 
0217 rtems_timer_service_routine Delayed_routine(
0218   rtems_id  ignored_id,
0219   void     *ignored_address
0220 )
0221 {
0222   /* Empty routine that gets passed to rtems_timer_fire_when */
0223 }
0224 
0225 #define CONFIGURE_INIT
0226 /* configuration information */
0227 
0228 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0229 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0230 
0231 /* Two Tasks: Init and Timer Server */
0232 #define CONFIGURE_MAXIMUM_TASKS           2
0233 #define CONFIGURE_MAXIMUM_TIMERS          1
0234 #define CONFIGURE_INIT_TASK_STACK_SIZE    (RTEMS_MINIMUM_STACK_SIZE * 2)
0235 
0236 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0237 
0238 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0239 
0240 #define CONFIGURE_EXTRA_TASK_STACKS       (1 * RTEMS_MINIMUM_STACK_SIZE)
0241 
0242 #include <rtems/confdefs.h>