Debian Codegraph @

testsuite/systemtap.syscall/coverage.tcl

raw
1 #!/usr/bin/env tclsh
2
3 # List of systemcalls that the systemtap.syscall tests will not cover.
4 #
5 # - bdflush: obsolete since 2.6
6 # - dmi_field_show: Non-syscall picked up by the "sys_*" wildcard below.
7 # - dmi_modalias_show: Ditto.
8 # - copyarea: Ditto.
9 # - fillrect: Ditto.
10 # - imageblit: Ditto.
11 # - ni_syscall: non-implemented syscall
12 # - rt_sigreturn: rt_sigreturn is a syscall that you don't call
13 # directly, so we can't really test it. glibc calls it
14 # in signal handlers.
15 # - sigreturn: Ditto.
16 # - socketcall: common entry point for other socket syscalls
17 # - tux: obsolete
18 set badlist {
19 bdflush dmi_field_show dmi_modalias_show copyarea fillrect
20 imageblit ni_syscall rt_sigreturn sigreturn socketcall tux
21 }
22
23 foreach f $badlist {
24 set funcname($f) -1
25 }
26
27 # Get list of syscalls.
28 set cmd {stap -l "kernel.function(\"sys_*\").call"}
29 if {[catch {eval exec $cmd} output]} {
30 puts "ERROR running stap: $output"
31 exit
32 }
33 foreach line [split $output "\n"] {
34 if {[regexp {^kernel.function\(\"[Ss]y[Ss]_([^@\"]+)} $line match fn]} {
35 # arm (and perhaps other platforms) has assembly language
36 # syscall wrappers like "sigreturn_wrapper". Notice we're
37 # ignoring these.
38 if {![info exists funcname($fn)] && ![regexp {_wrapper$} $fn]} {
39 set funcname($fn) 0
40 }
41 }
42 }
43
44 # Get list of syscall probes.
45 set cmd {stap -l "syscall.*"}
46 if {[catch {eval exec $cmd} output]} {
47 puts "ERROR running '${cmd}': $output"
48 exit
49 }
50 foreach line [split $output "\n"] {
51 if {[regexp {^syscall\.(.+)$} $line match pn]} {
52 set probename($pn) 1
53 }
54 }
55
56 # Get list of covered functions.
57 foreach filename [glob *.c] {
58 if {[catch {open $filename r} fd]} {
59 puts "ERROR opening $filename: $fd"
60 exit
61 }
62 while {[gets $fd line] >= 0} {
63 if {[regexp {/* COVERAGE: ([^\*]*)\*/} $line match res]} {
64 foreach f [split $res] {
65 if {[info exists funcname($f)]} {
66 incr funcname($f)
67 }
68 }
69 }
70 }
71 close $fd
72 }
73
74 set uncovlist {}
75 set covered 0
76 set uncovered 0
77 set handled 0
78 set unhandled 0
79 set unhandled_list {}
80 foreach {func val} [array get funcname] {
81 if {$val < 0} {
82 continue
83 }
84
85 if {$val > 0} {
86 incr covered
87 } elseif {$val == 0} {
88 incr uncovered
89 lappend uncovlist $func
90 }
91
92 # If we've got a test program for it, by definition it is
93 # handled. It is also handled if we've got a probe for it.
94 if {$val > 0 || [info exists probename($func)]} {
95 incr handled
96 } elseif {$val == 0} {
97 incr unhandled
98 lappend unhandled_list $func
99 }
100 }
101
102 # Display list of covered/uncovered syscalls. A covered syscall has a
103 # syscall test for it.
104 set total [expr $covered + $uncovered]
105 puts "Covered $covered out of $total. [format "%2.1f" [expr ($covered * 100.0)/$total]]%"
106
107 puts "\nUNCOVERED FUNCTIONS"
108 set i 0
109 foreach f [lsort $uncovlist] {
110 puts -nonewline [format "%-24s" $f]
111 incr i
112 if {$i >= 3} {
113 puts ""
114 set i 0
115 }
116 }
117 if {$i != 0} { puts "\n" }
118
119 # Display list of handled/unhandled syscalls. A syscall is "handled"
120 # if syscall/nd_syscall probes exists for the syscall.
121 set total [expr $handled + $unhandled]
122 puts "Handled $handled out of $total. [format "%2.1f" [expr ($handled * 100.0)/$total]]%"
123 if {$unhandled > 0} {
124 puts "\nUNHANDLED FUNCTIONS"
125
126 set i 0
127 foreach f [lsort $unhandled_list] {
128 puts -nonewline [format "%-24s" $f]
129 incr i
130 if {$i >= 3} {
131 puts ""
132 set i 0
133 }
134 }
135 if {$i != 0} { puts "\n" }
136 }
137