source: rtems/testsuites/tmtests/tmck/task1.c @ 51b3cbca

5
Last change on this file since 51b3cbca was 51b3cbca, checked in by Sebastian Huber <sebastian.huber@…>, on 10/04/18 at 13:23:25

tests: Use rtems_task_exit()

Update #3533.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2013.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#define CONFIGURE_INIT
16#include "system.h"
17
18#define MAXIMUM_DISTRIBUTION 1000
19
20#undef OPERATION_COUNT
21#define OPERATION_COUNT    100000
22
23const char rtems_test_name[] = "TIME CHECKER";
24
25uint32_t Distribution[ MAXIMUM_DISTRIBUTION + 1 ];
26
27rtems_task Task_1(
28  rtems_task_argument argument
29);
30
31void check_read_timer( void );
32
33rtems_task Init(
34  rtems_task_argument argument
35)
36{
37  rtems_id          id;
38  rtems_status_code status;
39
40  /*
41   *  Tell the Timer Driver what we are doing
42   */
43
44  benchmark_timer_disable_subtracting_average_overhead( 1 );
45
46  Print_Warning();
47
48  TEST_BEGIN();
49
50  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' ),
51
52  status = rtems_task_create(
53    1,
54    5,
55    RTEMS_MINIMUM_STACK_SIZE,
56    RTEMS_DEFAULT_MODES,
57    RTEMS_DEFAULT_ATTRIBUTES,
58    &id
59  );
60  directive_failed( status, "rtems_task_create of TA1" );
61
62  status = rtems_task_start( id, Task_1, 0 );
63  directive_failed( status, "rtems_task_start of TA1" );
64
65  rtems_task_exit();
66}
67
68rtems_task Task_1(
69  rtems_task_argument argument
70)
71{
72  uint32_t   index;
73
74  check_read_timer();
75rtems_test_pause();
76
77  benchmark_timer_initialize();
78  end_time = benchmark_timer_read();
79
80  put_time(
81    "Time Check: NULL timer stopped at",
82    end_time,
83    1,
84    0,
85    0
86  );
87
88  benchmark_timer_initialize();
89  for ( index = 1 ; index <= 1000 ; index++ )
90    (void) benchmark_timer_empty_function();
91  end_time = benchmark_timer_read();
92
93  put_time(
94    "Time Check: LOOP (1000) timer stopped at",
95    end_time,
96    1,
97    0,
98    0
99  );
100
101  benchmark_timer_initialize();
102  for ( index = 1 ; index <= 10000 ; index++ )
103    (void) benchmark_timer_empty_function();
104  end_time = benchmark_timer_read();
105
106  put_time(
107    "Time Check: LOOP (10000) timer stopped at",
108    end_time,
109    1,
110    0,
111    0
112  );
113
114  benchmark_timer_initialize();
115  for ( index = 1 ; index <= 50000 ; index++ )
116    (void) benchmark_timer_empty_function();
117  end_time = benchmark_timer_read();
118
119  put_time(
120    "Time Check: LOOP (50000) timer stopped at",
121    end_time,
122    1,
123    0,
124    0
125  );
126
127  benchmark_timer_initialize();
128  for ( index = 1 ; index <= 100000 ; index++ )
129    (void) benchmark_timer_empty_function();
130  end_time = benchmark_timer_read();
131
132  put_time(
133    "Time Check: LOOP (100000) timer stopped at",
134    end_time,
135    1,
136    0,
137    0
138  );
139
140  TEST_END();
141  rtems_test_exit( 0 );
142}
143
144void check_read_timer()
145{
146  uint32_t   index;
147  uint32_t   time;
148
149  for ( index = 1 ; index <= MAXIMUM_DISTRIBUTION ; index++ )
150    Distribution[ index ] = 0;
151
152  for ( index = 1 ; index <= OPERATION_COUNT ; ) {
153    benchmark_timer_initialize();
154    end_time = benchmark_timer_read();
155    if ( end_time > MAXIMUM_DISTRIBUTION ) {
156      /*
157       *  Under UNIX a simple process swap takes longer than we
158       *  consider valid for our testing purposes.
159       */
160      printf( "TOO LONG (%" PRIu32 ") at index %" PRIu32 "!!!\n", end_time, index );
161      continue;
162    }
163    Distribution[ end_time ]++;
164    index++;
165  }
166
167  printf( "Units may not be in microseconds for this test!!!\n" );
168  time = 0;
169  for ( index = 0 ; index <= MAXIMUM_DISTRIBUTION ; index++ ) {
170    time += (Distribution[ index ] * index);
171    if ( Distribution[ index ] != 0 )
172      printf( "%" PRId32 " %" PRId32 "\n", index, Distribution[ index ] );
173  }
174  printf( "Total time = %" PRId32 "\n", time );
175  printf( "Average time = %" PRId32 "\n", time / OPERATION_COUNT );
176}
Note: See TracBrowser for help on using the repository browser.