Skip to content

Apply toolset's testRunner property in swift test #8254

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 10 commits into from
Jan 29, 2025

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Jan 28, 2025

Motivation:

Per SE-0378 toolsets can specify an optional testRunner property, which so far had no effect. We should respect this property in swift test invocations when any toolsets or Swift SDKs are selected.

This property specifies a path to a test harness that has implementation-specific knowledge of interpreting produced test bundles.

This allows testing cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, qemu or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a WASI binary.

Modifications:

Updated SwiftRunCommand to check for the debugger property in toolsets or Swift SDKs when such are specified. Its value is then used to launch a freshly built binary.

Changed test bundle extension from .wasm to .xctest used for other platforms to reduce special casing in corresponding code paths. Without this change, initial implementation crashed here in the bundlePath property, triggering fatalError, as lookup logic always assumes .xctest extension:

fatalError("could not find test bundle path from '\(binaryPath)'")

Result:

Cross-compiled tests can be directly launched with a swift test invocation.

Per [SE-0378 toolsets can specify an optional `debugger` property](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md#toolsetjson-files), which so far had no effect. We should respect this property in `swift run` invocations when any toolsets or Swift SDKs are selected.

This allows running and debugging cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, qemu or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a WASI binary.
Per [SE-0378 toolsets can specify an optional `testRunner` property](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md#toolsetjson-files), which so far had no effect. We should respect this property in `swift test` invocations when any toolsets or Swift SDKs are selected.

This allows testing cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, qemu or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a WASI binary.
@MaxDesiatov MaxDesiatov added cross-compilation swift test Changes impacting `swift test` tool labels Jan 28, 2025
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov MaxDesiatov changed the base branch from maxd/toolset-debugger to main January 28, 2025 15:50
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

…o maxd/toolset-test-runner

# Conflicts:
#	Fixtures/Miscellaneous/EchoExecutable/echo.sh
#	Fixtures/Miscellaneous/EchoExecutable/toolset.json
#	Tests/CommandsTests/RunCommandTests.swift
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@bkhouri bkhouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments from a testing perspective.

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov MaxDesiatov enabled auto-merge (squash) January 28, 2025 17:42
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

1 similar comment
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

@MaxDesiatov MaxDesiatov merged commit b14e431 into main Jan 29, 2025
5 checks passed
@MaxDesiatov MaxDesiatov deleted the maxd/toolset-test-runner branch January 29, 2025 12:21
MaxDesiatov added a commit that referenced this pull request Feb 4, 2025
Cherry-pick of #8254 merged as b14e431.

**Explanation**: Per [SE-0378 toolsets can specify an optional `testRunner` property](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md#toolsetjson-files), which so far had no effect. We should respect this property in `swift test` invocations when any toolsets or Swift SDKs are selected.

This allows testing cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, QEMU or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a Wasm binary.
**Scope**: Only impacts `swift-test` when a toolset or a Swift SDK are selected.
**Risk**: Low, due to limited scope and automated testing.
**Testing**: Added a new test cause to the existing XCTest suite.
**Issue**: rdar://143815066
**Reviewer**: @dschaefer2
bripeticca pushed a commit to bripeticca/swift-package-manager that referenced this pull request Feb 28, 2025
### Motivation:

Per [SE-0378 toolsets can specify an optional `testRunner` property](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md#toolsetjson-files), which so far had no effect. We should respect this property in `swift test` invocations when any toolsets or Swift SDKs are selected.

This property specifies a path to a test harness that has implementation-specific knowledge of interpreting produced test bundles.

This allows testing cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, qemu or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a WASI binary.

### Modifications:

Updated SwiftRunCommand to check for the debugger property in toolsets or Swift SDKs when such are specified. Its value is then used to launch a freshly built binary.

Changed test bundle extension from `.wasm` to `.xctest` used for other platforms to reduce special casing in corresponding code paths. Without this change, initial implementation crashed here in the `bundlePath`
property, triggering `fatalError`, as lookup logic always assumes `.xctest` extension: https://github.com/swiftlang/swift-package-manager/blob/6aa009fd30992c3cba9af3fcb439ef57b61b75da/Sources/SPMBuildCore/BuiltTestProduct.swift#L35

### Result:

Cross-compiled tests can be directly launched with a `swift test` invocation.
kateinoigakukun added a commit to swiftwasm/carton that referenced this pull request Mar 7, 2025
swiftlang/swift-package-manager#8254 introduced
a change to produce `.xctest` files for test products instead of `.wasm`
files. This change updates the CartonTestPlugin to support both formats
and use the `.xctest` file if it is available.
kateinoigakukun added a commit to swiftwasm/carton that referenced this pull request Mar 7, 2025
swiftlang/swift-package-manager#8254 introduced
a change to produce `.xctest` files for test products instead of `.wasm`
files. This change updates the CartonTestPlugin to support both formats
and use the `.xctest` file if it is available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cross-compilation swift test Changes impacting `swift test` tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants