Skip to content

SwiftVM: Swift tests and coverage

Run Swift Testing suites and capture LLVM code coverage inside disposable Apple Silicon macOS 27 virtual machines using the optional SwiftVM provider (darwin-arm64). Provisioned guests include Command Line Tools 27.0 (Swift 6.4, swiftbuild, and llvm-cov export format 3.0.1), so Swift packages build and test cleanly without Xcode.

Interactive walkthrough: Explore Swift Testing and LLVM coverage workflows.

Two workflows are supported:

  1. Your Swift packages in Reflow flows (vm.guest_run): Stage your package and test script by digest, build with --enable-code-coverage, export binaries, xunit results, and raw .profraw profiles under workspace out/, and ingest full coverage on the host with Reflow LLVM code coverage.
  2. Built-in fixture verification (svm run): Build and run SwiftVM’s reference AppKit + Swift Testing fixture via the svm host tool to verify template toolchains, xunit integrity, host re-hashing, and llvm-cov summary parity.

One provider, SwiftVM (flow alias vm), covers this page and SwiftVM: macOS VM, which describes templates, guest jobs, off-screen display capture, and host setup.

The macOS VM host requirements apply in full. In short:

  • An Apple Silicon Mac on physical hardware (no nested macOS virtualization), running macOS 27, with guests on macOS 27 or later.
  • A logged-in graphical session on the host. Virtual machines run on an offscreen display by default, so nothing appears on the desktop, but the session’s window server is still needed.
  • Command Line Tools 27.0 on the host (Swift 6.4, SDK 27.0); provisioning installs its own copy in the guest. About 100 GB of free disk for first-time setup.
  • The host tool signed with the com.apple.security.virtualization entitlement.
  • Direct HTTPS from the guest to Apple’s software update servers while the template is provisioned.

The guest has Command Line Tools, not Xcode, so tests use Swift Testing only. XCTest and .xcresult bundles are not supported.

Inside the guest, svm builds the package with Swift Build and coverage enabled (passing the package and scratch paths, the Swift Testing macro plugin path, and rpaths to the Command Line Tools testing libraries):

Terminal window
swift build --build-system swiftbuild --build-tests --enable-code-coverage

The tests then run through the toolchain’s swiftpm-testing-helper with --testing-library swift-testing, writing xunit XML.

svm run validates SwiftVM’s built-in reference fixture (an AppKit app with passing, failing, and slow suites for timeout/cancellation checks). To run your own Swift packages inside Reflow flows, stage and execute them as vm.guest_run jobs and export xunit XML and coverage profiles through workspace out/.

Test results are accepted only in a pinned xunit dialect from the Command Line Tools 27.0 / Swift 6.4 helper. Test identities must match exactly and summaries must be consistent; errors, skipped tests, duplicates and malformed counts are refused. If a template records a different Command Line Tools or Swift version, the run warns and adds a limitation to its report.

Artifacts are listed by the guest with their sizes and SHA-256 hashes and re-hashed on the host. A failed or mismatched transfer is recorded as corrupt and its partial file is deleted. The selected tests must come with the test bundle they were linked into. This proves the artifacts were transferred intact and that the evidence is consistent. It does not prove the guest is honest: the guest can fabricate results, and untrusted job code is not supported.

The run’s verdict and exit code are described on the macOS VM page.

When coverage is requested:

  1. Each test process writes a raw profile named <name>-%p.profraw.
  2. In the guest, llvm-profdata merge -sparse merges them and llvm-cov export -summary-only writes a summary.
  3. On the host, llvm-cov export -summary-only runs again over the guest’s merged profile and binary, and its summary is validated.

Command Line Tools 27’s llvm-cov writes export format 3.0.1, which svm validates.

A run that requests coverage never passes: at best it ends incomplete (exit 4), even when every test and coverage-integrity check passes. A failed check, unconfirmed cleanup or an interrupt gives that run’s usual exit code instead. There is no coverage policy, no default threshold, and no complete record tying the source, the build and the profiles together. Missing policy or provenance is never treated as a pass.

Coverage has one more trust limit: the host’s llvm-cov parses profiles and binaries produced inside the guest, and that parsing is not sandboxed.

The fixture’s summary-only coverage export is not a canonical Reflow coverage document: it lacks full per-file and per-function data, and no automatic fixture adapter exists. Its incomplete coverage verdict remains unchanged.

For vm.guest_run, build an instrumented app, retain its exact binaries and profiles under workspace out/, then bind and ingest the exported coverage on the host. A guest job passing does not itself ingest coverage or prove a coverage policy. See Swift and other LLVM languages for the required full llvm-cov export and process counts. The CLI accepts export formats 2.0.1 and 3.0.1, including Command Line Tools 27’s format.

  • Swift Testing only: Guests carry Command Line Tools 27 rather than Xcode, so XCTest and .xcresult bundles are not supported.
  • Host tool: Template provisioning and built-in fixture verification use the svm host tool built from source; provisioning requires direct outbound HTTPS for Command Line Tools.
  • Custom packages: Run your own Swift packages via vm.guest_run jobs and ingest full coverage on the host via reflow coverage ingest --format llvm-cov (there is no separate Reflow-level Swift Testing adapter command).
  • Fixture coverage mode: svm run coverage is a diagnostic check (exits 4 at best) and does not substitute for full llvm-cov ingestion into Reflow code coverage.