summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.syscall/coverage.tcl
blob: 559039c1dbf6b94720c5d0efa0bfbed04d987333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env tclsh

# List of systemcalls that may or may not be in kernels. Until we
# fix PR2645, we cannot implement syscall probes for these.

set badlist { add_key tux }

foreach f $badlist {
    set funcname($f) -1
}

set cmd {stap -p2 -e "probe kernel.function(\"sys_*\"), kernel.function(\"sys32_*\") ? \{\}"}
if {[catch {eval exec $cmd} output]} {
    puts "ERROR running stap: $output"
    exit
}


foreach line [split $output "\n"] {
    if {[regexp {kernel.function\(\"sys_([^@]+)} $line match fn]} {
	if {![info exists funcname($fn)]} {
	    set funcname($fn) 0
	}
    }
    if {[regexp {kernel.function\(\"sys32_([^@]+)} $line match fn]} {
	set fn "32_$fn"
	if {![info exists funcname($fn)]} {
	    set funcname($fn) 0
	}
    }
}

foreach filename [glob *.c] {
    if {[catch {open $filename r} fd]} {
	puts "ERROR opening $filename: $fd"
	exit
    }
    while {[gets $fd line] >= 0} {
	if {[regexp {/* COVERAGE: ([^\*]*)\*/} $line match res]} {
	    foreach f [split $res] {
		if {[info exists funcname($f)]} {
		    incr funcname($f)
		}
	    }
	}
    }
    close $fd
}

set covlist {}
set uncovlist {}
set covered 0
set uncovered 0
foreach {func val} [array get funcname] {
    if {$val > 0} {
	incr covered
	lappend covlist $func
    } elseif {$val == 0} {
	incr uncovered
	lappend uncovlist $func
    }
}

set total [expr $covered + $uncovered]
puts "Covered $covered out of $total. [format "%2.1f" [expr ($covered * 100.0)/$total]]%"

puts "\nUNCOVERED FUNCTIONS"
set i 0
foreach f [lsort $uncovlist] {
    puts -nonewline [format "%-24s" $f]
    incr i
    if {$i >= 3} {
	puts ""
	set i 0
    }
}
puts "\n"