[squeak-dev] FFI: FFI-Tests-mt.18.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Jun 11 09:23:11 UTC 2020
Marcel Taeumel uploaded a new version of FFI-Tests to project FFI:
http://source.squeak.org/FFI/FFI-Tests-mt.18.mcz
==================== Summary ====================
Name: FFI-Tests-mt.18
Author: mt
Time: 11 June 2020, 11:23:10.390059 am
UUID: 468e6185-2cb9-c248-9288-e67137e7b144
Ancestors: FFI-Tests-mt.17
- Adds tests for type-name lookup, which is used during struct-field and FFI-call compilation. Organize fixtures in "FFI-Tests-Fixtures".
- Explicates #ffiLongVsInt issue.
- Fixes one test that actually called to a 'long' in C to use 'c_long' instead of 'long'.
- Adds tests for 'bool' support, which maps to 'unsigned int' in the FFI plugin, which you can see in ByteArray>>#booleanAt:(put:).
- Exposes new functions, which are already exported in the current FFI plugin: ffiTest4IntSum, ffiTest8IntSum.
=============== Diff against FFI-Tests-mt.17 ===============
Item was changed:
SystemOrganization addCategory: #'FFI-Tests'!
+ SystemOrganization addCategory: #'FFI-Tests-Fixtures'!
Item was added:
+ ----- Method: FFIPluginTests>>testGenericBoolCall (in category 'simple tests') -----
+ testGenericBoolCall
+ "Test using generic FFI spec"
+ | result |
+ result := FFITestLibrary ffiTestBool: true with: false with: true with: false.
+ self assert: result.!
Item was added:
+ ----- Method: FFIPluginTests>>testGenericBoolCall2 (in category 'simple tests') -----
+ testGenericBoolCall2
+ "Test using generic FFI spec"
+ | result |
+ result := FFITestLibrary ffiTestBool: false with: false with: true with: true.
+ self deny: result.!
Item was added:
+ ----- Method: FFIPluginTests>>testGenericBoolCall3 (in category 'simple tests') -----
+ testGenericBoolCall3
+ "Test using generic FFI spec"
+ | result |
+ result := FFITestLibrary ffiTestBool: -1 with: 1 with: 0 with: 0.
+ self deny: result.!
Item was changed:
----- Method: FFIPluginTests>>testGenericIntCall (in category 'simple tests') -----
testGenericIntCall
"Test using generic FFI spec"
| result |
+ self flag: #ffiLongVsInt.
result := FFITestLibrary ffiTestInt: $A with: 65 with: 65.0 with: true.
self assert: result = 130.!
Item was added:
+ ----- Method: FFIPluginTests>>testGenericLongCall (in category 'simple tests') -----
+ testGenericLongCall
+ "Test using generic FFI spec"
+ | result |
+ self flag: #ffiLongVsInt.
+ result := FFITestLibrary ffiTestLong: $A with: 65 with: 65.0 with: true.
+ self assert: result = 130.!
Item was changed:
----- Method: FFIPluginTests>>testMixedDoublesAndLongsSum (in category 'simple tests') -----
testMixedDoublesAndLongsSum
"Test using generic FFI spec"
| result meth n args |
meth := ExternalLibraryFunction
name:'ffiTestMixedDoublesAndLongs' module: FFITestLibrary moduleName
callType: 0 returnType: ExternalType double
+ argumentTypes: ((1 to: (n := 20)) collect:[:i| i odd ifTrue: [ExternalType double] ifFalse: [ExternalType c_long]]).
- argumentTypes: ((1 to: (n := 20)) collect:[:i| i odd ifTrue: [ExternalType double] ifFalse: [ExternalType long]]).
args := (1 to: n) collect: [:i| i odd ifTrue: [(i // 2) odd ifTrue: [123.456 * (10 raisedTo: i)] ifFalse: [-654.321 * (10 raisedTo: i)]] ifFalse: [(i // 2) odd ifTrue: [54321 * i] ifFalse: [-54321 * i]]].
result := meth invokeWithArguments: args asArray.
self assert: args sum equals: result!
Item was added:
+ ----- Method: FFIPluginTests>>testUintRange (in category 'simple tests') -----
+ testUintRange
+ "Simple test for making sure the FFI can call certain numbers in the uint range."
+ | result |
+ self flag: #ffiLongVsInt.
+ self shouldnt:[result := FFITestLibrary ffiTestUint: 3894967296 "1<<32-4e8 " with: 3894967296 with: 3103854339 with: 3103854339] raise: Error.
+ self should: result = -8e8.!
Item was changed:
----- Method: FFIPluginTests>>testUlongRange (in category 'simple tests') -----
testUlongRange
"Simple test for making sure the FFI can call certain numbers in the ulong range.
+ Note: since primitive is using unsigned int under the hood, avoid an integer overflow by choosing appropriate unsigned values.
- Note: since primitive is using signed int under the hood, avoid an integer overflow by choosing appropriate unsigned values.
Note: only first two parameters are added"
| result |
+ self flag: #ffiLongVsInt.
self shouldnt:[result := FFITestLibrary ffiTestUlong: 3894967296 "1<<32-4e8 " with: 3894967296 with: 3103854339 with: 3103854339] raise: Error.
self should: result = -8e8.!
Item was changed:
ExternalStructure subclass: #FFISmallStruct1
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestBiggerStruct
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestCompoundStruct
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalLibrary subclass: #FFITestLibrary
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
!FFITestLibrary commentStamp: 'ar 8/14/2006 23:06' prior: 0!
ExternalLibrarty used in FFI tests!
Item was added:
+ ----- Method: FFITestLibrary class>>ffiTest4IntSum:with:with:with: (in category 'primitives - long vs. int') -----
+ ffiTest4IntSum: c1 with: c2 with: c3 with: c4
+ "FFITestLibrary ffiTest4IntSum: 1 with: 2 with: 3 with: 4"
+ <cdecl: int 'ffiTest4IntSum' (int int int int) module:'SqueakFFIPrims'>
+ self flag: #ffiLongVsInt.
+ ^self externalCallFailed!
Item was added:
+ ----- Method: FFITestLibrary class>>ffiTest4LongSum:with:with:with: (in category 'primitives - long vs. int') -----
+ ffiTest4LongSum: c1 with: c2 with: c3 with: c4
+ "FFITestLibrary ffiTest4LongSum: 1 with: 2 with: 3 with: 4"
+ <cdecl: long 'ffiTest4IntSum' (long long long long) module:'SqueakFFIPrims'>
+ self flag: #ffiLongVsInt.
+ ^self externalCallFailed!
Item was added:
+ ----- Method: FFITestLibrary class>>ffiTest8IntSum:with:with:with:with:with:with:with: (in category 'primitives - long vs. int') -----
+ ffiTest8IntSum: c1 with: c2 with: c3 with: c4 with: c5 with: c6 with: c7 with: c8
+ "FFITestLibrary ffiTest8IntSum: 1 with: 2 with: 3 with: 4 with: 5 with: 6 with: 7 with: 8"
+ <cdecl: int 'ffiTest8IntSum' (int int int int int int int int) module:'SqueakFFIPrims'>
+ self flag: #ffiLongVsInt.
+ ^self externalCallFailed!
Item was added:
+ ----- Method: FFITestLibrary class>>ffiTest8LongSum:with:with:with:with:with:with:with: (in category 'primitives - long vs. int') -----
+ ffiTest8LongSum: c1 with: c2 with: c3 with: c4 with: c5 with: c6 with: c7 with: c8
+ "FFITestLibrary ffiTest8LongSum: 1 with: 2 with: 3 with: 4 with: 5 with: 6 with: 7 with: 8"
+ <cdecl: long 'ffiTest8IntSum' (long long long long long long long long) module:'SqueakFFIPrims'>
+ self flag: #ffiLongVsInt.
+ ^self externalCallFailed!
Item was added:
+ ----- Method: FFITestLibrary class>>ffiTestBool:with:with:with: (in category 'primitives') -----
+ ffiTestBool: b1 with: b2 with: b3 with: b4
+ "FFITestLibrary ffiTestBool: true with: false with: true with: false"
+ <cdecl: bool 'ffiTestInts' (bool bool bool bool) module:'SqueakFFIPrims'>
+ ^self externalCallFailed!
Item was changed:
+ ----- Method: FFITestLibrary class>>ffiTestInt:with:with:with: (in category 'primitives - long vs. int') -----
- ----- Method: FFITestLibrary class>>ffiTestInt:with:with:with: (in category 'primitives') -----
ffiTestInt: c1 with: c2 with: c3 with: c4
"FFITestLibrary ffiTestInt: $A with: 65 with: 65.0 with: true"
+ <cdecl: int 'ffiTestInts' (int int int int) module:'SqueakFFIPrims'>
+ self flag: #ffiLongVsInt.
- <cdecl: long 'ffiTestInts' (long long long long) module:'SqueakFFIPrims'>
^self externalCallFailed!
Item was added:
+ ----- Method: FFITestLibrary class>>ffiTestLong:with:with:with: (in category 'primitives - long vs. int') -----
+ ffiTestLong: c1 with: c2 with: c3 with: c4
+ "FFITestLibrary ffiTestLong: $A with: 65 with: 65.0 with: true"
+ <cdecl: long 'ffiTestInts' (long long long long) module:'SqueakFFIPrims'>
+ self flag: #ffiLongVsInt.
+ ^self externalCallFailed!
Item was added:
+ ----- Method: FFITestLibrary class>>ffiTestUint:with:with:with: (in category 'primitives - long vs. int') -----
+ ffiTestUint: c1 with: c2 with: c3 with: c4
+ "FFITestLibrary ffiTestUint: 3103854339 with: 3103854339 with: 3103854339 with: 3103854339"
+ <cdecl: int 'ffiTestInts' (uint uint uint uint) module:'SqueakFFIPrims'>
+ self flag: #ffiLongVsInt.
+ ^self externalCallFailed!
Item was changed:
+ ----- Method: FFITestLibrary class>>ffiTestUlong:with:with:with: (in category 'primitives - long vs. int') -----
- ----- Method: FFITestLibrary class>>ffiTestUlong:with:with:with: (in category 'primitives') -----
ffiTestUlong: c1 with: c2 with: c3 with: c4
"FFITestLibrary ffiTestUlong: 3103854339 with: 3103854339 with: 3103854339 with: 3103854339"
<cdecl: long 'ffiTestInts' (ulong ulong ulong ulong) module:'SqueakFFIPrims'>
+ self flag: #ffiLongVsInt.
^self externalCallFailed!
Item was added:
+ ----- Method: FFITestLibrary class>>ffiTestVoid (in category 'mocks') -----
+ ffiTestVoid
+ "Note that ffiTestVoid does exist in the module."
+ <cdecl: void 'ffiTestVoid' (void) module:'SqueakFFIPrims'>
+ ^self externalCallFailed!
Item was added:
+ ----- Method: FFITestLibrary class>>ffiTestVoidPointer (in category 'mocks') -----
+ ffiTestVoidPointer
+ "Note that ffiTestVoidPointer does exist in the module."
+ <cdecl: void* 'ffiTestVoidPointer' (void*) module:'SqueakFFIPrims'>
+ ^self externalCallFailed!
Item was changed:
ExternalStructure subclass: #FFITestMisalignedCompoundStruct
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestMisalignedStruct
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestPoint2
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
!FFITestPoint2 commentStamp: 'ar 8/14/2006 23:06' prior: 0!
A class used for testing structures as arguments for the FFI.!
Item was changed:
ExternalStructure subclass: #FFITestPoint4
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
!FFITestPoint4 commentStamp: 'ar 8/14/2006 23:06' prior: 0!
A class used for testing structures as arguments for the FFI.!
Item was changed:
ExternalStructure subclass: #FFITestSSdi5
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSUfdUdSi2
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSUfdUfi
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSd2
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSdi
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSf2
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSf2d
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSf4
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSfd
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSfdf
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSfi
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSi2
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSl2
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSs2
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSs2i
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSs4
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSsSsf
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSsSsi
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSsf
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSsi
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSsis
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSslf
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalStructure subclass: #FFITestSsls
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalUnion subclass: #FFITestUdSi2
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalUnion subclass: #FFITestUfd
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was changed:
ExternalUnion subclass: #FFITestUfi
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
+ category: 'FFI-Tests-Fixtures'!
- category: 'FFI-Tests'!
Item was added:
+ TestCase subclass: #FFITypeNameTests
+ instanceVariableNames: ''
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'FFI-Tests'!
Item was added:
+ ----- Method: FFITypeNameTests>>argTypesAt: (in category 'support') -----
+ argTypesAt: selector
+
+ ^ (FFITestLibrary class >> selector) externalLibraryFunction argTypes!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicBool (in category 'tests') -----
+ testAtomicBool
+
+ self
+ flag: #ffiLongVsInt;
+ assert: (self argTypesAt: #ffiTestBool:with:with:with:)
+ equals: (Array new: 5 withAll: ExternalType bool).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicChar (in category 'tests') -----
+ testAtomicChar
+
+ self
+ flag: #ffiLongVsInt;
+ assert: (self argTypesAt: #ffiTestChar:with:with:with:)
+ equals: (Array new: 5 withAll: ExternalType char).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicCharPointer (in category 'tests') -----
+ testAtomicCharPointer
+
+ self
+ assert: (self argTypesAt: #ffiPrintString:)
+ equals: (Array new: 2 withAll: ExternalType char asPointerType).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicDouble (in category 'tests') -----
+ testAtomicDouble
+
+ self
+ assert: (self argTypesAt: #ffiTestDoubles:with:)
+ equals: (Array new: 3 withAll: ExternalType double).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicFloat (in category 'tests') -----
+ testAtomicFloat
+
+ self
+ assert: (self argTypesAt: #ffiTestFloats:with:)
+ equals: (Array new: 3 withAll: ExternalType float).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicInt (in category 'tests') -----
+ testAtomicInt
+
+ self
+ flag: #ffiLongVsInt;
+ assert: (self argTypesAt: #ffiTestInt:with:with:with:)
+ equals: (Array new: 5 withAll: ExternalType int).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicLong (in category 'tests') -----
+ testAtomicLong
+
+ self
+ flag: #ffiLongVsInt;
+ assert: (self argTypesAt: #ffiTestLong:with:with:with:)
+ equals: (Array new: 5 withAll: ExternalType long).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicLongLong (in category 'tests') -----
+ testAtomicLongLong
+
+ self
+ assert: (self argTypesAt: #ffiTestLongLong:with:)
+ equals: (Array new: 3 withAll: ExternalType longlong).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicString (in category 'tests') -----
+ testAtomicString
+
+ self
+ assert: (self argTypesAt: #ffiPrintString:)
+ equals: (Array new: 2 withAll: ExternalType string).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicUint (in category 'tests') -----
+ testAtomicUint
+
+ self
+ flag: #ffiLongVsInt;
+ assert: (self argTypesAt: #ffiTestUint:with:with:with:) allButFirst
+ equals: (Array new: 4 withAll: ExternalType uint).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicUlong (in category 'tests') -----
+ testAtomicUlong
+
+ self
+ flag: #ffiLongVsInt;
+ assert: (self argTypesAt: #ffiTestUlong:with:with:with:) allButFirst
+ equals: (Array new: 4 withAll: ExternalType ulong).!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicVoid (in category 'tests') -----
+ testAtomicVoid
+ "Only test for return type since argument 'void' means 'no argument' in C."
+
+ self
+ assert: (self argTypesAt: #ffiTestVoid)
+ equals: {ExternalType void}.!
Item was added:
+ ----- Method: FFITypeNameTests>>testAtomicVoidPointer (in category 'tests') -----
+ testAtomicVoidPointer
+
+ self
+ assert: (self argTypesAt: #ffiTestVoidPointer)
+ equals: (Array new: 2 withAll: ExternalType void asPointerType).!
Item was added:
+ ----- Method: FFITypeNameTests>>testStruct (in category 'tests') -----
+ testStruct
+
+ self
+ assert: (self argTypesAt: #ffiTestPoint2:with:)
+ equals: (Array new: 3 withAll: FFITestPoint2 externalType).!
Item was added:
+ ----- Method: FFITypeNameTests>>testStructPointer (in category 'tests') -----
+ testStructPointer
+
+ self
+ assert: (self argTypesAt: #ffiTestPointers:with:)
+ equals: (Array new: 3 withAll: FFITestPoint4 externalType asPointerType).!
More information about the Squeak-dev
mailing list
|