source: rtems/testsuites/tmtests/tm22/task1.c

Last change on this file was b331f40, checked in by Joel Sherrill <joel@…>, on 04/01/22 at 19:05:19

testsuites/tmtests/*: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *
5 *  COPYRIGHT (c) 1989-2013.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#if !defined(OPERATION_COUNT)
31#define OPERATION_COUNT 100
32#endif
33
34#ifdef HAVE_CONFIG_H
35#include "config.h"
36#endif
37
38#include <rtems/btimer.h>
39
40#define CONFIGURE_INIT
41#include "system.h"
42
43const char rtems_test_name[] = "TIME TEST 22";
44
45rtems_id Queue_id;
46
47long Buffer[4];
48
49rtems_task Low_task(
50  rtems_task_argument argument
51);
52
53rtems_task High_task(
54  rtems_task_argument argument
55);
56
57rtems_task Preempt_task(
58  rtems_task_argument argument
59);
60
61rtems_task Init(
62  rtems_task_argument argument
63)
64{
65  rtems_id          id;
66  rtems_status_code status;
67
68  Print_Warning();
69
70  TEST_BEGIN();
71
72  status = rtems_message_queue_create(
73    rtems_build_name( 'M', 'Q', '1', ' '),
74    100,
75    MESSAGE_SIZE,
76    RTEMS_DEFAULT_ATTRIBUTES,
77    &Queue_id
78  );
79  directive_failed( status, "rtems_message_queue_create" );
80
81  status = rtems_task_create(
82    rtems_build_name( 'L', 'O', 'W', ' ' ),
83    10,
84    RTEMS_MINIMUM_STACK_SIZE,
85    RTEMS_NO_PREEMPT,
86    RTEMS_DEFAULT_ATTRIBUTES,
87    &id
88  );
89  directive_failed( status, "rtems_task_create" );
90
91  status = rtems_task_start( id, Low_task, 0 );
92  directive_failed( status, "rtems_task_start LOW" );
93
94  status = rtems_task_create(
95    1,
96    11,
97    RTEMS_MINIMUM_STACK_SIZE,
98    RTEMS_DEFAULT_MODES,
99    RTEMS_DEFAULT_ATTRIBUTES,
100    &id
101  );
102  directive_failed( status, "rtems_task_create RTEMS_PREEMPT" );
103
104  status = rtems_task_start( id, Preempt_task, 0 );
105  directive_failed( status, "rtems_task_start RTEMS_PREEMPT" );
106
107  rtems_task_exit();
108}
109
110rtems_task High_task(
111  rtems_task_argument argument
112)
113{
114  uint32_t    count;
115  rtems_status_code status;
116
117  benchmark_timer_initialize();
118    (void) rtems_message_queue_broadcast(
119             Queue_id,
120             Buffer,
121             MESSAGE_SIZE,
122             &count
123           );
124  end_time = benchmark_timer_read();
125
126  put_time(
127    "rtems_message_queue_broadcast: task readied returns to caller",
128    end_time,
129    1,
130    0,
131    0
132  );
133
134  status = rtems_task_suspend(RTEMS_SELF);
135  directive_failed( status, "rtems_task_suspend" );
136}
137
138rtems_task Low_task(
139  rtems_task_argument argument
140)
141{
142  rtems_id          id;
143  uint32_t          index;
144  uint32_t          count;
145  size_t            size;
146  rtems_status_code status;
147
148  status = rtems_task_create(
149    rtems_build_name( 'H', 'I', 'G', 'H' ),
150    5,
151    RTEMS_MINIMUM_STACK_SIZE,
152    RTEMS_NO_PREEMPT,
153    RTEMS_DEFAULT_ATTRIBUTES,
154    &id
155  );
156  directive_failed( status, "rtems_task_create" );
157
158  status = rtems_task_start( id, High_task, 0 );
159  directive_failed( status, "rtems_task_start HIGH" );
160
161  status = rtems_message_queue_receive(
162    Queue_id,
163    (long (*)[4]) Buffer,
164    &size,
165    RTEMS_DEFAULT_OPTIONS,
166    RTEMS_NO_TIMEOUT
167  );
168  directive_failed( status, "message_queu_receive" );
169
170  benchmark_timer_initialize();
171    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
172      (void) rtems_message_queue_broadcast(
173               Queue_id,
174               Buffer,
175               MESSAGE_SIZE,
176               &count
177             );
178  end_time = benchmark_timer_read();
179
180  put_time(
181    "rtems_message_queue_broadcast: no waiting tasks",
182    end_time,
183    OPERATION_COUNT,
184    1,
185    0
186  );
187
188  (void) rtems_message_queue_receive(
189           Queue_id,
190           (long (*)[4]) Buffer,
191           &size,
192           RTEMS_DEFAULT_OPTIONS,
193           RTEMS_NO_TIMEOUT
194         );
195
196  /* should go to Preempt_task here */
197
198  end_time = benchmark_timer_read();
199
200  put_time(
201    "rtems_message_queue_broadcast: task readied -- preempts caller",
202    end_time,
203    1,
204    0,
205    0
206  );
207
208  TEST_END();
209  rtems_test_exit( 0 );
210}
211
212rtems_task Preempt_task(
213  rtems_task_argument argument
214)
215{
216  uint32_t    count;
217
218  benchmark_timer_initialize();
219    (void) rtems_message_queue_broadcast(
220             Queue_id,
221             Buffer,
222             MESSAGE_SIZE,
223             &count
224           );
225
226 /* should be preempted by low task */
227}
Note: See TracBrowser for help on using the repository browser.