Debian Codegraph @

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

raw
1 # Test cases for procfs probes
2
3 set test "PROCFS"
4
5 if {![installtest_p]} { untested $test; return }
6
7 proc proc_read_value { test path} {
8 set value "<unknown>"
9 if [catch {open $path RDONLY} channel] {
10 fail "$test $channel"
11 } else {
12 set value [read -nonewline $channel]
13 close $channel
14 pass "$test read $value"
15 }
16 return $value
17 }
18
19 proc proc_write_value { test path value} {
20 if [catch {open $path WRONLY} channel] {
21 fail "$test $channel"
22 } else {
23 puts $channel $value
24 close $channel
25 pass "$test wrote $value"
26 }
27 }
28
29 proc proc_read_write {} {
30 global test
31 set path "/proc/systemtap/$test/command"
32
33 # read the initial value, which should be '100'
34 set value [proc_read_value $test $path]
35 if { $value == "100" } {
36 pass "$test received correct initial value"
37 } else {
38 fail "$test received incorrect initial value: $value"
39 }
40
41 # write a new value of '200'
42 proc_write_value $test $path "200"
43
44 # make sure it got set to '200'
45 set value [proc_read_value $test $path]
46 if { $value == "200" } {
47 pass "$test received correct value: 200"
48 } else {
49 fail "$test received incorrect value: $value"
50 }
51
52 # read it again to make sure nothing changed
53 set value [proc_read_value "$test again" $path]
54 if { $value == "200" } {
55 pass "$test received correct value: 200 again"
56 } else {
57 fail "$test received incorrect value: $value again"
58 }
59
60 # write a new value of 'hello'
61 proc_write_value $test $path "hello"
62
63 # make sure it got set to 'hello'
64 set value [proc_read_value $test $path]
65 if { $value == "hello" } {
66 pass "$test received correct value: hello"
67 } else {
68 fail "$test received incorrect value: $value"
69 }
70
71 # write a new value of 'goodbye'
72 proc_write_value $test $path "goodbye"
73
74 # make sure it got set to 'goodbye'
75 set value [proc_read_value $test $path]
76 if { $value == "goodbye" } {
77 pass "$test received correct value: goodbye"
78 } else {
79 fail "$test received incorrect 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
90 set systemtap_script {
91 global saved_value
92
93 probe procfs("command").read {
94 $value = saved_value
95 }
96 probe procfs("command").write {
97 saved_value = $value
98 }
99
100 probe begin {
101 saved_value = "100\n"
102 printf("systemtap starting probe\n")
103 }
104 probe end {
105 printf("systemtap ending probe\n")
106 printf("final value = %s", saved_value)
107 }
108 }
109
110 # test procfs probes
111 set output_string "\\mfinal value = goodbye\\M\r\n"
112 stap_run $test proc_read_write $output_string -e $systemtap_script -m $test
113
114 exec /bin/rm -f ${test}.ko