1 /* Copyright (c) 2008, 2017, 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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software Foundation,
21 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22
23 #include <my_global.h>
24 #include <my_pthread.h>
25 #include <pfs_timer.h>
26 #include "my_sys.h"
27 #include <tap.h>
28
test_timers()29 void test_timers()
30 {
31 ulonglong t1_a;
32 ulonglong t2_a;
33 ulonglong t3_a;
34 ulonglong t4_a;
35 ulonglong t5_a;
36 ulonglong t1_b;
37 ulonglong t2_b;
38 ulonglong t3_b;
39 ulonglong t4_b;
40 ulonglong t5_b;
41
42 init_timers();
43
44 t1_a= get_timer_pico_value(TIMER_NAME_CYCLE);
45 /* Wait 5 seconds */
46 my_sleep(5000000);
47 t1_b= get_timer_pico_value(TIMER_NAME_CYCLE);
48
49 t2_a= get_timer_pico_value(TIMER_NAME_NANOSEC);
50 my_sleep(5000000);
51 t2_b= get_timer_pico_value(TIMER_NAME_NANOSEC);
52
53 t3_a= get_timer_pico_value(TIMER_NAME_MICROSEC);
54 my_sleep(5000000);
55 t3_b= get_timer_pico_value(TIMER_NAME_MICROSEC);
56
57 t4_a= get_timer_pico_value(TIMER_NAME_MILLISEC);
58 my_sleep(5000000);
59 t4_b= get_timer_pico_value(TIMER_NAME_MILLISEC);
60
61 t5_a= get_timer_pico_value(TIMER_NAME_TICK);
62 my_sleep(5000000);
63 t5_b= get_timer_pico_value(TIMER_NAME_TICK);
64
65 /*
66 Print the timer values, for manual inspection by a human.
67 Tests involving low level timers can not be automated.
68 */
69 diag("cycle a: %13llu", t1_a);
70 diag("nano a: %13llu", t2_a);
71 diag("micro a: %13llu", t3_a);
72 diag("milli a: %13llu", t4_a);
73 diag("tick a: %13llu", t5_a);
74
75 diag("cycle b: %13llu", t1_b);
76 diag("nano b: %13llu", t2_b);
77 diag("micro b: %13llu", t3_b);
78 diag("milli b: %13llu", t4_b);
79 diag("tick b: %13llu", t5_b);
80
81 diag("cycle b-a: %13llu", t1_b-t1_a);
82 diag("nano b-a: %13llu", t2_b-t2_a);
83 diag("micro b-a: %13llu", t3_b-t3_a);
84 diag("milli b-a: %13llu", t4_b-t4_a);
85 diag("tick b-a: %13llu", t5_b-t5_a);
86
87 if ((t1_a == 0) && (t1_b == 0))
88 skip(1, "cycle timer not implemented");
89 else
90 ok(t1_b > t1_a, "cycle timer ascending");
91
92 if ((t2_a == 0) && (t2_b == 0))
93 skip(1, "nano timer not implemented");
94 else
95 ok(t2_b > t2_a, "nano timer ascending");
96
97 if ((t3_a == 0) && (t3_b == 0))
98 skip(1, "micro timer not implemented");
99 else
100 ok(t3_b > t3_a, "micro timer ascending");
101
102 if ((t4_a == 0) && (t4_b == 0))
103 skip(1, "milli timer not implemented");
104 else
105 ok(t4_b > t4_a, "milli timer ascending");
106
107 if ((t5_a == 0) && (t5_b == 0))
108 skip(1, "tick timer not implemented");
109 else
110 ok(t5_b > t5_a, "tick timer ascending");
111 }
112
do_all_tests()113 void do_all_tests()
114 {
115 PFS_atomic::init();
116
117 test_timers();
118
119 PFS_atomic::cleanup();
120 }
121
main(int,char **)122 int main(int, char **)
123 {
124 plan(5);
125 MY_INIT("pfs_timer-t");
126 do_all_tests();
127 return (exit_status());
128 }
129
130