source: rtems/testsuites/samples/nsecs/init.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 *  Nanoseconds accuracy timestamp test
3 */
4
5/*  COPYRIGHT (c) 1989-2011.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <rtems.h>
18#include <inttypes.h>
19#include <stdio.h>
20#include <string.h>
21#include <stdlib.h>
22#include <unistd.h>
23#include <sys/time.h>
24
25#define CONFIGURE_INIT
26#include "system.h"
27
28#include <rtems/score/timespec.h> /* _Timespec_Substract */
29
30#include "tmacros.h"
31#include "pritime.h"
32
33static char *my_ctime( time_t t )
34{
35  static char b[32];
36  ctime_r(&t, b);
37  b[ strlen(b) - 1] = '\0';
38  return b;
39}
40
41static void subtract_em(
42  struct timespec *start,
43  struct timespec *stop,
44  struct timespec *t
45)
46{
47  t->tv_sec = 0;
48  t->tv_nsec = 0;
49  _Timespec_Subtract( start, stop, t );
50}
51
52
53rtems_task Init(
54  rtems_task_argument argument
55)
56{
57  rtems_status_code status;
58  rtems_time_of_day time;
59  int index;
60
61  puts( "\n\n*** NANOSECOND CLOCK TEST ***" );
62
63  time.year   = 2007;
64  time.month  = 03;
65  time.day    = 24;
66  time.hour   = 11;
67  time.minute = 15;
68  time.second = 0;
69  time.ticks  = 0;
70
71  status = rtems_clock_set( &time );
72  directive_failed( status, "clock set" );
73
74  /*
75   *  Iterate 10 times showing difference in TOD
76   */
77  printf( "10 iterations of getting TOD\n" );
78  for (index=0 ; index <10 ; index++ ) {
79    struct timespec start, stop;
80    struct timespec diff;
81#if 0
82    clock_gettime( CLOCK_REALTIME, &start );
83    clock_gettime( CLOCK_REALTIME, &stop );
84#else
85    _TOD_Get( &start );
86    _TOD_Get( &stop );
87#endif
88
89    subtract_em( &start, &stop, &diff );
90    printf( "Start: %s:%ld\nStop : %s:%ld",
91      my_ctime(start.tv_sec), start.tv_nsec,
92      my_ctime(stop.tv_sec), stop.tv_nsec
93    );
94
95    printf( " --> %" PRIdtime_t ":%ld\n", diff.tv_sec, diff.tv_nsec );
96  }
97
98  /*
99   *  Iterate 10 times showing difference in Uptime
100   */
101  printf( "\n10 iterations of getting Uptime\n" );
102  for (index=0 ; index <10 ; index++ ) {
103    struct timespec start, stop;
104    struct timespec diff;
105    rtems_clock_get_uptime( &start );
106    rtems_clock_get_uptime( &stop );
107
108    subtract_em( &start, &stop, &diff );
109    printf( "%" PRIdtime_t ":%ld %" PRIdtime_t ":%ld --> %" PRIdtime_t ":%ld\n",
110      start.tv_sec, start.tv_nsec,
111      stop.tv_sec, stop.tv_nsec,
112      diff.tv_sec, diff.tv_nsec
113   );
114  }
115
116  /*
117   *  Iterate 10 times showing difference in Uptime with different counts
118   */
119  printf( "\n10 iterations of getting Uptime with different loop values\n" );
120  for (index=1 ; index <=10 ; index++ ) {
121    struct timespec start, stop;
122    struct timespec diff;
123    int j, max = (index * 10000);
124    rtems_clock_get_uptime( &start );
125      for (j=0 ; j<max ; j++ )
126        dummy_function_empty_body_to_force_call();
127    rtems_clock_get_uptime( &stop );
128
129    subtract_em( &start, &stop, &diff );
130    printf( "loop of %d %" PRIdtime_t ":%ld %" PRIdtime_t ":%ld --> %" PRIdtime_t ":%ld\n",
131      max,
132      start.tv_sec, start.tv_nsec,
133      stop.tv_sec, stop.tv_nsec,
134      diff.tv_sec, diff.tv_nsec
135   );
136  }
137
138  sleep(1);
139
140  puts( "*** END OF NANOSECOND CLOCK TEST ***" );
141  exit(0);
142}
143
Note: See TracBrowser for help on using the repository browser.