1 | /* |
---|
2 | * |
---|
3 | * COPYRIGHT (c) 1989-2013. |
---|
4 | * On-Line Applications Research Corporation (OAR). |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * http://www.rtems.org/license/LICENSE. |
---|
9 | */ |
---|
10 | |
---|
11 | #if !defined(OPERATION_COUNT) |
---|
12 | #define OPERATION_COUNT 100 |
---|
13 | #endif |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/btimer.h> |
---|
20 | |
---|
21 | #define CONFIGURE_INIT |
---|
22 | #include "system.h" |
---|
23 | |
---|
24 | const char rtems_test_name[] = "TIME TEST 22"; |
---|
25 | |
---|
26 | rtems_id Queue_id; |
---|
27 | |
---|
28 | long Buffer[4]; |
---|
29 | |
---|
30 | rtems_task Low_task( |
---|
31 | rtems_task_argument argument |
---|
32 | ); |
---|
33 | |
---|
34 | rtems_task High_task( |
---|
35 | rtems_task_argument argument |
---|
36 | ); |
---|
37 | |
---|
38 | rtems_task Preempt_task( |
---|
39 | rtems_task_argument argument |
---|
40 | ); |
---|
41 | |
---|
42 | rtems_task Init( |
---|
43 | rtems_task_argument argument |
---|
44 | ) |
---|
45 | { |
---|
46 | rtems_id id; |
---|
47 | rtems_status_code status; |
---|
48 | |
---|
49 | Print_Warning(); |
---|
50 | |
---|
51 | TEST_BEGIN(); |
---|
52 | |
---|
53 | status = rtems_message_queue_create( |
---|
54 | rtems_build_name( 'M', 'Q', '1', ' '), |
---|
55 | 100, |
---|
56 | MESSAGE_SIZE, |
---|
57 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
58 | &Queue_id |
---|
59 | ); |
---|
60 | directive_failed( status, "rtems_message_queue_create" ); |
---|
61 | |
---|
62 | status = rtems_task_create( |
---|
63 | rtems_build_name( 'L', 'O', 'W', ' ' ), |
---|
64 | 10, |
---|
65 | RTEMS_MINIMUM_STACK_SIZE, |
---|
66 | RTEMS_NO_PREEMPT, |
---|
67 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
68 | &id |
---|
69 | ); |
---|
70 | directive_failed( status, "rtems_task_create" ); |
---|
71 | |
---|
72 | status = rtems_task_start( id, Low_task, 0 ); |
---|
73 | directive_failed( status, "rtems_task_start LOW" ); |
---|
74 | |
---|
75 | status = rtems_task_create( |
---|
76 | 1, |
---|
77 | 11, |
---|
78 | RTEMS_MINIMUM_STACK_SIZE, |
---|
79 | RTEMS_DEFAULT_MODES, |
---|
80 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
81 | &id |
---|
82 | ); |
---|
83 | directive_failed( status, "rtems_task_create RTEMS_PREEMPT" ); |
---|
84 | |
---|
85 | status = rtems_task_start( id, Preempt_task, 0 ); |
---|
86 | directive_failed( status, "rtems_task_start RTEMS_PREEMPT" ); |
---|
87 | |
---|
88 | rtems_task_exit(); |
---|
89 | } |
---|
90 | |
---|
91 | rtems_task High_task( |
---|
92 | rtems_task_argument argument |
---|
93 | ) |
---|
94 | { |
---|
95 | uint32_t count; |
---|
96 | rtems_status_code status; |
---|
97 | |
---|
98 | benchmark_timer_initialize(); |
---|
99 | (void) rtems_message_queue_broadcast( |
---|
100 | Queue_id, |
---|
101 | Buffer, |
---|
102 | MESSAGE_SIZE, |
---|
103 | &count |
---|
104 | ); |
---|
105 | end_time = benchmark_timer_read(); |
---|
106 | |
---|
107 | put_time( |
---|
108 | "rtems_message_queue_broadcast: task readied returns to caller", |
---|
109 | end_time, |
---|
110 | 1, |
---|
111 | 0, |
---|
112 | 0 |
---|
113 | ); |
---|
114 | |
---|
115 | status = rtems_task_suspend(RTEMS_SELF); |
---|
116 | directive_failed( status, "rtems_task_suspend" ); |
---|
117 | } |
---|
118 | |
---|
119 | rtems_task Low_task( |
---|
120 | rtems_task_argument argument |
---|
121 | ) |
---|
122 | { |
---|
123 | rtems_id id; |
---|
124 | uint32_t index; |
---|
125 | uint32_t count; |
---|
126 | size_t size; |
---|
127 | rtems_status_code status; |
---|
128 | |
---|
129 | status = rtems_task_create( |
---|
130 | rtems_build_name( 'H', 'I', 'G', 'H' ), |
---|
131 | 5, |
---|
132 | RTEMS_MINIMUM_STACK_SIZE, |
---|
133 | RTEMS_NO_PREEMPT, |
---|
134 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
135 | &id |
---|
136 | ); |
---|
137 | directive_failed( status, "rtems_task_create" ); |
---|
138 | |
---|
139 | status = rtems_task_start( id, High_task, 0 ); |
---|
140 | directive_failed( status, "rtems_task_start HIGH" ); |
---|
141 | |
---|
142 | status = rtems_message_queue_receive( |
---|
143 | Queue_id, |
---|
144 | (long (*)[4]) Buffer, |
---|
145 | &size, |
---|
146 | RTEMS_DEFAULT_OPTIONS, |
---|
147 | RTEMS_NO_TIMEOUT |
---|
148 | ); |
---|
149 | directive_failed( status, "message_queu_receive" ); |
---|
150 | |
---|
151 | benchmark_timer_initialize(); |
---|
152 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
153 | (void) rtems_message_queue_broadcast( |
---|
154 | Queue_id, |
---|
155 | Buffer, |
---|
156 | MESSAGE_SIZE, |
---|
157 | &count |
---|
158 | ); |
---|
159 | end_time = benchmark_timer_read(); |
---|
160 | |
---|
161 | put_time( |
---|
162 | "rtems_message_queue_broadcast: no waiting tasks", |
---|
163 | end_time, |
---|
164 | OPERATION_COUNT, |
---|
165 | 1, |
---|
166 | 0 |
---|
167 | ); |
---|
168 | |
---|
169 | (void) rtems_message_queue_receive( |
---|
170 | Queue_id, |
---|
171 | (long (*)[4]) Buffer, |
---|
172 | &size, |
---|
173 | RTEMS_DEFAULT_OPTIONS, |
---|
174 | RTEMS_NO_TIMEOUT |
---|
175 | ); |
---|
176 | |
---|
177 | /* should go to Preempt_task here */ |
---|
178 | |
---|
179 | end_time = benchmark_timer_read(); |
---|
180 | |
---|
181 | put_time( |
---|
182 | "rtems_message_queue_broadcast: task readied -- preempts caller", |
---|
183 | end_time, |
---|
184 | 1, |
---|
185 | 0, |
---|
186 | 0 |
---|
187 | ); |
---|
188 | |
---|
189 | TEST_END(); |
---|
190 | rtems_test_exit( 0 ); |
---|
191 | } |
---|
192 | |
---|
193 | rtems_task Preempt_task( |
---|
194 | rtems_task_argument argument |
---|
195 | ) |
---|
196 | { |
---|
197 | uint32_t count; |
---|
198 | |
---|
199 | benchmark_timer_initialize(); |
---|
200 | (void) rtems_message_queue_broadcast( |
---|
201 | Queue_id, |
---|
202 | Buffer, |
---|
203 | MESSAGE_SIZE, |
---|
204 | &count |
---|
205 | ); |
---|
206 | |
---|
207 | /* should be preempted by low task */ |
---|
208 | } |
---|