MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pfs_timer-t.cc
1 /* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 #include <my_global.h>
17 #include <my_pthread.h>
18 #include <pfs_timer.h>
19 #include "my_sys.h"
20 #include <tap.h>
21 
22 void test_timers()
23 {
24  ulonglong t1_a;
25  ulonglong t2_a;
26  ulonglong t3_a;
27  ulonglong t4_a;
28  ulonglong t5_a;
29  ulonglong t1_b;
30  ulonglong t2_b;
31  ulonglong t3_b;
32  ulonglong t4_b;
33  ulonglong t5_b;
34 
35  init_timers();
36 
37  t1_a= get_timer_pico_value(TIMER_NAME_CYCLE);
38  /* Wait 5 seconds */
39  my_sleep(5000000);
40  t1_b= get_timer_pico_value(TIMER_NAME_CYCLE);
41 
42  t2_a= get_timer_pico_value(TIMER_NAME_NANOSEC);
43  my_sleep(5000000);
44  t2_b= get_timer_pico_value(TIMER_NAME_NANOSEC);
45 
46  t3_a= get_timer_pico_value(TIMER_NAME_MICROSEC);
47  my_sleep(5000000);
48  t3_b= get_timer_pico_value(TIMER_NAME_MICROSEC);
49 
50  t4_a= get_timer_pico_value(TIMER_NAME_MILLISEC);
51  my_sleep(5000000);
52  t4_b= get_timer_pico_value(TIMER_NAME_MILLISEC);
53 
54  t5_a= get_timer_pico_value(TIMER_NAME_TICK);
55  my_sleep(5000000);
56  t5_b= get_timer_pico_value(TIMER_NAME_TICK);
57 
58  /*
59  Print the timer values, for manual inspection by a human.
60  Tests involving low level timers can not be automated.
61  */
62  diag("cycle a: %13llu", t1_a);
63  diag("nano a: %13llu", t2_a);
64  diag("micro a: %13llu", t3_a);
65  diag("milli a: %13llu", t4_a);
66  diag("tick a: %13llu", t5_a);
67 
68  diag("cycle b: %13llu", t1_b);
69  diag("nano b: %13llu", t2_b);
70  diag("micro b: %13llu", t3_b);
71  diag("milli b: %13llu", t4_b);
72  diag("tick b: %13llu", t5_b);
73 
74  diag("cycle b-a: %13llu", t1_b-t1_a);
75  diag("nano b-a: %13llu", t2_b-t2_a);
76  diag("micro b-a: %13llu", t3_b-t3_a);
77  diag("milli b-a: %13llu", t4_b-t4_a);
78  diag("tick b-a: %13llu", t5_b-t5_a);
79 
80  if ((t1_a == 0) && (t1_b == 0))
81  skip(1, "cycle timer not implemented");
82  else
83  ok(t1_b > t1_a, "cycle timer ascending");
84 
85  if ((t2_a == 0) && (t2_b == 0))
86  skip(1, "nano timer not implemented");
87  else
88  ok(t2_b > t2_a, "nano timer ascending");
89 
90  if ((t3_a == 0) && (t3_b == 0))
91  skip(1, "micro timer not implemented");
92  else
93  ok(t3_b > t3_a, "micro timer ascending");
94 
95  if ((t4_a == 0) && (t4_b == 0))
96  skip(1, "milli timer not implemented");
97  else
98  ok(t4_b > t4_a, "milli timer ascending");
99 
100  if ((t5_a == 0) && (t5_b == 0))
101  skip(1, "tick timer not implemented");
102  else
103  ok(t5_b > t5_a, "tick timer ascending");
104 }
105 
106 void do_all_tests()
107 {
109 
110  test_timers();
111 
113 }
114 
115 int main(int, char **)
116 {
117  plan(5);
118  MY_INIT("pfs_timer-t");
119  do_all_tests();
120  return 0;
121 }
122