source: rtems/testsuites/psxtests/psxclock/init.c @ 1e2d7510

4.104.11
Last change on this file since 1e2d7510 was 1e2d7510, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 14, 2009 at 12:15:55 AM

2009-09-13 Joel Sherrill <joel.sherrill@…>

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