The record text below was written before entry 30. Entry 20 fixes 3 of the 4 tests. TFUFFICallbackTest>>testCallbacksInOtherThread is fixed by entry 30 together with the Cog change for a callback from another thread (see the Cog section); on stock Cog without the change the test still skips for the same-thread runner, because the VM would stop.
scripts/image-fixes/20-TFFI-disabled-tests.stFFICallbackParametersTest>>testIdentityStruct, TFCallbacksTest>>testCallbackNotRespectingLIFOOrderFailsReturn, TFUFFIFunctionCallTest>>testLongCalloutDoesNotBlockImageThree of the four tests are repaired by a fix file. FFICallbackParametersTest>>testIdentityStruct and TFCallbacksTest>>testCallbackNotRespectingLIFOOrderFailsReturn were disabled by an unconditional true ifTrue: [^self skip] with an obsolete reason; with the skip removed both pass on our VM and Cog (3 of 3 runs each; LIFO in both runner variants). TFUFFIFunctionCallTest>>testLongCalloutDoesNotBlockImage skipped for TFTestLibraryUsingSameThreadRunner, but a same-thread callout blocks the whole image by design, so the test now expects #finishedCallout first for that runner and #waitingForCallout first for the worker runner. It also does a 0 second warm-up callout first, because the first call compiles the ffiCall method, and under load on our JIT VM a higher-priority process could preempt the callout process in that window (4 of 24 runs failed before; 0 of 60 after, with 6 parallel runs). TFUFFICallbackTest>>testCallbacksInOtherThread, same-thread variant, is NOT repaired: stock Cog segfaults in callbackFrontend when the callback arrives from a foreign thread with the same-thread runner ("Not in VM thread"; the VM aborts). Our VM passes that variant (5 of 5 runs). Because the Cog crash would kill a whole sweep batch, no entry is filed for that test and the skip stays. The worker variant of that test passes on both VMs. Everything is measured on the Pharo 14 build 791 base images; Cog is x86 under no translation (native arm64 Cog v12.0.6 as set up by the tools).
| Test | Defect in | State | Cause |
|---|---|---|---|
FFICallbackParametersTest>>testIdentityStruct |
test | repaired | Unconditional true ifTrue: [ ^ self skip. ] with the comment 'the tests are not running with Alien callbacks'. That is obsolete: FFICallback>>invokeAsFunctionWithArguments: runs the callback and the struct round trip works on both VMs. |
TFCallbacksTest>>testCallbackNotRespectingLIFOOrderFailsReturn |
test | repaired | Unconditional true ifTrue: [ ^ self skip ]. With it removed the test passes in both runner variants (SameThread runner and TFWorker) on both VMs, so the skip hides nothing that still fails. |
TFUFFICallbackTest>>testCallbacksInOtherThread |
cog-vm | needs a VM change | The same-thread variant: the foreign thread calls the libffi closure, callbackFrontend calls sameThreadCallbackEnter, which calls ptEnterInterpreterFromCallback. Cog documents that function as 'Enter the interpreter from a callback in the VM thread', so a call from another thread segfaults (log: 'Not in VM thread', Segmentation fault: 11, rc=255, the VM dies). Our VM passes the variant. The worker variant passes on both VMs with the skip in place already. |
TFUFFIFunctionCallTest>>testLongCalloutDoesNotBlockImage |
test | repaired | The same-thread variant was skipped because TFSameThreadRunner runs the callout in the VM thread and so blocks the image; that is the defined behaviour, not an error. Without the skip the original assertion fails on both VMs ('Got #finishedCallout instead of #waitingForCallout'). The test now expects #finishedCallout first for the same-thread library and #waitingForCallout first for the worker library. A warm-up call longCallout: 0 compiles the ffiCall method before the timed part: on our JIT VM under load the compile window (about 30 ms, measured with a timestamp probe: mainResumed at 31 ms while the callout was in progress) let a higher-priority process preempt the callout process, which put the test process first and made the same-thread run fail in 4 of 24 runs (0 of 24 on ours-nojit and on Cog). |
Regression check: Only test methods were changed, so no other code is affected. The four owner classes (FFICallbackParametersTest, TFCallbacksTest, TFUFFICallbackTest, TFUFFIFunctionCallTest) were run with every parametrization (my runner <local work directory>, because the stock runtest.sh builds cases without the ParametrizedTestMatrix suite). Our VM (JIT on): base 37 PASS 5 SKIP, with fix 41 PASS 1 SKIP. Stock Cog: base 37 PASS 5 SKIP, with fix 41 PASS 1 SKIP. The remaining SKIP is the same-thread variant of testCallbacksInOtherThread. Our VM without JIT was used only for the flakiness check of testLongCalloutDoesNotBlockImage (24 of 24 PASS before the warm-up). Note: the tools/runtest.sh builds a case with selector: only, so ParametrizedTestCase options are missing; use the par_test.st variant to see both runner parametrizations.
VM change: Cog (pharo-vm, branch pharo-12), file src/ffi/sameThread/sameThread.c, function sameThreadCallbackEnter (called from callbackFrontend in src/ffi/callbacks/callbacks.c). It calls ptEnterInterpreterFromCallback(vmcc) whatever thread the callback arrives on, but smalltalksrc/VMMaker/StackInterpreterPrimitives.class.st ptEnterInterpreterFromCallback: says it must be entered 'in the VM thread'. A callback from a foreign thread (a C library thread that calls a callback created for the same-thread runner) therefore runs the interpreter on the wrong thread and the VM dies. Proposal for the review: in sameThreadCallbackEnter, when the calling thread is not the VM thread, do what the worker runner does (put the invocation on the callback queue with queue_add_pending_callback and wait until the image has run the callback and signalled the return) instead of entering the interpreter; or fail the callback with a clear message instead of a segfault. Minimal reproducer (Pharo 14 image with the ThreadedFFI test library, run with arch-native Cog v12.0.6 on arm64): TFUFFICallbackTest with the skip removed from testCallbacksInOtherThread, parametrization TFTestLibraryUsingSameThreadRunner: callback := self newCallbackWithSignature: #(int (int a)) block: [ :a | a + 1 ]. self callbackFromAnotherThread: callback. 1 second wait. (the C function callbackFromAnotherThread in ffiTestLibrary/src/callbacks.c starts a pthread that calls the callback after sleep(3)). Output on Cog: '[ERROR] ... scheduler could not find a runnable process', 'SameThreadCalloutSuspendedProcessStack is empty', 'Not in VM thread.', 'Segmentation fault: 11', exit 255 (log: <local work directory>). Output on our VM: PASS (getValue = 43). This is a proposal only; no Cog source was changed and no pull request was made. A separate observation about our VM (not needed for the fix): without the warm-up call, testLongCalloutDoesNotBlockImage failed on our JIT VM in about 17 percent of runs under load, and never on ours-nojit or Cog (0 of 24 each); the timestamp probe showed a process switch about 30 ms after the callout process started, before the callout blocked. A preemption by a higher-priority process with back-append (preemptionYields true, as in Cog) is the likely route, so the JIT build only takes the longer compile window; I did not prove the exact route.
Open points: TFUFFICallbackTest>>testCallbacksInOtherThread (same-thread runner variant) cannot pass on stock Cog without a change in pharo-vm src/ffi/sameThread/sameThread.c (Cog segfaults). No entry is filed for it, so the skip stays; filing an entry that removes the skip would crash every stock-Cog sweep batch that reaches the test. The proposal is in vmChange and needs the owner's review before anything goes to the Cog project. Also: tools/runtest.sh and one_test.st run ParametrizedTestCase tests without the parametrization and therefore skip or mislead for these classes; I used my own copy (par_test.st / prt.sh in the ag directory).
Upstream note: Pharo (UnifiedFFI-Tests, ThreadedFFI-Tests, ThreadedFFI-UFFI-Tests). Title: Re-enable three skipped FFI tests. Description: FFICallbackParametersTest>>testIdentityStruct and TFCallbacksTest>>testCallbackNotRespectingLIFOOrderFailsReturn were skipped with an unconditional true ifTrue: [ ^ self skip ]; both pass on Pharo 14 with Cog v12.0.6 and are re-enabled. TFUFFIFunctionCallTest>>testLongCalloutDoesNotBlockImage skipped for the same-thread runner; the test now expects the order that belongs to each runner (the same-thread callout blocks the image, so #finishedCallout comes first) and does a 0 second warm-up callout so that the compile of the ffiCall method does not fall in the timed part. Not included: TFUFFICallbackTest>>testCallbacksInOtherThread for the same-thread runner, which crashes stock Cog (callback from a foreign thread enters the interpreter in sameThread.c); that needs a pharo-vm change which the owner must review first.
Last full sweeps of 2026-11-17: iospharo (sweep14-new14) and stock Cog with the Cog changes (sweepcogp14-new10), with all image fixes. "Before" is the state of the test before the repairs. The Stock Cog column has a value only where the record measured stock Cog: "PASS 3 of 3 (repair run)" is the check of each repair on stock Cog v12.0.6 with the fix entry; "-" is not measured separately.
| Test | Before | State | iospharo VM | Patched Cog | Stock Cog |
|---|---|---|---|---|---|
FFICallbackParametersTest>>testIdentityStruct | SKIP | repaired | PASS | PASS | PASS 3 of 3 (repair run) |
TFCallbacksTest>>testCallbackNotRespectingLIFOOrderFailsReturn | SKIP | repaired | PASS 2x | PASS 2x | PASS 3 of 3 (repair run) |
TFUFFIFunctionCallTest>>testLongCalloutDoesNotBlockImage | SKIP | repaired | PASS 2x | PASS 2x | PASS 3 of 3 (repair run) |
TFUFFICallbackTest>>testCallbacksInOtherThread | SKIP | needs a VM change | PASS 2x | PASS 2x | SKIP (the VM stops without the Cog change) |
Run the tests in a Pharo 14 image (build 791). Before the fix they skip, fail or carry the expected-failure mark.
"Run in a Playground of a Pharo 14 image (Do it and print each line)." ((FFICallbackParametersTest selector: #testIdentityStruct) run) printString. ((TFCallbacksTest selector: #testCallbackNotRespectingLIFOOrderFailsReturn) run) printString. ((TFUFFICallbackTest selector: #testCallbacksInOtherThread) run) printString. ((TFUFFIFunctionCallTest selector: #testLongCalloutDoesNotBlockImage) run) printString.
testIdentityStruct
| param result |
"This is ugly, but the tests are not running with Alien callbacks"
true ifTrue: [ ^ self skip. ].
callback := FFICallback
signature: #(FFITestStructureSmallIntFloatStructure (FFITestStructureSmallIntFloatStructure a))
block: [ :a |
self assert: a x equals: 2.0.
self assert: a y equals: 3.
self assert: a w equals: 5.0.
self assert: a z equals: 7.0.
a x: 3.0.
a y: 4.
a w: 6.0.
a z: 8.0.
a
].
param := FFITestStructureSmallIntFloatStructure new
x: 2.0;
y: 3;
w: 5.0;
z: 7;
yourself.
result := self callCallback: callback withArgs: { param }.
"They are passed and returned by copy, so they should not be the same"
self deny: param equals: result.
self assert: result x equals: 3.0.
self assert: result y equals: 4.
self assert: result w equals: 6.0.
self assert: result z equals: 8.0.testCallbackNotRespectingLIFOOrderFailsReturn | smain s1 c1 s2 c2 returned | smain := Semaphore new. true ifTrue: [ ^ self skip ]. returned := false. s1 := Semaphore new. c1 := self newTestCallbackDoing: [ smain signal. s1 wait ]. s2 := Semaphore new. c2 := self newTestCallbackDoing: [ smain signal. s2 wait ]. [ self callCallback: c1. returned := true ] fork. [ self callCallback: c2 ] fork. "wait until both callbacks arrive" smain wait; wait. "make callback 1 to finish while callback 2 is suspended" s1 signal. "Wait until C1 tries to return" 100 milliSecond wait. "It should not return until C2 returns" self deny: returned. "Signal s2 to make c2 return" s2 signal. "Wait until C1 tries to return" 100 milliSecond wait. self assert: returned
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
testLongCalloutDoesNotBlockImage "Tricky test. This tests checks that during a callout the image is not completely suspended. To do that, we do a 1 second long callout in a separate Pharo process. When that process starts executing (signals the calloutEnter semaphore), we wait for half a second to let the callback really start executing and then do something before the callback returns." | calloutEnter calloutExit orderOfFinishing | "If we are running in the same thread execution, it will block the interpreter. So the test is skipped." (self ffiLibrary = TFTestLibraryUsingSameThreadRunner) ifTrue: [ ^ self skip ]. calloutEnter := Semaphore new. calloutExit := Semaphore new. orderOfFinishing := OrderedCollection new. [ calloutEnter signal. self longCallout: 1. orderOfFinishing add: #finishedCallout. calloutExit signal ] fork. calloutEnter wait. 0.3 seconds wait. orderOfFinishing add: #waitingForCallout. calloutExit wait. self assert: orderOfFinishing first equals: #waitingForCallout
How to apply an entries file: file in 00-header.st and the entries file as one chunk (the iospharo script scripts/gen-image-fixes.py makes that chunk). Each entry checks for the defect first and prints FIXED, ADDED or SKIP. Download 00-header.st.
fix value: #FFICallbackParametersTest value: #testIdentityStruct
value: [ :s | s includesSubstring: 'true ifTrue: [ ^ self skip. ]' ]
value: 'testIdentityStruct
| param result |
callback := FFICallback
signature: #(FFITestStructureSmallIntFloatStructure (FFITestStructureSmallIntFloatStructure a))
block: [ :a |
self assert: a x equals: 2.0.
self assert: a y equals: 3.
self assert: a w equals: 5.0.
self assert: a z equals: 7.0.
a x: 3.0.
a y: 4.
a w: 6.0.
a z: 8.0.
a
].
param := FFITestStructureSmallIntFloatStructure new
x: 2.0;
y: 3;
w: 5.0;
z: 7;
yourself.
result := self callCallback: callback withArgs: { param }.
self deny: param equals: result.
self assert: result x equals: 3.0.
self assert: result y equals: 4.
self assert: result w equals: 6.0.
self assert: result z equals: 8.0.'.
fix value: #TFCallbacksTest value: #testCallbackNotRespectingLIFOOrderFailsReturn
value: [ :s | s includesSubstring: 'self skip' ]
value: 'testCallbackNotRespectingLIFOOrderFailsReturn
| smain s1 c1 s2 c2 returned |
smain := Semaphore new.
returned := false.
s1 := Semaphore new.
c1 := self newTestCallbackDoing: [ smain signal. s1 wait ].
s2 := Semaphore new.
c2 := self newTestCallbackDoing: [ smain signal. s2 wait ].
"The second callout starts after the first callback is entered. With two forks in a row, a preemption
of the first process before its callout let the second callback enter first (1 of 40 runs on one VM),
and the test then saw the first callout return early."
[ self callCallback: c1. returned := true ] fork.
smain wait.
[ self callCallback: c2 ] fork.
smain wait.
s1 signal.
100 milliSecond wait.
self deny: returned.
s2 signal.
100 milliSecond wait.
self assert: returned'.
fix value: #TFUFFIFunctionCallTest value: #testLongCalloutDoesNotBlockImage
value: [ :s | s includesSubstring: 'self skip' ]
value: 'testLongCalloutDoesNotBlockImage
"Tricky test.
This test checks what a callout does to the other Pharo processes.
A 1 second long callout runs in a separate Pharo process. When that process starts (signals calloutEnter), the test process waits 0.3 seconds and then notes #waitingForCallout.
With a worker runner the callout runs in another thread, so the image is not suspended: #waitingForCallout comes before #finishedCallout.
TFSameThreadRunner runs the callout in the VM thread, so the whole image is suspended for the 1 second: #finishedCallout comes first. The test checks the order that belongs to the runner."
| calloutEnter calloutExit orderOfFinishing expectedFirst |
expectedFirst := self ffiLibrary = TFTestLibraryUsingSameThreadRunner
ifTrue: [ #finishedCallout ]
ifFalse: [ #waitingForCallout ].
"The first call of an ffiCall: method compiles the callout. That takes tens of milliseconds, during which a higher priority process can preempt the callout process and let the test process run first. Call once with 0 seconds, so the compile is done before the timed part."
self longCallout: 0.
calloutEnter := Semaphore new.
calloutExit := Semaphore new.
orderOfFinishing := OrderedCollection new.
[
calloutEnter signal.
self longCallout: 1.
orderOfFinishing add: #finishedCallout.
calloutExit signal ] fork.
calloutEnter wait.
0.3 seconds wait.
orderOfFinishing add: #waitingForCallout.
calloutExit wait.
self assert: orderOfFinishing first equals: expectedFirst'.
"TFUFFICallbackTest>>testCallbacksInOtherThread skips for the same-thread FFI runner (2026-11-17). The remark in the test says why: 'Using same thread runner with callbacks from other threads produce a segmentation fault'. Stock Cog v12 enters the interpreter from the thread that made the callback, while the VM thread runs. Our VM runs such a callback in the VM thread. docs/upstream has the change for Cog (cog-same-thread-runner-callback-from-other-thread.patch). The test cannot run on a stock Cog without that change: the VM stops. So the skip stays for a VM that does not have the repair, and goes for a VM that has it. The test asks the VM: our VM is known by its version text, and a Cog build with the change is known by the environment variable PHARO_FFI_CALLBACK_FROM_OTHER_THREAD, which scripts/vmrun.sh sets for the VM name cogp." add value: #TFUFFICallbackTest value: #sameThreadRunnerTakesCallbackFromOtherThread value: 'private' value: 'sameThreadRunnerTakesCallbackFromOtherThread "Stock Cog v12 enters the interpreter from the thread of the callback and stops with a segmentation fault. A VM that runs such a callback in the VM thread says so: the iospharo VM by its version text, a Cog build with the repair by an environment variable." ^ (Smalltalk vm interpreterSourceVersion includesSubstring: ''iospharo'') or: [ (OSEnvironment current at: ''PHARO_FFI_CALLBACK_FROM_OTHER_THREAD'' ifAbsent: [ nil ]) notNil ]'. fix value: #TFUFFICallbackTest value: #testCallbacksInOtherThread value: [ :source | source includesSubstring: 'ffiLibrary = TFTestLibraryUsingSameThreadRunner ifTrue: [ ^ self skip ].' ] value: ((TFUFFICallbackTest >> #testCallbacksInOtherThread) sourceCode copyReplaceAll: 'ffiLibrary = TFTestLibraryUsingSameThreadRunner ifTrue: [ ^ self skip ].' with: '(ffiLibrary = TFTestLibraryUsingSameThreadRunner and: [ self sameThreadRunnerTakesCallbackFromOtherThread not ]) ifTrue: [ ^ self skip ].').
State of 2026-11-20. Made from the test records of the iospharo project (a second Pharo VM). The fixes are proposals for review.