Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/target_set.exp

raw
1 # Test for target_set tapset
2
3 set test target_set
4
5 if {![installtest_p]} { untested $test; continue }
6
7 set file $srcdir/$subdir/target_set.stp
8 set time 12345
9 set stap_cmd "( ( /bin/sleep $time ) ; ( /bin/sleep $time ) ; ( /bin/sleep $time ) )"
10 set stap_cmd_sleep_count 3
11 set stap_cmd_child_level 3
12
13 proc failtest {reason} {
14 global test
15 catch close; catch wait;
16 fail "$test - $reason"
17 }
18
19 proc expect_target_set_string {} {
20 expect {
21 "^target set:\r\n" { }
22 -re {^WARNING: Child process exited.+\r\n} { exp_continue }
23 timeout { failtest "timeout (expect_target_set_string)"
24 return -code return }
25 eof { failtest "eof (expect_target_set_string)"
26 return -code return }
27 }
28 }
29
30 proc expect_target_set_pids generations {
31 global test
32 global stp_pid
33 for {set i 0} {$i < $generations} {incr i} {
34 expect {
35 -re {^([0-9]+) begat ([0-9]+)\r\n} { set pid_array($expect_out(1,string)) $expect_out(2,string) }
36 -re {^WARNING: Child process exited.+\r\n} { exp_continue }
37 timeout { failtest "timeout (expect_target_set_pids)"
38 return -code return }
39 eof { failtest "eof (expect_target_set_pids)"
40 return -code return }
41 }
42 }
43 set pid_it $stp_pid
44 while {[info exists pid_array($pid_it)]} {
45 if {[exec pgrep -P $pid_it] != $pid_array($pid_it)} {
46 failtest "(expect_target_set_pids)"
47 return -code return
48 }
49 set pid_it $pid_array($pid_it)
50 }
51 if {$generations > 1} {
52 kill -INT $pid_it
53 }
54 }
55
56 spawn stap $file $time -c "$stap_cmd"
57
58 expect {
59 -timeout 180
60 -re "semantic error:" { failtest "semantic error (main1)"; return }
61 -re {^(\d+)\r\n} { set stp_pid $expect_out(1,string) }
62 timeout { failtest "timeout (main1)"; return }
63 eof { failtest "eof (main1)"; return }
64 }
65
66 expect_target_set_pids 1
67 for {set i 0} {$i < $stap_cmd_sleep_count} {incr i} {
68 expect_target_set_string
69 expect_target_set_pids $stap_cmd_child_level
70 }
71 expect_target_set_string
72 expect_target_set_pids 0
73
74 expect {
75 eof {}
76 timeout { failtest "timeout (main2)"; return }
77 }
78
79 catch close; catch wait;
80 pass $test