source: rtems/testsuites/psxtests/psxclock/init.c @ 4562dd8

4.115
Last change on this file since 4562dd8 was 4562dd8, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/30/11 at 02:53:32

2011-09-30 Ralf Corsépius <ralf.corsepius@…>

  • psx01/init.c, psx07/init.c, psx09/init.c, psx12/init.c, psxclock/init.c, psxtimer01/psxtimer.c: Include "pritime.h". Use PRIdtime_t to print time_t.
  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <time.h>
17#include <errno.h>
18
19#include "pmacros.h"
20#include "pritime.h"
21
22void check_enosys(int status);
23
24void check_enosys(int status)
25{
26  if ( (status == -1) && (errno == ENOSYS) )
27    return;
28  puts( "ERROR -- did not return ENOSYS as expected" );
29  rtems_test_exit(0);
30}
31
32rtems_task Init(
33  rtems_task_argument argument
34)
35{
36  struct timespec tv;
37  struct timespec tr;
38  int             sc;
39  time_t          seconds;
40  time_t          seconds1;
41  unsigned int    remaining;
42  struct tm       tm;
43  struct timespec delay_request;
44
45  puts( "\n\n*** POSIX CLOCK TEST ***" );
46
47  tm_build_time( &tm, TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
48
49  /* error cases in clock_gettime and clock_settime */
50
51  puts( "Init: clock_gettime - EINVAL (NULL timespec)" );
52  sc = clock_gettime( CLOCK_REALTIME, NULL );
53  rtems_test_assert( sc == -1 );
54  rtems_test_assert( errno == EINVAL );
55
56  puts( "Init: clock_gettime - EINVAL (invalid clockid)" );
57  sc = clock_gettime( (clockid_t)-1, &tv );
58  rtems_test_assert( sc == -1 );
59  rtems_test_assert( errno == EINVAL );
60
61  puts( "Init: clock_settime - EINVAL (invalid clockid)" );
62  sc = clock_settime( (clockid_t)-1, &tv );
63  rtems_test_assert( sc == -1 );
64  rtems_test_assert( errno == EINVAL );
65
66  /* way back near the dawn of time :D */
67  tv.tv_sec = 1;
68  tv.tv_nsec = 0;
69  printf( ctime( &tv.tv_sec ) );
70  puts( "Init: clock_settime - before 1988 EINVAL" );
71  sc = clock_settime( CLOCK_REALTIME, &tv );
72  rtems_test_assert( sc == -1 );
73  rtems_test_assert( errno == EINVAL );
74
75  /* exercise clock_getres */
76
77  puts( "Init: clock_getres - EINVAL (invalid clockid)" );
78  sc = clock_getres( (clockid_t) -1, &tv );
79  rtems_test_assert( sc == -1 );
80  rtems_test_assert( errno == EINVAL );
81
82  puts( "Init: clock_getres - EINVAL (NULL resolution)" );
83  sc = clock_getres( CLOCK_REALTIME, NULL );
84  rtems_test_assert( sc == -1 );
85  rtems_test_assert( errno == EINVAL );
86
87  puts( "Init: clock_getres - SUCCESSFUL" );
88  sc = clock_getres( CLOCK_REALTIME, &tv );
89  printf( "Init: resolution = sec (%" PRIdtime_t "), nsec (%ld)\n", tv.tv_sec, tv.tv_nsec );
90  rtems_test_assert( !sc );
91
92  /* set the time of day, and print our buffer in multiple ways */
93
94  tv.tv_sec = mktime( &tm );
95  rtems_test_assert( tv.tv_sec != -1 );
96
97  tv.tv_nsec = 0;
98
99  /* now set the time of day */
100
101  empty_line();
102
103  printf( asctime( &tm ) );
104  puts( "Init: clock_settime - SUCCESSFUL" );
105  sc = clock_settime( CLOCK_REALTIME, &tv );
106  rtems_test_assert( !sc );
107
108  printf( asctime( &tm ) );
109  printf( ctime( &tv.tv_sec ) );
110
111  /* use sleep to delay */
112
113  remaining = sleep( 3 );
114  rtems_test_assert( !remaining );
115
116  /* print new times to make sure it has changed and we can get the realtime */
117  sc = clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &tv );
118  rtems_test_assert( !sc );
119  printf("Time since boot: (%" PRIdtime_t ", %ld)\n", tv.tv_sec,tv.tv_nsec );
120
121  sc = clock_gettime( CLOCK_REALTIME, &tv );
122  rtems_test_assert( !sc );
123
124  printf( ctime( &tv.tv_sec ) );
125
126  seconds = time( NULL );
127  printf( ctime( &seconds ) );
128
129  /*  just to have the value copied out through the parameter */
130
131  seconds = time( &seconds1 );
132  rtems_test_assert( seconds == seconds1 );
133
134  /* check the time remaining */
135
136  printf( "Init: seconds remaining (%d)\n", (int)remaining );
137  rtems_test_assert( !remaining );
138
139  /* error cases in nanosleep */
140
141  empty_line();
142  puts( "Init: nanosleep - EINVAL (NULL time)" );
143  sc = nanosleep ( NULL, &tr );
144  rtems_test_assert( sc == -1 );
145  rtems_test_assert( errno == EINVAL );
146
147  tv.tv_sec = 0;
148  tv.tv_nsec = TOD_NANOSECONDS_PER_SECOND * 2;
149  puts( "Init: nanosleep - EINVAL (too many nanoseconds)" );
150  sc = nanosleep ( &tv, &tr );
151  rtems_test_assert( sc == -1 );
152  rtems_test_assert( errno == EINVAL );
153
154  /* this is an error */
155  tv.tv_sec = -1;
156  tv.tv_nsec = 0;
157  puts( "Init: nanosleep - negative seconds - EINVAL" );
158  sc = nanosleep ( &tv, &tr );
159  rtems_test_assert( sc == -1 );
160  rtems_test_assert( errno == EINVAL );
161
162  /* this is also an error */
163  tv.tv_sec = 0;
164  tv.tv_nsec = -1;
165  puts( "Init: nanosleep - negative nanoseconds - EINVAL" );
166  sc = nanosleep ( &tv, &tr );
167  rtems_test_assert( sc == -1 );
168  rtems_test_assert( errno == EINVAL );
169
170  /* this is actually a small delay */
171  tv.tv_sec = 0;
172  tv.tv_nsec = 1;
173  puts( "Init: nanosleep - delay so small results in one tick" );
174  sc = nanosleep ( &tv, &tr );
175  rtems_test_assert( !sc );
176  rtems_test_assert( !tr.tv_sec );
177  rtems_test_assert( !tr.tv_nsec );
178
179  /* use nanosleep to yield */
180
181  tv.tv_sec = 0;
182  tv.tv_nsec = 0;
183
184  puts( "Init: nanosleep - yield with remaining" );
185  sc = nanosleep ( &tv, &tr );
186  rtems_test_assert( !sc );
187  rtems_test_assert( !tr.tv_sec );
188  rtems_test_assert( !tr.tv_nsec );
189
190  puts( "Init: nanosleep - yield with NULL time remaining" );
191  sc = nanosleep ( &tv, NULL );
192  rtems_test_assert( !sc );
193  rtems_test_assert( !tr.tv_sec );
194  rtems_test_assert( !tr.tv_nsec );
195
196  /* use nanosleep to delay */
197
198  tv.tv_sec = 3;
199  tv.tv_nsec = 500000;
200
201  puts( "Init: nanosleep - 1.05 seconds" );
202  sc = nanosleep ( &tv, &tr );
203  rtems_test_assert( !sc );
204
205  /* print the current real time again */
206  sc = clock_gettime( CLOCK_REALTIME, &tv );
207  rtems_test_assert( !sc );
208  printf( ctime( &tv.tv_sec ) );
209
210  /* check the time remaining */
211
212  printf( "Init: sec (%" PRIdtime_t "), nsec (%ld) remaining\n", tr.tv_sec, tr.tv_nsec );
213  rtems_test_assert( !tr.tv_sec && !tr.tv_nsec );
214
215  puts( "Init: nanosleep - 1.35 seconds" );
216  delay_request.tv_sec = 1;
217  delay_request.tv_nsec = 35000000;
218  sc = nanosleep( &delay_request, NULL );
219  rtems_test_assert( !sc );
220
221  /* print the current real time again */
222  sc = clock_gettime( CLOCK_REALTIME, &tv );
223  rtems_test_assert( !sc );
224  printf( ctime( &tv.tv_sec ) );
225
226  empty_line();
227  puts( "clock_gettime - CLOCK_THREAD_CPUTIME_ID -- ENOSYS" );
228  #if defined(_POSIX_THREAD_CPUTIME)
229    {
230      struct timespec tp;
231      sc = clock_gettime( CLOCK_THREAD_CPUTIME_ID, &tp );
232      check_enosys( sc );
233    }
234  #endif
235
236  puts( "clock_settime - CLOCK_PROCESS_CPUTIME_ID -- ENOSYS" );
237  #if defined(_POSIX_CPUTIME)
238    {
239      struct timespec tp;
240      sc = clock_settime( CLOCK_PROCESS_CPUTIME_ID, &tp );
241      check_enosys( sc );
242    }
243  #endif
244
245  puts( "clock_settime - CLOCK_THREAD_CPUTIME_ID -- ENOSYS" );
246  #if defined(_POSIX_THREAD_CPUTIME)
247    {
248      struct timespec tp;
249      sc = clock_settime( CLOCK_THREAD_CPUTIME_ID, &tp );
250      check_enosys( sc );
251    }
252  #endif
253
254  puts( "*** END OF POSIX CLOCK TEST ***" );
255  rtems_test_exit(0);
256}
257
258
259/* configuration information */
260#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
261#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
262
263#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
264#define CONFIGURE_MAXIMUM_TASKS             1
265
266#define CONFIGURE_INIT
267#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.