summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.base/target_set.exp
blob: 4b6e0a5d6e6a22bbdf4c9491724c479cfb8ae34e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Test for target_set tapset

set test target_set

if {![installtest_p]} { untested $test; continue }

set file $srcdir/$subdir/target_set.stp
set time 12345
set stap_cmd  "( ( /bin/sleep $time ) ; ( /bin/sleep $time ) ; ( /bin/sleep $time ) )"
set stap_cmd_sleep_count 3
set stap_cmd_child_level 3

proc failtest {} {
	global test
	fail $test
}

proc expect_target_set_string {} {
	expect {
		"^target set:\r\n" { }
		timeout { failtest; return -code return }
	}
}

proc expect_target_set_pids generations {
	global test
	global stp_pid
	for {set i 0} {$i < $generations} {incr i} {
		expect {
			-re {^([0-9]+) begat ([0-9]+)\r\n} { set pid_array($expect_out(1,string)) $expect_out(2,string) }
			timeout { failtest; return -code return }
		}
	}
	set pid_it $stp_pid
	while {[info exists pid_array($pid_it)]} {
		if {[exec pgrep -P $pid_it] != $pid_array($pid_it)} {
			failtest; return -code return
		}
		set pid_it $pid_array($pid_it)
	}
	if {$generations > 1} {
		exec kill -INT $pid_it
	}
}

spawn stap $file $time -c "$stap_cmd"

expect {
	-timeout 180
	-re {^(\d+)\r\n} { set stp_pid $expect_out(1,string) }
	timeout { failtest; return }
}

expect_target_set_pids 1
for {set i 0} {$i < $stap_cmd_sleep_count} {incr i} {
	expect_target_set_string
	expect_target_set_pids $stap_cmd_child_level
}
expect_target_set_string
expect_target_set_pids 0

expect {
	eof {}
	timeout { failtest; return }
}

wait
pass $test