source: rtems/testsuites/psxtests/psx12/init.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[54e34e7]1/*
[08311cc3]2 *  COPYRIGHT (c) 1989-1999.
[54e34e7]3 *  On-Line Applications Research Corporation (OAR).
4 *
[98e4ebf5]5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
[03f2154e]7 *  http://www.OARcorp.com/rtems/license.html.
[54e34e7]8 *
9 *  $Id$
10 */
11
12#define CONFIGURE_INIT
13#include "system.h"
14#include <errno.h>
15
16void print_schedparam(
17  char               *prefix,
18  struct sched_param *schedparam
19)
20{
21  printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
22#if defined(_POSIX_SPORADIC_SERVER)
23  printf( "%sss_low_priority     = %d\n", prefix, schedparam->ss_low_priority );
24  printf( "%sss_replenish_period = (%ld, %ld)\n", prefix,
25     schedparam->ss_replenish_period.tv_sec,
26     schedparam->ss_replenish_period.tv_nsec );
27  printf( "%sss_initial_budget = (%ld, %ld)\n", prefix,
28     schedparam->ss_initial_budget.tv_sec,
29     schedparam->ss_initial_budget.tv_nsec );
30#else
31  printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" );
32#endif
33}
34
35void *POSIX_Init(
36  void *argument
37)
38{
39  int                 status;
40  pthread_attr_t      attr;
41  struct sched_param  schedparam;
42
43  puts( "\n\n*** POSIX TEST 12 ***" );
44
45  /* set the time of day, and print our buffer in multiple ways */
46
47  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
48
49  /* get id of this thread */
50
51  Init_id = pthread_self();
52  printf( "Init's ID is 0x%08x\n", Init_id );
53 
54  /* invalid scheduling policy error */
55
56  puts( "Init: pthread_attr_init - SUCCESSFUL" );
57  status = pthread_attr_init( &attr );
58  assert( !status );
59
[2ffcc2ed]60  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
61  assert( !status );
[54e34e7]62  attr.schedpolicy = -1;
63
64  puts( "Init: pthread_create - EINVAL (invalid scheduling policy)" );
65  status = pthread_create( &Task_id, &attr, Task_1, NULL );
66  assert( status == EINVAL );
67
68  /* replenish period < budget error */
69
70  puts( "Init: pthread_attr_init - SUCCESSFUL" );
71  status = pthread_attr_init( &attr );
72  assert( !status );
73
74  puts( "Init: set scheduling parameter attributes for sporadic server" );
75  status = pthread_attr_setschedpolicy( &attr, SCHED_SPORADIC );
76  assert( !status );
77
78  schedparam.ss_replenish_period.tv_sec = 1;
79  schedparam.ss_replenish_period.tv_nsec = 0;
80  schedparam.ss_initial_budget.tv_sec = 2;
81  schedparam.ss_initial_budget.tv_nsec = 0;
82 
83  schedparam.sched_priority = 200;
84  schedparam.ss_low_priority = 100;
85
86  status = pthread_attr_setschedparam( &attr, &schedparam );
87  assert( !status );
88
[2ffcc2ed]89  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
90  assert( !status );
91 
[54e34e7]92  puts( "Init: pthread_create - EINVAL (replenish < budget)" );
93  status = pthread_create( &Task_id, &attr, Task_1, NULL );
94  assert( status == EINVAL );
95
96  /* invalid ss_low_priority error */
97
98  schedparam.ss_replenish_period.tv_sec = 2;
99  schedparam.ss_replenish_period.tv_nsec = 0;
100  schedparam.ss_initial_budget.tv_sec = 1;
101  schedparam.ss_initial_budget.tv_nsec = 0;
102 
103  schedparam.sched_priority = 200;
104  schedparam.ss_low_priority = -1;
105
106  status = pthread_attr_setschedparam( &attr, &schedparam );
107  assert( !status );
108
109  puts( "Init: pthread_create - EINVAL (invalid ss_low_priority)" );
110  status = pthread_create( &Task_id, &attr, Task_1, NULL );
111  assert( status == EINVAL );
112
113  /* create a thread as a sporadic server */
114
115  schedparam.ss_replenish_period.tv_sec = 2;
116  schedparam.ss_replenish_period.tv_nsec = 0;
117  schedparam.ss_initial_budget.tv_sec = 1;
118  schedparam.ss_initial_budget.tv_nsec = 0;
119 
120  schedparam.sched_priority = 200;
121  schedparam.ss_low_priority = 100;
122 
123  status = pthread_attr_setschedparam( &attr, &schedparam );
124  assert( !status );
125 
126  puts( "Init: pthread_create - SUCCESSFUL" );
127  status = pthread_create( &Task_id, &attr, Task_1, NULL );
128  assert( !status );
129
130  status = pthread_join( Task_id, NULL );
131  assert( status );
132
133    /* switch to Task_1 */
134
135  puts( "*** END OF POSIX TEST 12 ***" );
136  exit( 0 );
137
138  return NULL; /* just so the compiler thinks we returned something */
139}
Note: See TracBrowser for help on using the repository browser.