FFI: FFI-Tests-mt.45.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

FFI: FFI-Tests-mt.45.mcz

commits-2
Marcel Taeumel uploaded a new version of FFI-Tests to project FFI:
http://source.squeak.org/FFI/FFI-Tests-mt.45.mcz

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

Name: FFI-Tests-mt.45
Author: mt
Time: 21 May 2021, 11:11:03.010138 am
UUID: 4632b985-36be-564f-9ddc-e30405f110e9
Ancestors: FFI-Tests-mt.44

More robust tests for the "base type" of atomic types to really check the headerWord.

More tests for sub-array access.

=============== Diff against FFI-Tests-mt.44 ===============

Item was changed:
  ----- Method: ExternalTypeTests>>testBasicTypeForAtomicType (in category 'tests - compiled spec') -----
  testBasicTypeForAtomicType
+ "Check all information about atomics compiled in the compiledSpec's headerWord. While there might be polymorphic optimizations for in-image type checking, the basic type MUST contain all that information, too. Some checks will signal errors, which is okay as long as there are errors for the basic type, too."
+
+ ExternalType atomicTypes do: [:type |
+ | baseType |
+ baseType := type asBasicType.
+ #(isAtomic atomicType byteSize size
+ isIntegerType isFloatType isCharType isBoolType isVoid
+ isEmpty)
+ do: [:selector |
+ self
+ assert: (type perform: selector)
+ equals: (baseType perform: selector)].
+ #(isSigned isUnsigned isSinglePrecision isDoublePrecision)
+ do: [:selector |
+ self
+ assert: ([type perform: selector] on: Error do: [#error])
+ equals: ([baseType perform: selector] on: Error do: [#error])]].!
-
- | 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: FFIAllocateExternalTests>>test17ArrayFromUnkownSize (in category 'tests - array') -----
+ test17ArrayFromUnkownSize
+ "Overwritten because there is no out-of-bounds check for external memory."
+
+ | array portion |
+ array := self allocate: 'int32_t' size: 5.
+ 1 to: array size do: [:index | array at: index put: index].
+
+ array setSize: nil. "Possible but limited for byte-array handles."
+ portion := array reader from: 3.
+ self assert: 3 equals: (portion at: 1).
+ self assert: 4 equals: (portion at: 2).!

Item was added:
+ ----- Method: FFIAllocateTests>>test13ArrayFirst (in category 'tests - array') -----
+ test13ArrayFirst
+ "Access a sub-range in the external data."
+
+ | array portion |
+ array := self allocate: 'int32_t' size: 5.
+ 1 to: array size do: [:index | array at: index put: index].
+
+ array setSize: nil. "Not needed for #first:."
+ portion := array reader first: 2.
+ self assert: #(1 2) equals: (portion collect: #yourself).
+
+ portion at: 2 put: 42.
+ self assert: 42 equals: (array at: 2).!

Item was added:
+ ----- Method: FFIAllocateTests>>test14ArrayLast (in category 'tests - array') -----
+ test14ArrayLast
+ "Access a sub-range in the external data."
+
+ | array portion |
+ array := self allocate: 'int32_t' size: 5.
+ 1 to: array size do: [:index | array at: index put: index].
+
+ portion := array reader last: 2.
+ self assert: #(4 5) equals: (portion collect: #yourself).
+
+ portion at: 2 put: 42.
+ self assert: 42 equals: (array at: 5).!

Item was added:
+ ----- Method: FFIAllocateTests>>test15ArrayLastError (in category 'tests - array') -----
+ test15ArrayLastError
+ "Access a sub-range in the external data. Error for unknown size because #last: needs to access the end of the array."
+
+ | array |
+ array := self allocate: 'int32_t' size: 5.
+ array setSize: nil.
+ self should: [array last: 2] raise: Error.!

Item was added:
+ ----- Method: FFIAllocateTests>>test16ArrayFrom (in category 'tests - array') -----
+ test16ArrayFrom
+ "Access a sub-range in the external data by moving the start of the array."
+
+ | array portion |
+ array := self allocate: 'int32_t' size: 5.
+ 1 to: array size do: [:index | array at: index put: index].
+
+ portion := array reader from: 3.
+ self assert: #(3 4 5) equals: (portion collect: #yourself).!

Item was added:
+ ----- Method: FFIAllocateTests>>test17ArrayFromUnkownSize (in category 'tests - array') -----
+ test17ArrayFromUnkownSize
+ "Access a sub-range in the external data by moving the start of the array."
+
+ | array portion |
+ array := self allocate: 'int32_t' size: 5.
+ 1 to: array size do: [:index | array at: index put: index].
+
+ array setSize: nil. "Possible but limited for byte-array handles."
+ portion := array reader from: 3.
+ self assert: 3 equals: (portion at: 1).
+ self should: [portion at: 2] raise: Error.!

Item was added:
+ ----- Method: FFIAllocateTests>>test18ArrayMoveBackAndForth (in category 'tests - array') -----
+ test18ArrayMoveBackAndForth
+ "Check whether it is possible to move back-and-forth in memory without keeping track of the original array."
+
+ | array portion |
+ array := self allocate: 'int32_t' size: 5.
+ 1 to: array size do: [:index | array at: index put: index].
+
+ portion := array reader from: 3.
+ self assert: 3 equals: (portion at: 1).
+ portion := portion from: 0.
+ self assert: 2 equals: (portion at: 1).
+
+ portion := array reader from: 3.
+ self assert: 3 equals: (portion at: 1).
+ portion := portion from: -1.
+ self assert: 1 equals: (portion at: 1).
+
+ portion := portion from: 4.
+ self assert: 4 equals: (portion at: 1).!