Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 2014.
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 #define CONFIGURE_INIT
0034 #include "system.h"
0035 
0036 const char rtems_test_name[] = "SP CLOCK ERROR 2";
0037 
0038 rtems_task Init(
0039   rtems_task_argument argument
0040 )
0041 {
0042   rtems_time_of_day time;
0043   rtems_interval    interval;
0044   struct timeval    tv;
0045   rtems_status_code status;
0046   
0047   TEST_BEGIN();
0048  
0049   puts( "TA1 - rtems_clock_get_tod - RTEMS_INVALID_ADDRESS" );
0050   status = rtems_clock_get_tod( NULL );
0051   fatal_directive_status(
0052     status,
0053     RTEMS_INVALID_ADDRESS,
0054     "rtems_clock_get_tod NULL param"
0055   );
0056 
0057 /* errors before clock is set */
0058 
0059   status = rtems_clock_get_tod( &time );
0060   if ( status == RTEMS_SUCCESSFUL ) {
0061     puts(
0062      "TA1 - rtems_clock_get_tod - RTEMS_NOT_DEFINED -- "
0063          "DID BSP SET THE TIME OF DAY?"
0064     );
0065   } else {
0066     fatal_directive_status(
0067       status,
0068       RTEMS_NOT_DEFINED,
0069       "rtems_clock_get_tod before clock is set #1"
0070     );
0071     puts( "TA1 - rtems_clock_get_tod - RTEMS_NOT_DEFINED" );
0072   }
0073 
0074   puts( "TA1 - rtems_clock_get_seconds_since_epoch - RTEMS_INVALID_ADDRESS" );
0075   status = rtems_clock_get_seconds_since_epoch( NULL );
0076   fatal_directive_status(
0077     status,
0078     RTEMS_INVALID_ADDRESS,
0079     "rtems_clock_get_seconds_since_epoch NULL param"
0080   );
0081 
0082   status = rtems_clock_get_seconds_since_epoch( &interval );
0083   if ( status == RTEMS_SUCCESSFUL ) {
0084     puts(
0085      "TA1 - rtems_clock_get_seconds_since_epoch - RTEMS_NOT_DEFINED -- "
0086          "DID BSP SET THE TIME OF DAY?"
0087     );
0088   } else {
0089     fatal_directive_status(
0090       status,
0091       RTEMS_NOT_DEFINED,
0092       "rtems_clock_get_seconds_before_epoch"
0093     );
0094     puts( "TA1 - rtems_clock_get_seconds_since_epoch - RTEMS_NOT_DEFINED" );
0095   }
0096 
0097   puts( "TA1 - rtems_clock_get_uptime - RTEMS_INVALID_ADDRESS" );
0098   status = rtems_clock_get_uptime( NULL );
0099   fatal_directive_status(
0100     status,
0101     RTEMS_INVALID_ADDRESS,
0102     "rtems_clock_get_uptime NULL param"
0103   );
0104 
0105   puts( "TA1 - rtems_clock_get_uptime_timeval" );
0106   rtems_clock_get_uptime_timeval( &tv );
0107 
0108   puts( "TA1 - rtems_clock_get_uptime_seconds" );
0109   rtems_clock_get_uptime_seconds();
0110 
0111   puts( "TA1 - rtems_clock_get_uptime_nanoseconds" );
0112   rtems_clock_get_uptime_nanoseconds();
0113 
0114   puts( "TA1 - rtems_clock_get_tod_timeval - RTEMS_INVALID_ADDRESS" );
0115   status = rtems_clock_get_tod_timeval( NULL );
0116   fatal_directive_status(
0117     status,
0118     RTEMS_INVALID_ADDRESS,
0119     "rtems_clock_get_tod_timeval NULL param"
0120   );
0121 
0122   status = rtems_clock_get_tod_timeval( &tv );
0123   if ( status == RTEMS_SUCCESSFUL ) {
0124     puts(
0125      "TA1 - rtems_clock_get_tod_timeval - RTEMS_NOT_DEFINED -- "
0126          "DID BSP SET THE TIME OF DAY?"
0127     );
0128   } else {
0129     fatal_directive_status(
0130       status,
0131       RTEMS_NOT_DEFINED,
0132       "rtems_clock_get_timeval"
0133     );
0134     puts( "TA1 - rtems_clock_get_tod_timeval - RTEMS_NOT_DEFINED" );
0135   }
0136 
0137   /* NULL parameter */
0138   status = rtems_clock_set( NULL );
0139   fatal_directive_status(
0140     status,
0141     RTEMS_INVALID_ADDRESS,
0142     "rtems_clock_set sull pointer"
0143   );
0144   puts( "TA1 - rtems_clock_set - RTEMS_INVALID_ADDRESS" );
0145 
0146   build_time( &time, 2, 5, 1987, 8, 30, 45, 0 );
0147   print_time( "TA1 - rtems_clock_set - ", &time, "" );
0148   status = rtems_clock_set( &time );
0149   fatal_directive_status(
0150     status,
0151     RTEMS_INVALID_CLOCK,
0152     "rtems_clock_set with invalid year"
0153   );
0154   puts( " - RTEMS_INVALID_CLOCK" );
0155 
0156   build_time( &time, 15, 5, 1988, 8, 30, 45, 0 );
0157   print_time( "TA1 - rtems_clock_set - ", &time, "" );
0158   status = rtems_clock_set( &time );
0159   fatal_directive_status(
0160     status,
0161     RTEMS_INVALID_CLOCK,
0162     "rtems_clock_set with invalid month"
0163   );
0164   puts( " - RTEMS_INVALID_CLOCK" );
0165 
0166   build_time( &time, 2, 32, 1988, 8, 30, 45, 0 );
0167   print_time( "TA1 - rtems_clock_set - ", &time, "" );
0168   status = rtems_clock_set( &time );
0169   fatal_directive_status(
0170     status,
0171     RTEMS_INVALID_CLOCK,
0172     "rtems_clock_set with invalid day"
0173   );
0174   puts( " - RTEMS_INVALID_CLOCK" );
0175 
0176   build_time( &time, 2, 5, 1988, 25, 30, 45, 0 );
0177   print_time( "TA1 - rtems_clock_set - ", &time, "" );
0178   status = rtems_clock_set( &time );
0179   fatal_directive_status(
0180     status,
0181     RTEMS_INVALID_CLOCK,
0182     "rtems_clock_set with invalid hour"
0183   );
0184   puts( " - RTEMS_INVALID_CLOCK" );
0185 
0186   build_time( &time, 2, 5, 1988, 8, 61, 45, 0 );
0187   print_time( "TA1 - rtems_clock_set - ", &time, "" );
0188   status = rtems_clock_set( &time );
0189   fatal_directive_status(
0190     status,
0191     RTEMS_INVALID_CLOCK,
0192     "rtems_clock_set with invalid minute"
0193   );
0194   puts( " - RTEMS_INVALID_CLOCK" );
0195 
0196   build_time( &time, 2, 5, 1988, 8, 30, 61, 0 );
0197   print_time( "TA1 - rtems_clock_set - ", &time, "" );
0198   status = rtems_clock_set( &time );
0199   fatal_directive_status(
0200     status,
0201     RTEMS_INVALID_CLOCK,
0202     "rtems_clock_set with invalid second"
0203   );
0204   puts( " - RTEMS_INVALID_CLOCK" );
0205 
0206   build_time(
0207     &time, 2, 5, 1988, 8, 30, 45,
0208     rtems_clock_get_ticks_per_second() + 1
0209   );
0210   print_time( "TA1 - rtems_clock_set - ", &time, "" );
0211   status = rtems_clock_set( &time );
0212   fatal_directive_status(
0213     status,
0214     RTEMS_INVALID_CLOCK,
0215     "rtems_clock_set with invalid ticks per second"
0216   );
0217   puts( " - RTEMS_INVALID_CLOCK" );
0218 
0219   build_time( &time, 2, 5, 1988, 8, 30, 45, 0 );
0220   print_time( "TA1 - rtems_clock_set - ", &time, "" );
0221   status = rtems_clock_set( &time );
0222   directive_failed( status, "rtems_clock_set successful" );
0223   puts( " - RTEMS_SUCCESSFUL" );
0224 
0225   rtems_clock_get_tod( &time );
0226   print_time( "TA1 - current time - ", &time, "\n" );
0227 
0228   TEST_END();
0229   rtems_test_exit( 0 );
0230 }