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) 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 1";
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_timer_information  timer_info;
0054   rtems_name               timer_name;
0055   rtems_id                 timer_id;
0056   rtems_id                 junk_id;
0057 
0058   timer_name =  rtems_build_name( 'T', 'M', '1', ' ' );
0059 
0060   /* before time set */
0061   status = rtems_timer_fire_when( 0, &time, Delayed_routine, NULL );
0062   if ( status == RTEMS_SUCCESSFUL ) {
0063     puts(
0064     "TA1 - timer_wake_when - RTEMS_NOT_DEFINED -- DID BSP SET THE TIME OF DAY?"
0065     );
0066   } else {
0067     fatal_directive_status(
0068       status,
0069       RTEMS_NOT_DEFINED,
0070       "task_fire_when before clock is set"
0071     );
0072     puts( "TA1 - rtems_timer_fire_when - RTEMS_NOT_DEFINED" );
0073   }
0074 
0075   /* Set System time */
0076   build_time( &time, 12, 31, 1992, 9, 0, 0, 0 );
0077   status = rtems_clock_set( &time );
0078   directive_failed( status, "rtems_clock_set" );
0079 
0080   /* NULL Id */
0081   status = rtems_timer_create( timer_name, NULL );
0082   fatal_directive_status(
0083     status,
0084     RTEMS_INVALID_ADDRESS,
0085     "rtems_timer_create NULL param"
0086   );
0087   puts( "TA1 - rtems_timer_create - RTEMS_INVALID_ADDRESS" );
0088 
0089   /* bad name */
0090   status = rtems_timer_create( 0, &junk_id );
0091   fatal_directive_status(
0092     status,
0093     RTEMS_INVALID_NAME,
0094     "rtems_timer_create with illegal name"
0095   );
0096   puts( "TA1 - rtems_timer_create - RTEMS_INVALID_NAME" );
0097 
0098   /* OK */
0099   status = rtems_timer_create( timer_name, &timer_id );
0100   directive_failed( status, "rtems_timer_create" );
0101   puts( "TA1 - rtems_timer_create - 1 - RTEMS_SUCCESSFUL" );
0102 
0103   status = rtems_timer_create( 2, &junk_id );
0104   fatal_directive_status(
0105     status,
0106     RTEMS_TOO_MANY,
0107     "rtems_timer_create for too many"
0108   );
0109   puts( "TA1 - rtems_timer_create - 2 - RTEMS_TOO_MANY" );
0110 
0111   status = rtems_timer_delete( 100 );
0112   fatal_directive_status(
0113     status,
0114     RTEMS_INVALID_ID,
0115     "rtems_timer_delete with illegal id"
0116   );
0117   puts( "TA1 - rtems_timer_delete - local RTEMS_INVALID_ID" );
0118 
0119   status = rtems_timer_delete( rtems_build_id( 1, 1, 1, 256 ) );
0120   fatal_directive_status(
0121     status,
0122     RTEMS_INVALID_ID,
0123     "rtems_timer_delete with illegal id"
0124   );
0125   puts( "TA1 - rtems_timer_delete - global RTEMS_INVALID_ID" );
0126 
0127   status = rtems_timer_ident( 0, &junk_id );
0128   fatal_directive_status(
0129     status,
0130     RTEMS_INVALID_NAME,
0131     "rtems_timer_ident with illegal name"
0132   );
0133   puts( "TA1 - rtems_timer_ident - RTEMS_INVALID_NAME" );
0134 
0135   status = rtems_timer_cancel( rtems_build_id( 1, 1, 1, 256 ) );
0136   fatal_directive_status(
0137     status,
0138     RTEMS_INVALID_ID,
0139     "rtems_timer_cancel with illegal id"
0140   );
0141   puts( "TA1 - rtems_timer_cancel - RTEMS_INVALID_ID" );
0142 
0143   status = rtems_timer_reset( rtems_build_id( 1, 1, 1, 256 ) );
0144   fatal_directive_status(
0145     status,
0146     RTEMS_INVALID_ID,
0147     "rtems_timer_reset with illegal id"
0148   );
0149   puts( "TA1 - rtems_timer_reset - RTEMS_INVALID_ID" );
0150 
0151   status = rtems_timer_reset( timer_id );
0152   fatal_directive_status(
0153     status,
0154     RTEMS_NOT_DEFINED,
0155     "rtems_timer_reset before initiated"
0156   );
0157   puts( "TA1 - rtems_timer_reset - RTEMS_NOT_DEFINED" );
0158 
0159   /* bad id */
0160   status = rtems_timer_fire_after(
0161     rtems_build_id( 1, 1, 1, 256 ),
0162     5 * rtems_clock_get_ticks_per_second(),
0163     Delayed_routine,
0164     NULL
0165   );
0166   fatal_directive_status(
0167     status,
0168     RTEMS_INVALID_ID,
0169     "rtems_timer_fire_after illegal id"
0170   );
0171   puts( "TA1 - rtems_timer_fire_after - RTEMS_INVALID_ID" );
0172 
0173   /* bad id */
0174   build_time( &time, 12, 31, 1994, 9, 0, 0, 0 );
0175   status = rtems_timer_fire_when(
0176     rtems_build_id( 1, 1, 1, 256 ),
0177     &time,
0178     Delayed_routine,
0179     NULL
0180   );
0181   fatal_directive_status(
0182     status,
0183     RTEMS_INVALID_ID,
0184     "rtems_timer_fire_when with illegal id"
0185   );
0186   puts( "TA1 - rtems_timer_fire_when - RTEMS_INVALID_ID" );
0187 
0188   /* NULL routine */
0189   status = rtems_timer_fire_after( timer_id, 1, NULL, NULL );
0190   fatal_directive_status(
0191     status,
0192     RTEMS_INVALID_ADDRESS,
0193     "rtems_timer_fire_after with NULL handler"
0194   );
0195   puts( "TA1 - rtems_timer_fire_after - RTEMS_INVALID_ADDRESS" );
0196 
0197   /* 0 ticks */
0198   status = rtems_timer_fire_after( timer_id, 0, Delayed_routine, NULL );
0199   fatal_directive_status(
0200     status,
0201     RTEMS_INVALID_NUMBER,
0202     "rtems_timer_fire_after with 0 ticks"
0203   );
0204   puts( "TA1 - rtems_timer_fire_after - RTEMS_INVALID_NUMBER" );
0205 
0206   /* NULL routine */
0207   status = rtems_timer_fire_when( timer_id, &time, NULL, NULL );
0208   fatal_directive_status(
0209     status,
0210     RTEMS_INVALID_ADDRESS,
0211     "rtems_timer_fire_when with NULL handler"
0212   );
0213   puts( "TA1 - rtems_timer_fire_when - RTEMS_INVALID_ADDRESS" );
0214 
0215   /* invalid time -- before RTEMS epoch */
0216   build_time( &time, 2, 5, 1987, 8, 30, 45, 0 );
0217   status = rtems_timer_fire_when( timer_id, &time, Delayed_routine, NULL );
0218   fatal_directive_status(
0219     status,
0220     RTEMS_INVALID_CLOCK,
0221     "rtems_timer_fire_when with illegal time"
0222   );
0223   print_time(
0224     "TA1 - rtems_timer_fire_when - ",
0225     &time,
0226     " - RTEMS_INVALID_CLOCK\n"
0227   );
0228 
0229   status = rtems_clock_get_tod( &time );
0230   directive_failed( status, "rtems_clock_get_tod" );
0231   print_time( "TA1 - rtems_clock_get_tod       - ", &time, "\n" );
0232 
0233   build_time( &time, 2, 5, 1990, 8, 30, 45, 0 );
0234   status = rtems_timer_fire_when( timer_id, &time, Delayed_routine, NULL );
0235   fatal_directive_status(
0236     status,
0237     RTEMS_INVALID_CLOCK,
0238     "rtems_timer_fire_when before current time"
0239   );
0240   print_time(
0241     "TA1 - rtems_timer_fire_when - ",
0242     &time,
0243     " - before RTEMS_INVALID_CLOCK\n"
0244   );
0245 
0246   /* null param */
0247   status = rtems_timer_get_information( timer_id, NULL );
0248   fatal_directive_status(
0249     status,
0250     RTEMS_INVALID_ADDRESS,
0251     "rtems_timer_get_information with NULL param"
0252   );
0253   puts( "TA1 - rtems_timer_get_information - RTEMS_INVALID_ADDRESS" );
0254 
0255   /* invalid id */
0256   status = rtems_timer_get_information( 100, &timer_info );
0257   fatal_directive_status(
0258     status,
0259     RTEMS_INVALID_ID,
0260     "rtems_timer_get_information with illegal id"
0261   );
0262   puts( "TA1 - rtems_timer_get_information - RTEMS_INVALID_ID" );
0263 
0264 
0265   TEST_END();
0266 
0267   rtems_test_exit(0);
0268 }
0269 
0270 rtems_timer_service_routine Delayed_routine(
0271   rtems_id  ignored_id,
0272   void     *ignored_address
0273 )
0274 {
0275   /* Empty routine that gets passed to rtems_timer_fire_when */
0276 }
0277 
0278 /* configuration information */
0279 
0280 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0281 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0282 
0283 #define CONFIGURE_MAXIMUM_TASKS             1
0284 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0285 
0286 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0287 #define CONFIGURE_MAXIMUM_TIMERS              1
0288 
0289 #define CONFIGURE_INIT
0290 
0291 #include <rtems/confdefs.h>
0292 /* end of file */