source: rtems/testsuites/tmtests/tm12/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 12";
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
102  status = rtems_message_queue_create(
103    rtems_build_name( 'M', 'Q', '1', ' ' ),
104    (uint32_t) operation_count,
105    MESSAGE_SIZE,
106    RTEMS_DEFAULT_ATTRIBUTES,
107    &Queue_id
108  );
109  directive_failed( status, "rtems_message_queue_create" );
110
111  priority = RTEMS_MAXIMUM_PRIORITY - 1u;
112
113  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2 )
114    operation_count =  RTEMS_MAXIMUM_PRIORITY - 2;
115
116  for( index = 0; index < operation_count ; index++ ) {
117    status = rtems_task_create(
118      rtems_build_name( 'T', 'I', 'M', 'E' ),
119      priority,
120      RTEMS_MINIMUM_STACK_SIZE,
121      RTEMS_DEFAULT_MODES,
122      RTEMS_DEFAULT_ATTRIBUTES,
123      &task_id
124    );
125    directive_failed( status, "rtems_task_create LOOP" );
126
127    priority--;
128
129    if ( index == operation_count-1 ) task_entry = High_task;
130    else                              task_entry = Low_tasks;
131
132    status = rtems_task_start( task_id, task_entry, 0 );
133    directive_failed( status, "rtems_task_start LOOP" );
134  }
135}
136
137rtems_task High_task(
138  rtems_task_argument argument
139)
140{
141  int  index;
142
143  benchmark_timer_initialize();
144    for ( index=1 ; index < operation_count ; index++ )
145      (void) benchmark_timer_empty_function();
146  overhead = benchmark_timer_read();
147
148  benchmark_timer_initialize();
149    for ( index=1 ; index < operation_count ; index++ )
150      (void) rtems_message_queue_send( Queue_id, Buffer, MESSAGE_SIZE );
151  end_time = benchmark_timer_read();
152
153  put_time(
154    "rtems_message_queue_send: task readied returns to caller",
155    end_time,
156    operation_count - 1,
157    overhead,
158    0
159  );
160
161  TEST_END();
162  rtems_test_exit( 0 );
163}
164
165rtems_task Low_tasks(
166  rtems_task_argument argument
167)
168{
169  size_t  size;
170
171  (void) rtems_message_queue_receive(
172           Queue_id,
173           (long (*)[4]) Buffer,
174           &size,
175           RTEMS_DEFAULT_OPTIONS,
176           RTEMS_NO_TIMEOUT
177         );
178}
Note: See TracBrowser for help on using the repository browser.