Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/gtod.exp

raw
1 # test for checking monotonic timer (PR3916)
2 set test "gtod"
3 if {![installtest_p]} { untested $test; continue }
4
5 set wd [pwd]
6 set filename "$srcdir/$subdir/gtod.c"
7
8 target_compile $filename $wd/gtod executable ""
9
10 # Return the absolute difference between num1 and num2
11 proc abs_diff { num1 num2 } {
12 if {$num1 > $num2} {
13 return [expr $num1 - $num2]
14 }
15 return [expr $num2 - $num1]
16 }
17
18 # We're looking for lines in the following format:
19 #
20 # :00 1336494634008794 appl
21 # :00 1336494634008971 kern
22 # :00 1336494634009194 prog
23 # :01 1336494634009196 appl
24 # :01 1336494634009199 kern
25 # :01 1336494634009203 prog
26 # ...
27 #
28 # The lines should be in the order 'appl', 'kern', and 'prog', but we
29 # don't insist on it. If systemtap's time is a bit ahead of the
30 # kernel's real time, the 'kern' line can appear first. The first
31 # number, the count, must match on each of the 3 lines.
32
33 for {set i 0} { $i < 3 } {incr i } {
34 if {$i == 0} {
35 # non interval (check timer drift in short range)
36 set test "gtod (short range)"
37 spawn $srcdir/$subdir/gtod.sh $srcdir/$subdir/gtod.stp $wd/gtod
38 } elseif {$i == 1} {
39 # 10ms interval (check timer drift in middle range)
40 set test "gtod (10ms interval)"
41 spawn $srcdir/$subdir/gtod.sh $srcdir/$subdir/gtod.stp $wd/gtod 10000
42 } else {
43 # 100ms interval (calm down processors and CPU freq might be
44 # changed)
45 set test "gtod (100ms interval)"
46 spawn $srcdir/$subdir/gtod.sh $srcdir/$subdir/gtod.stp $wd/gtod 100000
47 }
48
49 # 'ok' is the number of passes
50 set ok 0
51
52 # 'iteration_num' contains the current iteration number for each
53 # of the 3 sets of lines
54 set iteration_num(appl) -1
55 set iteration_num(kern) -1
56 set iteration_num(prog) -1
57
58 # 'us_time' contains the reported time for each of the 3 sets of lines
59 set us_time(appl) 0
60 set us_time(kern) 0
61 set us_time(prog) 0
62
63 # 'max_diff' is used to remember the maximum difference between
64 # systemtap's time and the kernel's time
65 set max_diff 0
66
67 # 'variance' is the maximum number of microseconds difference
68 # between systemtap's time and the kernel's time that we'll accept
69 set variance 500
70
71 expect {
72 -timeout 120
73
74 # We found a 'appl|kern|prog' line
75 -re {^\:([0-9]+) ([0-9]+) (appl|kern|prog)\r\n} {
76 set type $expect_out(3,string)
77 set iteration_num($type) $expect_out(1,string)
78 set us_time($type) $expect_out(2,string)
79
80 # If we've seen all the lines for this iteration, check
81 # the times.
82 if {$iteration_num(appl) == $iteration_num(kern) \
83 && $iteration_num(kern) == $iteration_num(prog)} {
84 set appl_diff [abs_diff $us_time(appl) $us_time(kern)]
85 set prog_diff [abs_diff $us_time(prog) $us_time(kern)]
86 if {$appl_diff < $variance && $prog_diff < $variance} {
87 incr ok
88 } else {
89 verbose -log "difference of ($appl_diff, $prog_diff) for iteration $iteration_num(kern) is too large"
90 }
91 if {$appl_diff > $max_diff} { set max_diff $appl_diff }
92 if {$prog_diff > $max_diff} { set max_diff $prog_diff }
93 }
94 exp_continue
95 }
96
97 timeout { fail "$test (timeout)" }
98 eof { }
99 }
100 catch {close}; catch {wait}
101 if {$max_diff > 0} {
102 verbose -log "maximum time difference was $max_diff us"
103 }
104 if {$ok == 100} { pass "$test ($ok)" } { fail "$test ($ok)" }
105 }
106
107 exec rm -f $wd/gtod
108
109