source: rtems/testsuites/tmtests/tm15/task1.c @ b331f40

Last change on this file since b331f40 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.7 KB
Line 
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
42const char rtems_test_name[] = "TIME TEST 15";
43
44bool     time_set;
45uint32_t eventout;
46
47rtems_task High_tasks(
48  rtems_task_argument argument
49);
50
51rtems_task Low_task(
52  rtems_task_argument argument
53);
54
55void test_init(void);
56
57rtems_task Init(
58  rtems_task_argument argument
59)
60{
61  Print_Warning();
62
63  TEST_BEGIN();
64
65  test_init();
66
67  rtems_task_exit();
68}
69
70void test_init(void)
71{
72  rtems_id          id;
73  uint32_t    index;
74  rtems_event_set   event_out;
75  rtems_status_code status;
76
77  time_set = false;
78
79  status = rtems_task_create(
80    rtems_build_name( 'L', 'O', 'W', ' ' ),
81    10,
82    RTEMS_MINIMUM_STACK_SIZE,
83    RTEMS_NO_PREEMPT,
84    RTEMS_DEFAULT_ATTRIBUTES,
85    &id
86  );
87  directive_failed( status, "rtems_task_create LOW" );
88
89  status = rtems_task_start( id, Low_task, 0 );
90  directive_failed( status, "rtems_task_start LOW" );
91
92  for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {
93    status = rtems_task_create(
94      rtems_build_name( 'H', 'I', 'G', 'H' ),
95      5,
96      RTEMS_MINIMUM_STACK_SIZE,
97      RTEMS_DEFAULT_MODES,
98      RTEMS_DEFAULT_ATTRIBUTES,
99      &Task_id[ index ]
100    );
101    directive_failed( status, "rtems_task_create LOOP" );
102
103    status = rtems_task_start( Task_id[ index ], High_tasks, 0 );
104    directive_failed( status, "rtems_task_start LOOP" );
105  }
106
107  benchmark_timer_initialize();
108    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
109      (void) benchmark_timer_empty_function();
110  overhead = benchmark_timer_read();
111
112  benchmark_timer_initialize();
113    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
114    {
115        (void) rtems_event_receive(
116                 RTEMS_PENDING_EVENTS,
117                 RTEMS_DEFAULT_OPTIONS,
118                 RTEMS_NO_TIMEOUT,
119                 &event_out
120               );
121    }
122
123  end_time = benchmark_timer_read();
124
125  put_time(
126    "rtems_event_receive: obtain current events",
127    end_time,
128    OPERATION_COUNT,
129    overhead,
130    0
131  );
132
133
134  benchmark_timer_initialize();
135    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
136    {
137      (void) rtems_event_receive(
138               RTEMS_ALL_EVENTS,
139               RTEMS_NO_WAIT,
140               RTEMS_NO_TIMEOUT,
141               &event_out
142             );
143    }
144  end_time = benchmark_timer_read();
145
146  put_time(
147    "rtems_event_receive: not available NO_WAIT",
148    end_time,
149    OPERATION_COUNT,
150    overhead,
151    0
152  );
153}
154
155rtems_task Low_task(
156  rtems_task_argument argument
157)
158{
159  uint32_t    index;
160  rtems_event_set   event_out;
161
162  end_time = benchmark_timer_read();
163
164  put_time(
165    "rtems_event_receive: not available caller blocks",
166    end_time,
167    OPERATION_COUNT,
168    0,
169    0
170  );
171
172  benchmark_timer_initialize();
173    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
174      (void) benchmark_timer_empty_function();
175  overhead = benchmark_timer_read();
176
177  benchmark_timer_initialize();
178    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
179      (void) rtems_event_send( RTEMS_SELF, RTEMS_EVENT_16 );
180  end_time = benchmark_timer_read();
181
182  put_time(
183    "rtems_event_send: no task readied",
184    end_time,
185    OPERATION_COUNT,
186    overhead,
187    0
188  );
189
190  benchmark_timer_initialize();
191    (void) rtems_event_receive(
192             RTEMS_EVENT_16,
193             RTEMS_DEFAULT_OPTIONS,
194             RTEMS_NO_TIMEOUT,
195             &event_out
196           );
197  end_time = benchmark_timer_read();
198
199  put_time(
200    "rtems_event_receive: available",
201    end_time,
202    1,
203    0,
204    0
205  );
206
207  benchmark_timer_initialize();
208    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
209      (void) rtems_event_send( Task_id[ index ], RTEMS_EVENT_16 );
210  end_time = benchmark_timer_read();
211
212  put_time(
213    "rtems_event_send: task readied returns to caller",
214    end_time,
215    OPERATION_COUNT,
216    overhead,
217    0
218  );
219
220  TEST_END();
221  rtems_test_exit( 0 );
222}
223
224rtems_task High_tasks(
225  rtems_task_argument argument
226)
227{
228  if ( time_set )
229    (void) rtems_event_receive(
230      RTEMS_EVENT_16,
231      RTEMS_DEFAULT_OPTIONS,
232      RTEMS_NO_TIMEOUT,
233      &eventout
234    );
235  else {
236    time_set = true;
237    /* start blocking rtems_event_receive time */
238    benchmark_timer_initialize();
239    (void) rtems_event_receive(
240      RTEMS_EVENT_16,
241      RTEMS_DEFAULT_OPTIONS,
242      RTEMS_NO_TIMEOUT,
243      &eventout
244    );
245  }
246}
Note: See TracBrowser for help on using the repository browser.