source: rtems/testsuites/tmtests/tm11/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 11";
43
44rtems_id Queue_id;
45
46long Buffer[4];
47
48rtems_task test_init(
49  rtems_task_argument argument
50);
51
52rtems_task Middle_tasks(
53  rtems_task_argument argument
54);
55
56rtems_task High_task(
57  rtems_task_argument argument
58);
59
60int operation_count = OPERATION_COUNT;
61
62void Init(
63  rtems_task_argument argument
64)
65{
66  rtems_status_code status;
67  rtems_id id;
68
69  Print_Warning();
70
71  TEST_BEGIN();
72
73  status = rtems_task_create(
74    1,
75    RTEMS_MAXIMUM_PRIORITY - 1u,
76    RTEMS_MINIMUM_STACK_SIZE,
77    RTEMS_DEFAULT_MODES,
78    RTEMS_DEFAULT_ATTRIBUTES,
79    &id
80  );
81  directive_failed( status, "rtems_task_create" );
82
83  status = rtems_task_start( id, test_init, 0 );
84  directive_failed( status, "rtems_task_start" );
85
86  rtems_task_exit();
87}
88
89#define MESSAGE_SIZE (sizeof(long) * 4)
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/*  As each task is started, it preempts this task and
102 *  performs a blocking rtems_message_queue_receive.  Upon completion of
103 *  this loop all created tasks are blocked.
104 */
105
106  status = rtems_message_queue_create(
107    rtems_build_name( 'M', 'Q', '1', ' '  ),
108    OPERATION_COUNT,
109    MESSAGE_SIZE,
110    RTEMS_DEFAULT_ATTRIBUTES,
111    &Queue_id
112  );
113  directive_failed( status, "rtems_message_queue_create" );
114
115  priority = RTEMS_MAXIMUM_PRIORITY - 2u;
116
117  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
118    operation_count =  RTEMS_MAXIMUM_PRIORITY - 2u;
119  for( index = 0; index < operation_count ; index++ ) {
120    status = rtems_task_create(
121      rtems_build_name( 'T', 'I', 'M', 'E'  ),
122      priority,
123      RTEMS_MINIMUM_STACK_SIZE,
124      RTEMS_DEFAULT_MODES,
125      RTEMS_DEFAULT_ATTRIBUTES,
126      &task_id
127    );
128    directive_failed( status, "rtems_task_create LOOP" );
129
130    priority--;
131
132    if ( index==operation_count-1 ) task_entry = High_task;
133    else                            task_entry = Middle_tasks;
134
135    status = rtems_task_start( task_id, task_entry, 0 );
136    directive_failed( status, "rtems_task_start LOOP" );
137  }
138
139  benchmark_timer_initialize();
140    (void) rtems_message_queue_send( Queue_id, Buffer, MESSAGE_SIZE );
141}
142
143rtems_task Middle_tasks(
144  rtems_task_argument argument
145)
146{
147  size_t  size;
148
149  (void) rtems_message_queue_receive(
150           Queue_id,
151           (long (*)[4]) Buffer,
152           &size,
153           RTEMS_DEFAULT_OPTIONS,
154           RTEMS_NO_TIMEOUT
155         );
156
157  (void) rtems_message_queue_send( Queue_id, (long (*)[4]) Buffer, size );
158}
159
160rtems_task High_task(
161  rtems_task_argument argument
162)
163{
164  size_t  size;
165
166  (void) rtems_message_queue_receive(
167           Queue_id,
168           (long (*)[4]) Buffer,
169           &size,
170           RTEMS_DEFAULT_OPTIONS,
171           RTEMS_NO_TIMEOUT
172         );
173
174  end_time = benchmark_timer_read();
175
176  put_time(
177    "rtems_message_queue_send: task readied preempts caller",
178    end_time,
179    operation_count,
180    0,
181    0
182  );
183
184  TEST_END();
185  rtems_test_exit( 0 );
186}
Note: See TracBrowser for help on using the repository browser.