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

4.104.114.84.95
Last change on this file since e2ceeca7 was e2ceeca7, checked in by Mark Johannes <Mark.Johannes@…>, on Aug 23, 1996 at 3:50:53 PM

Added build_time statement to provide a tm for the test

  • Property mode set to 100644
File size: 5.6 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  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  time_t          remaining;
29  struct tm       tm;
30
31  puts( "\n\n*** POSIX TEST 1 ***" );
32
33  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 (invalid clockid)" );
38  status = clock_settime( -1, &tv );
39  assert( status == -1 );
40  assert( errno == EINVAL );
41
42  puts( "Init: clock_settime - EINVAL (invalid clockid)" );
43  status = clock_settime( -1, &tv );
44  assert( status == -1 );
45  assert( errno == EINVAL );
46
47  /* exercise clock_getres */
48
49  puts( "Init: clock_getres - EINVAL (invalid clockid)" );
50  status = clock_getres( -1, &tv );
51  assert( status == -1 );
52  assert( errno == EINVAL );
53
54  puts( "Init: clock_getres - EINVAL (NULL resolution)" );
55  status = clock_getres( CLOCK_REALTIME, NULL );
56  assert( status == -1 );
57  assert( errno == EINVAL );
58
59  puts( "Init: clock_getres - SUCCESSFUL" );
60  status = clock_getres( CLOCK_REALTIME, &tv );
61  printf( "Init: resolution = sec (%ld), nsec (%ld)\n", tv.tv_sec, tv.tv_nsec );
62  assert( !status );
63
64  /* set the time of day, and print our buffer in multiple ways */
65
66  tv.tv_sec = mktime( &tm );
67  assert( tv.tv_sec != -1 );
68
69  tv.tv_nsec = 0;
70
71  /* now set the time of day */
72
73  empty_line();
74
75  printf( asctime( &tm ) );
76  puts( "Init: clock_settime - SUCCESSFUL" );
77  status = clock_settime( CLOCK_REALTIME, &tv );
78  assert( !status );
79
80  printf( asctime( &tm ) );
81  printf( ctime( &tv.tv_sec ) );
82
83  /* use sleep to delay */
84
85  remaining = sleep( 3 );
86  assert( !remaining );
87
88  /* print new times to make sure it has changed and we can get the realtime */
89
90  status = clock_gettime( CLOCK_REALTIME, &tv );
91  assert( !status );
92
93  printf( ctime( &tv.tv_sec ) );
94
95  seconds = time( NULL );
96  printf( ctime( &seconds ) );
97
98  /*  just to have the value copied out through the parameter */
99 
100  seconds = time( &seconds1 );
101  assert( seconds == seconds1 );
102
103  /* check the time remaining */
104
105  printf( "Init: seconds remaining (%d)\n", (int)remaining );
106  assert( !remaining );
107
108  /* error cases in nanosleep */
109
110  empty_line();
111  puts( "Init: nanosleep - EINVAL (NULL time)" );
112  status = nanosleep ( NULL, &tr );
113  assert( status == -1 );
114  assert( errno == EINVAL );
115
116  tv.tv_sec = -1;
117  puts( "Init: nanosleep - EAGAIN (negative seconds)" );
118  status = nanosleep ( &tv, &tr );
119  assert( status == -1 );
120  assert( errno == EAGAIN );
121
122  tv.tv_sec = 0;
123  tv.tv_nsec = TOD_NANOSECONDS_PER_SECOND * 2;
124  puts( "Init: nanosleep - EINVAL (too many nanoseconds)" );
125  status = nanosleep ( &tv, &tr );
126  assert( status == -1 );
127  assert( errno == EINVAL );
128
129  /* use nanosleep to yield */
130
131  tv.tv_sec = 0; 
132  tv.tv_nsec = 0; 
133
134  puts( "Init: nanosleep - yield" ); 
135  status = nanosleep ( &tv, &tr );
136  assert( !status );
137  assert( !tr.tv_sec );
138  assert( !tr.tv_nsec );
139
140  /* use nanosleep to delay */
141
142  tv.tv_sec = 3; 
143  tv.tv_nsec = 500000; 
144
145  puts( "Init: nanosleep - 3.05 seconds" ); 
146  status = nanosleep ( &tv, &tr );
147  assert( !status );
148
149  /* print the current real time again */
150
151  status = clock_gettime( CLOCK_REALTIME, &tv );
152  assert( !status );
153 
154  printf( ctime( &tv.tv_sec ) );
155
156  /* check the time remaining */
157
158  printf( "Init: sec (%ld), nsec (%ld) remaining\n", tr.tv_sec, tr.tv_nsec );
159  assert( !tr.tv_sec && !tr.tv_nsec );
160
161  /* get id of this thread */
162
163  Init_id = pthread_self();
164  printf( "Init: ID is 0x%08x\n", Init_id );
165
166  /* exercise get minimum priority */
167
168  priority = sched_get_priority_min( SCHED_FIFO );
169  printf( "Init: sched_get_priority_min (SCHED_FIFO) -- %d\n", priority );
170  assert( priority != -1 );
171
172  puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" );
173  priority = sched_get_priority_min( -1 );
174  assert( priority == -1 );
175  assert( errno == EINVAL );
176
177  /* exercise get maximum priority */
178 
179  priority = sched_get_priority_max( SCHED_FIFO );
180  printf( "Init: sched_get_priority_max (SCHED_FIFO) -- %d\n", priority );
181  assert( priority != -1 );
182
183  puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" );
184  priority = sched_get_priority_min( -1 );
185  assert( priority == -1 );
186  assert( errno == EINVAL );
187
188  /* print the round robin time quantum */
189 
190  status = sched_rr_get_interval( getpid(), &tr );
191  printf(
192    "Init: Round Robin quantum is %ld seconds, %ld nanoseconds\n",
193    tr.tv_sec,
194    tr.tv_nsec
195  );
196  assert( !status );
197 
198  /* create a thread */
199
200  puts( "Init: pthread_create - SUCCESSFUL" );
201  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
202  assert( !status );
203
204  /* too may threads error */
205
206  puts( "Init: pthread_create - EAGAIN (too many threads)" );
207  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
208  assert( status == EAGAIN );
209
210  puts( "Init: sched_yield to Task_1" );
211  status = sched_yield();
212  assert( !status );
213
214    /* switch to Task_1 */
215
216  /* exit this thread */
217
218  puts( "Init: pthread_exit" );
219  pthread_exit( NULL );
220
221    /* switch to Task_1 */
222
223  return NULL; /* just so the compiler thinks we returned something */
224}
Note: See TracBrowser for help on using the repository browser.