source: rtems/testsuites/psxtests/psx12/init.c @ 54e34e7

4.104.114.84.95
Last change on this file since 54e34e7 was 54e34e7, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 8, 1996 at 11:02:13 PM

new test to test scheduling policy and paremeter paths in pthread_create.

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