Debian Codegraph @

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

raw
1 set test "task_fd_lookup"
2 set srcpath "${srcdir}/${subdir}/${test}.c"
3 set exepath "[pwd]/${test}"
4
5 # Only run on make installcheck
6 if {! [installtest_p]} { untested "$test"; return }
7
8 # Compile the test exectuable (which opens several directories, pipes,
9 # and a socket).
10 set res [target_compile $srcpath $exepath executable "additional_flags=-g"]
11 if { $res != "" } {
12 verbose "target_compile failed: $res" 2
13 fail "unable to compile $srcpath"
14 return
15 }
16
17 # Create a tempory directory.
18 if {[catch {exec mktemp -d -t staptestXXXXXX} tmpdir]} {
19 verbose -log "Failed to create temporary directory: $tmpdir"
20 return
21 }
22
23 # Create a deep directory inside the temporary directory.
24 set full_tmpdir "${tmpdir}/a/b/c/d/e/f/g"
25 if {[catch {exec mkdir -p ${full_tmpdir}} res]} {
26 verbose -log "Failed to create temporary directory: $tmpdir"
27 catch {exec rm -rf "$tmpdir"}
28 return
29 }
30
31 spawn stap $srcdir/$subdir/$test.stp --compatible 4.0 -c "$exepath $full_tmpdir"
32 verbose -log "stap $srcdir/$subdir/$test.stp --compatible 4.0 -c \"$exepath $full_tmpdir\""
33 set found_root 0
34 set found_tmpdir 0
35 set found_pipe 0
36 set found_socket 0
37 expect {
38 -timeout 180
39 -re {^[0-9]+: /\r\n} { incr found_root; exp_continue }
40 -re "^\[0-9\]+: ${full_tmpdir}\r\n" { incr found_tmpdir; exp_continue }
41 -re {^[0-9]+: pipe:\[[0-9]+\]\r\n} {
42 # We don't want to count the pipes left open by the testsuite,
43 # so only count pipes after we've seen the root directory.
44 if {$found_root} { incr found_pipe }
45 exp_continue }
46 -re {^[0-9]+: socket:\[[0-9]+\]\r\n} { incr found_socket; exp_continue }
47 -re {^[^\r\n]+\r\n} {
48 # ignore everything else
49 exp_continue }
50 eof { }
51 timeout { fail "$test (timeout)" }
52 }
53 catch {close}; catch {wait}
54
55 # The test executable opens "/", the tmpdir, 2 pipes, and a
56 # socket.
57 if {$found_root == 1 && $found_tmpdir == 1 && $found_pipe == 2
58 && $found_socket == 1} {
59 pass "$test"
60 } else {
61 fail "$test ($found_root, $found_tmpdir, $found_pipe, $found_socket)"
62 }
63
64 # Cleanup.
65 catch {exec rm -rf "$tmpdir $exepath"}
66 return