Marcel Taeumel uploaded a new version of FFI-Tests to project FFI:
http://source.squeak.org/FFI/FFI-Tests-mt.43.mcz ==================== Summary ==================== Name: FFI-Tests-mt.43 Author: mt Time: 19 May 2021, 11:49:10.499615 am UUID: f6ac8199-1124-3f4c-9e7a-29f27148057f Ancestors: FFI-Tests-mt.42 Complements FFI-Kernel-mt.161. Adds tests for large arrays and arrays of empty structs. =============== Diff against FFI-Tests-mt.42 =============== Item was changed: TestCase subclass: #ExternalTypeTests instanceVariableNames: 'heapObject' classVariableNames: '' + poolDictionaries: 'FFIConstants' - poolDictionaries: '' category: 'FFI-Tests'! Item was changed: ----- Method: ExternalTypeTests>>expectedFailures (in category 'failures') ----- expectedFailures ^ #( + testBasicTypeForArrayType "Fails because compiledSpec does not yet encode that information" - testIsArrayType "Fails because compiledSpec does not yet encode that maybe because of extra information that needs to be stored in an extra instVar." - testByteSizeArrayType "(see above)" - testSizeArrayType "(see above)" )! Item was added: + ----- Method: ExternalTypeTests>>testArrayOfStructsEmpty (in category 'tests - array types') ----- + testArrayOfStructsEmpty + + | structClass arrayType contentType | + structClass := FFITestEmptyStruct. + contentType := structClass externalType. + arrayType := structClass externalType asArrayType: 5. + + self assert: contentType isEmpty. + self assert: 0 equals: contentType byteSize. + self assert: 0 equals: arrayType byteSize. + + self assert: arrayType isArrayType. + self assert: contentType identical: arrayType contentType. + self assert: 5 equals: arrayType size. + + self deny: arrayType isAtomic. + self deny: arrayType isStructureType. + self deny: arrayType isPointerType. + self deny: arrayType isTypeAlias. + + self + assert: structClass + identical: arrayType referentClass.! Item was added: + ----- Method: ExternalTypeTests>>testArrayWithLargeByteSize (in category 'tests - array types') ----- + testArrayWithLargeByteSize + + | arrayType byteSize contentType arraySize | + byteSize := FFIStructSizeMask + 1. + contentType := ExternalType uint64_t. + arraySize := (byteSize / contentType byteSize) rounded. + arrayType := contentType asArrayType: arraySize. + self assert: arrayType byteSize > FFIStructSizeMask.! Item was added: + ----- Method: ExternalTypeTests>>testBasicType (in category 'tests - compiled spec') ----- + testBasicType + + | type baseType | + type := ExternalType int32_t. + baseType := type asBasicType. + self assert: ExternalType identical: baseType asNonPointerType class. + self assert: ExternalType identical: baseType asPointerType class.! Item was added: + ----- Method: ExternalTypeTests>>testBasicTypeForArrayType (in category 'tests - compiled spec') ----- + testBasicTypeForArrayType + + | type baseType | + type := ExternalType typeNamed: 'char[5]'. + baseType := type asBasicType. + self assert: type isArrayType equals: baseType isArrayType. + self assert: type byteSize equals: baseType byteSize. + self assert: type size equals: baseType size. ! Item was added: + ----- Method: ExternalTypeTests>>testBasicTypeForAtomicType (in category 'tests - compiled spec') ----- + testBasicTypeForAtomicType + + | type baseType | + type := ExternalType int32_t. + baseType := type asBasicType. + self assert: type isAtomic equals: baseType isAtomic. + self assert: type byteSize equals: baseType byteSize. + self assert: type size equals: baseType size. ! Item was added: + ----- Method: ExternalTypeTests>>testBasicTypeForPointerType (in category 'tests - compiled spec') ----- + testBasicTypeForPointerType + + | type baseType | + type := ExternalType int32_t asPointerType. + baseType := type asBasicType. + self assert: type isPointerType equals: baseType isPointerType. + self assert: type byteSize equals: baseType byteSize. + self assert: type size equals: baseType size.! Item was added: + ----- Method: ExternalTypeTests>>testBasicTypeForStructureType (in category 'tests - compiled spec') ----- + testBasicTypeForStructureType + + | type baseType | + type := ExternalType typeNamed: 'FFITestSdi'. + baseType := type asBasicType. + self assert: type isStructureType equals: baseType isStructureType. + self assert: type byteSize equals: baseType byteSize. + self assert: type size equals: baseType size. ! Item was removed: - ----- Method: ExternalTypeTests>>testByteSizeArrayType (in category 'tests - compiled spec') ----- - testByteSizeArrayType - - | type baseType | - type := ExternalType typeNamed: 'char[5]'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalArrayType identical: type class. - self assert: ExternalType identical: baseType class. - - self assert: type byteSize equals: baseType byteSize.! Item was removed: - ----- Method: ExternalTypeTests>>testByteSizeAtomicType (in category 'tests - compiled spec') ----- - testByteSizeAtomicType - - | type baseType | - type := ExternalType typeNamed: 'int32_t'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalAtomicType identical: type class. - - self assert: type byteSize equals: baseType byteSize.! Item was removed: - ----- Method: ExternalTypeTests>>testByteSizePointerType (in category 'tests - compiled spec') ----- - testByteSizePointerType - - | type baseType | - type := ExternalType typeNamed: 'int32_t*'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalPointerType identical: type class. - self assert: ExternalType identical: baseType class. - - self assert: type byteSize equals: baseType byteSize.! Item was removed: - ----- Method: ExternalTypeTests>>testByteSizeStructureType (in category 'tests - compiled spec') ----- - testByteSizeStructureType - - | type baseType | - type := ExternalType typeNamed: 'FFITestSdi'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalStructureType identical: type class. - self assert: ExternalType identical: baseType class. - - self assert: type byteSize equals: baseType byteSize.! Item was removed: - ----- Method: ExternalTypeTests>>testIsArrayType (in category 'tests - compiled spec') ----- - testIsArrayType - "#isArrayType should be independent from the subclass but also encoded in the #compiledSpec's #headerWord." - - | type baseType | - type := ExternalType typeNamed: 'char[5]'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalArrayType identical: type class. - self assert: ExternalType identical: baseType class. - - self assert: type isArrayType. - self assert: baseType isArrayType.! Item was removed: - ----- Method: ExternalTypeTests>>testIsAtomicType (in category 'tests - compiled spec') ----- - testIsAtomicType - "#isAtomic should be independent from the subclass but also encoded in the #compiledSpec's #headerWord." - - | type baseType | - type := ExternalType typeNamed: 'int32_t'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalAtomicType identical: type class. - - self assert: type isAtomic. - self assert: baseType isAtomic.! Item was removed: - ----- Method: ExternalTypeTests>>testIsPointerType (in category 'tests - compiled spec') ----- - testIsPointerType - "#isPointerType should be independent from the subclass but also encoded in the #compiledSpec's #headerWord." - - | type baseType | - type := ExternalType typeNamed: 'int32_t*'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalPointerType identical: type class. - self assert: ExternalType identical: baseType class. - - self assert: type isPointerType. - self assert: baseType isPointerType.! Item was removed: - ----- Method: ExternalTypeTests>>testIsStructureType (in category 'tests - compiled spec') ----- - testIsStructureType - "#isStructureType should be independent from the subclass but also encoded in the #compiledSpec's #headerWord." - - | type baseType | - type := ExternalType typeNamed: 'FFITestSdi'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalStructureType identical: type class. - self assert: ExternalType identical: baseType class. - - self assert: type isStructureType. - self assert: baseType isStructureType.! Item was removed: - ----- Method: ExternalTypeTests>>testSizeArrayType (in category 'tests - compiled spec') ----- - testSizeArrayType - - | type baseType | - type := ExternalType typeNamed: 'char[5]'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalArrayType identical: type class. - self assert: ExternalType identical: baseType class. - - self assert: type size equals: baseType size.! Item was removed: - ----- Method: ExternalTypeTests>>testSizeAtomicType (in category 'tests - compiled spec') ----- - testSizeAtomicType - - | type baseType | - type := ExternalType typeNamed: 'int32_t'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalAtomicType identical: type class. - - self assert: type size equals: baseType size.! Item was removed: - ----- Method: ExternalTypeTests>>testSizePointerType (in category 'tests - compiled spec') ----- - testSizePointerType - - | type baseType | - type := ExternalType typeNamed: 'int32_t*'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalPointerType identical: type class. - self assert: ExternalType identical: baseType class. - - self assert: type size equals: baseType size.! Item was removed: - ----- Method: ExternalTypeTests>>testSizeStructureType (in category 'tests - compiled spec') ----- - testSizeStructureType - - | type baseType | - type := ExternalType typeNamed: 'FFITestSdi'. - baseType := type copy changeClassTo: ExternalType. - - self assert: ExternalStructureType identical: type class. - self assert: ExternalType identical: baseType class. - - self assert: type size equals: baseType size.! Item was changed: TestCase subclass: #FFIAllocateTests instanceVariableNames: 'externalObjects' classVariableNames: '' + poolDictionaries: 'FFIConstants' - poolDictionaries: '' category: 'FFI-Tests'! !FFIAllocateTests commentStamp: 'mt 5/10/2021 10:18' prior: 0! A collection of tests around the allocation of structs, unions, and arrays of atomics/structs/unions. Includes tests about accessing (field read/write) those after allocation.! Item was added: + ----- Method: FFIAllocateTests>>test12ArrayWithLargeSize (in category 'tests - array') ----- + test12ArrayWithLargeSize + + | array byteSize contentType arraySize | + byteSize := FFIStructSizeMask + 1. + contentType := ExternalType uint64_t. + arraySize := (byteSize / contentType byteSize) rounded. + array := self allocate: contentType size: arraySize. + self assert: array byteSize > FFIStructSizeMask.! |
Free forum by Nabble | Edit this page |