source: rtems/testsuites/psxtests/psx12/init.c @ 2e7e636f

4.104.115
Last change on this file since 2e7e636f was 2e7e636f, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/09 at 01:41:16

2009-05-10 Joel Sherrill <joel.sherrill@…>

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