source: rtems/testsuites/tmtests/tmck/task1.c @ d23649d2

4.104.115
Last change on this file since d23649d2 was d23649d2, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/27/09 at 04:03:41

Use PRIu32 to print uint32_t's.

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