source: rtems/c/src/tests/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 08/23/96 at 15:50:53

Added build_time statement to provide a tm for the test

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[9594cdb]1/*
[abd604a]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
[0252200]13#define CONFIGURE_INIT
[abd604a]14#include "system.h"
[0a359a7]15#include <sched.h>
[abd604a]16
[be1c11ed]17void *POSIX_Init(
[0252200]18  void *argument
[abd604a]19)
20{
[e2ceeca7]21  struct timespec tv;
22  struct timespec tr;
[9594cdb]23  int             status;
[95645a4]24  int             priority;
[9594cdb]25  pthread_t       thread_id;
26  time_t          seconds;
[d60d9505]27  time_t          seconds1;
[e984c645]28  time_t          remaining;
[9594cdb]29  struct tm       tm;
[86fc81e]30
[0252200]31  puts( "\n\n*** POSIX TEST 1 ***" );
[86fc81e]32
[e2ceeca7]33  build_time( &tm, TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
34
[c4f5e752]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
[5da2ae8]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
[c4f5e752]71  /* now set the time of day */
72
[5da2ae8]73  empty_line();
74
[c4f5e752]75  printf( asctime( &tm ) );
76  puts( "Init: clock_settime - SUCCESSFUL" );
[9594cdb]77  status = clock_settime( CLOCK_REALTIME, &tv );
78  assert( !status );
79
80  printf( asctime( &tm ) );
81  printf( ctime( &tv.tv_sec ) );
82
[19962562]83  /* use sleep to delay */
84
[e984c645]85  remaining = sleep( 3 );
86  assert( !remaining );
[19962562]87
88  /* print new times to make sure it has changed and we can get the realtime */
[9594cdb]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
[d60d9505]98  /*  just to have the value copied out through the parameter */
99 
100  seconds = time( &seconds1 );
101  assert( seconds == seconds1 );
102
[e984c645]103  /* check the time remaining */
104
[644c0fa6]105  printf( "Init: seconds remaining (%d)\n", (int)remaining );
[e984c645]106  assert( !remaining );
107
[c4f5e752]108  /* error cases in nanosleep */
109
[5da2ae8]110  empty_line();
[c4f5e752]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
[19962562]140  /* use nanosleep to delay */
141
142  tv.tv_sec = 3;
143  tv.tv_nsec = 500000;
144
[c4f5e752]145  puts( "Init: nanosleep - 3.05 seconds" );
[19962562]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
[644c0fa6]158  printf( "Init: sec (%ld), nsec (%ld) remaining\n", tr.tv_sec, tr.tv_nsec );
[19962562]159  assert( !tr.tv_sec && !tr.tv_nsec );
160
[15974b65]161  /* get id of this thread */
162
163  Init_id = pthread_self();
[644c0fa6]164  printf( "Init: ID is 0x%08x\n", Init_id );
[15974b65]165
[f643e230]166  /* exercise get minimum priority */
[95645a4]167
168  priority = sched_get_priority_min( SCHED_FIFO );
[f643e230]169  printf( "Init: sched_get_priority_min (SCHED_FIFO) -- %d\n", priority );
[95645a4]170  assert( priority != -1 );
171
[f643e230]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 */
[95645a4]178 
179  priority = sched_get_priority_max( SCHED_FIFO );
[f643e230]180  printf( "Init: sched_get_priority_max (SCHED_FIFO) -- %d\n", priority );
[95645a4]181  assert( priority != -1 );
182
[f643e230]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
[95645a4]188  /* print the round robin time quantum */
189 
190  status = sched_rr_get_interval( getpid(), &tr );
191  printf(
[644c0fa6]192    "Init: Round Robin quantum is %ld seconds, %ld nanoseconds\n",
193    tr.tv_sec,
194    tr.tv_nsec
[95645a4]195  );
196  assert( !status );
197 
[9594cdb]198  /* create a thread */
[86fc81e]199
[f643e230]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
[fdf6917]206  puts( "Init: pthread_create - EAGAIN (too many threads)" );
[2197a2e1]207  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
[fdf6917]208  assert( status == EAGAIN );
[f643e230]209
210  puts( "Init: sched_yield to Task_1" );
211  status = sched_yield();
[2197a2e1]212  assert( !status );
213
[f643e230]214    /* switch to Task_1 */
215
[9594cdb]216  /* exit this thread */
217
[f643e230]218  puts( "Init: pthread_exit" );
[0252200]219  pthread_exit( NULL );
[2197a2e1]220
[f643e230]221    /* switch to Task_1 */
222
[893103c]223  return NULL; /* just so the compiler thinks we returned something */
[abd604a]224}
Note: See TracBrowser for help on using the repository browser.