1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * COPYRIGHT (c) 1989-2013. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions |
---|
9 | * are met: |
---|
10 | * 1. Redistributions of source code must retain the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer. |
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer in the |
---|
14 | * documentation and/or other materials provided with the distribution. |
---|
15 | * |
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
27 | */ |
---|
28 | |
---|
29 | #if !defined(OPERATION_COUNT) |
---|
30 | #define OPERATION_COUNT 100 |
---|
31 | #endif |
---|
32 | |
---|
33 | #ifdef HAVE_CONFIG_H |
---|
34 | #include "config.h" |
---|
35 | #endif |
---|
36 | |
---|
37 | #include <rtems/btimer.h> |
---|
38 | |
---|
39 | #define CONFIGURE_INIT |
---|
40 | #include "system.h" |
---|
41 | |
---|
42 | const char rtems_test_name[] = "TIME TEST 16"; |
---|
43 | |
---|
44 | uint32_t Task_count; |
---|
45 | |
---|
46 | rtems_task test_init( |
---|
47 | rtems_task_argument argument |
---|
48 | ); |
---|
49 | |
---|
50 | rtems_task Middle_tasks( |
---|
51 | rtems_task_argument argument |
---|
52 | ); |
---|
53 | |
---|
54 | rtems_task High_task( |
---|
55 | rtems_task_argument argument |
---|
56 | ); |
---|
57 | |
---|
58 | int operation_count = OPERATION_COUNT; |
---|
59 | |
---|
60 | rtems_task Init( |
---|
61 | rtems_task_argument argument |
---|
62 | ) |
---|
63 | { |
---|
64 | rtems_id id; |
---|
65 | rtems_status_code status; |
---|
66 | |
---|
67 | Print_Warning(); |
---|
68 | |
---|
69 | TEST_BEGIN(); |
---|
70 | |
---|
71 | status = rtems_task_create( |
---|
72 | rtems_build_name( 'T', 'E', 'S', 'T' ), |
---|
73 | RTEMS_MAXIMUM_PRIORITY - 1u, |
---|
74 | RTEMS_MINIMUM_STACK_SIZE, |
---|
75 | RTEMS_DEFAULT_MODES, |
---|
76 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
77 | &id |
---|
78 | ); |
---|
79 | directive_failed( status, "rtems_task_create of test_init" ); |
---|
80 | |
---|
81 | status = rtems_task_start( id, test_init, 0 ); |
---|
82 | directive_failed( status, "rtems_task_start of test_init" ); |
---|
83 | |
---|
84 | rtems_task_exit(); |
---|
85 | } |
---|
86 | |
---|
87 | rtems_task test_init( |
---|
88 | rtems_task_argument argument |
---|
89 | ) |
---|
90 | { |
---|
91 | rtems_task_priority priority; |
---|
92 | rtems_status_code status; |
---|
93 | int index; |
---|
94 | rtems_task_entry task_entry; |
---|
95 | |
---|
96 | /* As each task is started, it preempts this task and |
---|
97 | * performs a blocking rtems_event_receive. Upon completion of |
---|
98 | * this loop all created tasks are blocked. |
---|
99 | */ |
---|
100 | |
---|
101 | priority = RTEMS_MAXIMUM_PRIORITY - 2u; |
---|
102 | if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u ) |
---|
103 | operation_count = (int) (RTEMS_MAXIMUM_PRIORITY - 2u); |
---|
104 | |
---|
105 | for( index = 0 ; index < operation_count ; index++ ) { |
---|
106 | status = rtems_task_create( |
---|
107 | rtems_build_name( 'M', 'I', 'D', ' ' ), |
---|
108 | priority, |
---|
109 | RTEMS_MINIMUM_STACK_SIZE, |
---|
110 | RTEMS_DEFAULT_MODES, |
---|
111 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
112 | &Task_id[ index ] |
---|
113 | ); |
---|
114 | directive_failed( status, "rtems_task_create LOOP" ); |
---|
115 | |
---|
116 | if ( index == operation_count-1 ) task_entry = High_task; |
---|
117 | else task_entry = Middle_tasks; |
---|
118 | |
---|
119 | status = rtems_task_start( Task_id[ index ], task_entry, 0 ); |
---|
120 | directive_failed( status, "rtems_task_start LOOP" ); |
---|
121 | |
---|
122 | priority--; |
---|
123 | } |
---|
124 | |
---|
125 | Task_count = 0; |
---|
126 | |
---|
127 | benchmark_timer_initialize(); |
---|
128 | (void) rtems_event_send( Task_id[ Task_count ], RTEMS_EVENT_16 ); |
---|
129 | /* preempts task */ |
---|
130 | } |
---|
131 | |
---|
132 | rtems_task Middle_tasks( |
---|
133 | rtems_task_argument argument |
---|
134 | ) |
---|
135 | { |
---|
136 | rtems_event_set event_out; |
---|
137 | |
---|
138 | (void) rtems_event_receive( /* task blocks */ |
---|
139 | RTEMS_EVENT_16, |
---|
140 | RTEMS_DEFAULT_OPTIONS, |
---|
141 | RTEMS_NO_TIMEOUT, |
---|
142 | &event_out |
---|
143 | ); |
---|
144 | |
---|
145 | Task_count++; |
---|
146 | |
---|
147 | (void) rtems_event_send( /* preempts task */ |
---|
148 | Task_id[ Task_count ], |
---|
149 | RTEMS_EVENT_16 |
---|
150 | ); |
---|
151 | } |
---|
152 | |
---|
153 | rtems_task High_task( |
---|
154 | rtems_task_argument argument |
---|
155 | ) |
---|
156 | { |
---|
157 | rtems_event_set event_out; |
---|
158 | |
---|
159 | (void) rtems_event_receive( /* task blocks */ |
---|
160 | RTEMS_EVENT_16, |
---|
161 | RTEMS_DEFAULT_OPTIONS, |
---|
162 | RTEMS_NO_TIMEOUT, |
---|
163 | &event_out |
---|
164 | ); |
---|
165 | |
---|
166 | end_time = benchmark_timer_read(); |
---|
167 | |
---|
168 | put_time( |
---|
169 | "rtems_event_send: task readied preempts caller", |
---|
170 | end_time, |
---|
171 | operation_count - 1u, |
---|
172 | 0u, |
---|
173 | 0 |
---|
174 | ); |
---|
175 | |
---|
176 | TEST_END(); |
---|
177 | rtems_test_exit( 0 ); |
---|
178 | } |
---|