source: rtems/testsuites/psxtests/psxtime/test.c @ a91dc98b

4.115
Last change on this file since a91dc98b was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 *  This test exercises the time of day services via the Classic
3 *  and POSIX APIs to make sure they are consistent.
4 *
5 *  COPYRIGHT (c) 1989-2009.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <tmacros.h>
18#include <sys/stat.h>
19#include <fcntl.h>
20#include <stdio.h>
21#include <unistd.h>
22#include <errno.h>
23#include <string.h>
24#include <rtems.h>
25#include <rtems/libio.h>
26#include <sys/time.h>
27
28#if !HAVE_DECL_ADJTIME
29extern int adjtime(const struct timeval *delta, struct timeval *olddelta);
30#endif
31
32extern int _gettimeofday(struct timeval *__p, void *__tz);
33
34void test_adjtime(void);
35void check_a_tod(
36  rtems_time_of_day *the_tod
37);
38
39/*
40 *  List of dates and times to test.
41 */
42#define NUMBER_OF_DATES   8
43rtems_time_of_day Dates[ NUMBER_OF_DATES ] = {
44  /* YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, TICKS */
45  {  1988,   1,    1,   12,    45,     00,     0 },
46  {  1988,  12,   31,    9,    00,     00,     0 },
47  {  1999,  12,   31,   23,    55,     59,     0 },
48  {  1999,  06,   30,   00,    01,     30,     0 },
49  {  2000,   1,    1,    0,    15,     59,     0 },
50  {  2005,   2,    2,    5,    10,     59,     0 },
51  {  2010,   3,    3,   10,     5,     59,     0 },
52  {  2020,   4,    4,   15,     0,     59,     0 },
53};
54
55/*
56 *  Check out a single date and time
57 */
58
59void check_a_tod(
60  rtems_time_of_day *the_tod
61)
62{
63  rtems_status_code status;
64  rtems_time_of_day new_tod;
65  time_t            a_time_t;
66  struct timeval    tv;
67  struct tm        *a_tm;
68  int               result;
69  int               i = 0;
70
71  print_time( "rtems_clock_set          ", the_tod, "\n" );
72  status = rtems_clock_set( the_tod );
73  rtems_test_assert( !status );
74
75  do {
76    status = rtems_clock_get_tod( &new_tod );
77    rtems_test_assert( !status );
78    print_time( "rtems_clock_get_tod          ", &new_tod, "\n" );
79
80    /* now do the posix time gets */
81    result = gettimeofday( &tv, 0 );
82    rtems_test_assert( result == 0 );
83    a_time_t = tv.tv_sec;   /* ctime() takes a time_t */
84    printf( "gettimeofday: %s", ctime( &a_time_t) );
85
86    a_time_t = time( 0 );
87    printf( "time:         %s", ctime( &a_time_t ) );
88
89    a_tm = localtime( &a_time_t );
90    printf( "localtime:    %s", asctime( a_tm ) );
91
92    a_tm = gmtime( &a_time_t );
93    printf( "gmtime:       %s\n",  asctime( a_tm ) );
94
95    status = rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
96
97    i++;
98
99  } while( i < 6 );
100}
101
102void test_adjtime(void)
103{
104  int                sc;
105  rtems_status_code  status;
106  struct timeval     delta;
107  struct timeval     olddelta;
108  rtems_time_of_day *the_tod;
109  rtems_time_of_day  tod;
110  rtems_interval     ticks;
111
112  the_tod = &Dates[0];
113
114  print_time( "rtems_clock_set          ", the_tod, "\n" );
115  status = rtems_clock_set( the_tod );
116  rtems_test_assert( !status );
117
118  delta.tv_sec = 0;
119  delta.tv_usec = 0;
120  olddelta.tv_sec = 0;
121  olddelta.tv_usec = 0;
122
123  puts( "adjtime - NULL delta - EINVAL" );
124  sc = adjtime( NULL, &olddelta );
125  rtems_test_assert( sc == -1 );
126  rtems_test_assert( errno == EINVAL );
127
128  puts( "adjtime - delta out of range - EINVAL" );
129  delta.tv_usec = 1000000000; /* 100 seconds worth */
130  sc = adjtime( &delta, &olddelta );
131  rtems_test_assert( sc == -1 );
132  rtems_test_assert( errno == EINVAL );
133
134  puts( "adjtime - delta too small - do nothing" );
135  delta.tv_sec = 0;
136  delta.tv_usec = 1;
137  sc = adjtime( &delta, &olddelta );
138  rtems_test_assert( sc == 0 );
139
140  puts( "adjtime - delta too small - do nothing, olddelta=NULL" );
141  sc = adjtime( &delta, NULL );
142  rtems_test_assert( sc == 0 );
143
144  puts( "adjtime - delta of one second forward, olddelta=NULL" );
145  delta.tv_sec = 1;
146  delta.tv_usec = 0;
147  sc = adjtime( &delta, NULL );
148  rtems_test_assert( sc == 0 );
149
150  puts( "adjtime - delta of one second forward" );
151  delta.tv_sec = 1;
152  delta.tv_usec = 0;
153  sc = adjtime( &delta, &olddelta );
154  rtems_test_assert( sc == 0 );
155
156  puts( "adjtime - delta of almost two seconds forward" );
157  delta.tv_sec = 1;
158  delta.tv_usec = 1000000 - 1;
159  sc = adjtime( &delta, &olddelta );
160  rtems_test_assert( sc == 0 );
161
162  /*
163   * spin until over 1/2 of the way to the
164   */
165  ticks = rtems_clock_get_ticks_per_second();
166  rtems_test_assert( ticks );
167  ticks /= 2;
168  do {
169    status = rtems_clock_get_tod( &tod );
170    rtems_test_assert( !status );
171  } while ( tod.ticks <= ticks );
172
173  puts( "adjtime - delta of almost one second forward which bumps second" );
174  delta.tv_sec = 0;
175  delta.tv_usec = 1000000 - 1;
176  sc = adjtime( &delta, &olddelta );
177  rtems_test_assert( sc == 0 );
178
179  status = rtems_clock_get_tod( &tod );
180  rtems_test_assert( !status );
181  print_time( "rtems_clock_get_tod          ", &tod, "\n" );
182}
183
184/*
185 *  main entry point to the test
186 */
187
188#if defined(__rtems__)
189int test_main(void);
190
191int test_main(void)
192#else
193int main(
194  int    argc,
195  char **argv
196)
197#endif
198{
199  int i;
200  int sc;
201
202  puts( "\n\n*** POSIX TIME OF DAY TEST ***" );
203
204  puts( "gettimeofday( NULL, NULL ) - EFAULT" );
205  sc = gettimeofday( NULL, NULL );
206  rtems_test_assert( sc == -1 );
207  rtems_test_assert( errno == EFAULT );
208
209  puts( "_gettimeofday( NULL, NULL ) - EFAULT" );
210  sc = _gettimeofday( NULL, NULL );
211  rtems_test_assert( sc == -1 );
212  rtems_test_assert( errno == EFAULT );
213
214  test_adjtime();
215
216  /*
217   * Now test a number of dates
218   */
219
220  i = 0;
221  while ( i < NUMBER_OF_DATES ) {
222    check_a_tod( &Dates[i] );
223    i++;
224  }
225
226  puts( "\n\n*** END OF TIME OF DAY TEST 01 ***" );
227  rtems_test_exit(0);
228}
Note: See TracBrowser for help on using the repository browser.