source: rtems/testsuites/tmtests/tm14/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.4 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 14";
43
44rtems_id Queue_id;
45
46long Buffer[4];
47
48rtems_task test_init(
49  rtems_task_argument argument
50);
51
52rtems_task High_task(
53  rtems_task_argument argument
54);
55
56rtems_task Low_tasks(
57  rtems_task_argument argument
58);
59
60#define MESSAGE_SIZE (sizeof(long) * 4)
61
62int operation_count = OPERATION_COUNT;
63
64rtems_task Init(
65  rtems_task_argument argument
66)
67{
68  rtems_id          task_id;
69  rtems_status_code status;
70
71  Print_Warning();
72
73  TEST_BEGIN();
74
75  status = rtems_task_create(
76    1,
77    RTEMS_MAXIMUM_PRIORITY - 1u,
78    RTEMS_MINIMUM_STACK_SIZE,
79    RTEMS_DEFAULT_MODES,
80    RTEMS_DEFAULT_ATTRIBUTES,
81    &task_id
82  );
83  directive_failed( status, "rtems_task_create" );
84
85  status = rtems_task_start( task_id, test_init, 0 );
86  directive_failed( status, "rtems_task_start" );
87
88  rtems_task_exit();
89}
90
91rtems_task test_init(
92  rtems_task_argument argument
93)
94{
95  int                  index;
96  rtems_task_entry     task_entry;
97  rtems_task_priority  priority;
98  rtems_id             task_id;
99  rtems_status_code    status;
100
101  status = rtems_message_queue_create(
102    rtems_build_name( 'M', 'Q', '1', ' ' ),
103    OPERATION_COUNT,
104    MESSAGE_SIZE,
105    RTEMS_DEFAULT_ATTRIBUTES,
106    &Queue_id
107  );
108  directive_failed( status, "rtems_message_queue_create" );
109
110  priority = RTEMS_MAXIMUM_PRIORITY - 2u;
111  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
112    operation_count =  (int) (RTEMS_MAXIMUM_PRIORITY - 2u);
113
114  for( index = 0; index < operation_count ; index++ ) {
115    status = rtems_task_create(
116      rtems_build_name( 'T', 'I', 'M', 'E' ),
117      priority,
118      RTEMS_MINIMUM_STACK_SIZE,
119      RTEMS_DEFAULT_MODES,
120      RTEMS_DEFAULT_ATTRIBUTES,
121      &task_id
122    );
123    directive_failed( status, "rtems_task_create LOOP" );
124
125    priority--;
126
127    if ( index==operation_count-1 ) task_entry = High_task;
128    else                            task_entry = Low_tasks;
129
130    status = rtems_task_start( task_id, task_entry, 0 );
131    directive_failed( status, "rtems_task_start LOOP" );
132  }
133}
134
135rtems_task High_task(
136  rtems_task_argument argument
137)
138{
139  int  index;
140
141  benchmark_timer_initialize();
142    for ( index=1 ; index < operation_count ; index++ )
143      (void) benchmark_timer_empty_function();
144  overhead = benchmark_timer_read();
145
146  benchmark_timer_initialize();
147    for ( index=1 ; index <= operation_count ; index++ )
148      (void) rtems_message_queue_urgent( Queue_id, Buffer, MESSAGE_SIZE );
149  end_time = benchmark_timer_read();
150
151  put_time(
152    "rtems_message_queue_urgent: task readied returns to caller",
153    end_time,
154    operation_count,
155    overhead,
156    0
157  );
158
159  TEST_END();
160  rtems_test_exit( 0 );
161}
162
163rtems_task Low_tasks(
164  rtems_task_argument argument
165)
166{
167  size_t  size;
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}
Note: See TracBrowser for help on using the repository browser.