Debian Codegraph @

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

raw
1 # Test cases for multiple procfs.write probes to a file
2
3 set test "procfs_multi_write"
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 -nonewline $channel $value
24 close $channel
25 pass "$test wrote $value"
26 }
27 }
28
29 proc proc_read_write {} {
30 global test
31 set path1 "/proc/systemtap/$test/command"
32 set path2 "/proc/systemtap/$test/test"
33
34 proc_write_value $test $path1 "x"
35 set value [proc_read_value $test $path1 ]
36 if { $value == "xaxb" } {
37 pass "$test received correct value: $value"
38 } else {
39 fail "$test received incorrect value: $value"
40 }
41
42 proc_write_value $test $path2 "y"
43 set value [proc_read_value $test $path1]
44 if { $value == "xaxby1y2y3" } {
45 pass "$test recieved correct value: $value"
46 } else {
47 fail "$test received incorrect value: $value"
48 }
49
50 proc_write_value $test $path1 "zzz"
51 # make sure it got set to 'goodbye'
52 set value [proc_read_value $test $path1]
53 if { $value == "zzzazzzb" } {
54 pass "$test received correct value: $value"
55 } else {
56 fail "$test received incorrect value: $value"
57 }
58
59 return 0;
60 }
61
62 set systemtap_script {
63 global val
64
65 probe procfs.write {
66 val = $value . "a"
67 }
68
69 probe procfs.read {
70 $value = val
71 }
72
73 probe procfs.write {
74 val .= $value . "b"
75 }
76
77 probe procfs("test").write {
78 val .= $value . "1"
79 }
80
81 probe procfs("test").write {
82 val .= $value . "2"
83 }
84
85 probe procfs("test").write {
86 val .= $value . "3"
87 }
88
89 probe begin {
90 val = ""
91 printf("systemtap starting probe\n")
92 }
93
94 probe end {
95 printf("systemtap ending probe\n")
96 }
97 }
98
99 stap_run $test proc_read_write "" -e $systemtap_script -m $test
100
101 exec /bin/rm -f ${test}.ko