source: rtems/testsuites/tmtests/tm10/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: 4.6 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 10";
43
44rtems_id Queue_id;
45long Buffer[4];
46
47rtems_task High_task(
48  rtems_task_argument argument
49);
50
51rtems_task Middle_tasks(
52  rtems_task_argument argument
53);
54
55rtems_task Low_task(
56  rtems_task_argument argument
57);
58
59void test_init(void);
60
61int operation_count = OPERATION_COUNT;
62
63rtems_task Init(
64  rtems_task_argument argument
65)
66{
67  Print_Warning();
68
69  TEST_BEGIN();
70
71  test_init();
72
73  rtems_task_exit();
74}
75
76void test_init()
77{
78  int                 index;
79  size_t              size;
80  rtems_task_entry    task_entry;
81  rtems_status_code   status;
82  rtems_task_priority priority;
83  rtems_id            task_id;
84
85  priority = 2;
86
87  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2 )
88    operation_count =  RTEMS_MAXIMUM_PRIORITY - 2;
89
90  for( index = 0; index < operation_count ; index++ ) {
91    status = rtems_task_create(
92      rtems_build_name( 'T', 'I', 'M', 'E' ),
93      priority,
94      RTEMS_MINIMUM_STACK_SIZE,
95      RTEMS_DEFAULT_MODES,
96      RTEMS_DEFAULT_ATTRIBUTES,
97      &task_id
98    );
99    directive_failed( status, "rtems_task_create LOOP" );
100
101    priority++;
102
103    if ( index==0 )                    task_entry = High_task;
104    else if ( index==operation_count-1 ) task_entry = Low_task;
105    else                               task_entry = Middle_tasks;
106
107    status = rtems_task_start( task_id, task_entry, 0 );
108    directive_failed( status, "rtems_task_start LOOP" );
109  }
110
111  status = rtems_message_queue_create(
112    1,
113    (uint32_t)operation_count,
114    16,
115    RTEMS_DEFAULT_ATTRIBUTES,
116    &Queue_id
117  );
118  directive_failed( status, "rtems_message_queue_create" );
119
120  benchmark_timer_initialize();
121    for ( index=1 ; index < operation_count ; index++ )
122      (void) benchmark_timer_empty_function();
123  overhead = benchmark_timer_read();
124
125  benchmark_timer_initialize();
126    for ( index=1 ; index < operation_count ; index++ )
127      (void) rtems_message_queue_receive(
128               Queue_id,
129               (long (*)[4]) Buffer,
130               &size,
131               RTEMS_NO_WAIT,
132               RTEMS_NO_TIMEOUT
133             );
134  end_time = benchmark_timer_read();
135
136  put_time(
137    "rtems_message_queue_receive: not available NO_WAIT",
138    end_time,
139    operation_count,
140    overhead,
141    0
142  );
143
144}
145
146rtems_task High_task(
147  rtems_task_argument argument
148)
149{
150  size_t  size;
151
152  benchmark_timer_initialize();
153     (void) rtems_message_queue_receive(
154              Queue_id,
155              (long (*)[4]) Buffer,
156              &size,
157              RTEMS_DEFAULT_OPTIONS,
158              RTEMS_NO_TIMEOUT
159            );
160}
161
162rtems_task Middle_tasks(
163  rtems_task_argument argument
164)
165{
166  size_t  size;
167
168  (void) rtems_message_queue_receive(
169           Queue_id,
170           (long (*)[4]) Buffer,
171           &size,
172           RTEMS_DEFAULT_OPTIONS,
173           RTEMS_NO_TIMEOUT
174         );
175}
176
177
178rtems_task Low_task(
179  rtems_task_argument argument
180)
181{
182  end_time = benchmark_timer_read();
183
184  put_time(
185    "rtems_message_queue_receive: not available caller blocks",
186    end_time,
187    operation_count - 1,
188    0,
189    0
190  );
191
192  TEST_END();
193  rtems_test_exit( 0 );
194}
Note: See TracBrowser for help on using the repository browser.