source: rtems/testsuites/psxtests/psx12/init.c @ 749eae97

4.104.115
Last change on this file since 749eae97 was 75c9dfbd, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/25/09 at 17:33:03

2009-10-25 Ralf Corsépius <ralf.corsepius@…>

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