Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2009, 2017.
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 #ifndef __POSIX_TEST_MACROS_h
0030 #define __POSIX_TEST_MACROS_h
0031 
0032 #if defined(__rtems__)
0033 #include <bsp.h>
0034 #endif
0035 #include <pthread.h>
0036 #include <stdio.h>
0037 #include <string.h>
0038 #include <time.h>
0039 #include <unistd.h>
0040 
0041 #include <tmacros.h>
0042 #include <buffer_test_io.h>
0043 
0044 /*
0045  *  These help manipulate the "struct tm" form of time
0046  */
0047 
0048 #define TM_SUNDAY    0
0049 #define TM_MONDAY    1
0050 #define TM_TUESDAY   2
0051 #define TM_WEDNESDAY 3
0052 #define TM_THURSDAY  4
0053 #define TM_FRIDAY    5
0054 #define TM_SATURDAY  6
0055 
0056 #define TM_JANUARY     0
0057 #define TM_FEBRUARY    1
0058 #define TM_MARCH       2
0059 #define TM_APRIL       3
0060 #define TM_MAY         4
0061 #define TM_JUNE        5
0062 #define TM_JULY        6
0063 #define TM_AUGUST      7
0064 #define TM_SEPTEMBER   8
0065 #define TM_OCTOBER     9
0066 #define TM_NOVEMBER   10
0067 #define TM_DECEMBER   11
0068 
0069 #ifndef tm_build_time
0070 #define tm_build_time( TM, WEEKDAY, MON, DAY, YR, HR, MIN, SEC ) \
0071   { (TM)->tm_year = YR;  \
0072     (TM)->tm_mon  = MON; \
0073     (TM)->tm_mday = DAY; \
0074     (TM)->tm_wday  = WEEKDAY; \
0075     (TM)->tm_hour = HR;  \
0076     (TM)->tm_min  = MIN; \
0077     (TM)->tm_sec  = SEC; }
0078 #endif
0079 
0080 #define set_time( WEEKDAY, MON, DAY, YR, HR, MIN, SEC ) \
0081   do { \
0082     struct tm tm; \
0083     struct timespec tv; \
0084     int status; \
0085     \
0086     tm_build_time( &tm, WEEKDAY, MON, DAY, YR, HR, MIN, SEC ); \
0087     \
0088     tv.tv_sec = mktime( &tm ); \
0089     tv.tv_nsec = 0; \
0090     rtems_test_assert(  tv.tv_sec != -1 ); \
0091     \
0092     status = clock_settime( CLOCK_REALTIME, &tv ); \
0093     rtems_test_assert(  !status ); \
0094   } while ( 0 )
0095 
0096 #define print_current_time(s1, s2) \
0097   do { \
0098     char _time_buffer[32]; \
0099     int  _status; \
0100     struct timespec _tv; \
0101     \
0102     _status = clock_gettime( CLOCK_REALTIME, &_tv ); \
0103     rtems_test_assert(  !_status ); \
0104     \
0105     (void) ctime_r( &_tv.tv_sec, _time_buffer ); \
0106     _time_buffer[ strlen( _time_buffer ) - 1 ] = 0; \
0107     printf( "%s%s%s\n", s1, _time_buffer, s2 ); \
0108   } while ( 0 )
0109 
0110 #define empty_line() puts( "" )
0111 
0112 #endif
0113 
0114 /* end of file */