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-1999. |
---|
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.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #include <tmacros.h> |
---|
16 | #include <assert.h> |
---|
17 | #include <sys/stat.h> |
---|
18 | #include <fcntl.h> |
---|
19 | #include <stdio.h> |
---|
20 | #include <unistd.h> |
---|
21 | #include <errno.h> |
---|
22 | #include <string.h> |
---|
23 | #include <rtems.h> |
---|
24 | #include <rtems/libio.h> |
---|
25 | |
---|
26 | /* |
---|
27 | * List of dates and times to test. |
---|
28 | */ |
---|
29 | #define NUMBER_OF_DATES 7 |
---|
30 | rtems_time_of_day Dates[ NUMBER_OF_DATES ] = { |
---|
31 | /* YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, TICKS */ |
---|
32 | { 1988, 1, 1, 12, 45, 00, 0 }, |
---|
33 | { 1988, 12, 31, 9, 00, 00, 0 }, |
---|
34 | { 1999, 12, 31, 23, 55, 59, 0 }, |
---|
35 | { 1999, 06, 30, 00, 01, 30, 0 }, |
---|
36 | { 2000, 1, 1, 0, 15, 59, 0 }, |
---|
37 | { 2005, 2, 2, 5, 10, 59, 0 }, |
---|
38 | { 2010, 3, 3, 10, 5, 59, 0 }, |
---|
39 | { 2020, 4, 4, 15, 0, 59, 0 }, |
---|
40 | }; |
---|
41 | |
---|
42 | /* |
---|
43 | * Check out a single date and time |
---|
44 | */ |
---|
45 | |
---|
46 | void check_a_tod( |
---|
47 | rtems_time_of_day *the_tod |
---|
48 | ) |
---|
49 | { |
---|
50 | rtems_status_code status; |
---|
51 | rtems_time_of_day new_tod; |
---|
52 | time_t a_time_t; |
---|
53 | struct timeval tv; |
---|
54 | struct tm *a_tm; |
---|
55 | int result; |
---|
56 | int i = 0; |
---|
57 | |
---|
58 | print_time( "rtems_clock_set ", the_tod, "\n" ); |
---|
59 | status = rtems_clock_set( the_tod ); |
---|
60 | assert( !status ); |
---|
61 | |
---|
62 | do { |
---|
63 | status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &new_tod ); |
---|
64 | assert( !status ); |
---|
65 | print_time( "rtems_clock_get ", &new_tod, "\n" ); |
---|
66 | |
---|
67 | /* now do the posix time gets */ |
---|
68 | result = gettimeofday( &tv, 0 ); |
---|
69 | assert( result == 0 ); |
---|
70 | printf( "gettimeofday: %s", ctime( &tv.tv_sec ) ); |
---|
71 | |
---|
72 | a_time_t = time( 0 ); |
---|
73 | printf( "time: %s", ctime( &a_time_t ) ); |
---|
74 | |
---|
75 | a_tm = localtime( &a_time_t ); |
---|
76 | printf( "localtime: %s", asctime( a_tm ) ); |
---|
77 | |
---|
78 | a_tm = gmtime( &a_time_t ); |
---|
79 | printf( "gmtime: %s\n", asctime( a_tm ) ); |
---|
80 | |
---|
81 | status = rtems_task_wake_after( 5 * TICKS_PER_SECOND ); |
---|
82 | |
---|
83 | i++; |
---|
84 | |
---|
85 | } while( i < 6 ); |
---|
86 | } |
---|
87 | |
---|
88 | /* |
---|
89 | * main entry point to the test |
---|
90 | */ |
---|
91 | |
---|
92 | #if defined(__rtems__) |
---|
93 | int test_main(void) |
---|
94 | #else |
---|
95 | int main( |
---|
96 | int argc, |
---|
97 | char **argv |
---|
98 | ) |
---|
99 | #endif |
---|
100 | { |
---|
101 | int i; |
---|
102 | |
---|
103 | puts( "\n\n*** POSIX TIME OF DAY TEST ***" ); |
---|
104 | |
---|
105 | i = 0; |
---|
106 | while ( i < NUMBER_OF_DATES ) { |
---|
107 | check_a_tod( &Dates[i] ); |
---|
108 | i++; |
---|
109 | } |
---|
110 | |
---|
111 | puts( "\n\n*** END OF TIME OF DAY TEST 01 ***" ); |
---|
112 | exit(0); |
---|
113 | } |
---|
114 | |
---|