| 1 |
if {![installtest_p]} { untested "rename_module"; return } |
| 2 |
|
| 3 |
# Script we'll use while testing: |
| 4 |
set script {probe begin{printf("Hello\n");}} |
| 5 |
|
| 6 |
########## Inserting 2 Identical Modules: Basic Stap call ################# |
| 7 |
# Should not give an error when inserting 2 identical modules |
| 8 |
set test "Inserting 2 Identical Modules: Basic Stap Call" |
| 9 |
|
| 10 |
if {![installtest_p]} { untested $test; return } |
| 11 |
|
| 12 |
set failed1 1 |
| 13 |
set failed2 1 |
| 14 |
|
| 15 |
# Run first module. Stays running since no exit() call. |
| 16 |
# Also keep track of its PID, so we can kill it later. |
| 17 |
spawn stap -e $script |
| 18 |
set firstid $spawn_id |
| 19 |
|
| 20 |
# Run second, identical module. Before, it would cause an |
| 21 |
# error, since it would have the same name as the previous |
| 22 |
# one, but now it inserts without a problem, since it is |
| 23 |
# renamed. |
| 24 |
# Note: The outputs must also be the same - they will have |
| 25 |
# different names to begin with otherwise. |
| 26 |
spawn stap -e $script |
| 27 |
set secondid $spawn_id |
| 28 |
|
| 29 |
# Make sure they both output "Hello" |
| 30 |
expect { |
| 31 |
-i $firstid Hello { |
| 32 |
set failed1 0 |
| 33 |
exp_continue |
| 34 |
} |
| 35 |
-i $secondid Hello { |
| 36 |
set failed2 0 |
| 37 |
exp_continue |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
# Kill both of the spawned processes |
| 42 |
catch {kill -INT -[exp_pid -i $firstid] 2} |
| 43 |
catch {close -i $firstid}; catch {wait -i $firstid} |
| 44 |
catch {kill -INT -[exp_pid -i $secondid] 2} |
| 45 |
catch {close -i $secondid}; catch {wait -i $secondid} |
| 46 |
|
| 47 |
if {$failed1 || $failed2} { |
| 48 |
fail "$test ($failed1, $failed2)" |
| 49 |
} else { |
| 50 |
pass "$test" |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
########## Compile test module ################# |
| 55 |
# Compile the module we'll be using for the rest of the tests (which |
| 56 |
# is actually already compiled, but we need the filename of the cached |
| 57 |
# module). |
| 58 |
set test "test module" |
| 59 |
if {[catch { exec stap -e $script -p4 } module]} { |
| 60 |
verbose -log "$module" |
| 61 |
fail "$test - compile problem" |
| 62 |
return |
| 63 |
} elseif {![file exists $module]} { |
| 64 |
verbose -log "$module" |
| 65 |
fail "$test - file exist problem" |
| 66 |
return |
| 67 |
} else { |
| 68 |
pass "$test compiles" |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
########## Inserting 2 Identical Modules: Staprun without -R ################# |
| 73 |
# Should give an error when inserting 2 identical modules |
| 74 |
# when calling staprun directly without using -R |
| 75 |
set test "Inserting 2 Identical Modules: Staprun without -R" |
| 76 |
set failed1 1 |
| 77 |
set failed2 0 |
| 78 |
|
| 79 |
spawn staprun $module |
| 80 |
set firstid $spawn_id |
| 81 |
|
| 82 |
# Make sure the first staprun works |
| 83 |
expect { |
| 84 |
-i $firstid Hello { |
| 85 |
set failed1 0 |
| 86 |
exp_continue |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
spawn staprun $module |
| 91 |
set secondid $spawn_id |
| 92 |
|
| 93 |
# Make sure the second staprun fails |
| 94 |
expect { |
| 95 |
-timeout 60 |
| 96 |
-re {^ERROR: Couldn't insert module .*: File exists\r\n} { |
| 97 |
exp_continue |
| 98 |
} |
| 99 |
-re {^ERROR: Rerun with staprun option '\-R' to rename this module.\r\n} { |
| 100 |
exp_continue |
| 101 |
} |
| 102 |
-re {^[^\r\n]*\r\n} { |
| 103 |
set failed2 1 |
| 104 |
exp_continue |
| 105 |
} |
| 106 |
timeout { set failed2 1 } |
| 107 |
} |
| 108 |
|
| 109 |
# Kill both of the spawned processes |
| 110 |
catch {kill -INT -[exp_pid -i $firstid] 2} |
| 111 |
catch {close -i $firstid}; catch {wait -i $firstid} |
| 112 |
catch {kill -INT -[exp_pid -i $secondid] 2} |
| 113 |
catch {close -i $secondid}; catch {wait -i $secondid} |
| 114 |
|
| 115 |
if {$failed1 || $failed2} { |
| 116 |
verbose -log "$failed1, $failed2" |
| 117 |
# On failure, don't leave any modules behind. |
| 118 |
catch {exec staprun -d $module} |
| 119 |
fail "$test ($failed1, $failed2)" |
| 120 |
} else { |
| 121 |
pass "$test" |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
########## Inserting 2 Identical Modules: Staprun with -R ################# |
| 126 |
# Should not give an error when inserting 2 identical modules |
| 127 |
# when calling staprun directly with -R |
| 128 |
set test "Inserting 2 Identical Modules: Staprun with -R" |
| 129 |
set failed1 1 |
| 130 |
set failed2 1 |
| 131 |
|
| 132 |
spawn staprun -R $module |
| 133 |
set firstid $spawn_id |
| 134 |
|
| 135 |
spawn staprun -R $module |
| 136 |
set secondid $spawn_id |
| 137 |
|
| 138 |
# Make sure they both output "Hello" |
| 139 |
expect { |
| 140 |
-i $firstid Hello { |
| 141 |
set failed1 0 |
| 142 |
exp_continue |
| 143 |
} |
| 144 |
-i $secondid Hello { |
| 145 |
set failed2 0 |
| 146 |
exp_continue |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
# Kill both of the spawned processes |
| 151 |
catch {kill -INT -[exp_pid -i $firstid] 2} |
| 152 |
catch {close -i $firstid}; catch {wait -i $firstid} |
| 153 |
catch {kill -INT -[exp_pid -i $secondid] 2} |
| 154 |
catch {close -i $secondid}; catch {wait -i $secondid} |
| 155 |
|
| 156 |
if {$failed1 || $failed2} { |
| 157 |
# On failure, don't leave any modules behind. |
| 158 |
catch {exec staprun -d $module} |
| 159 |
fail "$test ($failed1, $failed2)" |
| 160 |
} else { |
| 161 |
pass "$test" |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
# Now again, with a very short name |
| 166 |
|
| 167 |
set test "short named test module" |
| 168 |
if {[catch { exec stap -m x -e $script -p4 } module]} { |
| 169 |
verbose -log "$module" |
| 170 |
fail "$test - compile problem" |
| 171 |
return |
| 172 |
} elseif {![file exists $module]} { |
| 173 |
verbose -log "$module" |
| 174 |
fail "$test - file exist problem" |
| 175 |
return |
| 176 |
} else { |
| 177 |
pass "$test compiles" |
| 178 |
} |
| 179 |
|
| 180 |
set module x.ko |
| 181 |
spawn staprun -R $module |
| 182 |
set firstid $spawn_id |
| 183 |
|
| 184 |
# Make sure it does run. |
| 185 |
set ok 0 |
| 186 |
expect { |
| 187 |
-re {^WARNING: Old module name[^\r\n]*\r\n} { incr ok; exp_continue } |
| 188 |
-re {Hello} { incr ok } |
| 189 |
} |
| 190 |
|
| 191 |
catch {kill -INT -[exp_pid -i $firstid] 2} |
| 192 |
catch {close -i $firstid}; catch {wait -i $firstid} |
| 193 |
|
| 194 |
if { $ok == 2 } then { |
| 195 |
pass "$test execution" |
| 196 |
} else { |
| 197 |
fail "$test execution $ok" |
| 198 |
} |