Source file
src/runtime/traceback_test.go
Documentation: runtime
1
2
3
4
5 package runtime_test
6
7 import (
8 "bytes"
9 "runtime"
10 "testing"
11 )
12
13 var testTracebackArgsBuf [1000]byte
14
15 func TestTracebackArgs(t *testing.T) {
16 tests := []struct {
17 fn func() int
18 expect string
19 }{
20
21 {
22 func() int { return testTracebackArgs1(1, 2, 3, 4, 5) },
23 "testTracebackArgs1(0x1, 0x2, 0x3, 0x4, 0x5)",
24 },
25
26 {
27 func() int {
28 return testTracebackArgs2(false, struct {
29 a, b, c int
30 x [2]int
31 }{1, 2, 3, [2]int{4, 5}}, [0]int{}, [3]byte{6, 7, 8})
32 },
33 "testTracebackArgs2(0x0, {0x1, 0x2, 0x3, {0x4, 0x5}}, {}, {0x6, 0x7, 0x8})",
34 },
35 {
36 func() int { return testTracebackArgs3([3]byte{1, 2, 3}, 4, 5, 6, [3]byte{7, 8, 9}) },
37 "testTracebackArgs3({0x1, 0x2, 0x3}, 0x4, 0x5, 0x6, {0x7, 0x8, 0x9})",
38 },
39
40 {
41 func() int { return testTracebackArgs4(false, [1][1][1][1][1][1][1][1][1][1]int{}) },
42 "testTracebackArgs4(0x0, {{{{{...}}}}})",
43 },
44
45 {
46 func() int {
47 z := [0]int{}
48 return testTracebackArgs5(false, struct {
49 x int
50 y [0]int
51 z [2][0]int
52 }{1, z, [2][0]int{}}, z, z, z, z, z, z, z, z, z, z, z, z)
53 },
54 "testTracebackArgs5(0x0, {0x1, {}, {{}, {}}}, {}, {}, {}, {}, {}, ...)",
55 },
56
57
58
59 {
60 func() int { return testTracebackArgs6a(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) },
61 "testTracebackArgs6a(0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa)",
62 },
63
64 {
65 func() int { return testTracebackArgs6b(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) },
66 "testTracebackArgs6b(0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, ...)",
67 },
68
69 {
70 func() int { return testTracebackArgs7a([10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) },
71 "testTracebackArgs7a({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa})",
72 },
73
74 {
75 func() int { return testTracebackArgs7b([11]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}) },
76 "testTracebackArgs7b({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, ...})",
77 },
78
79 {
80 func() int { return testTracebackArgs7c([10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 11) },
81 "testTracebackArgs7c({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa}, ...)",
82 },
83
84 {
85 func() int { return testTracebackArgs7d([11]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 12) },
86 "testTracebackArgs7d({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, ...}, ...)",
87 },
88
89 {
90 func() int { return testTracebackArgs8a(testArgsType8a{1, 2, 3, 4, 5, 6, 7, 8, [2]int{9, 10}}) },
91 "testTracebackArgs8a({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, {0x9, 0xa}})",
92 },
93
94 {
95 func() int { return testTracebackArgs8b(testArgsType8b{1, 2, 3, 4, 5, 6, 7, 8, [3]int{9, 10, 11}}) },
96 "testTracebackArgs8b({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, {0x9, 0xa, ...}})",
97 },
98
99 {
100 func() int { return testTracebackArgs8c(testArgsType8c{1, 2, 3, 4, 5, 6, 7, 8, [2]int{9, 10}, 11}) },
101 "testTracebackArgs8c({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, {0x9, 0xa}, ...})",
102 },
103
104 {
105 func() int { return testTracebackArgs8d(testArgsType8d{1, 2, 3, 4, 5, 6, 7, 8, [3]int{9, 10, 11}, 12}) },
106 "testTracebackArgs8d({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, {0x9, 0xa, ...}, ...})",
107 },
108 }
109 for _, test := range tests {
110 n := test.fn()
111 got := testTracebackArgsBuf[:n]
112 if !bytes.Contains(got, []byte(test.expect)) {
113 t.Errorf("traceback does not contain expected string: want %q, got\n%s", test.expect, got)
114 }
115 }
116 }
117
118
119 func testTracebackArgs1(a, b, c, d, e int) int {
120 n := runtime.Stack(testTracebackArgsBuf[:], false)
121 if a < 0 {
122
123 return a + b + c + d + e
124 }
125 return n
126 }
127
128
129 func testTracebackArgs2(a bool, b struct {
130 a, b, c int
131 x [2]int
132 }, _ [0]int, d [3]byte) int {
133 n := runtime.Stack(testTracebackArgsBuf[:], false)
134 if a {
135
136 return b.a + b.b + b.c + b.x[0] + b.x[1] + int(d[0]) + int(d[1]) + int(d[2])
137 }
138 return n
139
140 }
141
142
143
144 func testTracebackArgs3(x [3]byte, a, b, c int, y [3]byte) int {
145 n := runtime.Stack(testTracebackArgsBuf[:], false)
146 if a < 0 {
147
148 return int(x[0]) + int(x[1]) + int(x[2]) + a + b + c + int(y[0]) + int(y[1]) + int(y[2])
149 }
150 return n
151 }
152
153
154 func testTracebackArgs4(a bool, x [1][1][1][1][1][1][1][1][1][1]int) int {
155 n := runtime.Stack(testTracebackArgsBuf[:], false)
156 if a {
157 panic(x)
158 }
159 return n
160 }
161
162
163 func testTracebackArgs5(a bool, x struct {
164 x int
165 y [0]int
166 z [2][0]int
167 }, _, _, _, _, _, _, _, _, _, _, _, _ [0]int) int {
168 n := runtime.Stack(testTracebackArgsBuf[:], false)
169 if a {
170 panic(x)
171 }
172 return n
173 }
174
175
176 func testTracebackArgs6a(a, b, c, d, e, f, g, h, i, j int) int {
177 n := runtime.Stack(testTracebackArgsBuf[:], false)
178 if a < 0 {
179
180 return a + b + c + d + e + f + g + h + i + j
181 }
182 return n
183 }
184
185
186 func testTracebackArgs6b(a, b, c, d, e, f, g, h, i, j, k int) int {
187 n := runtime.Stack(testTracebackArgsBuf[:], false)
188 if a < 0 {
189
190 return a + b + c + d + e + f + g + h + i + j + k
191 }
192 return n
193 }
194
195
196 func testTracebackArgs7a(a [10]int) int {
197 n := runtime.Stack(testTracebackArgsBuf[:], false)
198 if a[0] < 0 {
199
200 return a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9]
201 }
202 return n
203 }
204
205
206 func testTracebackArgs7b(a [11]int) int {
207 n := runtime.Stack(testTracebackArgsBuf[:], false)
208 if a[0] < 0 {
209
210 return a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9] + a[10]
211 }
212 return n
213 }
214
215
216 func testTracebackArgs7c(a [10]int, b int) int {
217 n := runtime.Stack(testTracebackArgsBuf[:], false)
218 if a[0] < 0 {
219
220 return a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9] + b
221 }
222 return n
223 }
224
225
226 func testTracebackArgs7d(a [11]int, b int) int {
227 n := runtime.Stack(testTracebackArgsBuf[:], false)
228 if a[0] < 0 {
229
230 return a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9] + a[10] + b
231 }
232 return n
233 }
234
235 type testArgsType8a struct {
236 a, b, c, d, e, f, g, h int
237 i [2]int
238 }
239 type testArgsType8b struct {
240 a, b, c, d, e, f, g, h int
241 i [3]int
242 }
243 type testArgsType8c struct {
244 a, b, c, d, e, f, g, h int
245 i [2]int
246 j int
247 }
248 type testArgsType8d struct {
249 a, b, c, d, e, f, g, h int
250 i [3]int
251 j int
252 }
253
254
255 func testTracebackArgs8a(a testArgsType8a) int {
256 n := runtime.Stack(testTracebackArgsBuf[:], false)
257 if a.a < 0 {
258
259 return a.b + a.c + a.d + a.e + a.f + a.g + a.h + a.i[0] + a.i[1]
260 }
261 return n
262 }
263
264
265 func testTracebackArgs8b(a testArgsType8b) int {
266 n := runtime.Stack(testTracebackArgsBuf[:], false)
267 if a.a < 0 {
268
269 return a.b + a.c + a.d + a.e + a.f + a.g + a.h + a.i[0] + a.i[1] + a.i[2]
270 }
271 return n
272 }
273
274
275 func testTracebackArgs8c(a testArgsType8c) int {
276 n := runtime.Stack(testTracebackArgsBuf[:], false)
277 if a.a < 0 {
278
279 return a.b + a.c + a.d + a.e + a.f + a.g + a.h + a.i[0] + a.i[1] + a.j
280 }
281 return n
282 }
283
284
285 func testTracebackArgs8d(a testArgsType8d) int {
286 n := runtime.Stack(testTracebackArgsBuf[:], false)
287 if a.a < 0 {
288
289 return a.b + a.c + a.d + a.e + a.f + a.g + a.h + a.i[0] + a.i[1] + a.i[2] + a.j
290 }
291 return n
292 }
293
View as plain text