Pharo test defects

Fuel-cleanblock

State
Fixed (image fix)
Defect in
the test
Tests
9
Fix
image fix 20-Fuel-cleanblock.st
Upstream repository
pharo-project/pharo

Record

All 9 tests are repaired and pass on both VMs. Eight of them start with Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ]. That guard is left over from the time when clean blocks were not fully supported. With the guard removed, the eight pass on both VMs with no other change. The ninth, FLGlobalEnvironmentTest>>testCompiledMethodChanged, failed once the skip was removed, on both VMs. The cause is in the test. With clean blocks on, m ^ 42 and m ^ [ 42 yourself ] compile to the same bytecodes (#[32 92], push literal then return top) because the clean block is a literal, so FLGlobalCompiledMethodCluster compares equal bytecodesHash and correctly raises nothing. The fix keeps the check (differing bytecodes must raise FLMethodChanged) and changes method B to m ^ [ 42 yourself ] value, whose bytecodes differ. The sibling tests testCompiledMethodChangedConstant and testCompiledMethodChangedNonClean still pass. Fuel's bytecodesHash excludes literals, so ^ 42 against ^ 43 is not detected; that is a design limit of Fuel, not touched here.

Test Defect in State Cause
FLFullHeaderSerializationTest>>testPostMaterializationActions test repaired Obsolete optionCleanBlockClosure skip guard in the test
FLFullHeaderSerializationTest>>testPreMaterializationActions test repaired Obsolete optionCleanBlockClosure skip guard in the test
FLHeaderSerializationTest>>testPostMaterializationActions test repaired Obsolete optionCleanBlockClosure skip guard in the test
FLHeaderSerializationTest>>testPreMaterializationActions test repaired Obsolete optionCleanBlockClosure skip guard in the test
FLSortedCollectionSerializationTest>>testSortedCollection test repaired Obsolete optionCleanBlockClosure skip guard in the test
FLSortedCollectionSerializationTest>>testSortedCollectionWithClassVariableChanges test repaired Obsolete optionCleanBlockClosure skip guard in the test
FLSortedCollectionSerializationTest>>testSortedCollectionWithClassVariableReference test repaired Obsolete optionCleanBlockClosure skip guard in the test
FLUserGuidesTest>>testDemo test repaired Obsolete optionCleanBlockClosure skip guard in the test
FLGlobalEnvironmentTest>>testCompiledMethodChanged test repaired Skip guard obsolete, and the premise is wrong with clean blocks: '^ 42' and '^ [ 42 yourself ]' compile to the same bytecodes (#[32 92]), so no FLMethodChanged is raised. Method B changed to '^ [ 42 yourself ] value', which has different bytecodes.

Regression check: Only test methods are changed. The five owning classes (FLFullHeaderSerializationTest, FLGlobalEnvironmentTest, FLHeaderSerializationTest, FLSortedCollectionSerializationTest, FLUserGuidesTest) were run in full, once each way, on both VMs. Base image: 27 of 36 pass on our VM and on Cog. Fixed image: 36 of 36 pass on our VM and on Cog. The 9 repaired tests were run 3 times on each VM and all passed. Our VM was run with its default configuration (the tools' "ours" mode); the ours-nojit mode was not run.

Upstream note: Title: Fuel tests: remove obsolete optionCleanBlockClosure skips. Project: pharo (Fuel-Core-Tests). Eight Fuel tests skip themselves when optionCleanBlockClosure is on. They pass without the skip, so the skip line can be removed. FLGlobalEnvironmentTest>>testCompiledMethodChanged also needs a new fixture. With clean blocks, 'm ^ 42' and 'm ^ [ 42 yourself ]' have identical bytecodes, so the test now compiles 'm ^ [ 42 yourself ] value' in the second class. The test still checks that FLMethodChanged is raised when the bytecodes differ. I measured this only on Pharo 14 build 791. This is a proposal for human review and is not submitted.

Results

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.

TestBeforeStateiospharo VMPatched CogStock Cog
FLFullHeaderSerializationTest>>testPostMaterializationActionsSKIPrepairedPASSPASSPASS 3 of 3 (repair run)
FLFullHeaderSerializationTest>>testPreMaterializationActionsSKIPrepairedPASSPASSPASS 3 of 3 (repair run)
FLGlobalEnvironmentTest>>testCompiledMethodChangedSKIPrepairedPASSPASSPASS 3 of 3 (repair run)
FLHeaderSerializationTest>>testPostMaterializationActionsSKIPrepairedPASSPASSPASS 3 of 3 (repair run)
FLHeaderSerializationTest>>testPreMaterializationActionsSKIPrepairedPASSPASSPASS 3 of 3 (repair run)
FLSortedCollectionSerializationTest>>testSortedCollectionSKIPrepairedPASSPASSPASS 3 of 3 (repair run)
FLSortedCollectionSerializationTest>>testSortedCollectionWithClassVariableChangesSKIPrepairedPASSPASSPASS 3 of 3 (repair run)
FLSortedCollectionSerializationTest>>testSortedCollectionWithClassVariableReferenceSKIPrepairedPASSPASSPASS 3 of 3 (repair run)
FLUserGuidesTest>>testDemoSKIPrepairedPASSPASSPASS 3 of 3 (repair run)

Test

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)."
((FLFullHeaderSerializationTest selector: #testPostMaterializationActions) run) printString.
((FLFullHeaderSerializationTest selector: #testPreMaterializationActions) run) printString.
((FLGlobalEnvironmentTest selector: #testCompiledMethodChanged) run) printString.
((FLHeaderSerializationTest selector: #testPostMaterializationActions) run) printString.
((FLHeaderSerializationTest selector: #testPreMaterializationActions) run) printString.
((FLSortedCollectionSerializationTest selector: #testSortedCollection) run) printString.
((FLSortedCollectionSerializationTest selector: #testSortedCollectionWithClassVariableChanges) run) printString.
((FLSortedCollectionSerializationTest selector: #testSortedCollectionWithClassVariableReference) run) printString.
((FLUserGuidesTest selector: #testDemo) run) printString.

Source of the tests before the fix

FLFullHeaderSerializationTest>>testPostMaterializationActions before the fix (Pharo 14 build 791)
testPostMaterializationActions

	| aClass |
	Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

	aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariables: #(TestClassVariable TestClassVariable2) ].
	self classFactory
		silentlyCompile: 'postLoadMethod TestClassVariable := 1' in: aClass class;
		silentlyCompile: 'postLoadMethod2 TestClassVariable := 2' in: aClass class;
		silentlyCompile: 'classVariable ^ TestClassVariable ' in: aClass class.

	aClass perform: #postLoadMethod.
	self assert: (aClass perform: #classVariable) equals: 1.
	self serializer
		at: #className putAdditionalObject: aClass name;
		fullySerializeBehavior: aClass;
		addPostMaterializationAction: [ :materializedObjects :environment |
			(environment at: (materializedObjects additionalObjectAt: #className)) perform: #postLoadMethod2 ].
	self serialize: aClass.
	self assert: (aClass perform: #classVariable) equals: 1.
	self materialized.
	self assert: (aClass perform: #classVariable) equals: 2
FLFullHeaderSerializationTest>>testPreMaterializationActions before the fix (Pharo 14 build 791)
testPreMaterializationActions

	| aClass |
	Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

	aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariables: #(TestClassVariable TestClassVariable2) ].
	self classFactory
		silentlyCompile: 'postLoadMethod TestClassVariable := 1' in: aClass class;
		silentlyCompile: 'postLoadMethod2 TestClassVariable := 2' in: aClass class;
		silentlyCompile: 'classVariable ^TestClassVariable' in: aClass class.

	aClass perform: #postLoadMethod.
	self assert: (aClass perform: #classVariable) equals: 1.
	self serializer
		at: #className putAdditionalObject: aClass name;
		addPreMaterializationAction: [ :header :environment | (environment at: (header additionalObjectAt: #className)) perform: #postLoadMethod2 ].
	self serialize: aClass.
	self assert: (aClass perform: #classVariable) equals: 1.
	self materialized.
	self assert: (aClass perform: #classVariable) equals: 2
FLGlobalEnvironmentTest>>testCompiledMethodChanged before the fix (Pharo 14 build 791)
testCompiledMethodChanged
	"A compiled methods should be serialized as global by default.
	On materialization, it must be found in the global environment, and the bytecodes hash must be the same.
	Else, raise a proper error."
	
	| classA classB |
	Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

	classA := self classFactory silentlyNewClass.
	self classFactory
		silentlyCompile:  'm  ^ 42'
		in: classA.
	classB := self classFactory silentlyNewClass.
	self classFactory
		silentlyCompile: 'm  ^ [ 42 yourself ]'
		in: classB.

	self materializer environment: (Dictionary new
		at: classA name put: classB;
		yourself).

	self serialize: classA >> #m.

	self
		should: [ self materialized ]
		raise: FLMethodChanged 
		description: 'Serialized and materialized methods should have the same bytecodes.'
FLHeaderSerializationTest>>testPostMaterializationActions before the fix (Pharo 14 build 791)
testPostMaterializationActions

	| aClass |
	Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

	aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariables: #(TestClassVariable TestClassVariable2) ].
	self classFactory
		silentlyCompile: 'postLoadMethod TestClassVariable := 1' in: aClass class;
		silentlyCompile: 'postLoadMethod2 TestClassVariable := 2' in: aClass class;
		silentlyCompile: 'classVariable ^ TestClassVariable ' in: aClass class.

	aClass perform: #postLoadMethod.
	self assert: (aClass perform: #classVariable) equals: 1.
	self serializer
		at: #class putAdditionalObject: aClass;
		addPostMaterializationAction: [ :header | "Can't use `self environmentOfTest` or `aClass name` here because the closure
			must be clean."
			(header additionalObjectAt: #class) perform: #postLoadMethod2 ].
	self serialize: aClass.
	self assert: (aClass perform: #classVariable) equals: 1.
	self materialized.
	self assert: (aClass perform: #classVariable) equals: 2
FLHeaderSerializationTest>>testPreMaterializationActions before the fix (Pharo 14 build 791)
testPreMaterializationActions

	| aClass |
	Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

	aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariables: #(TestClassVariable TestClassVariable2) ].
	self classFactory
		silentlyCompile: 'postLoadMethod TestClassVariable := 1' in: aClass class;
		silentlyCompile: 'postLoadMethod2 TestClassVariable := 2' in: aClass class;
		silentlyCompile: 'classVariable ^TestClassVariable' in: aClass class.

	aClass perform: #postLoadMethod.
	self assert: (aClass perform: #classVariable) equals: 1.
	self serializer
		at: #class putAdditionalObject: aClass;
		addPreMaterializationAction: [ :header | "Can't use `self environmentOfTest` or `aClass name` here because the closure
			must be clean."
			(header additionalObjectAt: #class) perform: #postLoadMethod2 ].
	self serialize: aClass.
	self assert: (aClass perform: #classVariable) equals: 1.
	self materialized.
	self assert: (aClass perform: #classVariable) equals: 2
FLSortedCollectionSerializationTest>>testSortedCollection before the fix (Pharo 14 build 791)
testSortedCollection
	"Tests that a SortedCollection works fine after materialization. 
	Note: Equality can not be used to assert, since its behavior is this:
	| x y |
	x := SortedCollection sortBlock: [:a :b | a >= b ].
	y := SortedCollection sortBlock: [:a :b | a >= b ].
	self assert: x ~= y"

	| aSortBlock aSortedCollection materialized |
	Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

	aSortBlock := [ :a :b | a >= b ].
	aSortedCollection := SortedCollection sortBlock: aSortBlock.

	materialized := self resultOfSerializeAndMaterialize: aSortedCollection.
	self assert: aSortedCollection sortBlock ~~ materialized sortBlock.

	materialized addAll: #(2 1 3).
	aSortedCollection addAll: #(2 1 3).
	self assert: aSortedCollection asArray equals: materialized asArray
FLSortedCollectionSerializationTest>>testSortedCollectionWithClassVariableChanges before the fix (Pharo 14 build 791)
testSortedCollectionWithClassVariableChanges
	"Tests serialization of a SortedCollection whose sortBlock has a reference to a class variable and its value is changed. See also FLBlockClosureSerializationTest >> testBlockClosureWithClassVariableChanges  and FLCompiledMethodSerializationTest >> testMethodChangingClassVariable"

	| aSortedCollection materialized compiledBlock index literalHolder |
	Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

	ClassVariableForTesting := false.
	
	aSortedCollection := self class sortedCollectionForTestingWithClassVariable.
	materialized := self resultOfSerializeAndMaterialize: aSortedCollection.
	"the class variable ClassVariableForTesting should be false"
	
	compiledBlock := materialized sortBlock.
	
	literalHolder := compiledBlock isFullBlock 
		ifTrue: [ compiledBlock method ] 
		ifFalse: [ materialized sortBlock outerContext method ].
	index := literalHolder literals indexOf: (self class bindingOf: #ClassVariableForTesting).
	
	self deny: (literalHolder literalAt: index) value.
	ClassVariableForTesting := true.
	"the class variable ClassVariableForTesting should be true"
	self assert: (literalHolder literalAt: index) value
FLSortedCollectionSerializationTest>>testSortedCollectionWithClassVariableReference before the fix (Pharo 14 build 791)
testSortedCollectionWithClassVariableReference
	"Tests serialization of a SortedCollection whose sortBlock has a reference to the outer context. 
	Note: Equality can not be used to assert, since its behavior is this:
	| x y |
	x := SortedCollection sortBlock: [:a :b | a >= b ].
	y := SortedCollection sortBlock: [:a :b | a >= b ].
	self assert: x ~= y"

	| aSortedCollection materialized |
	Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

	ClassVariableForTesting := false.

	aSortedCollection := self class sortedCollectionForTestingWithClassVariable.
	materialized := self resultOfSerializeAndMaterialize: aSortedCollection.
	ClassVariableForTesting := true.
	materialized addAll: #(2 3 1).
	aSortedCollection addAll: #(2 3 1).

	aSortedCollection sortBlock assertWellMaterializedInto: materialized sortBlock in: self.
	self assert: aSortedCollection asArray equals: materialized asArray
FLUserGuidesTest>>testDemo before the fix (Pharo 14 build 791)
testDemo
	| sourceArray loadedArray |
	Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

	sourceArray := Array
		with: 'a string'
		with: Smalltalk
		with: [
			Smalltalk vm.
			'a string' ].
	"Store to the file"
	FLSerializer new
		filePath: 'example.FL';
		object: sourceArray;
		serialize.
	"Load from the file"
	loadedArray := FLMaterializer new
		filePath: 'example.FL';
		materializeRoot.
	"The arrays are not the same"
	self assert: sourceArray ~~ loadedArray.
	"The strings are not the same"
	self assert: sourceArray first ~~ loadedArray first.
	self assert: sourceArray first equals: loadedArray first.
	"The global instance Smalltalk is the same"
	self assert: sourceArray second identicalTo: loadedArray second.
	"Evaluating the loaded block prints a string"
	self assert: loadedArray third value equals: 'a string'

Fix

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.

20-Fuel-cleanblock.st (download)
Smalltalk at: #FLCBSkip put: 'Smalltalk compiler compilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].'.
{ {#FLFullHeaderSerializationTest. #testPostMaterializationActions}.
  {#FLFullHeaderSerializationTest. #testPreMaterializationActions}.
  {#FLHeaderSerializationTest. #testPostMaterializationActions}.
  {#FLHeaderSerializationTest. #testPreMaterializationActions}.
  {#FLSortedCollectionSerializationTest. #testSortedCollection}.
  {#FLSortedCollectionSerializationTest. #testSortedCollectionWithClassVariableChanges}.
  {#FLSortedCollectionSerializationTest. #testSortedCollectionWithClassVariableReference}.
  {#FLUserGuidesTest. #testDemo} } do: [ :p |
	fix value: p first value: p second
		value: [ :s | s includesSubstring: (Smalltalk at: #FLCBSkip) ]
		value: (((Smalltalk at: p first) >> p second) sourceCode copyReplaceAll: (Smalltalk at: #FLCBSkip) with: (String empty)) ].

"With optionCleanBlockClosure the method 'm ^ [ 42 yourself ]' compiles to the same
 bytecodes as 'm ^ 42' (push literal, return top): the clean block is a literal.  The
 test must compare a method without a closure against a method with a different
 bytecode sequence; sending #value to the block makes the bytecodes differ."
fix value: #FLGlobalEnvironmentTest value: #testCompiledMethodChanged
	value: [ :s | s includesSubstring: 'optionCleanBlockClosure ifTrue: [ ^ self skip ]' ]
	value: 'testCompiledMethodChanged
	"A compiled methods should be serialized as global by default.
	On materialization, it must be found in the global environment, and the bytecodes hash must be the same.
	Else, raise a proper error."
	
	| classA classB |
	classA := self classFactory silentlyNewClass.
	self classFactory
		silentlyCompile:  ''m  ^ 42''
		in: classA.
	classB := self classFactory silentlyNewClass.
	self classFactory
		silentlyCompile: ''m  ^ [ 42 yourself ] value''
		in: classB.

	self materializer environment: (Dictionary new
		at: classA name put: classB;
		yourself).

	self serialize: classA >> #m.

	self
		should: [ self materialized ]
		raise: FLMethodChanged 
		description: ''Serialized and materialized methods should have the same bytecodes.''' .

State of 2026-11-20. Made from the test records of the iospharo project (a second Pharo VM). The fixes are proposals for review.