From c3e70cc8b57ebe3fb7d2f9162d1737a7af22252f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 22 Aug 2013 15:39:26 -0700 Subject: [PATCH] Simplify the testsuite tests for uprobes and utrace - Searching /proc/kallsyms is now standardized to grep_kallsyms. - utrace and uprobes tests are broken into separate procs for the different variants, then a unified proc combines variants. --- testsuite/lib/systemtap.exp | 105 ++++++++++----------- testsuite/systemtap.printf/ring_buffer.exp | 7 +- testsuite/systemtap.stress/conversions.exp | 3 +- 3 files changed, 52 insertions(+), 63 deletions(-) diff --git a/testsuite/lib/systemtap.exp b/testsuite/lib/systemtap.exp index 5229e6838..355d1ebf7 100644 --- a/testsuite/lib/systemtap.exp +++ b/testsuite/lib/systemtap.exp @@ -9,90 +9,85 @@ proc installtest_p {} { } -# only original rhel5/6-era utrace need apply -proc utrace_orig_p {} { - set path "/proc/kallsyms" - if {! [catch {exec grep -q utrace_attach $path} dummy]} { +proc grep_kallsyms { pattern } { + if {! [catch {exec grep -q "$pattern" "/proc/kallsyms"} dummy]} { return 1 } return 0 } -proc utrace_p {} { - set path "/proc/kallsyms" - # We've got 2 ways to provide utrace support: - # - # (1) Kernel built-in utrace (CONFIG_UTRACE). Look for - # 'utrace_attach'. - if {! [catch {exec grep -q utrace_attach $path} dummy]} { - return 1 +# Test for kernel built-in utrace (CONFIG_UTRACE). +# Only original rhel5/6-era utrace need apply. +proc utrace_orig_p {} { + # We want utrace_attach (rhel5) or utrace_attach_task (rhel6), but don't + # get confused by the private module version of any active stap module. + return [grep_kallsyms "T utrace_attach"] +} - # (2) Tracepoint-based utrace. Check for the set of 5 tracepoints - # we need and task_work_add() (see - # runtime/autoconf-utrace-via-tracepoints.c for details). - } elseif {! [catch {exec grep -q tracepoint_sched_process_fork $path} dummy] - && ! [catch {exec grep -q tracepoint_sched_process_exit $path} dummy] - && ! [catch {exec grep -q tracepoint_sys_enter $path} dummy] - && ! [catch {exec grep -q tracepoint_sys_exit $path} dummy] - && ! [catch {exec grep -q tracepoint_sched_process_exec $path} dummy] - && ! [catch {exec grep -q task_work_add $path} dummy]} { - return 1 - } - return 0 +# Test for tracepoint-based utrace, or rather the in-kernel +# facilities which enable our emulation of utrace. +proc utrace_emu_p {} { + # Check for the set of 5 tracepoints we need and task_work_add() + # (see runtime/autoconf-utrace-via-tracepoints.c for details). + return [expr [grep_kallsyms task_work_add] \ + && [grep_kallsyms tracepoint_sched_process_fork] \ + && [grep_kallsyms tracepoint_sched_process_exec] \ + && [grep_kallsyms tracepoint_sched_process_exit] \ + && [grep_kallsyms tracepoint_sys_enter] \ + && [grep_kallsyms tracepoint_sys_exit] \ + ] } -proc uprobes_p {} { - set path "/proc/kallsyms" +# Test for utrace - any flavor will do... +proc utrace_p {} { + return [expr [utrace_orig_p] || [utrace_emu_p] ] +} + + +proc classic_uprobes_p {} { # If this is a utrace kernel, then we can use our version of uprobes. # No need to build it now, stap will handle that itself. # - # classical utrace? - if {! [catch {exec grep -q utrace_attach $path} dummy]} { - # Although ia64 has classical utrace, uprobes hasn't been - # ported there (PR7081). - if {[istarget ia64-*-*]} { - return 0 - } - return 1 - } + # Although ia64 has classical utrace, uprobes hasn't been + # ported there (PR7081). + return [expr [utrace_orig_p] && ! [istarget ia64-*-*] ] +} - # inode-uprobes or (unlikely compiled-in classical uprobes?) +proc inode_uprobes_p {} { + # inode-uprobes (or unlikely compiled-in classical uprobes?) # # Note we're looking for " uprobe_register" to avoid finding # 'kallsyms_uprobe_register' from a loaded systemtap module. - if {! [catch {exec grep -q register_uprobe $path} dummy] - || ! [catch {exec grep -q " uprobe_register" $path} dummy]} { - return 1 - } - return 0 + return [expr [grep_kallsyms register_uprobe] \ + || [grep_kallsyms " uprobe_register"] \ + ] } -proc inode_uprobes_p {} { - set path "/proc/kallsyms" +proc uprobes_p {} { + return [expr [classic_uprobes_p] || [inode_uprobes_p] ] +} - # Note we're looking for " uprobe_register" to avoid finding - # 'kallsyms_uprobe_register' from a loaded systemtap module. - if {! [catch {exec grep -q " uprobe_register" $path} dummy]} { - return 1 - } - return 0 + +proc classic_uretprobes_p {} { + # Classic uprobes always has uretprobes + return [classic_uprobes_p] } +proc inode_uretprobes_p {} { + # inode-uprobes, now with return probes! Looking for any mention of + # uretprobe, notably arch_uretprobe_hijack_return_addr + return [expr [inode_uprobes_p] && [grep_kallsyms uretprobe] ] +} proc uretprobes_p {} { - set path "/proc/kallsyms" - if {! [uprobes_p]} { return 0 } - if {! [catch {exec grep -q uretprobe $path} dummy]} { return 1 } - if {! [catch {exec grep -q utrace_attach $path} dummy]} { return 1 } - return 0 + return [expr [classic_uretprobes_p] || [inode_uretprobes_p] ] } - proc dyninst_p {} { global systemtap_dyninst_p return $systemtap_dyninst_p diff --git a/testsuite/systemtap.printf/ring_buffer.exp b/testsuite/systemtap.printf/ring_buffer.exp index ad1bee2e4..1c044d5da 100644 --- a/testsuite/systemtap.printf/ring_buffer.exp +++ b/testsuite/systemtap.printf/ring_buffer.exp @@ -1,12 +1,7 @@ # Basic ring_buffer test. proc ring_buffer_p {} { - set path "/proc/kallsyms" - if {! [catch {exec grep -q ring_buffer_consume $path} dummy]} { - return 1 - } else { - return 0 - } + return [grep_kallsyms ring_buffer_consume] } set script { diff --git a/testsuite/systemtap.stress/conversions.exp b/testsuite/systemtap.stress/conversions.exp index 052952f36..2e5506ec7 100644 --- a/testsuite/systemtap.stress/conversions.exp +++ b/testsuite/systemtap.stress/conversions.exp @@ -44,8 +44,7 @@ if {! [catch {exec stap -l "kernel.trace(\"sched_switch\")"} dummy]} { run_conv_test $srcdir/$subdir/conversions_profile.stp # Test memory accesses from perf probes (if we've got perf probes). -set path "/proc/kallsyms" -if {! [catch {exec grep -q perf_event_create_kernel_counter $path} dummy]} { +if {[grep_kallsyms perf_event_create_kernel_counter]} { run_conv_test $srcdir/$subdir/conversions_perf.stp } else { untested "conversions_perf.stp" -- 2.43.5