-
Notifications
You must be signed in to change notification settings - Fork 67
/
VMFFIWorkerArgumentMarshallingTest.class.st
131 lines (96 loc) · 3.6 KB
/
VMFFIWorkerArgumentMarshallingTest.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
Class {
#name : #VMFFIWorkerArgumentMarshallingTest,
#superclass : #VMFFIArgumentMarshallingTest,
#instVars : [
'aFunctionBlock',
'tfExternalFunction',
'parametersArray',
'worker',
'workerOop',
'semaphoreIndex',
'task',
'savedValue'
],
#category : #VMMakerTests
}
{ #category : #implementation }
VMFFIWorkerArgumentMarshallingTest >> doTestFuntionWithArgumentType: argumentType smalltalkValue: smalltalkValue expectedValue: expectedValue [
self doWorkerCallWithValue: smalltalkValue ofType: argumentType.
self deny: interpreter failed description: 'The primitive call should not fail'.
"It should be only one task in the worker"
self assert: worker tasks size equals: 1.
"Extracting the value stored in the task"
task := worker tasks at: 1.
savedValue := argumentType marshallToSmalltalk: (task parametersAddress at: 0).
"The stored value in the worker task should be the expected"
self assert: savedValue equals: expectedValue
]
{ #category : #implementation }
VMFFIWorkerArgumentMarshallingTest >> doTestFuntionWithArgumentType: argumentType smalltalkValue: smalltalkValue failsWith: expectedErrorCode [
self doWorkerCallWithValue: smalltalkValue ofType: argumentType.
self assert: interpreter failed.
self assert: interpreter primFailCode equals: expectedErrorCode.
]
{ #category : #implementation }
VMFFIWorkerArgumentMarshallingTest >> doWorkerCallWithValue: smalltalkValue ofType: argumentType [
aFunctionBlock := [ :anArgument | self fail: 'It should enqueue it, not execute it' ].
tfExternalFunction := self
createExternalFunctionFor: aFunctionBlock
withArgumentTypes: { argumentType }
withReturnType: interpreter libFFI void.
parametersArray := self newArrayWithSlots: 1.
memory
storePointer: 0
ofObject: parametersArray
withValue: smalltalkValue.
worker := interpreter libFFI testWorker.
workerOop := self newArrayWithSlots: 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 }
VMFFIWorkerArgumentMarshallingTest >> initializationOptions [
^ super initializationOptions , {
#FEATURE_THREADED_FFI . true }
]
{ #category : #running }
VMFFIWorkerArgumentMarshallingTest >> setUp [
super setUp.
interpreter libFFI testWorker clear
]
{ #category : #tests }
VMFFIWorkerArgumentMarshallingTest >> testCalloutWithoutArgumentsMarshallsCorrectly [
aFunctionBlock := [ :anArgument | self fail: 'It should enqueue it, not execute it' ].
tfExternalFunction := self
createExternalFunctionFor: aFunctionBlock
withArgumentTypes: {}
withReturnType: interpreter libFFI void.
parametersArray := self newArrayWithSlots: 0.
worker := interpreter libFFI testWorker.
workerOop := self newArrayWithSlots: 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.
self deny: interpreter failed.
"Extracting the value stored in the task"
task := worker tasks at: 1.
self assert: task returnHolderAddress equals: nil.
self assert: task parametersAddress equals: nil.
]