-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathcall_amd64_test.go
122 lines (114 loc) · 2.73 KB
/
call_amd64_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (c) 2012 The 'objc' Package Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package objc
import (
"testing"
"unsafe"
)
// todo(mkrautz): move to call_amd64.go?
const (
nint = 6
nfloat = 8
nregular = nint + nfloat
nstack = 5
)
func TestFrameFetcherNoStack(t *testing.T) {
frame := &amd64frame{
rdi: 0,
rsi: 1,
rdx: 2,
rcx: 3,
r8: 4,
r9: 5,
xmm0: 0,
xmm1: 1,
xmm2: 2,
xmm3: 3,
xmm4: 4,
xmm5: 5,
xmm6: 6,
xmm7: 7,
}
fetcher := frameFetcher(frame)
for i := 0; i < 6; i++ {
if val := fetcher.Int(); val != uintptr(i) {
t.Errorf("fetched int: got %v, expected %v", val, i)
}
}
for i := 0; i < 8; i++ {
if val := fetcher.Float(); val != uintptr(i) {
t.Errorf("fetched float: got %v, expected %v", val, i)
}
}
}
func TestFrameFetcherStack(t *testing.T) {
var buf [nregular + nstack]uintptr
for i := 0; i < nstack; i++ {
buf[nregular+i] = uintptr(i)
}
frame := (*amd64frame)(unsafe.Pointer(&buf))
fetcher := frameFetcher(frame)
for i := 0; i < nstack; i++ {
if val := fetcher.Stack(); val != uintptr(i) {
t.Errorf("fetched stack: got %v, expected %v", val, i)
}
}
}
func TestFrameFetcherStackIntFallback(t *testing.T) {
var buf [nregular + nstack]uintptr
for i := 0; i < nstack; i++ {
buf[nregular+i] = uintptr(i)
}
frame := (*amd64frame)(unsafe.Pointer(&buf))
fetcher := frameFetcher(frame)
for i := 0; i < nint; i++ {
_ = fetcher.Int()
}
for i := 0; i < nstack; i++ {
if val := fetcher.Int(); val != uintptr(i) {
t.Errorf("int stack fallback: got %v, expected %v", val, i)
}
}
}
func TestFrameFetcherStackFloatFallback(t *testing.T) {
var buf [nregular + nstack]uintptr
for i := 0; i < nstack; i++ {
buf[nregular+i] = uintptr(i)
}
frame := (*amd64frame)(unsafe.Pointer(&buf))
fetcher := frameFetcher(frame)
for i := 0; i < nfloat; i++ {
_ = fetcher.Float()
}
for i := 0; i < nstack; i++ {
if val := fetcher.Float(); val != uintptr(i) {
t.Errorf("float stack fallback: got %v, expected %v", val, i)
}
}
}
func TestFrameFetcherStackMixedFallback(t *testing.T) {
var buf [nregular + nstack]uintptr
for i := 0; i < nstack; i++ {
buf[nregular+i] = uintptr(i)
}
frame := (*amd64frame)(unsafe.Pointer(&buf))
fetcher := frameFetcher(frame)
for i := 0; i < nint; i++ {
_ = fetcher.Int()
}
for i := 0; i < nfloat; i++ {
_ = fetcher.Float()
}
for i := 0; i < nstack; i++ {
if i%2 == 0 {
if val := fetcher.Float(); val != uintptr(i) {
t.Errorf("mixed (float) stack fallback: got %v, expected %v", val, i)
}
} else {
if val := fetcher.Int(); val != uintptr(i) {
t.Errorf("mixed (int) stack fallback: got %v, expected %v", val, i)
}
}
}
}