| 1 |
set test "hw_breakpoint" |
| 2 |
if {![installtest_p]} { untested $test; return } |
| 3 |
# Note that 'hwbkpt_probes_p' really tests for kernel support. We |
| 4 |
# won't know if this hardware actually supports these probes until we |
| 5 |
# try them below. |
| 6 |
if {![hwbkpt_probes_p]} { untested $test; return } |
| 7 |
|
| 8 |
set build_dir "" |
| 9 |
set uname [exec /bin/uname -r] |
| 10 |
set mod_base stap_hwbkpt_kmod |
| 11 |
set mod_name ${mod_base}.ko |
| 12 |
set mod_cmd /proc/stap_hwbkpt_cmd |
| 13 |
|
| 14 |
proc build_and_install_module {} { |
| 15 |
global build_dir |
| 16 |
global srcdir subdir |
| 17 |
global mod_name mod_base |
| 18 |
|
| 19 |
# Create the build directory and populate it |
| 20 |
if {[catch {exec mktemp -d -t staptestXXXXXX} build_dir]} { |
| 21 |
verbose -log "Failed to create temporary directory: $build_dir" |
| 22 |
return 0 |
| 23 |
} |
| 24 |
if {[catch {exec cp $srcdir/$subdir/${mod_base}.c $build_dir/} res]} { |
| 25 |
verbose -log "$res" |
| 26 |
return 0 |
| 27 |
} |
| 28 |
if {[catch {exec cp -p $srcdir/$subdir/${mod_base}.Makefile $build_dir/Makefile } res]} { |
| 29 |
verbose -log "$res" |
| 30 |
return 0 |
| 31 |
} |
| 32 |
|
| 33 |
# Build the module |
| 34 |
if {[catch {exec make -C $build_dir clean} res]} { |
| 35 |
verbose -log "$res" |
| 36 |
return 0 |
| 37 |
} |
| 38 |
catch {exec make -C $build_dir} res |
| 39 |
if {![file exists $build_dir/${mod_name}]} { |
| 40 |
verbose -log "$res" |
| 41 |
return 0 |
| 42 |
} |
| 43 |
set res [as_root [list cp $build_dir/${mod_name} /lib/modules/$::uname/kernel/]] |
| 44 |
if { $res != 0 } { |
| 45 |
verbose -log "$res" |
| 46 |
return 0 |
| 47 |
} |
| 48 |
|
| 49 |
# Install the module |
| 50 |
set res [as_root [list /sbin/insmod /lib/modules/$::uname/kernel/${mod_name}]] |
| 51 |
if {$res != 0} { |
| 52 |
verbose -log "$res" |
| 53 |
return 0 |
| 54 |
} |
| 55 |
return 1 |
| 56 |
} |
| 57 |
|
| 58 |
proc cleanup_module {} { |
| 59 |
global build_dir mod_name mod_base |
| 60 |
as_root [list /bin/rm -f /lib/modules/$::uname/kernel/${mod_name}] |
| 61 |
as_root [list /sbin/rmmod ${mod_base}] |
| 62 |
if {$build_dir != ""} { |
| 63 |
catch { exec rm -rf $build_dir } |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
if {[build_and_install_module] == 0} { |
| 68 |
verbose -log "BUILD FAILED" |
| 69 |
fail "$test (could not build/install module)" |
| 70 |
return |
| 71 |
} else { |
| 72 |
pass "$test (built and installed module)" |
| 73 |
} |
| 74 |
|
| 75 |
set sym_name "stap_hwbkpt_data" |
| 76 |
if {[catch {exec grep ${sym_name} /proc/kallsyms | awk "{print \$1}" } \ |
| 77 |
res]} { |
| 78 |
fail "$test (couldn't find module data)" |
| 79 |
cleanup_module |
| 80 |
return 0 |
| 81 |
} |
| 82 |
|
| 83 |
set sym_addr "0x${res}" |
| 84 |
pass "$test (found symbol address)" |
| 85 |
verbose -log "probing ${sym_addr}..." |
| 86 |
|
| 87 |
# Make sure cmd file exists |
| 88 |
if {! [file exists ${mod_cmd}]} { |
| 89 |
fail "$test (couldn't find cmd file - $mod_cmd)" |
| 90 |
cleanup_module |
| 91 |
return 0 |
| 92 |
} |
| 93 |
pass "$test (found cmd file - $mod_cmd)" |
| 94 |
|
| 95 |
set found 0 |
| 96 |
set no_hardware_support 0 |
| 97 |
|
| 98 |
# Test address support |
| 99 |
spawn stap -e {probe kernel.data($1).rw { printf("value accessed\n"); exit() }} -c "echo 0 > ${mod_cmd}" ${sym_addr} |
| 100 |
expect { |
| 101 |
-timeout 240 |
| 102 |
-re {ERROR: probe kernel.data.+ registration error} { |
| 103 |
incr no_hardware_support; exp_continue } |
| 104 |
-re {value accessed\r\n} { incr found; exp_continue } |
| 105 |
eof { } |
| 106 |
timeout { fail "$test - addr (${script_name} (timeout))" } |
| 107 |
} |
| 108 |
catch {close} |
| 109 |
|
| 110 |
# get the return code of the process |
| 111 |
set rc [lindex [wait -i $spawn_id] 3] |
| 112 |
|
| 113 |
if { $no_hardware_support == 1 } { |
| 114 |
xfail "$test - addr (kernel support, but no hardware support)" |
| 115 |
} elseif { $rc == 0 && $found == 1 } { |
| 116 |
pass "$test - addr (hw breakpoint support)" |
| 117 |
} elseif { $res == 0 } { |
| 118 |
xfail "$test - addr {no module data address}" |
| 119 |
} else { |
| 120 |
fail "$test - addr ($rc, $found)" |
| 121 |
} |
| 122 |
|
| 123 |
set found 0 |
| 124 |
set no_hardware_support 0 |
| 125 |
|
| 126 |
# Test symbol support |
| 127 |
spawn stap -e {probe kernel.data(@1).rw { printf("value accessed\n"); exit() }} -c "echo 0 > ${mod_cmd}" ${sym_name} |
| 128 |
expect { |
| 129 |
-timeout 240 |
| 130 |
-re {ERROR: probe kernel.data.+ registration error} { |
| 131 |
incr no_hardware_support; exp_continue } |
| 132 |
-re {value accessed\r\n} { incr found; exp_continue } |
| 133 |
eof { } |
| 134 |
timeout { fail "$test - ${script_name} (timeout)" } |
| 135 |
} |
| 136 |
catch {close} |
| 137 |
|
| 138 |
# get the return code of the process |
| 139 |
set rc [lindex [wait -i $spawn_id] 3] |
| 140 |
|
| 141 |
if { $no_hardware_support == 1 } { |
| 142 |
xfail "$test - symbol (kernel support, but no hardware support)" |
| 143 |
} elseif { $rc == 0 && $found == 1 } { |
| 144 |
pass "$test - symbol (hw breakpoint support)" |
| 145 |
} else { |
| 146 |
fail "$test - symbol ($rc, $found)" |
| 147 |
} |
| 148 |
|
| 149 |
cleanup_module |