The Trunk: MethodMassage-dtl.72.mcz

[email protected]
Newsgroups gmane.comp.lang.smalltalk.squeak.general
Message-ID <[email protected]>
David T. Lewis uploaded a new version of MethodMassage to project The Trunk:
http://source.squeak.org/trunk/MethodMassage-dtl.72.mcz

==================== Summary ====================

Name: MethodMassage-dtl.72
Author: dtl
Time: 19 May 2026, 8:11:50.800356 pm
UUID: 60d4be03-11cb-4e4c-bb54-1c100343a30b
Ancestors: MethodMassage-dtl.71

Test coverage for BytecodeCoverer>>#uncoverMethod: verifying that method bytecodes are manipulated as expected by the BytecodeCoverer, then restored to original values.

=============== Diff against MethodMassage-dtl.71 ===============

Item was added:
+ ----- Method: BytecodeCoverageTests>>testCoverAndUncover (in category 'tests') -----
+ testCoverAndUncover
+ 	"Verify that ByteCodeCoverer correctly modifies and restores the bytecodes in a method"
+ 
+ 	| theMethod originalBytecodes bytecodes modifiedBytecodes |
+ 
+ 	 "Start wtih a newly compiled method created in #setUp that does not affect the original
+ 	BytecodeAssemblerTests>>#testBasicBlockLabelsFor: method"
+ 	theMethod := self class >> #testBasicBlockLabelsFor:.
+ 	theMethod removeProperty: #coverage.
+ 
+ 	"Save a copy of the original method bytecodes that will be manipulated by ByteCodeCoverer"
+ 	originalBytecodes := ByteArray streamContents: [ :strm | 
+ 		theMethod initialPC to: theMethod endPC do: [ :e | strm nextPut: (theMethod byteAt: e)]].
+ 
+ 	"Replace all bytecodes that are targets of branches with the unknown bytecode"
+ 	BytecodeCoverer new coverMethod: theMethod.
+ 	self assert: (theMethod propertyValueAt: #coverage) notNil.
+ 	self assert: (theMethod propertyValueAt: #coverage) notEmpty.
+ 
+ 	 "Some bytecodes will have been overwritten by coverMethod"
+ 	bytecodes := ByteArray streamContents: [ :strm | 
+ 		theMethod initialPC to: theMethod endPC do: [ :e | strm nextPut: (theMethod byteAt: e)]].
+ 	self deny: bytecodes equals: originalBytecodes.
+ 
+ 	"The coverage map records each modified bytecode, so map size equals number of bytecodes replaced by coverMethod"
+ 	modifiedBytecodes := bytecodes difference: originalBytecodes.
+ 	self assert: (theMethod propertyValueAt: #coverage) size equals: modifiedBytecodes size.
+ 
+ 	"Clean up and restore original bytecodes"
+ 	BytecodeCoverer new uncoverMethod: theMethod.
+ 	self assert: (theMethod propertyValueAt: #coverage) isNil. "uncoverMethod has removed using this temporary property that is no longer needed"
+ 
+ 	"All method bytecode are restored to original values"
+ 	bytecodes := ByteArray streamContents: [ :strm | 
+ 		theMethod initialPC to: theMethod endPC do: [ :e | strm nextPut: (theMethod byteAt: e)]].
+ 	self assert: bytecodes equals: originalBytecodes. "Bytecodes overwritten by coverMethod have been restored to original values"
+ !

Squeak-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.