source: rtems/testsuites/psxtests/psxclock/init.c @ af43554

5
Last change on this file since af43554 was af43554, checked in by Sebastian Huber <sebastian.huber@…>, on 10/26/17 at 11:59:11

tests: Remove TEST_INIT

The TEST_EXTERN is a used only by the system.h style tests and they use
CONFIGURE_INIT appropriately.

Update #3170.
Update #3199.

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