source: rtems/testsuites/samples/nsecs/init.c

Last change on this file was af43554, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 26, 2017 at 11:59:11 AM

tests: Remove TEST_INIT

The TEST_EXTERN is a used only by the system.h style tests and they use
CONFIGURE_INIT appropriately.

Update #3170.
Update #3199.

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