source: rtems/testsuites/psxtests/psx12/init.c @ cafefbf

4.115
Last change on this file since cafefbf was cafefbf, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 09:47:36

Add HAVE_CONFIG_H.

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