Skip to content
Permalink
Browse files

Adding test for callbacks from another thread that is nor the VM, nor…

… the runner
  • Loading branch information
tesonep committed Jan 27, 2020
1 parent 8ff8076 commit d868e9b21e66454ecd112499e18ae161474c83f4
Showing with 31 additions and 0 deletions.
  1. +31 −0 src/ThreadedFFI-UFFI-Tests/TFUFFICallbackTest.class.st
@@ -4,12 +4,24 @@ Class {
#category : #'ThreadedFFI-UFFI-Tests'
}

{ #category : #tests }
TFUFFICallbackTest >> callbackFromAnotherThread: callback [

^ self ffiCall: #(void callbackFromAnotherThread(void* callback))
]

{ #category : #tests }
TFUFFICallbackTest >> callbackInALoop: callback [

^ self ffiCall: #(int callbackInALoop(void* callback))
]

{ #category : #tests }
TFUFFICallbackTest >> getValue [

^ self ffiCall: #(int getValue())
]

{ #category : #tests }
TFUFFICallbackTest >> returnAnswer [

@@ -139,3 +151,22 @@ TFUFFICallbackTest >> testCallbackWithErrorHanlded [
UIManager nonInteractiveDuring: [self assert: (runner invokeFunction: fun withArguments: {1}) equals: -1]

]

{ #category : #tests }
TFUFFICallbackTest >> testCallbacksInOtherThread [

| callback semaphore|

"Using same thread runner with callbacks from other threads produce a segmentation fault"
ffiLibrary = TFTestLibraryUsingSameThreadRunner ifTrue: [ self skip ].

semaphore := Semaphore new.

callback := self newCallbackWithSignature: #(int (int a)) block: [ :a | semaphore signal. a + 1 ].
self callbackFromAnotherThread: callback.
semaphore wait.

1 second wait.
self assert: self getValue equals: 43

]

0 comments on commit d868e9b

Please sign in to comment.
You can’t perform that action at this time.