source: rtems/testsuites/psxtests/psx01/init.c @ a20190a4

4.104.114.84.95
Last change on this file since a20190a4 was a20190a4, checked in by Joel Sherrill <joel.sherrill@…>, on 11/16/99 at 16:15:05

Added test cases for uname().

  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-1998.
3 *  On-Line Applications Research Corporation (OAR).
4 *  Copyright assigned to U.S. Government, 1994.
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.OARcorp.com/rtems/license.html.
9 *
10 *  $Id$
11 */
12
13#define CONFIGURE_INIT
14#include "system.h"
15#include <sched.h>
16#include <sys/utsname.h>
17
18void *POSIX_Init(
19  void *argument
20)
21{
22  struct timespec tv;
23  struct timespec tr;
24  int             status;
25  int             priority;
26  pthread_t       thread_id;
27  time_t          seconds;
28  time_t          seconds1;
29  time_t          remaining;
30  struct tm       tm;
31  struct utsname  uts;
32
33  puts( "\n\n*** POSIX TEST 1 ***" );
34
35  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  assert( status == -1 );
42  assert( errno == EFAULT );
43   
44  status = uname( &uts );
45  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 (invalid clockid)" );
56  status = clock_settime( -1, &tv );
57  assert( status == -1 );
58  assert( errno == EINVAL );
59
60  puts( "Init: clock_settime - EINVAL (invalid clockid)" );
61  status = clock_settime( -1, &tv );
62  assert( status == -1 );
63  assert( errno == EINVAL );
64
65  /* exercise clock_getres */
66
67  puts( "Init: clock_getres - EINVAL (invalid clockid)" );
68  status = clock_getres( -1, &tv );
69  assert( status == -1 );
70  assert( errno == EINVAL );
71
72  puts( "Init: clock_getres - EINVAL (NULL resolution)" );
73  status = clock_getres( CLOCK_REALTIME, NULL );
74  assert( status == -1 );
75  assert( errno == EINVAL );
76
77  puts( "Init: clock_getres - SUCCESSFUL" );
78  status = clock_getres( CLOCK_REALTIME, &tv );
79  printf( "Init: resolution = sec (%ld), nsec (%ld)\n", tv.tv_sec, tv.tv_nsec );
80  assert( !status );
81
82  /* set the time of day, and print our buffer in multiple ways */
83
84  tv.tv_sec = mktime( &tm );
85  assert( tv.tv_sec != -1 );
86
87  tv.tv_nsec = 0;
88
89  /* now set the time of day */
90
91  empty_line();
92
93  printf( asctime( &tm ) );
94  puts( "Init: clock_settime - SUCCESSFUL" );
95  status = clock_settime( CLOCK_REALTIME, &tv );
96  assert( !status );
97
98  printf( asctime( &tm ) );
99  printf( ctime( &tv.tv_sec ) );
100
101  /* use sleep to delay */
102
103  remaining = sleep( 3 );
104  assert( !remaining );
105
106  /* print new times to make sure it has changed and we can get the realtime */
107
108  status = clock_gettime( CLOCK_REALTIME, &tv );
109  assert( !status );
110
111  printf( ctime( &tv.tv_sec ) );
112
113  seconds = time( NULL );
114  printf( ctime( &seconds ) );
115
116  /*  just to have the value copied out through the parameter */
117 
118  seconds = time( &seconds1 );
119  assert( seconds == seconds1 );
120
121  /* check the time remaining */
122
123  printf( "Init: seconds remaining (%d)\n", (int)remaining );
124  assert( !remaining );
125
126  /* error cases in nanosleep */
127
128  empty_line();
129  puts( "Init: nanosleep - EINVAL (NULL time)" );
130  status = nanosleep ( NULL, &tr );
131  assert( status == -1 );
132  assert( errno == EINVAL );
133
134  tv.tv_sec = 0;
135  tv.tv_nsec = TOD_NANOSECONDS_PER_SECOND * 2;
136  puts( "Init: nanosleep - EINVAL (too many nanoseconds)" );
137  status = nanosleep ( &tv, &tr );
138  assert( status == -1 );
139  assert( errno == EINVAL );
140
141  /* this is actually a small delay or yield */
142  tv.tv_sec = -1;
143  tv.tv_nsec = 0;
144  puts( "Init: nanosleep - negative seconds small delay " );
145  status = nanosleep ( &tv, &tr );
146  assert( !status );
147
148  /* use nanosleep to yield */
149
150  tv.tv_sec = 0;
151  tv.tv_nsec = 0;
152
153  puts( "Init: nanosleep - yield" );
154  status = nanosleep ( &tv, &tr );
155  assert( !status );
156  assert( !tr.tv_sec );
157  assert( !tr.tv_nsec );
158
159  /* use nanosleep to delay */
160
161  tv.tv_sec = 3;
162  tv.tv_nsec = 500000;
163
164  puts( "Init: nanosleep - 3.05 seconds" );
165  status = nanosleep ( &tv, &tr );
166  assert( !status );
167
168  /* print the current real time again */
169
170  status = clock_gettime( CLOCK_REALTIME, &tv );
171  assert( !status );
172 
173  printf( ctime( &tv.tv_sec ) );
174
175  /* check the time remaining */
176
177  printf( "Init: sec (%ld), nsec (%ld) remaining\n", tr.tv_sec, tr.tv_nsec );
178  assert( !tr.tv_sec && !tr.tv_nsec );
179
180  /* get id of this thread */
181
182  Init_id = pthread_self();
183  printf( "Init: ID is 0x%08x\n", Init_id );
184
185  /* exercise get minimum priority */
186
187  priority = sched_get_priority_min( SCHED_FIFO );
188  printf( "Init: sched_get_priority_min (SCHED_FIFO) -- %d\n", priority );
189  assert( priority != -1 );
190
191  puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" );
192  priority = sched_get_priority_min( -1 );
193  assert( priority == -1 );
194  assert( errno == EINVAL );
195
196  /* exercise get maximum priority */
197 
198  priority = sched_get_priority_max( SCHED_FIFO );
199  printf( "Init: sched_get_priority_max (SCHED_FIFO) -- %d\n", priority );
200  assert( priority != -1 );
201
202  puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" );
203  priority = sched_get_priority_min( -1 );
204  assert( priority == -1 );
205  assert( errno == EINVAL );
206
207  /* print the round robin time quantum */
208 
209  status = sched_rr_get_interval( getpid(), &tr );
210  printf(
211    "Init: Round Robin quantum is %ld seconds, %ld nanoseconds\n",
212    tr.tv_sec,
213    tr.tv_nsec
214  );
215  assert( !status );
216 
217  /* create a thread */
218
219  puts( "Init: pthread_create - SUCCESSFUL" );
220  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
221  assert( !status );
222
223  /* too may threads error */
224
225  puts( "Init: pthread_create - EAGAIN (too many threads)" );
226  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
227  assert( status == EAGAIN );
228
229  puts( "Init: sched_yield to Task_1" );
230  status = sched_yield();
231  assert( !status );
232
233    /* switch to Task_1 */
234
235  /* exit this thread */
236
237  puts( "Init: pthread_exit" );
238  pthread_exit( NULL );
239
240    /* switch to Task_1 */
241
242  return NULL; /* just so the compiler thinks we returned something */
243}
Note: See TracBrowser for help on using the repository browser.