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 | |
---|
16 | void print_schedparam( |
---|
17 | char *prefix, |
---|
18 | struct sched_param *schedparam |
---|
19 | ); |
---|
20 | |
---|
21 | void 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 | |
---|
40 | void *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 | } |
---|