source: rtems/testsuites/psxtests/psx12/init.c @ 5abf63d

4.104.115
Last change on this file since 5abf63d was 5abf63d, checked in by Joel Sherrill <joel.sherrill@…>, on 12/14/08 at 18:41:18

2008-12-14 Joel Sherrill <joel.sherrill@…>

  • psx05/init.c, psx07/init.c, psx09/init.c, psx11/init.c, psx12/init.c: Run all tests successfully with maxixum number of priorities as 16 instead of 256. This was done by temporarily modifying the score priority.h maximum. This allowed testing of all API code to ensure that it worked properly with a reduced number of priorities. Most modifications were to switch from hard-coded maximum to using the API provided methods to determine maximum number of priority levels.
  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2008.
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#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
60  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
61  assert( !status );
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
89  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
90  assert( !status );
91
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 = sched_get_priority_max( SCHED_FIFO );
121  schedparam.ss_low_priority = sched_get_priority_max( SCHED_FIFO ) - 6;
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  rtems_test_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.