File: hw_breakpoint.exp

package info (click to toggle)
systemtap 5.1-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 47,964 kB
  • sloc: cpp: 80,838; ansic: 54,757; xml: 49,725; exp: 43,665; sh: 11,527; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (149 lines) | stat: -rw-r--r-- 4,100 bytes parent folder | download | duplicates (3)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
set test "hw_breakpoint"
if {![installtest_p]} { untested $test; return }
# Note that 'hwbkpt_probes_p' really tests for kernel support. We
# won't know if this hardware actually supports these probes until we
# try them below.
if {![hwbkpt_probes_p]} { untested $test; return }

set build_dir ""
set uname [exec /bin/uname -r]
set mod_base stap_hwbkpt_kmod
set mod_name ${mod_base}.ko
set mod_cmd /proc/stap_hwbkpt_cmd

proc build_and_install_module {} {
    global build_dir
    global srcdir subdir
    global mod_name mod_base

    # Create the build directory and populate it
    if {[catch {exec mktemp -d -t staptestXXXXXX} build_dir]} {
	verbose -log "Failed to create temporary directory: $build_dir"
	return 0
    }
    if {[catch {exec cp $srcdir/$subdir/${mod_base}.c $build_dir/} res]} {
	verbose -log "$res"
	return 0
    }
    if {[catch {exec cp -p $srcdir/$subdir/${mod_base}.Makefile $build_dir/Makefile } res]} {
	verbose -log "$res"
	return 0
    }

    # Build the module
    if {[catch {exec make -C $build_dir clean} res]} {
	verbose -log "$res"
	return 0
    }
    catch {exec make -C $build_dir} res
    if {![file exists $build_dir/${mod_name}]} {
	verbose -log "$res"
	return 0
    }
    set res [as_root [list cp $build_dir/${mod_name} /lib/modules/$::uname/kernel/]]
    if { $res != 0 } {
	verbose -log "$res"
	return 0
    }

    # Install the module
    set res [as_root [list /sbin/insmod /lib/modules/$::uname/kernel/${mod_name}]]
    if {$res != 0} {
	verbose -log "$res"
	return 0
    }
    return 1
}

proc cleanup_module {} {
    global build_dir mod_name mod_base
    as_root [list /bin/rm -f /lib/modules/$::uname/kernel/${mod_name}]
    as_root [list /sbin/rmmod ${mod_base}]
    if {$build_dir != ""} {
	catch { exec rm -rf $build_dir }
    }
}

if {[build_and_install_module] == 0} {
    verbose -log "BUILD FAILED"
    fail "$test (could not build/install module)"
    return
} else {
    pass "$test (built and installed module)"
}

set sym_name "stap_hwbkpt_data"
if {[catch {exec grep ${sym_name} /proc/kallsyms | awk "{print \$1}" } \
     res]} {
    fail "$test (couldn't find module data)"
    cleanup_module
    return 0
}
    
set sym_addr "0x${res}"
pass "$test (found symbol address)"
verbose -log "probing ${sym_addr}..."

# Make sure cmd file exists
if {! [file exists ${mod_cmd}]} {
    fail "$test (couldn't find cmd file - $mod_cmd)"
    cleanup_module
    return 0
}
pass "$test (found cmd file - $mod_cmd)"

set found 0
set no_hardware_support 0

# Test address support
spawn stap -e {probe kernel.data($1).rw { printf("value accessed\n"); exit() }} -c "echo 0 > ${mod_cmd}" ${sym_addr}
expect {
    -timeout 240
    -re {ERROR: probe kernel.data.+ registration error} {
	incr no_hardware_support; exp_continue } 
    -re {value accessed\r\n} { incr found; exp_continue }
    eof { }
    timeout { fail "$test - addr (${script_name} (timeout))" }
}
catch {close}

# get the return code of the process
set rc [lindex [wait -i $spawn_id] 3]

if { $no_hardware_support == 1 } {
    xfail "$test - addr (kernel support, but no hardware support)"
} elseif { $rc == 0 && $found == 1 } {
    pass "$test - addr (hw breakpoint support)"
} elseif { $res == 0 } {
    xfail "$test - addr {no module data address}"
} else {
    fail "$test - addr ($rc, $found)"
}

set found 0
set no_hardware_support 0

# Test symbol support
spawn stap -e {probe kernel.data(@1).rw { printf("value accessed\n"); exit() }} -c "echo 0 > ${mod_cmd}" ${sym_name}
expect {
    -timeout 240
    -re {ERROR: probe kernel.data.+ registration error} {
	incr no_hardware_support; exp_continue } 
    -re {value accessed\r\n} { incr found; exp_continue }
    eof { }
    timeout { fail "$test - ${script_name} (timeout)" }
}
catch {close}

# get the return code of the process
set rc [lindex [wait -i $spawn_id] 3]

if { $no_hardware_support == 1 } {
    xfail "$test - symbol (kernel support, but no hardware support)"
} elseif { $rc == 0 && $found == 1 } {
    pass "$test - symbol (hw breakpoint support)"
} else {
    fail "$test - symbol ($rc, $found)"
}

cleanup_module