Blame view

RIOT/tests/xtimer_hang/main.c 1.98 KB
fb11e647   vrobic   reseau statique a...
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  /*
   * Copyright (C) 2015 Daniel Krebs <github@daniel-krebs.net>
   *               2015 Kaspar Schleiser <kaspar@schleiser.de>
   *
   * 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 test application
   *
   * This test used to hang many boards.
   *
   * @author      Daniel Krebs <github@daniel-krebs.net>
   * @author      Kaspar Schleiser <kaspar@schleiser.de>
   *
   * @}
   */
  #include <stdio.h>
  
  #include "xtimer.h"
  #include "thread.h"
  
  #define TEST_SECONDS        (10LU)
  #define TEST_TIME           (TEST_SECONDS * SEC_IN_USEC)
  #define STACKSIZE_TIMER     (THREAD_STACKSIZE_DEFAULT)
  
  char stack_timer1[STACKSIZE_TIMER];
  char stack_timer2[STACKSIZE_TIMER];
  
  unsigned int count = 0;
  
  void* timer_func1(void* arg)
  {
      (void)arg;
      while(1)
      {
          xtimer_usleep(1000);
      }
  }
  
  void* timer_func2(void* arg)
  {
      (void)arg;
      while(1)
      {
          xtimer_usleep(1100);
      }
  }
  
  int main(void)
  {
      puts("xTimer hang test\n");
  
      printf("This test will print \"Testing... (<percentage>)\" every 100ms for %u seconds.\n", (unsigned)TEST_SECONDS);
      printf("If it stops before, the test failed.\n\n");
  
      thread_create(stack_timer1,
                    STACKSIZE_TIMER,
                    2,
                    THREAD_CREATE_STACKTEST,
                    timer_func1,
                    NULL,
                    "timer1");
  
      thread_create(stack_timer2,
                    STACKSIZE_TIMER,
                    3,
                    THREAD_CREATE_STACKTEST,
                    timer_func2,
                    NULL,
                    "timer2");
  
      xtimer_ticks32_t end = xtimer_now();
      end.ticks32 += _xtimer_ticks_from_usec(TEST_TIME);
      while(_xtimer_now() < end.ticks32)
      {
          count++;
          xtimer_usleep(100LU * 1000);
          printf("Testing... (%u%%)\n", count);
      }
  
      printf("Test successful.\n");
  
      return 0;
  }