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