# Marker tests. Note that we can't really run (pass 5) marker tests, # since we have no idea where in the kernel they are (and what would # trigger a specific marker). So, we'll try to compile lots of tests # to do as much as we can. # stap_compile TEST_NAME flags script args # - TEST_NAME is the name of the current test # - compile indicates whether the script is supposed to compile # - script is the script to compile # Additional arguments are passed to stap as-is. proc stap_compile { TEST_NAME compile script args } { set cmd [concat {stap -v -p4 -e} $script $args] #puts "running $cmd" eval spawn $cmd set compile_errors 0 expect { -re {^Pass\ [1234]:[^\r]*\ in\ .*\ ms.\r\n} {exp_continue} -re {^Pass\ [34]: using cached [^\r\n]+\r\n} {exp_continue} # pass-4 output -re {^/[^\r\n]+.ko\r\n} {exp_continue} -re "parse error" { incr compile_errors 1; exp_continue} -re "compilation failed" {incr compile_errors 1; exp_continue} -re "semantic error:" {incr compile_errors 1; exp_continue} } catch close wait # If we've got compile errors and the script was supposed to # compile, fail. if {$compile_errors > 0} { if {$compile == 1} { fail "$TEST_NAME compilation failed" } else { pass "$TEST_NAME compilation failed correctly" } } else { if {$compile == 1} { pass "$TEST_NAME compilation succeeded" } else { fail "$TEST_NAME compilation succeeded unexpectedly" } } } # Initialize variables set kernel_markers_found 0 set kernel_marker_names {} set kernel_script {"probe kernel.mark(\"%s\") { }"} set kernel_script_arg {"probe kernel.mark(\"%s\") { print(%s) }"} set kernel_script_arg2 {"probe kernel.mark(\"%s\") { %s = 0 }"} # Try to read in the marker list from the Module.markers file. set uname [exec /bin/uname -r] set arch [exec arch] set path "/usr/src/kernels/$uname-$arch/Module.markers" if {! [catch {open $path RDONLY} fl]} { while {[gets $fl s] >= 0} { # This regexp only picks up markers that contain arguments. # This helps ensure that K_MARKER04 passes correctly. if [regexp {^([^ \t]+)\t[^ \t]+.+$} $s match name] { set kernel_markers_found 1 lappend kernel_marker_names $name } } catch {close $fl} } # # Do some marker tests. # set TEST_NAME "K_MARKER01" if {$kernel_markers_found == 0} { untested "$TEST_NAME : no kernel markers present" } else { # Try compiling a script that probes all kernel markers using a # wildcard. set script [format $kernel_script "*"] stap_compile $TEST_NAME 1 $script } set TEST_NAME "K_MARKER02" if {$kernel_markers_found == 0} { untested "$TEST_NAME : no kernel markers present" } else { # Try compiling a script that probes the first kernel marker # found. set script [format $kernel_script [lindex $kernel_marker_names 0]] stap_compile $TEST_NAME 1 $script } # We can go ahead and try this test even if the kernel doesn't have # marker support, since we're probing a marker that doesn't exist. set TEST_NAME "K_MARKER03" # Try compiling a script that probes a kernel marker that doesn't # exist. set script [format $kernel_script "X_marker_that_does_not_exist_X"] stap_compile $TEST_NAME 0 $script set TEST_NAME "K_MARKER04" if {$kernel_markers_found == 0} { untested "$TEST_NAME : no kernel markers present" } else { # Try compiling a script that prints the first argument of a # marker. This one might fail if the marker we pick doesn't have # any arguments (but hopefully our kernel marker list only # contains markers that have at least one argument). set script [format $kernel_script_arg \ [lindex $kernel_marker_names 0] {\$arg1}] stap_compile $TEST_NAME 1 $script } set TEST_NAME "K_MARKER05" if {$kernel_markers_found == 0} { untested "$TEST_NAME : no kernel markers present" } else { # Try compiling a script that prints an marker argument that # doesn't exist. This one might fail if the marker we pick # has a 200th argument (which isn't likely). set script [format $kernel_script_arg \ [lindex $kernel_marker_names 0] {\$arg200}] stap_compile $TEST_NAME 0 $script } set TEST_NAME "K_MARKER06" if {$kernel_markers_found == 0} { untested "$TEST_NAME : no kernel markers present" } else { # Try compiling a script that prints marker argument $arg0 # (which doesn't exist). set script [format $kernel_script_arg \ [lindex $kernel_marker_names 0] {\$arg0}] stap_compile $TEST_NAME 0 $script } set TEST_NAME "K_MARKER07" if {$kernel_markers_found == 0} { untested "$TEST_NAME : no kernel markers present" } else { # Try compiling a script that prints marker argument $foo1 (which # doesn't exist). set script [format $kernel_script_arg \ [lindex $kernel_marker_names 0] {\$foo1}] stap_compile $TEST_NAME 0 $script } set TEST_NAME "K_MARKER08" if {$kernel_markers_found == 0} { untested "$TEST_NAME : no kernel markers present" } else { # Try compiling a script that writes to marker argument $arg1 (which # isn't allowed). set script [format $kernel_script_arg2 \ [lindex $kernel_marker_names 0] {\$arg1}] stap_compile $TEST_NAME 0 $script }