Debian Codegraph @

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

raw
1 set test "atomic"
2
3 if {![installtest_p]} {untested $test; return}
4
5 #
6 # First test atomic_long_read()
7 #
8
9 set script_template {
10 probe begin {
11 print("systemtap starting probe\n")
12 exit()
13 }
14
15 probe end {
16 print("systemtap ending probe\n")
17 printf("%%d\n", %s_read(%s))
18 }
19 }
20
21 # First try reading from address 0, which should fail.
22 set test "atomic1"
23 set error {read fault .* at 0x[^\r]+}
24 set script [format $script_template "atomic_long" "0"]
25 # s390x machines don't error when reading address 0
26 if {[istarget s390x-*-*]} { setup_kfail S390X [istarget] }
27 stap_run_error $test 1 $error "0\r\n" -e $script
28
29 # Try reading from address -1 (top of memory), which should fail.
30 set test "atomic2"
31 set script [format $script_template "atomic_long" "-1"]
32 stap_run_error $test 1 $error "0\r\n" -e $script
33
34 # Try reading from address 3, which should fail (if nothing else
35 # because it isn't aligned properly).
36 set test "atomic3"
37 set script [format $script_template "atomic_long" "3"]
38 # s390x machines don't error when reading address 3
39 if {[istarget s390x-*-*]} { setup_kfail S390X [istarget] }
40 stap_run_error $test 1 $error "0\r\n" -e $script
41
42 # Since we want to fail semi-gracefully (no compile errors), if we
43 # don't have atomic_long_t support on this kernel (no
44 # ATOMIC_LONG_INIT) the testcase will compile, but fail.
45
46 set atomic_long_script_module_template {
47 %%{
48 #include <asm/atomic.h>
49 #ifdef ATOMIC_LONG_INIT
50 struct {
51 ulong barrier1;
52 atomic_long_t a;
53 ulong barrier2;
54 } stp_atomic_struct = { ULONG_MAX, ATOMIC_LONG_INIT(5), ULONG_MAX };
55 #else
56 struct {
57 ulong barrier1;
58 long a;
59 ulong barrier2;
60 } stp_atomic_struct = { ULONG_MAX, 5, ULONG_MAX };
61 #endif
62 %%}
63
64 function get_atomic_long_addr:long()
65 %%{
66 STAP_RETVALUE = (long)&stp_atomic_struct.a;
67 %%}
68
69 probe begin {
70 print("systemtap starting probe\n")
71 exit()
72 }
73
74 probe end {
75 print("systemtap ending probe\n")
76 printf("%%d\n", atomic_long_read(get_atomic_long_addr() + %s))
77 }
78 }
79
80 set test "atomic4"
81 set script [format $atomic_long_script_module_template "0"]
82 stap_run_error $test 0 $error "5\r\n" -ge $script
83
84 # We should be able to check for trying to read the atomic_long_t with
85 # bad alignment here, but it succeeds on {x86, x86_64} and fails on
86 # ia64. Since it doesn't fail consistently, we'll comment this out.
87 #set test "atomic5"
88 #set script [format $atomic_long_script_module_template "3"]
89 #stap_run_error $test 1 $error "" -ge $script
90
91 #
92 # Now test atomic_read()
93 #
94
95 # First try reading from address 0, which should fail.
96 set test "atomic5"
97 set error {read fault .* at 0x[^\r]+}
98 set script [format $script_template "atomic" "0"]
99 # s390x machines don't error when reading address 0
100 if {[istarget s390x-*-*]} { setup_kfail S390X [istarget] }
101 stap_run_error $test 1 $error "0\r\n" -e $script
102
103 # Try reading from address -1 (top of memory), which should fail.
104 set test "atomic6"
105 set script [format $script_template "atomic" "-1"]
106 stap_run_error $test 1 $error "0\r\n" -e $script
107
108 # Try reading from address 3, which should fail (if nothing else
109 # because it isn't aligned properly).
110 set test "atomic7"
111 set script [format $script_template "atomic" "3"]
112 # s390x machines don't error when reading address 3
113 if {[istarget s390x-*-*]} { setup_kfail S390X [istarget] }
114 stap_run_error $test 1 $error "0\r\n" -e $script
115
116 set atomic_script_module_template {
117 %%{
118 #include <asm/atomic.h>
119 struct {
120 ulong barrier1;
121 atomic_t a;
122 ulong barrier2;
123 } stp_atomic_struct = { ULONG_MAX, ATOMIC_INIT(5), ULONG_MAX };
124 %%}
125
126 function get_atomic_addr:long()
127 %%{
128 STAP_RETVALUE = (long)&stp_atomic_struct.a;
129 %%}
130
131 probe begin {
132 print("systemtap starting probe\n")
133 exit()
134 }
135
136 probe end {
137 print("systemtap ending probe\n")
138 printf("%%d\n", atomic_read(get_atomic_addr() + %s))
139 }
140 }
141
142 set test "atomic8"
143 set script [format $atomic_script_module_template "0"]
144 stap_run_error $test 0 $error "5\r\n" -ge $script
145
146 # We should be able to check for trying to read the atomic_t with
147 # bad alignment here, but it succeeds on {x86, x86_64} and fails on
148 # ia64. Since it doesn't fail consistently, we'll comment this out.
149 #set test "atomic9"
150 #set script [format $atomic_script_module_template "3"]
151 #stap_run_error $test 1 $error "" -ge $script