Blame view

RIOT/tests/xtimer_now64_continuity/main.c 1.52 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  /*
   * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
   *               2017 HAW Hamburg
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup     tests
   * @{
   *
   * @file
   * @brief       xtimer_now64 continuity test application
   *
   * @author      Kaspar Schleiser <kaspar@schleiser.de>
   * @author      Sebastian Meiling <s@mlng.net>
   *
   * @}
   */
  
  #include <stdint.h>
  
  #include "xtimer.h"
  #include "fmt.h"
  
  #define ITERATIONS  (100000LU)
  #define MAXDIFF     (1000U)
  
  int main(void)
  {
      uint32_t n = ITERATIONS;
      uint64_t diff_min = UINT64_MAX;
      uint64_t diff_max = 0;
      uint64_t diff_sum = 0;
      xtimer_ticks64_t before = xtimer_now64();
      print_str("[START]\n");
      while(--n) {
          xtimer_ticks64_t now = xtimer_now64();
          xtimer_ticks64_t diff = xtimer_diff64(now, before);
          if (diff.ticks64 > diff_max) {
              diff_max = diff.ticks64;
          }
          if (diff.ticks64 < diff_min) {
              diff_min = diff.ticks64;
          }
          diff_sum += diff.ticks64;
          before = now;
      }
      print_str("[RESULTS] min=");
      print_u64_dec(diff_min);
      print_str(", avg=");
      print_u64_dec(diff_sum/ITERATIONS);
      print_str(", max=");
      print_u64_dec(diff_max);
      print_str("\n");
      if ((diff_max > MAXDIFF) || (diff_sum/ITERATIONS > MAXDIFF)) {
          print_str("[FAILURE]\n");
          return 1;
      }
      print_str("[SUCCESS]\n");
      return 0;
  }