Skip to content

Commit

Permalink
Fix iOS perf actions (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
albho authored Nov 25, 2024
1 parent 95071bc commit 6447034
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 123 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ios-browserstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- name: Make build dir
run: mkdir ddp

- name: Copy test_resources
run: ./copy_test_resources.sh

- name: Run Cocoapods
run: pod install

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ios-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:

- name: Installing Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- run:
pip3 install requests
Expand All @@ -48,6 +49,9 @@ jobs:
- name: Make build dir
run: mkdir ddp

- name: Copy test_resources
run: ./copy_test_resources.sh

- name: Run Cocoapods
run: pod install

Expand Down
4 changes: 3 additions & 1 deletion binding/ios/EagleAppTest/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ build/*
*.pbxuser
xcuserdata
Pods
ddp
ddp

EagleAppTestUITests/test_resources/audio_samples/*
207 changes: 104 additions & 103 deletions binding/ios/EagleAppTest/EagleAppTest.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ class EagleAppTestUITests: BaseTest {

private func imposterUrl() -> URL {
let bundle = Bundle(for: type(of: self))
return bundle.url(forResource: "speaker_2_test_utt", withExtension: "wav", subdirectory: "audio_samples")!
return bundle.url(
forResource: "speaker_2_test_utt",
withExtension: "wav",
subdirectory: "audio_samples")!
}

private func testUrl() -> URL {
let bundle = Bundle(for: type(of: self))
return bundle.url(forResource: "speaker_1_test_utt", withExtension: "wav", subdirectory: "audio_samples")!
return bundle.url(
forResource: "speaker_1_test_utt",
withExtension: "wav",
subdirectory: "audio_samples")!
}

private func initEagle() throws -> Eagle {
Expand Down
Empty file.
36 changes: 21 additions & 15 deletions binding/ios/EagleAppTest/PerformanceTest/PerformanceTest.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 Picovoice Inc.
// Copyright 2023-2024 Picovoice Inc.
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
// file accompanying this source.
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
Expand All @@ -15,23 +15,26 @@ import Eagle
class PerformanceTest: XCTestCase {
let accessKey: String = "{TESTING_ACCESS_KEY_HERE}"
let iterationString: String = "{NUM_TEST_ITERATIONS}"
let indexThresholdString: String = "{INDEX_PERFORMANCE_THRESHOLD_SEC}"
let searchThresholdString: String = "{SEARCH_PERFORMANCE_THRESHOLD_SEC}"
let enrollThresholdString: String = "{ENROLL_PERFORMANCE_THRESHOLD_SEC}"
let procThresholdString: String = "{PROC_PERFORMANCE_THRESHOLD_SEC}"

override func setUp() {
super.setUp()
continueAfterFailure = false
}

func testProfilerPerformance() throws {
try XCTSkipIf(indexThresholdString == "{ENROLL_PERFORMANCE_THRESHOLD_SEC}")
try XCTSkipIf(enrollThresholdString == "{ENROLL_PERFORMANCE_THRESHOLD_SEC}")

let numTestIterations = Int(iterationString) ?? 30
let indexPerformanceThresholdSec = Double(indexThresholdString)
try XCTSkipIf(indexPerformanceThresholdSec == nil)
let enrollPerformanceThresholdSec = Double(enrollThresholdString)
try XCTSkipIf(enrollPerformanceThresholdSec == nil)

let bundle = Bundle(for: type(of: self))
let fileURL: URL = bundle.url(forResource: "test", withExtension: "wav")!
let fileURL: URL = bundle.url(
forResource: "speaker_1_test_utt",
withExtension: "wav",
subdirectory: "audio_samples")!
let audioData = try Data(contentsOf: fileURL)
var pcm = [Int16](repeating: 0, count: (audioData.count - 44) / 2)
_ = pcm.withUnsafeMutableBytes {
Expand All @@ -54,21 +57,21 @@ class PerformanceTest: XCTestCase {

let avgNSec = results.reduce(0.0, +) / Double(numTestIterations)
let avgSec = Double(round(avgNSec * 1000) / 1000)
XCTAssertLessThanOrEqual(avgSec, indexPerformanceThresholdSec!)
XCTAssertLessThanOrEqual(avgSec, enrollPerformanceThresholdSec!)
}

func testProcPerformance() throws {
try XCTSkipIf(searchThresholdString == "{PROC_PERFORMANCE_THRESHOLD_SEC}")
try XCTSkipIf(procThresholdString == "{PROC_PERFORMANCE_THRESHOLD_SEC}")

let numTestIterations = Int(iterationString) ?? 30
let searchPerformanceThresholdSec = Double(searchThresholdString)
try XCTSkipIf(searchPerformanceThresholdSec == nil)
let procPerformanceThresholdSec = Double(procThresholdString)
try XCTSkipIf(procPerformanceThresholdSec == nil)

let bundle = Bundle(for: type(of: self))

let enrollUrls: [URL] = [
bundle.url(forResource: "speaker_1_utt_1", withExtension: "wav")!,
bundle.url(forResource: "speaker_1_utt_2", withExtension: "wav")!
bundle.url(forResource: "speaker_1_utt_1", withExtension: "wav", subdirectory: "audio_samples")!,
bundle.url(forResource: "speaker_1_utt_2", withExtension: "wav", subdirectory: "audio_samples")!
]
let eagleProfiler = try EagleProfiler(accessKey: accessKey)
for enrollUrl in enrollUrls {
Expand All @@ -83,7 +86,10 @@ class PerformanceTest: XCTestCase {
let profile = try eagleProfiler.export()
eagleProfiler.delete()

let testAudioURL: URL = bundle.url(forResource: "test", withExtension: "wav")!
let testAudioURL: URL = bundle.url(
forResource: "speaker_2_test_utt",
withExtension: "wav",
subdirectory: "audio_samples")!
let audioData = try Data(contentsOf: testAudioURL)
var pcm = [Int16](repeating: 0, count: (audioData.count - 44) / 2)
_ = pcm.withUnsafeMutableBytes {
Expand All @@ -106,6 +112,6 @@ class PerformanceTest: XCTestCase {

let avgNSec = results.reduce(0.0, +) / Double(numTestIterations)
let avgSec = Double(round(avgNSec * 1000) / 1000)
XCTAssertLessThanOrEqual(avgSec, searchPerformanceThresholdSec!)
XCTAssertLessThanOrEqual(avgSec, procPerformanceThresholdSec!)
}
}
2 changes: 1 addition & 1 deletion binding/ios/EagleAppTest/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 32252195e8a4e7b7e29caf8a647533d7585f75e0

COCOAPODS: 1.11.3
COCOAPODS: 1.16.2
10 changes: 10 additions & 0 deletions binding/ios/EagleAppTest/copy_test_resources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LIB_DIR="../../../lib"
RESOURCE_DIR="../../../resources"
ASSETS_DIR="./EagleAppTestUITests/test_resources"

echo "Creating test resources asset directory"
mkdir -p ${ASSETS_DIR}

echo "Copying test audio samples..."
mkdir -p ${ASSETS_DIR}/audio_samples
cp ${RESOURCE_DIR}/audio_samples/*.wav ${ASSETS_DIR}/audio_samples
2 changes: 1 addition & 1 deletion script/automation/browserstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'Google Pixel 6 Pro-15.0'
],
'ios-min-max': [
'iPhone SE 2020-13',
'iPhone SE 2022-15',
'iPhone 14 Pro-16',
'iPhone 14-18'
],
Expand Down

0 comments on commit 6447034

Please sign in to comment.