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 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_atomic.h> |
19 | #include <pfs_timer.h> |
20 | #include "my_sys.h" |
21 | #include <tap.h> |
22 | |
23 | void test_timers() |
24 | { |
25 | ulonglong t1_a; |
26 | ulonglong t2_a; |
27 | ulonglong t3_a; |
28 | ulonglong t4_a; |
29 | ulonglong t5_a; |
30 | ulonglong t1_b; |
31 | ulonglong t2_b; |
32 | ulonglong t3_b; |
33 | ulonglong t4_b; |
34 | ulonglong t5_b; |
35 | |
36 | init_timers(); |
37 | |
38 | t1_a= get_timer_pico_value(TIMER_NAME_CYCLE); |
39 | /* Wait 5 seconds */ |
40 | my_sleep(5000000); |
41 | t1_b= get_timer_pico_value(TIMER_NAME_CYCLE); |
42 | |
43 | t2_a= get_timer_pico_value(TIMER_NAME_NANOSEC); |
44 | my_sleep(5000000); |
45 | t2_b= get_timer_pico_value(TIMER_NAME_NANOSEC); |
46 | |
47 | t3_a= get_timer_pico_value(TIMER_NAME_MICROSEC); |
48 | my_sleep(5000000); |
49 | t3_b= get_timer_pico_value(TIMER_NAME_MICROSEC); |
50 | |
51 | t4_a= get_timer_pico_value(TIMER_NAME_MILLISEC); |
52 | my_sleep(5000000); |
53 | t4_b= get_timer_pico_value(TIMER_NAME_MILLISEC); |
54 | |
55 | t5_a= get_timer_pico_value(TIMER_NAME_TICK); |
56 | my_sleep(5000000); |
57 | t5_b= get_timer_pico_value(TIMER_NAME_TICK); |
58 | |
59 | /* |
60 | Print the timer values, for manual inspection by a human. |
61 | Tests involving low level timers can not be automated. |
62 | */ |
63 | diag("cycle a: %13llu" , t1_a); |
64 | diag("nano a: %13llu" , t2_a); |
65 | diag("micro a: %13llu" , t3_a); |
66 | diag("milli a: %13llu" , t4_a); |
67 | diag("tick a: %13llu" , t5_a); |
68 | |
69 | diag("cycle b: %13llu" , t1_b); |
70 | diag("nano b: %13llu" , t2_b); |
71 | diag("micro b: %13llu" , t3_b); |
72 | diag("milli b: %13llu" , t4_b); |
73 | diag("tick b: %13llu" , t5_b); |
74 | |
75 | diag("cycle b-a: %13llu" , t1_b-t1_a); |
76 | diag("nano b-a: %13llu" , t2_b-t2_a); |
77 | diag("micro b-a: %13llu" , t3_b-t3_a); |
78 | diag("milli b-a: %13llu" , t4_b-t4_a); |
79 | diag("tick b-a: %13llu" , t5_b-t5_a); |
80 | |
81 | if ((t1_a == 0) && (t1_b == 0)) |
82 | skip(1, "cycle timer not implemented" ); |
83 | else |
84 | ok(t1_b > t1_a, "cycle timer ascending" ); |
85 | |
86 | if ((t2_a == 0) && (t2_b == 0)) |
87 | skip(1, "nano timer not implemented" ); |
88 | else |
89 | ok(t2_b > t2_a, "nano timer ascending" ); |
90 | |
91 | if ((t3_a == 0) && (t3_b == 0)) |
92 | skip(1, "micro timer not implemented" ); |
93 | else |
94 | ok(t3_b > t3_a, "micro timer ascending" ); |
95 | |
96 | if ((t4_a == 0) && (t4_b == 0)) |
97 | skip(1, "milli timer not implemented" ); |
98 | else |
99 | ok(t4_b > t4_a, "milli timer ascending" ); |
100 | |
101 | if ((t5_a == 0) && (t5_b == 0)) |
102 | skip(1, "tick timer not implemented" ); |
103 | else |
104 | ok(t5_b > t5_a, "tick timer ascending" ); |
105 | } |
106 | |
107 | void do_all_tests() |
108 | { |
109 | test_timers(); |
110 | } |
111 | |
112 | int main(int, char **) |
113 | { |
114 | plan(5); |
115 | MY_INIT("pfs_timer-t" ); |
116 | do_all_tests(); |
117 | my_end(0); |
118 | return (exit_status()); |
119 | } |
120 | |
121 | |