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

4.104.115
Last change on this file since cd4884a was 88271c33, checked in by Joel Sherrill <joel.sherrill@…>, on 09/13/09 at 20:36:36

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

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