source: rtems/testsuites/psxtests/psx01/init.c @ 2e7e636f

4.104.115
Last change on this file since 2e7e636f was 2e7e636f, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/09 at 01:41:16

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • psx01/init.c, psx01/task.c, psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx04/task1.c, psx04/task3.c, psx05/init.c, psx06/init.c, psx07/init.c, psx08/init.c, psx09/init.c, psx11/task.c, psx12/init.c, psx13/main.c, psx13/test.c, psxbarrier01/test.c, psxcancel/init.c, psxcleanup/psxcleanup.c, psxenosys/init.c, psxmsgq02/init.c, psxtime/main.c, psxtime/test.c, psxtimer01/psxtimer.c, psxtimer02/psxtimer.c: Fix warnings.
  • Property mode set to 100644
File size: 7.8 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#define CONFIGURE_INIT
13#include "system.h"
14#include <sched.h>
15#include <sys/utsname.h>
16
17void *POSIX_Init(
18  void *argument
19)
20{
21  struct timespec tv;
22  struct timespec tr;
23  int             status;
24  int             priority;
25  pthread_t       thread_id;
26  time_t          seconds;
27  time_t          seconds1;
28  unsigned int    remaining;
29  struct tm       tm;
30  struct utsname  uts;
31  useconds_t      useconds;
32
33  puts( "\n\n*** POSIX TEST 1 ***" );
34
35  tm_build_time( &tm, TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
36
37  /* print some system information */
38
39  puts( "Init: uname - EFAULT (invalid uts pointer argument)" );
40  status = uname( NULL );
41  rtems_test_assert( status == -1 );
42  rtems_test_assert( errno == EFAULT );
43
44  status = uname( &uts );
45  rtems_test_assert( !status );
46  printf( "Init: uts.sysname: %s\n", uts.sysname );
47  printf( "Init: uts.nodename: %s\n", uts.nodename );
48  printf( "Init: uts.release: %s\n", uts.release );
49  printf( "Init: uts.version: %s\n", uts.version );
50  printf( "Init: uts.machine: %s\n", uts.machine );
51  puts("");
52
53  /* error cases in clock_gettime and clock_settime */
54
55  puts( "Init: clock_gettime - EINVAL (NULL timespec)" );
56  status = clock_gettime( CLOCK_REALTIME, NULL );
57  rtems_test_assert( status == -1 );
58  rtems_test_assert( errno == EINVAL );
59
60  puts( "Init: clock_gettime - EINVAL (invalid clockid)" );
61  status = clock_gettime( (clockid_t)-1, &tv );
62  rtems_test_assert( status == -1 );
63  rtems_test_assert( errno == EINVAL );
64
65  puts( "Init: clock_settime - EINVAL (invalid clockid)" );
66  status = clock_settime( (clockid_t)-1, &tv );
67  rtems_test_assert( status == -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  status = clock_settime( CLOCK_REALTIME, &tv );
76  rtems_test_assert( status == -1 );
77  rtems_test_assert( errno == EINVAL );
78
79  /* exercise clock_getres */
80
81  puts( "Init: clock_getres - EINVAL (invalid clockid)" );
82  status = clock_getres( (clockid_t) -1, &tv );
83  rtems_test_assert( status == -1 );
84  rtems_test_assert( errno == EINVAL );
85
86  puts( "Init: clock_getres - EINVAL (NULL resolution)" );
87  status = clock_getres( CLOCK_REALTIME, NULL );
88  rtems_test_assert( status == -1 );
89  rtems_test_assert( errno == EINVAL );
90
91  puts( "Init: clock_getres - SUCCESSFUL" );
92  status = clock_getres( CLOCK_REALTIME, &tv );
93  printf( "Init: resolution = sec (%ld), nsec (%ld)\n", tv.tv_sec, tv.tv_nsec );
94  rtems_test_assert( !status );
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  status = clock_settime( CLOCK_REALTIME, &tv );
110  rtems_test_assert( !status );
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  status = clock_gettime( CLOCK_PROCESS_CPUTIME, &tv );
122  rtems_test_assert( !status );
123  printf("Time since boot: (%d, %d)\n", tv.tv_sec,tv.tv_nsec );
124
125  status = clock_gettime( CLOCK_REALTIME, &tv );
126  rtems_test_assert( !status );
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  status = nanosleep ( NULL, &tr );
148  rtems_test_assert( status == -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  status = nanosleep ( &tv, &tr );
155  rtems_test_assert( status == -1 );
156  rtems_test_assert( errno == EINVAL );
157
158  /* this is actually a small delay or yield */
159  tv.tv_sec = -1;
160  tv.tv_nsec = 0;
161  puts( "Init: nanosleep - negative seconds small delay " );
162  status = nanosleep ( &tv, &tr );
163  rtems_test_assert( status == -1 );
164  rtems_test_assert( errno == EINVAL );
165
166  /* use nanosleep to yield */
167
168  tv.tv_sec = 0;
169  tv.tv_nsec = 0;
170
171  puts( "Init: nanosleep - yield" );
172  status = nanosleep ( &tv, &tr );
173  rtems_test_assert( !status );
174  rtems_test_assert( !tr.tv_sec );
175  rtems_test_assert( !tr.tv_nsec );
176
177  /* use nanosleep to delay */
178
179  tv.tv_sec = 3;
180  tv.tv_nsec = 500000;
181
182  puts( "Init: nanosleep - 1.05 seconds" );
183  status = nanosleep ( &tv, &tr );
184  rtems_test_assert( !status );
185
186  /* print the current real time again */
187  status = clock_gettime( CLOCK_REALTIME, &tv );
188  rtems_test_assert( !status );
189  printf( ctime( &tv.tv_sec ) );
190
191  /* check the time remaining */
192
193  printf( "Init: sec (%ld), nsec (%ld) remaining\n", tr.tv_sec, tr.tv_nsec );
194  rtems_test_assert( !tr.tv_sec && !tr.tv_nsec );
195
196  puts( "Init: usleep - 1.35 seconds" );
197  useconds = usleep ( 1350000 );
198  rtems_test_assert( useconds < 1350000 );
199 
200  /* print the current real time again */
201  status = clock_gettime( CLOCK_REALTIME, &tv );
202  rtems_test_assert( !status );
203  printf( ctime( &tv.tv_sec ) );
204
205  /* get id of this thread */
206
207  Init_id = pthread_self();
208  printf( "Init: ID is 0x%08x\n", Init_id );
209
210  /* exercise get minimum priority */
211
212  priority = sched_get_priority_min( SCHED_FIFO );
213  printf( "Init: sched_get_priority_min (SCHED_FIFO) -- %d\n", priority );
214  rtems_test_assert( priority != -1 );
215
216  puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" );
217  priority = sched_get_priority_min( -1 );
218  rtems_test_assert( priority == -1 );
219  rtems_test_assert( errno == EINVAL );
220
221  /* exercise get maximum priority */
222
223  priority = sched_get_priority_max( SCHED_FIFO );
224  printf( "Init: sched_get_priority_max (SCHED_FIFO) -- %d\n", priority );
225  rtems_test_assert( priority != -1 );
226
227  puts( "Init: sched_get_priority_max -- EINVAL (invalid policy)" );
228  priority = sched_get_priority_max( -1 );
229  rtems_test_assert( priority == -1 );
230  rtems_test_assert( errno == EINVAL );
231
232  puts( "Init: sched_rr_get_interval -- ESRCH (invalid PID)" );
233  status = sched_rr_get_interval( 4, &tr );
234  rtems_test_assert( status == -1 );
235  rtems_test_assert( errno == ESRCH );
236 
237  puts( "Init: sched_rr_get_interval -- EINVAL (invalid interval pointer)" );
238  status = sched_rr_get_interval( getpid(), NULL );
239  rtems_test_assert( status == -1 );
240  rtems_test_assert( errno == EINVAL );
241 
242  /* print the round robin time quantum */
243
244  status = sched_rr_get_interval( getpid(), &tr );
245  printf(
246    "Init: Round Robin quantum is %ld seconds, %ld nanoseconds\n",
247    tr.tv_sec,
248    tr.tv_nsec
249  );
250  rtems_test_assert( !status );
251
252  /* create a thread */
253
254  puts( "Init: pthread_create - SUCCESSFUL" );
255  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
256  rtems_test_assert( !status );
257
258  /* too may threads error */
259
260  puts( "Init: pthread_create - EAGAIN (too many threads)" );
261  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
262  rtems_test_assert( status == EAGAIN );
263
264  puts( "Init: sched_yield to Task_1" );
265  status = sched_yield();
266  rtems_test_assert( !status );
267
268    /* switch to Task_1 */
269
270  /* exit this thread */
271
272  puts( "Init: pthread_exit" );
273  pthread_exit( NULL );
274
275    /* switch to Task_1 */
276
277  return NULL; /* just so the compiler thinks we returned something */
278}
Note: See TracBrowser for help on using the repository browser.