source: rtems/testsuites/sptests/spcpucounter01/init.c @ 6c0301d

4.115
Last change on this file since 6c0301d was 6c0301d, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:21

tests/sptests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <stdio.h>
20#include <inttypes.h>
21
22#include <rtems.h>
23#include <rtems/counter.h>
24
25#define TESTS_USE_PRINTF
26#include "tmacros.h"
27
28const char rtems_test_name[] = "SPCPUCOUNTER 1";
29
30#define NS_PER_TICK 1000000
31
32static rtems_interval sync_with_clock_tick(void)
33{
34  rtems_interval start = rtems_clock_get_ticks_since_boot();
35  rtems_interval current;
36
37  do {
38    current = rtems_clock_get_ticks_since_boot();
39  } while (current == start);
40
41  return current;
42}
43
44static void test_converter(void)
45{
46  CPU_Counter_ticks frequency = rtems_counter_nanoseconds_to_ticks(1000000000);
47  uint64_t ns = rtems_counter_ticks_to_nanoseconds(frequency);
48
49  printf("CPU counter frequency: %" PRIu32 "Hz\n", frequency);
50  printf("nanoseconds for frequency count ticks: %" PRIu64 "\n", ns);
51
52  rtems_test_assert(ns == 1000000000);
53}
54
55static void test_delay_nanoseconds(void)
56{
57  rtems_counter_ticks start;
58  rtems_counter_ticks end;
59  rtems_counter_ticks delta;
60  double ns_per_tick = NS_PER_TICK;
61  uint64_t ns_delta;
62  rtems_interval tick;
63  int n = 10;
64  int i;
65
66  printf("test delay nanoseconds (%i times)\n", n);
67
68  for (i = 0; i < n; ++i) {
69    tick = sync_with_clock_tick();
70
71    start = rtems_counter_read();
72    rtems_counter_delay_nanoseconds(NS_PER_TICK);
73    end = rtems_counter_read();
74
75    rtems_test_assert(tick < rtems_clock_get_ticks_since_boot());
76
77    delta = rtems_counter_difference(end, start);
78    ns_delta = rtems_counter_ticks_to_nanoseconds(delta);
79
80    /* Special case for CPU counters using the clock driver counter */
81    if (ns_delta < rtems_configuration_get_nanoseconds_per_tick()) {
82      printf(
83        "warning: the RTEMS counter seems to be unable to\n"
84        "  measure intervals greater than the clock tick interval\n"
85      );
86
87      ns_delta += rtems_configuration_get_nanoseconds_per_tick();
88    }
89
90    printf(
91      "busy wait duration: %" PRIu64 "ns\n"
92      "busy wait relative to clock tick: %f\n",
93      ns_delta,
94      (ns_delta - ns_per_tick) / ns_per_tick
95    );
96  }
97}
98
99static void Init(rtems_task_argument arg)
100{
101  TEST_BEGIN();
102
103  test_converter();
104  test_delay_nanoseconds();
105
106  TEST_END();
107
108  rtems_test_exit(0);
109}
110
111#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
112#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
113
114#define CONFIGURE_MICROSECONDS_PER_TICK (NS_PER_TICK / 1000)
115
116#define CONFIGURE_MAXIMUM_TASKS 1
117
118#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
119
120#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
121
122#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
123
124#define CONFIGURE_INIT
125
126#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.