-
Notifications
You must be signed in to change notification settings - Fork 67
/
VMFFISameThreadArgumentMarshallingTest.class.st
72 lines (52 loc) · 2.32 KB
/
VMFFISameThreadArgumentMarshallingTest.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
Class {
#name : #VMFFISameThreadArgumentMarshallingTest,
#superclass : #VMFFIArgumentMarshallingTest,
#category : #VMMakerTests
}
{ #category : #implementation }
VMFFISameThreadArgumentMarshallingTest >> doTestFuntionWithArgumentType: argumentType smalltalkValue: smalltalkValue expectedValue: expectedValue [
| parametersArray tfExternalFunction savedValue |
tfExternalFunction := self
createExternalFunctionFor: [ :anArgument | savedValue := anArgument ]
withArgumentTypes: { argumentType }
withReturnType: interpreter libFFI void.
parametersArray := self newArrayWithSlots: 1.
memory storePointer: 0 ofObject: parametersArray withValue: smalltalkValue.
interpreter push: memory nilObject.
interpreter push: tfExternalFunction.
interpreter push: parametersArray.
interpreter argumentCount: 2.
interpreter primitiveSameThreadCallout.
self deny: interpreter failed.
self assert: savedValue equals: expectedValue.
]
{ #category : #implementation }
VMFFISameThreadArgumentMarshallingTest >> doTestFuntionWithArgumentType: argumentType smalltalkValue: smalltalkValue failsWith: expectedErrorCode [
| parametersArray tfExternalFunction savedValue |
tfExternalFunction := self
createExternalFunctionFor: [ :anArgument | savedValue := anArgument ]
withArgumentTypes: { argumentType }
withReturnType: interpreter libFFI void.
parametersArray := self newArrayWithSlots: 1.
memory storePointer: 0 ofObject: parametersArray withValue: smalltalkValue.
interpreter push: memory nilObject.
interpreter push: tfExternalFunction.
interpreter push: parametersArray.
interpreter argumentCount: 2.
interpreter primitiveSameThreadCallout.
self assert: interpreter failed.
self assert: interpreter primFailCode equals: expectedErrorCode.
]
{ #category : #'tests - parameters marshalling' }
VMFFISameThreadArgumentMarshallingTest >> testCalloutWithoutArgumentsMarshallsCorrectly [
| parametersArray tfExternalFunction functionCalled |
functionCalled := false.
tfExternalFunction := self createReturnFloatExternalFunctionFor: [ functionCalled := true. 7.0 ].
parametersArray := self newArrayWithSlots: 0.
interpreter push: memory nilObject.
interpreter push: tfExternalFunction.
interpreter push: parametersArray.
interpreter argumentCount: 2.
interpreter primitiveSameThreadCallout.
self assert: functionCalled.
]