Debian Codegraph @

testsuite/systemtap.unprivileged/pr16806.exp

raw
1 set test "pr16806"
2
3 if {![installtest_p]} { untested $test; return }
4 if {![uprobes_p]} { untested $test; return }
5
6 set exepath "loop"
7 set sopath "libloop.so"
8 set modpath "modloop"
9
10 # This testcase verifies that utrace shuts down cleanly during rapid module
11 # insertion/removal and does not cause a kernel crash.
12
13 proc cleanup_test {} {
14 global exepath sopath modpath
15 if {[file exists "$exepath"]} { file delete "$exepath" }
16 if {[file exists "$sopath"]} { file delete "$sopath" }
17 if {[file exists "$modpath.ko"]} { file delete "$modpath.ko" }
18 }
19
20 # Need to build a user shared library.
21 set libflags [sdt_includes]
22 set libflags "$libflags additional_flags=-g"
23 set libflags "$libflags additional_flags=-O"
24 set libflags "$libflags additional_flags=-Wall"
25 set libflags "$libflags additional_flags=-Werror"
26 set libflags "$libflags additional_flags=-I."
27 set libflags "$libflags additional_flags=-shared"
28 set libflags "$libflags additional_flags=-fPIC"
29 set res [target_compile $srcdir/$subdir/libloop.c $sopath executable "$libflags"]
30 if { $res == "" } {
31 pass "$test library compile"
32 } else {
33 fail "$test library compile: $res"
34 cleanup_test
35 return
36 }
37
38 # Need to build a user application
39 set exeflags "additional_flags=-g"
40 # Add NOSLEEP to disable usleep() call. This makes a kernel crash much easier to
41 # trigger.
42 set exeflags "$exeflags additional_flags=-DNOSLEEP"
43 set exeflags "$exeflags additional_flags=-O"
44 set exeflags "$exeflags additional_flags=-lpthread"
45 set exeflags "$exeflags [sdt_includes]"
46 set exeflags "$exeflags additional_flags=-Wl,-rpath,[pwd]"
47 set exeflags "$exeflags additional_flags=-L[pwd] additional_flags=-lloop"
48 set exeflags "$exeflags compiler=gcc"
49 # ppc64 needs a more restrictive constraint for the probe args
50 if {[regexp "^(x86_64|i.86)$" $::tcl_platform(machine)] == 0} {
51 set exeflags "$exeflags additional_flags=-DSTAP_SDT_ARG_CONSTRAINT=nr"
52 }
53 set res [target_compile $srcdir/$subdir/loop.c $exepath executable "$exeflags"]
54 if { $res == "" } {
55 pass "$test exe compile"
56 } else {
57 fail "$test exe compile: $res"
58 cleanup_test
59 return
60 }
61
62 # Create module
63 set script " \
64 probe process(\"./$exepath\").function(\"ibar\") { \
65 println(\"entered ibar\") \
66 exit() \
67 } \
68 "
69
70 # If we're on a platform with uprobes not built in, we need to ensure first
71 # that it is inserted. Let's run the script once and hope the uprobes.ko stays
72 # inserted.
73 set rc [catch {eval exec stap -m $modpath -e {$script} -c /bin/true} out]
74 if {$rc == 0 && [file exists "$modpath.ko"]} {
75 pass "$test ko compile"
76 } else {
77 fail "$test ko compile"
78 verbose -log "stap output: $out"
79 cleanup_test
80 return
81 }
82
83 # For 60s, keep inserting the module using staprun. If we survive, just default
84 # to a pass (otherwise we would have crashed).
85 set max [expr [exec date +%s] + 60]
86 while {[expr [exec date +%s] < $max]} {
87 catch {exec staprun $modpath.ko -c "timeout -s KILL 1 ./$exepath"} out
88 if {![regexp "entered ibar" "$out"]} {
89 fail "$test staprun"
90 verbose -log "staprun output: $out"
91 cleanup_test
92 return
93 }
94 }
95
96 cleanup_test
97 pass "$test"
98