1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* Task_1 |
---|
4 | * |
---|
5 | * This test serves as a test task. It verifies timeslicing activities |
---|
6 | * and tswitch extension processing. |
---|
7 | * |
---|
8 | * Input parameters: |
---|
9 | * argument - task argument |
---|
10 | * |
---|
11 | * Output parameters: NONE |
---|
12 | * |
---|
13 | * COPYRIGHT (c) 1989-2009. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * Redistribution and use in source and binary forms, with or without |
---|
17 | * modification, are permitted provided that the following conditions |
---|
18 | * are met: |
---|
19 | * 1. Redistributions of source code must retain the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer. |
---|
21 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer in the |
---|
23 | * documentation and/or other materials provided with the distribution. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
35 | * POSSIBILITY OF SUCH DAMAGE. |
---|
36 | */ |
---|
37 | |
---|
38 | #ifdef HAVE_CONFIG_H |
---|
39 | #include "config.h" |
---|
40 | #endif |
---|
41 | |
---|
42 | #include "system.h" |
---|
43 | |
---|
44 | static void |
---|
45 | showTaskSwitches (void) |
---|
46 | { |
---|
47 | unsigned int i; |
---|
48 | unsigned int switches = taskSwitchLogIndex; |
---|
49 | |
---|
50 | for (i = 0 ; i < switches ; i++) { |
---|
51 | put_name( Task_name[taskSwitchLog[i].taskIndex], FALSE ); |
---|
52 | print_time( "- ", &taskSwitchLog[i].when, "\n" ); |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | static int test_no_preempt_step; |
---|
57 | |
---|
58 | static rtems_id high_task_id; |
---|
59 | |
---|
60 | static rtems_id low_task_id; |
---|
61 | |
---|
62 | static void high_task( rtems_task_argument arg ) |
---|
63 | { |
---|
64 | rtems_status_code sc; |
---|
65 | |
---|
66 | rtems_test_assert( test_no_preempt_step == 2 ); |
---|
67 | test_no_preempt_step = 3; |
---|
68 | |
---|
69 | sc = rtems_event_transient_send( Task_id[ 1 ] ); |
---|
70 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
71 | |
---|
72 | rtems_task_suspend(RTEMS_SELF); |
---|
73 | rtems_test_assert(0); |
---|
74 | } |
---|
75 | |
---|
76 | static void low_task( rtems_task_argument arg ) |
---|
77 | { |
---|
78 | rtems_test_assert( test_no_preempt_step == 1 ); |
---|
79 | test_no_preempt_step = 2; |
---|
80 | |
---|
81 | rtems_task_suspend(RTEMS_SELF); |
---|
82 | rtems_test_assert(0); |
---|
83 | } |
---|
84 | |
---|
85 | static void no_preempt_timer( rtems_id id, void *arg ) |
---|
86 | { |
---|
87 | rtems_status_code sc; |
---|
88 | |
---|
89 | rtems_test_assert( test_no_preempt_step == 0 ); |
---|
90 | test_no_preempt_step = 1; |
---|
91 | |
---|
92 | sc = rtems_task_start( low_task_id, low_task, 0 ); |
---|
93 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
94 | |
---|
95 | sc = rtems_task_start( high_task_id, high_task, 0 ); |
---|
96 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
97 | } |
---|
98 | |
---|
99 | static void test_no_preempt( void ) |
---|
100 | { |
---|
101 | rtems_status_code sc; |
---|
102 | rtems_id id; |
---|
103 | |
---|
104 | rtems_test_assert( test_no_preempt_step == 0 ); |
---|
105 | |
---|
106 | sc = rtems_task_delete( Task_id[ 2 ] ); |
---|
107 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
108 | |
---|
109 | sc = rtems_task_delete( Task_id[ 3 ] ); |
---|
110 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
111 | |
---|
112 | sc = rtems_task_create( |
---|
113 | rtems_build_name( 'H', 'I', 'G', 'H' ), |
---|
114 | 1, |
---|
115 | RTEMS_MINIMUM_STACK_SIZE, |
---|
116 | RTEMS_DEFAULT_MODES, |
---|
117 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
118 | &high_task_id |
---|
119 | ); |
---|
120 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
121 | |
---|
122 | sc = rtems_task_create( |
---|
123 | rtems_build_name( 'L', 'O', 'W', ' ' ), |
---|
124 | 2, |
---|
125 | RTEMS_MINIMUM_STACK_SIZE, |
---|
126 | RTEMS_NO_PREEMPT, |
---|
127 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
128 | &low_task_id |
---|
129 | ); |
---|
130 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
131 | |
---|
132 | sc = rtems_timer_create( rtems_build_name( 'N', 'O', 'P', 'R' ), &id ); |
---|
133 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
134 | |
---|
135 | sc = rtems_timer_fire_after( id, 1, no_preempt_timer, NULL ); |
---|
136 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
137 | |
---|
138 | sc = rtems_event_transient_receive( RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
---|
139 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
140 | |
---|
141 | sc = rtems_timer_delete( id ); |
---|
142 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
143 | |
---|
144 | sc = rtems_task_delete( high_task_id ); |
---|
145 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
146 | |
---|
147 | sc = rtems_task_delete( low_task_id ); |
---|
148 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
149 | |
---|
150 | rtems_test_assert( test_no_preempt_step == 3 ); |
---|
151 | } |
---|
152 | |
---|
153 | rtems_task Task_1( |
---|
154 | rtems_task_argument argument |
---|
155 | ) |
---|
156 | { |
---|
157 | uint32_t seconds; |
---|
158 | uint32_t old_seconds; |
---|
159 | rtems_mode previous_mode; |
---|
160 | rtems_time_of_day time; |
---|
161 | rtems_status_code status; |
---|
162 | uint32_t start_time; |
---|
163 | uint32_t end_time; |
---|
164 | |
---|
165 | puts( "TA1 - rtems_task_suspend - on Task 2" ); |
---|
166 | status = rtems_task_suspend( Task_id[ 2 ] ); |
---|
167 | directive_failed( status, "rtems_task_suspend of TA2" ); |
---|
168 | |
---|
169 | puts( "TA1 - rtems_task_suspend - on Task 3" ); |
---|
170 | status = rtems_task_suspend( Task_id[ 3 ] ); |
---|
171 | directive_failed( status, "rtems_task_suspend of TA3" ); |
---|
172 | |
---|
173 | status = rtems_clock_get_seconds_since_epoch( &start_time ); |
---|
174 | directive_failed( status, "rtems_clock_get_seconds_since_epoch" ); |
---|
175 | |
---|
176 | puts( "TA1 - killing time" ); |
---|
177 | |
---|
178 | for ( ; ; ) { |
---|
179 | status = rtems_clock_get_seconds_since_epoch( &end_time ); |
---|
180 | directive_failed( status, "rtems_clock_get_seconds_since_epoch" ); |
---|
181 | |
---|
182 | if ( end_time > (start_time + 2) ) |
---|
183 | break; |
---|
184 | } |
---|
185 | |
---|
186 | puts( "TA1 - rtems_task_resume - on Task 2" ); |
---|
187 | status = rtems_task_resume( Task_id[ 2 ] ); |
---|
188 | directive_failed( status, "rtems_task_resume of TA2" ); |
---|
189 | |
---|
190 | puts( "TA1 - rtems_task_resume - on Task 3" ); |
---|
191 | status = rtems_task_resume( Task_id[ 3 ] ); |
---|
192 | directive_failed( status, "rtems_task_resume of TA3" ); |
---|
193 | |
---|
194 | while ( FOREVER ) { |
---|
195 | if ( Run_count[ 1 ] >= 3 ) { |
---|
196 | puts( "TA1 - rtems_task_mode - change mode to NO RTEMS_PREEMPT" ); |
---|
197 | |
---|
198 | status = rtems_task_mode( |
---|
199 | RTEMS_NO_PREEMPT, |
---|
200 | RTEMS_PREEMPT_MASK, |
---|
201 | &previous_mode |
---|
202 | ); |
---|
203 | directive_failed( status, "rtems_task_mode" ); |
---|
204 | |
---|
205 | status = rtems_clock_get_tod( &time ); |
---|
206 | directive_failed( status, "rtems_clock_get_tod" ); |
---|
207 | |
---|
208 | old_seconds = time.second; |
---|
209 | |
---|
210 | for ( seconds = 0 ; seconds < 6 ; ) { |
---|
211 | status = rtems_clock_get_tod( &time ); |
---|
212 | directive_failed( status, "rtems_clock_get_tod" ); |
---|
213 | |
---|
214 | if ( time.second != old_seconds ) { |
---|
215 | old_seconds = time.second; |
---|
216 | seconds++; |
---|
217 | print_time( "TA1 - ", &time, "\n" ); |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | puts( "TA1 - rtems_task_mode - change mode to RTEMS_PREEMPT" ); |
---|
222 | status = rtems_task_mode( |
---|
223 | RTEMS_PREEMPT, |
---|
224 | RTEMS_PREEMPT_MASK, |
---|
225 | &previous_mode |
---|
226 | ); |
---|
227 | directive_failed( status, "rtems_task_mode" ); |
---|
228 | |
---|
229 | while ( !testsFinished ); |
---|
230 | showTaskSwitches (); |
---|
231 | |
---|
232 | puts( "TA1 - rtems_extension_delete - successful" ); |
---|
233 | status = rtems_extension_delete( Extension_id[1] ); |
---|
234 | directive_failed( status, "rtems_extension_delete" ); |
---|
235 | |
---|
236 | test_no_preempt(); |
---|
237 | |
---|
238 | TEST_END(); |
---|
239 | rtems_test_exit (0); |
---|
240 | } |
---|
241 | } |
---|
242 | } |
---|