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