-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMFFIReturnMarshallingTest.class.st
235 lines (180 loc) · 7.19 KB
/
VMFFIReturnMarshallingTest.class.st
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
Class {
#name : #VMFFIReturnMarshallingTest,
#superclass : #VMAbstractFFITest,
#category : #VMMakerTests
}
{ #category : #private }
VMFFIReturnMarshallingTest class >> isAbstract [
^ self = VMFFIReturnMarshallingTest
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> doTestCalloutWithReturnType: aLibFFIType returnValue: valueToReturn asserting: aBlock [
self subclassResponsibility
]
{ #category : #utils }
VMFFIReturnMarshallingTest >> doTestCalloutWithReturnType: aLibFFIType returnValue: valueToReturn expectedLargeIntegerValue: expectedValue [
self
doTestCalloutWithReturnType: aLibFFIType
returnValue: valueToReturn
asserting: [
self assert: interpreter primFailCode equals: 0.
expectedValue > 0
ifTrue: [self
assert: (memory classIndexOf: interpreter stackTop)
equals: ClassLargePositiveIntegerCompactIndex]
ifFalse: [self
assert: (memory classIndexOf: interpreter stackTop)
equals: ClassLargeNegativeIntegerCompactIndex ].
self assert: (interpreter signed64BitValueOf: interpreter stackTop) equals: expectedValue ].
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> doTestCalloutWithReturnType: aLibFFIType returnValue: valueToReturn expectedSmalltalkValue: expectedValue [
self
doTestCalloutWithReturnType: aLibFFIType
returnValue: valueToReturn
asserting: [
self assert: interpreter primFailCode equals: 0.
self assert: (memory integerValueOf: interpreter stackTop) <= memory maxSmallInteger.
self assert: (memory integerValueOf: interpreter stackTop) >= memory minSmallInteger.
self assert: (memory integerValueOf: interpreter stackTop) equals: expectedValue ].
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningAnStructPushesAByteArray [
| valueToReturn |
valueToReturn := ByteArray new: 16.
valueToReturn doubleAt: 1 put: 1.0.
valueToReturn doubleAt: 9 put: 2.0.
self
doTestCalloutWithReturnType: (interpreter libFFI structWith: {interpreter libFFI double. interpreter libFFI double.})
returnValue: valueToReturn asserting: [ | content |
self assert: interpreter primFailCode equals: 0.
self assert: (memory fetchClassOfNonImm: interpreter stackTop) equals: memory classByteArray.
self assert: (memory numBytesOf: interpreter stackTop) equals: 16.
content := memory cCoerce: (memory firstIndexableField: interpreter stackTop) to: #'double *'.
self assert: (content at: 0) equals: 1.0.
self assert: (content at: 1) equals: 2.0].
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningDoublePushSmallFloatInStack [
self
doTestCalloutWithReturnType: interpreter libFFI double
returnValue: 7.0
asserting: [
self assert: interpreter primFailCode equals: 0.
self assert: (memory floatValueOf: interpreter stackTop) equals: 7.0 ].
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningFloatPushSmallFloatInStack [
self
doTestCalloutWithReturnType: interpreter libFFI float
returnValue: 7.0
asserting: [
self assert: interpreter primFailCode equals: 0.
self assert: (memory floatValueOf: interpreter stackTop) equals: 7.0 ].
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningPointerPushesAnExternalAddress [
self
doTestCalloutWithReturnType: interpreter libFFI pointer
returnValue: 17
asserting: [
self assert: interpreter primFailCode equals: 0.
self assert: (memory fetchClassOfNonImm: interpreter stackTop) equals: memory classExternalAddress.
self assert: (interpreter readAddress: interpreter stackTop) equals: 17].
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningSINT16PushSmallInteger [
self
doTestCalloutWithReturnType: interpreter libFFI sint16
returnValue: INT16_MAX - 1
expectedSmalltalkValue: INT16_MAX - 1
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningSINT32PushLargeInteger [
| value |
value := wordSize = 8 ifTrue: [ ^ self skip ].
self
doTestCalloutWithReturnType: interpreter libFFI sint32
returnValue: INT32_MAX - 1
expectedLargeIntegerValue: INT32_MAX - 1
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningSINT32PushSmallInteger [
| value |
value := wordSize = 8
ifTrue: [ INT32_MAX - 1 ]
ifFalse: [ memory maxSmallInteger ].
self
doTestCalloutWithReturnType: interpreter libFFI sint32
returnValue: value
expectedSmalltalkValue: value
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningSINT64PushLargeInteger [
self
doTestCalloutWithReturnType: interpreter libFFI sint64
returnValue: INT64_MAX - 1
expectedLargeIntegerValue: INT64_MAX - 1
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningSINT64PushSmallInteger [
self
doTestCalloutWithReturnType: interpreter libFFI sint64
returnValue: memory maxSmallInteger
expectedSmalltalkValue: memory maxSmallInteger
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningSINT8PushSmallInteger [
self
doTestCalloutWithReturnType: interpreter libFFI sint8
returnValue: INT8_MAX - 1
expectedSmalltalkValue: INT8_MAX - 1
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningUINT16PushSmallInteger [
self
doTestCalloutWithReturnType: interpreter libFFI uint16
returnValue: INT16_MAX - 1
expectedSmalltalkValue: INT16_MAX - 1
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningUINT32PushLargeInteger [
| value |
value := wordSize = 8 ifTrue: [ ^ self skip ].
self
doTestCalloutWithReturnType: interpreter libFFI uint32
returnValue: INT32_MAX - 1
expectedLargeIntegerValue: INT32_MAX - 1
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningUINT32PushSmallInteger [
| value |
value := wordSize = 8
ifTrue: [ INT32_MAX - 1 ]
ifFalse: [ memory maxSmallInteger ].
self
doTestCalloutWithReturnType: interpreter libFFI uint32
returnValue: value
expectedSmalltalkValue: value
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningUINT64PushLargeInteger [
self
doTestCalloutWithReturnType: interpreter libFFI uint64
returnValue: INT64_MAX
expectedLargeIntegerValue: INT64_MAX
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningUINT64PushSmallInteger [
self
doTestCalloutWithReturnType: interpreter libFFI uint64
returnValue: memory maxSmallInteger
expectedSmalltalkValue: memory maxSmallInteger
]
{ #category : #'tests - marshalling return' }
VMFFIReturnMarshallingTest >> testPrimitiveCalloutReturningUINT8PushSmallInteger [
self
doTestCalloutWithReturnType: interpreter libFFI uint8
returnValue: INT8_MAX - 1
expectedSmalltalkValue: INT8_MAX - 1
]