Debian Codegraph @

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

raw
1 set test "stmt_rel"
2
3 # Tests that relative linenos are consistent with wildcard linenos.
4
5 proc get_listings { probe_point } {
6 global test
7
8 # Get listing from stap -l
9 if {![catch {exec stap -l ${probe_point} 2>@1} output]} {
10 return [split $output "\n"]
11 }
12 }
13
14 proc parse_lineno { function line } {
15 global test
16
17 # Look for digits between : and "
18 if {[regexp "\[^:\]+:(\[0-9\]+)\"" $line match submatch]} {
19 verbose -log "parsed lineno $submatch in line $line"
20 return $submatch
21 } else {
22 verbose -log "can't parse lineno in '$line'"
23 return 0
24 }
25 }
26
27 proc get_function_decl_line { function } {
28 set probe_point "kernel.function\(\"$function\"\)"
29 set line [lindex [get_listings $probe_point] 0]
30 return [parse_lineno $function $line]
31 }
32
33 proc collect_valid_linenos { function } {
34 set linenos ""
35 set probe_point "kernel.statement\(\"$function:*\"\)"
36 foreach line [get_listings $probe_point] {
37 lappend linenos [parse_lineno $function $line]
38 }
39 return $linenos
40 }
41
42 proc is_valid_rel_lineno { function decl_line rel } {
43 set probe_point "kernel.statement\(\"$function+$rel\"\)"
44 set lines [get_listings $probe_point]
45 if {$lines == ""} {
46 return 0
47 } else {
48 set line [lindex $lines 0]
49 set lineno [parse_lineno $function $line]
50 return [expr $lineno == [expr $decl_line + $rel]]
51 }
52 }
53
54 proc test_stmt_rel { function } {
55 global test
56
57 set valid_linenos [collect_valid_linenos $function]
58 set last_valid_lineno [lindex $valid_linenos end]
59 if {[llength $valid_linenos] == 0} {
60 fail "$test ($function - no valid linenos in $function)"
61 return
62 }
63
64 set decl_line [get_function_decl_line $function]
65 set max_valid_rel [expr $last_valid_lineno - $decl_line]
66
67 set valid_rel_linenos ""
68 foreach rel [exec seq 0 $max_valid_rel] {
69 if {[is_valid_rel_lineno $function $decl_line $rel]} {
70 lappend valid_rel_linenos [expr $decl_line + $rel]
71 }
72 }
73
74 foreach lineno $valid_linenos {
75 if {[lsearch -integer -exact $valid_rel_linenos $lineno] < 0} {
76 fail "$test ($function - lineno not in rel)"
77 verbose -log "wildcard lineno $lineno not in rel linenos: $valid_rel_linenos"
78 return
79 }
80 }
81
82 pass "$test ($function - linenos in wildcard also in rel)"
83 }
84
85 # Sanity check that bio_init has at least 3 linenos
86 if {[expr [llength [collect_valid_linenos {bio_init@*/bio.c}]] >= 3]} {
87 pass "$test (bio_init sanity check)"
88 } else {
89 fail "$test (bio_init sanity check)"
90 }
91
92 test_stmt_rel {bio_init@*/bio.c}
93 test_stmt_rel {bio_reset@*/bio.c}
94 test_stmt_rel {vfs_read@fs/read_write.c}
95 test_stmt_rel {vfs_write@fs/read_write.c}
96