Skip to content

Add a test target to SwiftPM package. #9557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,24 @@ let package = Package(
(value["libraries"] as? [String] ?? []).map { .linkedLibrary($0) }
),
]
}
} + [
.testTarget(
name: "tests",
dependencies: [
.target(name: "executorch_debug"),
.target(name: "kernels_portable"),
],
path: "extension/apple/ExecuTorch/__tests__",
resources: [
.copy("resources/add.pte")
],
linkerSettings: [
.linkedLibrary("c++"),
.unsafeFlags([
"-Xlinker", "-force_load",
"-Xlinker", "cmake-out/kernels_portable.xcframework/macos-arm64/libkernels_portable_macos.a",
])
]
)
]
)
11 changes: 9 additions & 2 deletions extension/apple/ExecuTorch/__tests__/ModuleTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
import XCTest

class ModuleTest: XCTestCase {
var resourceBundle: Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle(for: type(of: self))
#endif
}

func test() throws {
let bundle = Bundle(for: type(of: self))
guard let modelPath = bundle.path(forResource: "add", ofType: "pte") else {
guard let modelPath = resourceBundle.path(forResource: "add", ofType: "pte") else {
XCTFail("Couldn't find the model file")
return
}
Expand Down
7 changes: 6 additions & 1 deletion scripts/build_apple_frameworks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ cmake_build() {
cmake --build . \
--config "$mode" \
--verbose
cd ..
cd -
}

for index in ${!PLATFORMS[*]}; do
Expand Down Expand Up @@ -283,4 +283,9 @@ done

rm -rf "$HEADERS_PATH"

echo "Running tests"

cd "$SOURCE_ROOT_DIR"
swift test

echo "Build succeeded!"
Loading