| 1 |
|
| 2 |
set env(LC_ALL) "C" |
| 3 |
regexp "(.*\/)testsuite" $objdir objdir topdir |
| 4 |
|
| 5 |
# These are the same as include/c.h |
| 6 |
set usage_help "\\s*-h, --help\\s+display this help and exit\\s+" |
| 7 |
set usage_version "\\s*-V, --version\\s+output version information and exit\\s+" |
| 8 |
set usage_man "\\s*For more details see \\S+\\." |
| 9 |
|
| 10 |
proc kill_process pid { |
| 11 |
set cmdline "kill $pid" |
| 12 |
if { [catch { exec /bin/sh -c $cmdline } msg]} { |
| 13 |
warning "Could not kill process: $msg\n" |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
proc procps_v_version { tool } { |
| 18 |
global topdir |
| 19 |
set toolpath ${topdir}src/${tool} |
| 20 |
set tmp [ exec $toolpath -V ] |
| 21 |
regexp "from procps-ng (\[0-9.\]*)" $tmp tmp version |
| 22 |
clone_output "$toolpath version $version\n" |
| 23 |
} |
| 24 |
|
| 25 |
proc free_version {} { procps_v_version free } |
| 26 |
proc kill_version {} { procps_v_version kill } |
| 27 |
proc pgrep_version {} { procps_v_version pgrep } |
| 28 |
proc pkill_version {} { procps_v_version pkill } |
| 29 |
proc pmap_version {} { procps_v_version pmap } |
| 30 |
proc pwdx_version {} { procps_v_version pwdx } |
| 31 |
proc sysctl_version {} { procps_v_version sysctl } |
| 32 |
proc uptime_version {} { procps_v_version uptime } |
| 33 |
proc vmstat_version {} { procps_v_version vmstat } |
| 34 |
proc w_version {} { procps_v_version w } |
| 35 |
|
| 36 |
# |
| 37 |
# |
| 38 |
# common utilities |
| 39 |
proc expect_continue { testname reg } { |
| 40 |
expect { |
| 41 |
-re "$reg" { } |
| 42 |
eof { fail "$testname" } |
| 43 |
timeout { fail "$testname" } |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
proc expect_pass { testname reg } { |
| 48 |
expect { |
| 49 |
-re "$reg" { pass "$testname" } |
| 50 |
default { fail "$testname" } |
| 51 |
timeout { fail "$testname" } |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
proc is_spawn_id_dead {sid} { |
| 56 |
if {[catch {send -i $sid "\n"} err]} { |
| 57 |
# Catch true means a dead spawn id |
| 58 |
return 1 |
| 59 |
} else { |
| 60 |
# Catch is false means send was ok |
| 61 |
return 0 |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
# Fail if we see this message, pass if we get to EOF |
| 66 |
proc expect_fail { testname reg } { |
| 67 |
expect { |
| 68 |
-re "$reg" { fail "$testname" } |
| 69 |
timeout { fail "$testname" } |
| 70 |
eof { pass "$testname" } |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
proc expect_pipeproc_pass { testname reg } { |
| 75 |
global pipeproc_spawnid |
| 76 |
|
| 77 |
if {[is_spawn_id_dead $pipeproc_spawnid]} { |
| 78 |
fail "$testname (pipe process spawn id invalid)" |
| 79 |
return |
| 80 |
} |
| 81 |
expect { |
| 82 |
-i $pipeproc_spawnid |
| 83 |
-re "$reg" { pass "$testname" } |
| 84 |
default { fail "$testname" } |
| 85 |
timeout { fail "$testname (timeout)" } |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
proc expect_blank { testname } { |
| 90 |
expect { |
| 91 |
-re "\\w" { fail "$testname" } |
| 92 |
eof { pass "$testname" } |
| 93 |
timeout { pass "$testname" } |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
proc expect_blank_continue { testname } { |
| 98 |
expect { |
| 99 |
-re "\\w" { fail "$testname" } |
| 100 |
eof { } |
| 101 |
timeout { pass "$testname (timeout)" } |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
proc expect_table { test match_header match_items match_footer } { |
| 106 |
expect { |
| 107 |
-re "$match_header" { |
| 108 |
expect { |
| 109 |
-re "$match_items" { |
| 110 |
expect { |
| 111 |
-re "$match_footer" { pass "$test" } |
| 112 |
default { fail "$test (footer)" } |
| 113 |
} |
| 114 |
} |
| 115 |
default { fail "$test (items)" } |
| 116 |
} |
| 117 |
} |
| 118 |
default { fail "$test (header)" } |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
proc expect_table_dsc { test match_header match_item } { |
| 123 |
expect { |
| 124 |
-re $match_header {} |
| 125 |
default { |
| 126 |
fail "$test (header)" |
| 127 |
return |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
set do_loop 1 |
| 132 |
set last_value 99999999 |
| 133 |
set found_item 0 |
| 134 |
while { $do_loop ==1 } { |
| 135 |
expect { |
| 136 |
-re $match_item { |
| 137 |
set current_value $expect_out(1,string) |
| 138 |
if { $current_value > $last_value } { |
| 139 |
fail "$test (sorting $current_value > $last_value)" |
| 140 |
return |
| 141 |
} else { |
| 142 |
set found_item 1 |
| 143 |
set last_value $current_value |
| 144 |
} |
| 145 |
} |
| 146 |
default { |
| 147 |
if { $found_item == 0 } { |
| 148 |
fail "$test (items ${found_item})" |
| 149 |
} else { |
| 150 |
pass $test |
| 151 |
} |
| 152 |
return |
| 153 |
} |
| 154 |
eof { |
| 155 |
if { $found_item == 0 } { |
| 156 |
fail "$test (items eof)" |
| 157 |
} else { |
| 158 |
pass $test |
| 159 |
} |
| 160 |
return |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
#expect { |
| 165 |
# -re $match_footer { pass $test } |
| 166 |
# default { fail "$test (footer)" } |
| 167 |
#} |
| 168 |
} |
| 169 |
|
| 170 |
proc expect_spawn_retval { test retval } { |
| 171 |
# Check for spawn life |
| 172 |
if {[ catch { send "\n" } err]} { |
| 173 |
unsupported "$test (cannot check return value)" |
| 174 |
return |
| 175 |
} |
| 176 |
# Need to wait for EOF to stop race condition |
| 177 |
foreach {pid spawnid os_error_flag value x y} [wait] break |
| 178 |
|
| 179 |
if {$y != "" } { |
| 180 |
fail "$test (subprocess returned $y)" |
| 181 |
} |
| 182 |
if {$value == $retval} { |
| 183 |
return |
| 184 |
} |
| 185 |
fail "$test (exit value Want:$retval Got:$value)" |
| 186 |
} |
| 187 |
|
| 188 |
proc make_pipeproc { } { |
| 189 |
global pipeproc_pid pipeproc_spawnid topdir |
| 190 |
|
| 191 |
set testproc_realpath "${topdir}/src/tests/test_process" |
| 192 |
|
| 193 |
set pipeproc_pid [ spawn $testproc_realpath ] |
| 194 |
set pipeproc_spawnid $spawn_id |
| 195 |
|
| 196 |
} |
| 197 |
proc make_testproc {args} { |
| 198 |
global testproc_path testproc_comm testproc_arg_str testproc1_pid testproc2_pid topdir |
| 199 |
|
| 200 |
set testproc_realpath "${topdir}/src/tests/test_process" |
| 201 |
if {[llength $args] > 0} { |
| 202 |
set testproc_comm [lindex $args 0] |
| 203 |
set use_comm_flag 1 |
| 204 |
} else { |
| 205 |
set testproc_comm "spcorp" |
| 206 |
set use_comm_flag 0 |
| 207 |
} |
| 208 |
|
| 209 |
set testproc_path [ exec mktemp -u ] |
| 210 |
exec ln -s $testproc_realpath $testproc_path |
| 211 |
|
| 212 |
spawn readlink $testproc_path |
| 213 |
expect { |
| 214 |
-re "^$testproc_realpath\\s*$" { } |
| 215 |
timeout { perror "test proc does not link to test process" } |
| 216 |
eof { perror "test proc does not link to test process" } |
| 217 |
} |
| 218 |
|
| 219 |
# make a process with the argument set to a fraction of ARG_MAX length |
| 220 |
# but small enough we do not run TCL out of memory for regular expressions |
| 221 |
# nor do we get argument list too long (104857 was found to work on Ubuntu 18.04) |
| 222 |
set max_arg_len [ expr min([ exec /usr/bin/getconf ARG_MAX ], 104857) ] |
| 223 |
# ensure we have enough slack to launch the test prog and pgrep |
| 224 |
set reserved_space [expr max([ string length $testproc_path ], [ string length $topdir ] + 10)] |
| 225 |
set testproc_arg_str "a" |
| 226 |
set i $reserved_space |
| 227 |
while {$i<$max_arg_len} { |
| 228 |
incr i |
| 229 |
append testproc_arg_str "a" |
| 230 |
} |
| 231 |
|
| 232 |
if {$use_comm_flag} { |
| 233 |
set testproc1_pid [ exec $testproc_path -c $testproc_comm $testproc_arg_str & ] |
| 234 |
set testproc2_pid [ exec $testproc_path -c $testproc_comm & ] |
| 235 |
} else { |
| 236 |
set testproc1_pid [ exec $testproc_path $testproc_arg_str & ] |
| 237 |
set testproc2_pid [ exec $testproc_path & ] |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
proc make_testshm_proc { } { |
| 242 |
global testshmproc_pid testshm_spawnid topdir shmid shmaddr |
| 243 |
|
| 244 |
set testshm_realpath "${topdir}/src/tests/test_shm" |
| 245 |
|
| 246 |
set testshmproc_pid [ spawn $testshm_realpath ] |
| 247 |
set testshmproc_spawnid $spawn_id |
| 248 |
expect { |
| 249 |
-i $testshmproc_spawnid |
| 250 |
-re "^SHMID: (\[0-9a-f\]+)" { |
| 251 |
set shmid $expect_out(1,string) |
| 252 |
expect { |
| 253 |
-i $testshmproc_spawnid |
| 254 |
-re "SHMADDR: 0x(\[0-9a-f\]+)" { |
| 255 |
set shmaddr $expect_out(1,string) |
| 256 |
} |
| 257 |
default { set shmaddr "" } |
| 258 |
} |
| 259 |
} |
| 260 |
default { set shmid "" } |
| 261 |
} |
| 262 |
|
| 263 |
} |
| 264 |
|
| 265 |
proc kill_testshm_proc { } { |
| 266 |
global testshmproc_pid |
| 267 |
|
| 268 |
kill_process $testshmproc_pid |
| 269 |
} |
| 270 |
|
| 271 |
proc make_schedbatch_proc { nice_val } { |
| 272 |
global schedbatch_proc_pid topdir |
| 273 |
set schedbatch_path "${topdir}testsuite/test-schedbatch" |
| 274 |
|
| 275 |
set schedbatch_proc_pid [ spawn $schedbatch_path $nice_val ] |
| 276 |
} |
| 277 |
|
| 278 |
proc kill_schedbatch_proc { } { |
| 279 |
global schedbatch_proc_pid |
| 280 |
kill_process $schedbatch_proc_pid |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
proc make_zombie_proc { } { |
| 285 |
global zombie_ppid zombie_pid topdir |
| 286 |
|
| 287 |
set zombie_realpath "${topdir}testsuite/test-zombie" |
| 288 |
set zombie_ppid [ spawn $zombie_realpath ] |
| 289 |
set zombie_pid "" |
| 290 |
expect { |
| 291 |
-re "Zombie pid: (\[0-9\]+)" { set zombie_pid $expect_out(1,string) } |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
proc kill_zombie_proc { } { |
| 296 |
global zombie_ppid |
| 297 |
kill_process $zombie_ppid |
| 298 |
} |
| 299 |
|
| 300 |
proc kill_testproc { } { |
| 301 |
global testproc_path testproc1_pid testproc2_pid |
| 302 |
|
| 303 |
kill_process $testproc1_pid |
| 304 |
kill_process $testproc2_pid |
| 305 |
file delete $testproc_path |
| 306 |
} |
| 307 |
|
| 308 |
proc kill_pipeproc { } { |
| 309 |
global pipeproc_pid |
| 310 |
kill_process $pipeproc_pid |
| 311 |
} |
| 312 |
|
| 313 |
proc get_tty {} { |
| 314 |
if { [catch { set raw_tty [ exec tty ] } msg]} { |
| 315 |
warning "No TTY found" |
| 316 |
return "" |
| 317 |
} |
| 318 |
regexp "/dev/(.+)" $raw_tty > tty |
| 319 |
if { $tty == "tty" } { |
| 320 |
warning "TTY is tty" |
| 321 |
return "" |
| 322 |
} |
| 323 |
|
| 324 |
return $tty |
| 325 |
} |