Debian Codegraph @

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

raw
1 # Test cases for procfs probes with bpf runtime
2
3 set test "PROCFS_BPF"
4
5 if {![installtest_p]} { untested $test; return }
6
7 proc proc_read_value {test path} {
8 set value "<unknown>"
9 if [catch {exec timeout 1 cat $path} value] {
10 fail "$test read $path $value"
11 } else {
12 pass "$test read $path $value"
13 }
14 return $value
15 }
16
17 proc proc_write_value {test path value} {
18 if [catch {exec timeout 1 sh -c "echo $value > $path"} msg] {
19 fail "$test write $path $msg"
20 } else {
21 pass "$test write $path $value"
22 }
23 }
24
25 proc proc_read_write {} {
26 global test
27
28 # effective userid
29 set user [exec id -un]
30 set path_read "/var/tmp/systemtap-$user/$test/command"
31 set path_write "/var/tmp/systemtap-$user/$test/other"
32
33 # read the initial value, which should be '100'
34 set value [proc_read_value $test $path_read]
35 if { $value == "100" } {
36 pass "$test initial value"
37 } else {
38 fail "$test initial value: $value"
39 }
40
41 # write a new value of '200'
42 proc_write_value $test $path_write "200"
43
44 # make sure it got set to '200'
45 set value [proc_read_value $test $path_read]
46 if { $value == "200" } {
47 pass "$test value: 200"
48 } else {
49 fail "$test value: $value"
50 }
51
52 # read it again to make sure nothing changed
53 set value [proc_read_value "$test again" $path_read]
54 if { $value == "200" } {
55 pass "$test value: 200 again"
56 } else {
57 fail "$test value: $value again"
58 }
59
60 # write a new value of 'hello'
61 proc_write_value $test $path_write "hello"
62
63 # make sure it got set to 'hello'
64 set value [proc_read_value $test $path_read]
65 if { $value == "hello" } {
66 pass "$test value: hello"
67 } else {
68 fail "$test value: $value"
69 }
70
71 # write a new value of 'goodbye'
72 proc_write_value $test $path_write "goodbye"
73
74 # make sure it got set to 'goodbye'
75 set value [proc_read_value $test $path_read]
76 if { $value == "goodbye" } {
77 pass "$test value: goodbye"
78 } else {
79 fail "$test value: $value"
80 }
81
82 return 0;
83 }
84
85 # The script starts with a value of "100". If the user writes into
86 # /proc/systemtap/MODNAME/command, that value is returned by the next
87 # read.
88
89 set systemtap_script {
90 }
91
92
93 # test procfs probes
94 set output_string "\\mfinal value = goodbye\\M\r\n"
95 stap_run $test proc_read_write $output_string --bpf $srcdir/$subdir/procfs_bpf.stp -m $test
96
97 exec /bin/rm -f ${test}.bo