source: rtems/testsuites/tmtests/tmck/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: 4.8 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
42#if !defined(MAXIMUM_DISTRIBUTION)
43#define MAXIMUM_DISTRIBUTION 1000
44#endif
45
46const char rtems_test_name[] = "TIME CHECKER";
47
48uint32_t Distribution[ MAXIMUM_DISTRIBUTION + 1 ];
49
50rtems_task Task_1(
51  rtems_task_argument argument
52);
53
54void check_read_timer( void );
55
56rtems_task Init(
57  rtems_task_argument argument
58)
59{
60  rtems_id          id;
61  rtems_status_code status;
62
63  /*
64   *  Tell the Timer Driver what we are doing
65   */
66
67  benchmark_timer_disable_subtracting_average_overhead( 1 );
68
69  Print_Warning();
70
71  TEST_BEGIN();
72
73  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' ),
74
75  status = rtems_task_create(
76    1,
77    5,
78    RTEMS_MINIMUM_STACK_SIZE,
79    RTEMS_DEFAULT_MODES,
80    RTEMS_DEFAULT_ATTRIBUTES,
81    &id
82  );
83  directive_failed( status, "rtems_task_create of TA1" );
84
85  status = rtems_task_start( id, Task_1, 0 );
86  directive_failed( status, "rtems_task_start of TA1" );
87
88  rtems_task_exit();
89}
90
91rtems_task Task_1(
92  rtems_task_argument argument
93)
94{
95  uint32_t   index;
96
97  check_read_timer();
98
99  benchmark_timer_initialize();
100  end_time = benchmark_timer_read();
101
102  put_time(
103    "Time Check: NULL timer stopped at",
104    end_time,
105    1,
106    0,
107    0
108  );
109
110  benchmark_timer_initialize();
111  for ( index = 1 ; index <= 1000 ; index++ )
112    (void) benchmark_timer_empty_function();
113  end_time = benchmark_timer_read();
114
115  put_time(
116    "Time Check: LOOP (1000) timer stopped at",
117    end_time,
118    1,
119    0,
120    0
121  );
122
123  benchmark_timer_initialize();
124  for ( index = 1 ; index <= 10000 ; index++ )
125    (void) benchmark_timer_empty_function();
126  end_time = benchmark_timer_read();
127
128  put_time(
129    "Time Check: LOOP (10000) timer stopped at",
130    end_time,
131    1,
132    0,
133    0
134  );
135
136  benchmark_timer_initialize();
137  for ( index = 1 ; index <= 50000 ; index++ )
138    (void) benchmark_timer_empty_function();
139  end_time = benchmark_timer_read();
140
141  put_time(
142    "Time Check: LOOP (50000) timer stopped at",
143    end_time,
144    1,
145    0,
146    0
147  );
148
149  benchmark_timer_initialize();
150  for ( index = 1 ; index <= 100000 ; index++ )
151    (void) benchmark_timer_empty_function();
152  end_time = benchmark_timer_read();
153
154  put_time(
155    "Time Check: LOOP (100000) timer stopped at",
156    end_time,
157    1,
158    0,
159    0
160  );
161
162  TEST_END();
163  rtems_test_exit( 0 );
164}
165
166void check_read_timer()
167{
168  uint32_t   index;
169  uint32_t   time;
170
171  for ( index = 1 ; index <= MAXIMUM_DISTRIBUTION ; index++ )
172    Distribution[ index ] = 0;
173
174  for ( index = 1 ; index <= OPERATION_COUNT ; ) {
175    benchmark_timer_initialize();
176    end_time = benchmark_timer_read();
177    if ( end_time > MAXIMUM_DISTRIBUTION ) {
178      /*
179       *  Under UNIX a simple process swap takes longer than we
180       *  consider valid for our testing purposes.
181       */
182      printf( "TOO LONG (%" PRIu32 ") at index %" PRIu32 "!!!\n", end_time, index );
183      continue;
184    }
185    Distribution[ end_time ]++;
186    index++;
187  }
188
189  printf( "Units may not be in microseconds for this test!!!\n" );
190  time = 0;
191  for ( index = 0 ; index <= MAXIMUM_DISTRIBUTION ; index++ ) {
192    time += (Distribution[ index ] * index);
193    if ( Distribution[ index ] != 0 )
194      printf( "%" PRId32 " %" PRId32 "\n", index, Distribution[ index ] );
195  }
196  printf( "Total time = %" PRId32 "\n", time );
197  printf( "Average time = %" PRId32 "\n", time / OPERATION_COUNT );
198}
Note: See TracBrowser for help on using the repository browser.