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

5
Last change on this file since acc9d064 was 98c6d50, checked in by Chris Johns <chrisj@…>, on 10/19/17 at 05:39:16

testsuite: Use printk for all test output where possible.

  • Remove the printf support leaving the direct printk support configured with TESTS_USE_PRINTK and all other output goes via a buffered vsniprintf call to printk.
  • Control the test's single init for functions and global data with TEST_INIT and not CONFIGURE_INIT. They are now separate.

Updates #3170.

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