Debian Codegraph @

testsuite/systemtap.context/context_ns.exp

raw
1 set test_name "context namespaces"
2 if {! [installtest_p]} {
3 untested $test_name
4 return
5 }
6
7 # can't really test user_ns right now since we don't know other uids
8 set ns_tests { pid_ns }
9 set output_string "END\r\n"
10
11 # before we can even run the test, check that unshare is available
12 # probably only available in kernels >= 2.6.16
13 if {[catch {exec which unshare}]} {
14 untested "$test_name (no unshare)"
15 return
16 }
17
18 # weed out the kernels that don't have free_pid_ns available to us
19 if {![min_kernel_vers_p 3.7]} {
20 untested "$test_name (kernel version is too low)"
21 return
22 }
23
24 # Note we have to be root to run "unshare".
25 set effective_uid [exec /usr/bin/id -u]
26 if {$effective_uid != 0} {
27 untested "$test_name (must be root)"
28 return
29 }
30
31 # use unshare to generate new namespaces to use
32 # the returned pid is not the new proc's pid (as seen in the root ns)
33 spawn unshare -pf "sleep" 160
34 set exe_id $spawn_id
35
36 # instead, we'll use pgrep to find the sleep process. let's hope we only find one
37 # we'll narrow it down by specifying a parent proc id
38 set parent_proc [exp_pid -i $exe_id]
39 set child_proc [exec pgrep -P $parent_proc]
40
41 # make sure that we did find the child proc; if not, abort
42 if {!$child_proc || $child_proc < 0} {
43 untested "$test_name (cant make child_proc)"
44 return
45 }
46 verbose -log "child (global) pid:$child_proc"
47
48 foreach ns_test $ns_tests {
49 stap_run $ns_test no_load $output_string $srcdir/$subdir/$ns_test.stp -g --target-namespaces=$child_proc --disable-cache
50 }
51
52 # kill the parent
53 kill -INT -$parent_proc 2
54 catch {close -i $exe_id}
55 catch {wait -i $exe_id}
56
57 kill -INT -$child_proc 2