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

4.104.114.84.95
Last change on this file since fdf6917 was fdf6917, checked in by Joel Sherrill <joel.sherrill@…>, on 08/15/96 at 18:59:00

changed error for too many threads to EAGAIN

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