-
Notifications
You must be signed in to change notification settings - Fork 71
/
VMFFIWorkerCalloutTest.class.st
147 lines (110 loc) · 4.13 KB
/
VMFFIWorkerCalloutTest.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
Class {
#name : #VMFFIWorkerCalloutTest,
#superclass : #VMAbstractFFITest,
#instVars : [
'aFunctionBlock',
'tfExternalFunction',
'parametersArray',
'worker',
'workerOop',
'semaphoreIndex'
],
#category : #VMMakerTests
}
{ #category : #tests }
VMFFIWorkerCalloutTest >> doWorkerCallWithArguments: smalltalkValues ofTypes: argumentTypes [
^ self doWorkerCallWithArguments: smalltalkValues ofTypes: argumentTypes returnType: interpreter libFFI void
]
{ #category : #tests }
VMFFIWorkerCalloutTest >> doWorkerCallWithArguments: smalltalkValues ofTypes: argumentTypes returnType: returnType [
aFunctionBlock := [ self fail: 'It should enqueue it, not execute it' ].
tfExternalFunction := self
createExternalFunctionFor: aFunctionBlock
withArgumentTypes: argumentTypes
withReturnType: returnType.
parametersArray := self newArrayWith: smalltalkValues.
worker := interpreter libFFI testWorker.
workerOop := self newObjectWithSlots: 1.
memory
storePointer: 0
ofObject: workerOop
withValue: (self newExternalAddress: worker asInteger).
semaphoreIndex := 99.
interpreter push: workerOop.
interpreter push: tfExternalFunction.
interpreter push: parametersArray.
interpreter push: semaphoreIndex.
interpreter argumentCount: 4.
interpreter primitiveWorkerCallout
]
{ #category : #tests }
VMFFIWorkerCalloutTest >> initializationOptions [
^ super initializationOptions , {
#FEATURE_THREADED_FFI . true }
]
{ #category : #tests }
VMFFIWorkerCalloutTest >> testPrimitiveWorkerCalloutEnqueuesOnlyOneTask [
self doWorkerCallWithArguments: {} ofTypes: {}.
self assert: interpreter libFFI testWorker tasks size equals: 1
]
{ #category : #tests }
VMFFIWorkerCalloutTest >> testPrimitiveWorkerCalloutReleasesAllAllocatedMemoryIfPrimitiveFails [
| previous |
previous := interpreter allocatedElements size.
self doWorkerCallWithArguments: {
memory floatObjectOf: 1.0.
memory floatObjectOf: 2.0.
memory integerObjectOf: 3.
memory integerObjectOf: 4.
memory floatObjectOf: 5.0 } ofTypes: {
interpreter libFFI float.
interpreter libFFI double.
interpreter libFFI uint32.
interpreter libFFI sint8.
interpreter libFFI sint8 }
returnType: interpreter libFFI sint32.
self assert: interpreter failed.
self assert: interpreter allocatedElements size equals: previous.
]
{ #category : #tests }
VMFFIWorkerCalloutTest >> testPrimitiveWorkerCalloutReturningVoidDoesNotAllocateReturnHolder [
self doWorkerCallWithArguments: {} ofTypes: {}.
self assert: interpreter libFFI testWorker tasks first returnHolderAddress isNil
]
{ #category : #tests }
VMFFIWorkerCalloutTest >> testPrimitiveWorkerCalloutWithParametersAllocatesArgumentHoldersAndReturnHolderInCHeap [
| previous |
previous := interpreter allocatedElements size.
self doWorkerCallWithArguments: {
memory floatObjectOf: 1.0.
memory floatObjectOf: 2.0.
memory integerObjectOf: 3.
memory integerObjectOf: 4.
self newExternalAddress: 5 } ofTypes: {
interpreter libFFI float.
interpreter libFFI double.
interpreter libFFI uint32.
interpreter libFFI sint8.
interpreter libFFI pointer }
returnType: interpreter libFFI sint32.
self assert: interpreter allocatedElements size equals: previous + 7.
]
{ #category : #tests }
VMFFIWorkerCalloutTest >> testPrimitiveWorkerCalloutWithoutParametersAndWithReturnAllocateJustOne [
| previous |
previous := interpreter allocatedElements size.
self doWorkerCallWithArguments: {} ofTypes: {} returnType: interpreter libFFI sint32.
self assert: interpreter allocatedElements size equals: previous + 1.
]
{ #category : #tests }
VMFFIWorkerCalloutTest >> testPrimitiveWorkerCalloutWithoutParametersAndWithoutReturnDoesNotAllocate [
| previous |
previous := interpreter allocatedElements size.
self doWorkerCallWithArguments: {} ofTypes: {}.
self assert: interpreter allocatedElements size equals: previous.
]
{ #category : #tests }
VMFFIWorkerCalloutTest >> testPrimitiveWorkerCalloutWithoutParametersHasNilAsParametersPointer [
self doWorkerCallWithArguments: {} ofTypes: {}.
self assert: interpreter libFFI testWorker tasks first parametersAddress isNil
]