-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github action workflow to run tests (#56)
* add section to readme for running tests * add toc to readme * use dedicated xcode build action * fix compile error by renaming function in FMAPI.swift file * split tests into dedicated test cases * skip filter tests during CI * add trigger for pushes to develop
- Loading branch information
Showing
8 changed files
with
352 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Swift Integration Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
|
||
jobs: | ||
test: | ||
name: Tests | ||
runs-on: macos-latest | ||
strategy: | ||
matrix: | ||
destination: ['platform=iOS Simulator,OS=14.4,name=iPhone 12 Pro Max'] | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Build and Test | ||
uses: sersoft-gmbh/xcodebuild-action@v1 | ||
with: | ||
project: FantasmoSDK.xcodeproj | ||
scheme: FantasmoSDKTests | ||
destination: ${{ matrix.destination }} | ||
action: test | ||
skip-testing: 'FantasmoSDKTests/SDKFilterTests/testBlurFilter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
FantasmoSDK.xcodeproj/xcshareddata/xcschemes/FantasmoSDKTests.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1300" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A0D5E88626BA97DA00CE5B1C" | ||
BuildableName = "FantasmoSDKTests.xctest" | ||
BlueprintName = "FantasmoSDKTests" | ||
ReferencedContainer = "container:FantasmoSDK.xcodeproj"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// SDKFilterTests.swift | ||
// FantasmoSDKTests | ||
// | ||
// Created by lucas kuzma on 8/4/21. | ||
// Modified by che fisher on 27/9/21 | ||
|
||
import XCTest | ||
import CoreLocation | ||
import ARKit | ||
|
||
class SDKFilterTests: XCTestCase { | ||
|
||
override class func setUp() { | ||
// Put setup code here that is run once (equal to mocha "before" hook) | ||
} | ||
|
||
override func setUpWithError() throws { | ||
// Put setup code here is run before each test (equal to mocha "beforeEach" hook) | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
// Put teardown code that is run after each test case (equal to mocha "afterEach" hook) | ||
} | ||
|
||
override class func tearDown() { | ||
// Put teardown code that is run once (equal to mocha "after" hook) | ||
} | ||
|
||
// note: this test will not fail and not throw an error code if the pixelBuffer assignment fails | ||
func testMovementFilter() { | ||
let filter = FMMovementFilter() | ||
var transform = simd_float4x4(1) | ||
var pixelBuffer: CVPixelBuffer? = nil | ||
CVPixelBufferCreate(kCFAllocatorDefault, 64, 64, kCVPixelFormatType_OneComponent8, nil, &pixelBuffer) | ||
if let pixelBuffer = pixelBuffer { | ||
var frame = MockFrame(fmCamera: MockCamera(transform: transform), capturedImage: pixelBuffer) | ||
XCTAssertEqual(filter.accepts(frame), .rejected(reason: .movingTooLittle)) | ||
transform = simd_float4x4(1.1) | ||
frame = MockFrame(fmCamera: MockCamera(transform: transform), capturedImage: pixelBuffer) | ||
XCTAssertEqual(filter.accepts(frame), .accepted) | ||
transform = simd_float4x4(1.099) | ||
XCTAssertEqual(filter.accepts(frame), .rejected(reason: .movingTooLittle)) | ||
} else { | ||
print ("Couldn't allocate mock pixel buffer") | ||
} | ||
} | ||
|
||
// note: this test will not fail and not throw an error code if the nonnilBuffer assignment fails | ||
func testCameraPitchFilter() { | ||
let filter = FMCameraPitchFilter() | ||
var pixelBuffer: CVPixelBuffer? = nil | ||
CVPixelBufferCreate(kCFAllocatorDefault, 64, 64, kCVPixelFormatType_OneComponent8, nil, &pixelBuffer) | ||
var pitch : Float = deg2rad(-90) | ||
if let nonnilBuffer = pixelBuffer { | ||
var frame = MockFrame(fmCamera: MockCamera(pitch: pitch), capturedImage: nonnilBuffer) | ||
XCTAssertEqual(filter.accepts(frame), .rejected(reason: .pitchTooLow)) | ||
pitch = deg2rad(-65) | ||
frame = MockFrame(fmCamera: MockCamera(pitch: pitch), capturedImage: nonnilBuffer) | ||
XCTAssertEqual(filter.accepts(frame), .accepted) | ||
pitch = deg2rad(0) | ||
frame = MockFrame(fmCamera: MockCamera(pitch: pitch), capturedImage: nonnilBuffer) | ||
XCTAssertEqual(filter.accepts(frame), .accepted) | ||
pitch = deg2rad(30) | ||
frame = MockFrame(fmCamera: MockCamera(pitch: pitch), capturedImage: nonnilBuffer) | ||
XCTAssertEqual(filter.accepts(frame), .accepted) | ||
pitch = deg2rad(60) | ||
frame = MockFrame(fmCamera: MockCamera(pitch: pitch), capturedImage: nonnilBuffer) | ||
XCTAssertEqual(filter.accepts(frame), .rejected(reason: .pitchTooHigh)) | ||
} else { | ||
print ("Couldn't allocate mock pixel buffer") | ||
} | ||
} | ||
|
||
func testBlurFilter() { | ||
let filter = FMBlurFilter() | ||
let dayScan = UIImage(named: "dayScan", in: Bundle(for: type(of: self)), compatibleWith: nil) | ||
let dayScanFrame = MockFrame(capturedImage: dayScan!.pixelBuffer()!) | ||
let nightScan = UIImage(named: "nightScan", in: Bundle(for: type(of: self)), compatibleWith: nil) | ||
let nightScanFrame = MockFrame(capturedImage: nightScan!.pixelBuffer()!) | ||
|
||
// nighttime passes twice because of no throughput | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .accepted) | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .accepted) | ||
// daytime passes because it has enough variance | ||
XCTAssertEqual(filter.accepts(dayScanFrame), .accepted) | ||
XCTAssertEqual(filter.accepts(dayScanFrame), .accepted) | ||
XCTAssertEqual(filter.accepts(dayScanFrame), .accepted) | ||
XCTAssertEqual(filter.accepts(dayScanFrame), .accepted) | ||
// nighttime is rejected 6 times because it is too blurry and the throughput is superior to 0.25 on the last 8 frames | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .rejected(reason: .imageTooBlurry)) | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .rejected(reason: .imageTooBlurry)) | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .rejected(reason: .imageTooBlurry)) | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .rejected(reason: .imageTooBlurry)) | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .rejected(reason: .imageTooBlurry)) | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .rejected(reason: .imageTooBlurry)) | ||
// on the 7th nighttime picture in a row, throughput gets back under 0.25 and it passes again | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .accepted) | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .accepted) | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .accepted) | ||
XCTAssertEqual(filter.accepts(nightScanFrame), .accepted) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// SDKGeometricTests.swift | ||
// FantasmoSDKTests | ||
// | ||
// Created by lucas kuzma on 8/4/21. | ||
// Modified by che fisher on 27/9/21. | ||
|
||
import XCTest | ||
import CoreLocation | ||
import ARKit | ||
|
||
class SDKGeometricTests: XCTestCase { | ||
|
||
override class func setUp() { | ||
// Put setup code here that is run once (equal to mocha "before" hook) | ||
} | ||
|
||
override func setUpWithError() throws { | ||
// Put setup code here is run before each test (equal to mocha "beforeEach" hook) | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
// Put teardown code that is run after each test case (equal to mocha "afterEach" hook) | ||
} | ||
|
||
override class func tearDown() { | ||
// Put teardown code that is run once (equal to mocha "after" hook) | ||
} | ||
|
||
func testGeometricMedian() throws { | ||
var locations: [CLLocation] = [] | ||
var median = CLLocation() | ||
var expected = CLLocation() | ||
|
||
locations.append(CLLocation(latitude: 0, longitude: 0)) | ||
median = CLLocation.geometricMedian(locations) | ||
print(median.coordinate) | ||
|
||
expected = CLLocation(latitude: 0, longitude: 0); | ||
XCTAssertLessThan(median.degreeDistance(from: expected), 0.001) | ||
|
||
locations = [] | ||
locations.append(CLLocation(latitude: 10, longitude: 0)) | ||
locations.append(CLLocation(latitude: -10, longitude: 0)) | ||
median = CLLocation.geometricMedian(locations) | ||
print(median.coordinate) | ||
|
||
expected = CLLocation(latitude: 0, longitude: 0); | ||
XCTAssertLessThan(median.degreeDistance(from: expected), 0.001) | ||
|
||
locations.append(CLLocation(latitude: 0, longitude: 10)) | ||
median = CLLocation.geometricMedian(locations) | ||
print(median.coordinate) | ||
|
||
expected = CLLocation(latitude: 0, longitude: 5.77); | ||
XCTAssertLessThan(median.degreeDistance(from: expected), 0.01) | ||
|
||
locations = [] | ||
locations.append(CLLocation(latitude: 10, longitude: 10)) | ||
locations.append(CLLocation(latitude: 20, longitude: 10)) | ||
locations.append(CLLocation(latitude: 10, longitude: 20)) | ||
locations.append(CLLocation(latitude: 20, longitude: 20)) | ||
median = CLLocation.geometricMedian(locations) | ||
print(median.coordinate) | ||
|
||
expected = CLLocation(latitude: 15, longitude: 15); | ||
XCTAssertLessThan(median.degreeDistance(from: expected), 0.01) | ||
|
||
locations.append(CLLocation(latitude: 15, longitude: 15)) | ||
median = CLLocation.geometricMedian(locations) | ||
print(median.coordinate) | ||
|
||
XCTAssertLessThan(median.degreeDistance(from: expected), 0.01) | ||
} | ||
|
||
func testGeometricMedianColinear() throws { | ||
var locations: [CLLocation] = [] | ||
var median = CLLocation() | ||
var expected = CLLocation() | ||
|
||
locations = [] | ||
locations.append(CLLocation(latitude: 0, longitude: 0)) | ||
locations.append(CLLocation(latitude: 0, longitude: 10)) | ||
median = CLLocation.geometricMedian(locations) | ||
print(median.coordinate) | ||
|
||
expected = CLLocation(latitude: 0, longitude: 5); | ||
XCTAssertLessThan(median.degreeDistance(from: expected), 0.01) | ||
|
||
locations.append(CLLocation(latitude: 0, longitude: 20)) | ||
median = CLLocation.geometricMedian(locations) | ||
print(median.coordinate) | ||
|
||
expected = CLLocation(latitude: 0, longitude: 10); | ||
XCTAssertLessThan(median.degreeDistance(from: expected), 0.01) | ||
} | ||
} |
Oops, something went wrong.