Source file
src/runtime/traceback_test.go
1
2
3
4
5 package runtime_test
6
7 import (
8 "bytes"
9 "internal/goexperiment"
10 "internal/testenv"
11 "runtime"
12 "strings"
13 "testing"
14 )
15
16 var testTracebackArgsBuf [1000]byte
17
18 func TestTracebackArgs(t *testing.T) {
19 if *flagQuick {
20 t.Skip("-quick")
21 }
22 optimized := !strings.HasSuffix(testenv.Builder(), "-noopt")
23 abiSel := func(x, y string) string {
24
25
26 if optimized && goexperiment.RegabiArgs {
27 return x
28 }
29 return y
30 }
31
32 tests := []struct {
33 fn func() int
34 expect string
35 }{
36
37 {
38 func() int { return testTracebackArgs1(1, 2, 3, 4, 5) },
39 "testTracebackArgs1(0x1, 0x2, 0x3, 0x4, 0x5)",
40 },
41
42 {
43 func() int {
44 return testTracebackArgs2(false, struct {
45 a, b, c int
46 x [2]int
47 }{1, 2, 3, [2]int{4, 5}}, [0]int{}, [3]byte{6, 7, 8})
48 },
49 "testTracebackArgs2(0x0, {0x1, 0x2, 0x3, {0x4, 0x5}}, {}, {0x6, 0x7, 0x8})",
50 },
51 {
52 func() int { return testTracebackArgs3([3]byte{1, 2, 3}, 4, 5, 6, [3]byte{7, 8, 9}) },
53 "testTracebackArgs3({0x1, 0x2, 0x3}, 0x4, 0x5, 0x6, {0x7, 0x8, 0x9})",
54 },
55
56 {
57 func() int { return testTracebackArgs4(false, [1][1][1][1][1][1][1][1][1][1]int{}) },
58 "testTracebackArgs4(0x0, {{{{{...}}}}})",
59 },
60
61 {
62 func() int {
63 z := [0]int{}
64 return testTracebackArgs5(false, struct {
65 x int
66 y [0]int
67 z [2][0]int
68 }{1, z, [2][0]int{}}, z, z, z, z, z, z, z, z, z, z, z, z)
69 },
70 "testTracebackArgs5(0x0, {0x1, {}, {{}, {}}}, {}, {}, {}, {}, {}, ...)",
71 },
72
73
74
75 {
76 func() int { return testTracebackArgs6a(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) },
77 "testTracebackArgs6a(0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa)",
78 },
79
80 {
81 func() int { return testTracebackArgs6b(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) },
82 "testTracebackArgs6b(0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, ...)",
83 },
84
85 {
86 func() int { return testTracebackArgs7a([10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) },
87 "testTracebackArgs7a({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa})",
88 },
89
90 {
91 func() int { return testTracebackArgs7b([11]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}) },
92 "testTracebackArgs7b({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, ...})",
93 },
94
95 {
96 func() int { return testTracebackArgs7c([10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 11) },
97 "testTracebackArgs7c({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa}, ...)",
98 },
99
100 {
101 func() int { return testTracebackArgs7d([11]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 12) },
102 "testTracebackArgs7d({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, ...}, ...)",
103 },
104
105 {
106 func() int { return testTracebackArgs8a(testArgsType8a{1, 2, 3, 4, 5, 6, 7, 8, [2]int{9, 10}}) },
107 "testTracebackArgs8a({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, {0x9, 0xa}})",
108 },
109
110 {
111 func() int { return testTracebackArgs8b(testArgsType8b{1, 2, 3, 4, 5, 6, 7, 8, [3]int{9, 10, 11}}) },
112 "testTracebackArgs8b({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, {0x9, 0xa, ...}})",
113 },
114
115 {
116 func() int { return testTracebackArgs8c(testArgsType8c{1, 2, 3, 4, 5, 6, 7, 8, [2]int{9, 10}, 11}) },
117 "testTracebackArgs8c({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, {0x9, 0xa}, ...})",
118 },
119
120 {
121 func() int { return testTracebackArgs8d(testArgsType8d{1, 2, 3, 4, 5, 6, 7, 8, [3]int{9, 10, 11}, 12}) },
122 "testTracebackArgs8d({0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, {0x9, 0xa, ...}, ...})",
123 },
124
125
126
127
128 {
129 func() int {
130 poisonStack()
131 return testTracebackArgs9(1, 2, 3, 4, [2]int{5, 6}, 7)
132 },
133 abiSel(
134 "testTracebackArgs9(0x1, 0xffffffff?, 0x3, 0xff?, {0x5, 0x6}, 0x7)",
135 "testTracebackArgs9(0x1, 0x2, 0x3, 0x4, {0x5, 0x6}, 0x7)"),
136 },
137
138
139 {
140 func() int {
141 poisonStack()
142 return testTracebackArgs10(1, 2, 3, 4, 5)
143 },
144 abiSel(
145 "testTracebackArgs10(0xffffffff?, 0xffffffff?, 0xffffffff?, 0xffffffff?, 0xffffffff?)",
146 "testTracebackArgs10(0x1, 0x2, 0x3, 0x4, 0x5)"),
147 },
148
149
150 {
151 func() int {
152 poisonStack()
153 return testTracebackArgs11a(1, 2, 3)
154 },
155 abiSel(
156 "testTracebackArgs11a(0xffffffff?, 0xffffffff?, 0xffffffff?)",
157 "testTracebackArgs11a(0x1, 0x2, 0x3)"),
158 },
159
160
161 {
162 func() int {
163 poisonStack()
164 return testTracebackArgs11b(1, 2, 3, 4)
165 },
166 abiSel(
167 "testTracebackArgs11b(0xffffffff?, 0xffffffff?, 0x3?, 0x4)",
168 "testTracebackArgs11b(0x1, 0x2, 0x3, 0x4)"),
169 },
170 }
171 for _, test := range tests {
172 n := test.fn()
173 got := testTracebackArgsBuf[:n]
174 if !bytes.Contains(got, []byte(test.expect)) {
175 t.Errorf("traceback does not contain expected string: want %q, got\n%s", test.expect, got)
176 }
177 }
178 }
179
180
181 func testTracebackArgs1(a, b, c, d, e int) int {
182 n := runtime.Stack(testTracebackArgsBuf[:], false)
183 if a < 0 {
184
185 return a + b + c + d + e
186 }
187 return n
188 }
189
190
191 func testTracebackArgs2(a bool, b struct {
192 a, b, c int
193 x [2]int
194 }, _ [0]int, d [3]byte) int {
195 n := runtime.Stack(testTracebackArgsBuf[:], false)
196 if a {
197
198 return b.a + b.b + b.c + b.x[0] + b.x[1] + int(d[0]) + int(d[1]) + int(d[2])
199 }
200 return n
201
202 }
203
204
205
206 func testTracebackArgs3(x [3]byte, a, b, c int, y [3]byte) int {
207 n := runtime.Stack(testTracebackArgsBuf[:], false)
208 if a < 0 {
209
210 return int(x[0]) + int(x[1]) + int(x[2]) + a + b + c + int(y[0]) + int(y[1]) + int(y[2])
211 }
212 return n
213 }
214
215
216 func testTracebackArgs4(a bool, x [1][1][1][1][1][1][1][1][1][1]int) int {
217 n := runtime.Stack(testTracebackArgsBuf[:], false)
218 if a {
219 panic(x)
220 }
221 return n
222 }
223
224
225 func testTracebackArgs5(a bool, x struct {
226 x int
227 y [0]int
228 z [2][0]int
229 }, _, _, _, _, _, _, _, _, _, _, _, _ [0]int) int {
230 n := runtime.Stack(testTracebackArgsBuf[:], false)
231 if a {
232 panic(x)
233 }
234 return n
235 }
236
237
238 func testTracebackArgs6a(a, b, c, d, e, f, g, h, i, j int) int {
239 n := runtime.Stack(testTracebackArgsBuf[:], false)
240 if a < 0 {
241
242 return a + b + c + d + e + f + g + h + i + j
243 }
244 return n
245 }
246
247
248 func testTracebackArgs6b(a, b, c, d, e, f, g, h, i, j, k int) int {
249 n := runtime.Stack(testTracebackArgsBuf[:], false)
250 if a < 0 {
251
252 return a + b + c + d + e + f + g + h + i + j + k
253 }
254 return n
255 }
256
257
258 func testTracebackArgs7a(a [10]int) int {
259 n := runtime.Stack(testTracebackArgsBuf[:], false)
260 if a[0] < 0 {
261
262 return a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9]
263 }
264 return n
265 }
266
267
268 func testTracebackArgs7b(a [11]int) int {
269 n := runtime.Stack(testTracebackArgsBuf[:], false)
270 if a[0] < 0 {
271
272 return a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9] + a[10]
273 }
274 return n
275 }
276
277
278 func testTracebackArgs7c(a [10]int, b int) int {
279 n := runtime.Stack(testTracebackArgsBuf[:], false)
280 if a[0] < 0 {
281
282 return a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9] + b
283 }
284 return n
285 }
286
287
288 func testTracebackArgs7d(a [11]int, b int) int {
289 n := runtime.Stack(testTracebackArgsBuf[:], false)
290 if a[0] < 0 {
291
292 return a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9] + a[10] + b
293 }
294 return n
295 }
296
297 type testArgsType8a struct {
298 a, b, c, d, e, f, g, h int
299 i [2]int
300 }
301 type testArgsType8b struct {
302 a, b, c, d, e, f, g, h int
303 i [3]int
304 }
305 type testArgsType8c struct {
306 a, b, c, d, e, f, g, h int
307 i [2]int
308 j int
309 }
310 type testArgsType8d struct {
311 a, b, c, d, e, f, g, h int
312 i [3]int
313 j int
314 }
315
316
317 func testTracebackArgs8a(a testArgsType8a) int {
318 n := runtime.Stack(testTracebackArgsBuf[:], false)
319 if a.a < 0 {
320
321 return a.b + a.c + a.d + a.e + a.f + a.g + a.h + a.i[0] + a.i[1]
322 }
323 return n
324 }
325
326
327 func testTracebackArgs8b(a testArgsType8b) int {
328 n := runtime.Stack(testTracebackArgsBuf[:], false)
329 if a.a < 0 {
330
331 return a.b + a.c + a.d + a.e + a.f + a.g + a.h + a.i[0] + a.i[1] + a.i[2]
332 }
333 return n
334 }
335
336
337 func testTracebackArgs8c(a testArgsType8c) int {
338 n := runtime.Stack(testTracebackArgsBuf[:], false)
339 if a.a < 0 {
340
341 return a.b + a.c + a.d + a.e + a.f + a.g + a.h + a.i[0] + a.i[1] + a.j
342 }
343 return n
344 }
345
346
347 func testTracebackArgs8d(a testArgsType8d) int {
348 n := runtime.Stack(testTracebackArgsBuf[:], false)
349 if a.a < 0 {
350
351 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
352 }
353 return n
354 }
355
356
357
358
359
360 func testTracebackArgs9(a int64, b int32, c int16, d int8, x [2]int, y int) int {
361 if a < 0 {
362 println(&y)
363 }
364 n := runtime.Stack(testTracebackArgsBuf[:], false)
365 if a < 0 {
366
367 return int(a) + int(c)
368 }
369 return n
370 }
371
372
373
374
375
376 func testTracebackArgs10(a, b, c, d, e int32) int {
377
378 return runtime.Stack(testTracebackArgsBuf[:], false)
379 }
380
381
382
383
384
385
386
387 func testTracebackArgs11a(a, b, c int32) int {
388 if a < 0 {
389 println(a, b, c)
390 }
391 if b < 0 {
392 return int(a + b + c)
393 }
394 return runtime.Stack(testTracebackArgsBuf[:], false)
395 }
396
397
398
399
400
401
402
403 func testTracebackArgs11b(a, b, c, d int32) int {
404 var x int32
405 if a < 0 {
406 print()
407 x = b
408 } else {
409 print()
410 x = c
411 }
412 if d < 0 {
413 return int(x + d)
414 }
415 return runtime.Stack(testTracebackArgsBuf[:], false)
416 }
417
418
419
420
421 func poisonStack() [20]int {
422 return [20]int{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
423 }
424
View as plain text