# Parallel iOS Simulator Device Matrix on Cloud Mac

Canonical: https://figment.so/blog/mac-simulator-parallel-device-matrix

Run xcodebuild test once per Simulator UDID as a background job, give each its own derivedDataPath and resultBundlePath, wait on the recorded PIDs, and merge the bundles with xcresulttool. Size the Mac's memory by measuring your own suite.

**Run `xcodebuild test` once per Simulator destination as a background shell job, give every job its own `-derivedDataPath` and `-resultBundlePath`, wait on the recorded PIDs, and merge the resulting `.xcresult` bundles with `xcrun xcresulttool merge`.** Host the matrix on a Mac with enough memory for the Simulators you boot together. Parallel Simulators are memory-bound, so measure your own suite before you pick a plan.

Running Simulator targets back to back on an Apple silicon Mac usually leaves cores and memory headroom unused, but how much depends on your tests. Instead of quoting a per-Simulator core or RAM number, this guide gives you a measurement worksheet and a wrapper that does not step on itself across jobs or reruns. Apple's [running your app in Simulator or on a device](https://developer.apple.com/documentation/xcode/running-your-app-in-simulator-or-on-a-device) covers how `xcodebuild` resolves a destination, and [WWDC19 session 413, "Testing in Xcode"](https://developer.apple.com/videos/play/wwdc2019/413/) is the Apple reference for `xcresulttool` and the result-bundle format you will merge.

## How do I list the Simulators I actually have?

Match destinations by UDID so matrix rows cannot collide with a duplicate name, such as an "iPhone 16 Pro" on two runtimes:

```bash
xcrun simctl list devices available -j \
  | python3 -c '
import json, sys
data = json.load(sys.stdin)
for runtime, devices in data["devices"].items():
    for d in devices:
        if d.get("isAvailable"):
            print(d["udid"], runtime, d["name"])
' | grep -i "iOS"
```

Copy the UDIDs you want into your job. If a runtime is missing, install it from Xcode → Settings → Platforms or run `xcodebuild -downloadPlatform iOS`. For `xcresulttool` and `xcodebuild` option details, check the installed help on your own machine, because the surface changes between releases:

```bash
xcrun xcresulttool help
xcrun xcresulttool help merge
xcrun xcodebuild -help | less
```

The subcommand that used to be written `xcresulttool get --format json --path …` has been reshaped in recent Xcode versions. Prefer what `xcresulttool help` prints on the machine you use (for example `xcresulttool get test-results summary --path …` on current Xcode), and do not copy old flags blindly.

## What does a safe parallel-destinations wrapper look like?

The wrapper targets explicit UDIDs, gives every background job its own unique `-derivedDataPath` and `-resultBundlePath`, waits only on the PIDs it started, and cleans up only its own children on interrupt. It never runs `pkill xcodebuild` or wipes shared DerivedData. Adapt the scheme, project or workspace, and UDID list to your project. This example is untested and you must verify it on your installed Xcode.

```bash
#!/usr/bin/env bash
# parallel-destinations.sh — fan xcodebuild test out across iOS Simulator UDIDs.
set -euo pipefail

SCHEME="${SCHEME:?Set SCHEME to your Xcode test scheme}"
: "${UDIDS:?Set UDIDS to a bash array of Simulator UDIDs}"

if [[ -n "${WORKSPACE:-}" ]]; then
  BUILD_FLAGS=(-workspace "$WORKSPACE")
elif [[ -n "${PROJECT:-}" ]]; then
  BUILD_FLAGS=(-project "$PROJECT")
else
  echo "Set PROJECT=... or WORKSPACE=..." >&2; exit 2
fi

# Truly unique per invocation; safe across matrix cells and reruns.
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-$$-$RANDOM"
ROOT="$(pwd)/.parallel-sim/$RUN_ID"
mkdir -p "$ROOT"

PIDS=(); RESULTS=(); LABELS=()

cleanup() {
  # Only signal children we started; never a global xcodebuild sweep.
  for pid in "${PIDS[@]:-}"; do
    kill "$pid" 2>/dev/null || true
  done
}
trap cleanup INT TERM

for UDID in "${UDIDS[@]}"; do
  JOB_DIR="$ROOT/$UDID"
  mkdir -p "$JOB_DIR"
  RESULT="$JOB_DIR/result.xcresult"
  LOG="$JOB_DIR/xcodebuild.log"

  xcodebuild test \
    "${BUILD_FLAGS[@]}" \
    -scheme "$SCHEME" \
    -destination "platform=iOS Simulator,id=$UDID" \
    -parallel-testing-enabled NO \
    -derivedDataPath "$JOB_DIR/DerivedData" \
    -resultBundlePath "$RESULT" \
    > "$LOG" 2>&1 &

  PIDS+=("$!"); RESULTS+=("$RESULT"); LABELS+=("$UDID")
  echo "started $UDID pid=$!"
done

FAILED=0
for i in "${!PIDS[@]}"; do
  if wait "${PIDS[$i]}"; then
    echo "pass ${LABELS[$i]}"
  else
    echo "fail ${LABELS[$i]} (see $ROOT/${LABELS[$i]}/xcodebuild.log)" >&2
    FAILED=1
  fi
done

# Only merge bundles the build actually produced; do not count failures as passes.
MERGE_INPUTS=()
for r in "${RESULTS[@]}"; do [[ -d "$r" ]] && MERGE_INPUTS+=("$r"); done
if (( ${#MERGE_INPUTS[@]} > 0 )); then
  xcrun xcresulttool merge "${MERGE_INPUTS[@]}" --output-path "$ROOT/merged.xcresult"
  echo "merged bundle: $ROOT/merged.xcresult"
fi

exit "$FAILED"
```

Every destination uses `id=UDID`, so no two rows can be ambiguous. Each job writes into `./.parallel-sim/<run-id>/<udid>/`, which collides neither across matrix cells nor across reruns. Failed builds exit non-zero and are excluded from the merge, so the overall exit status reflects reality instead of being masked by the merge succeeding on the passes.

Invoke it with an explicit UDID list rather than hard-coding device names in the script:

```bash
UDIDS=(ABCD1234-... EFGH5678-... IJKL9012-...) \
SCHEME=MyAppTests PROJECT=MyApp.xcodeproj \
./parallel-destinations.sh
```

## How do I measure sequential versus concurrent runs?

Record real numbers once on your actual host instead of guessing cores and gigabytes per Simulator. `/usr/bin/time -l` reports wall time and peak resident set size on macOS, and `vm_stat 2` samples memory pressure during the run.

| Run | How to execute | Record |
|---|---|---|
| A: one device, baseline | `UDIDS=(UDID1) /usr/bin/time -l ./parallel-destinations.sh` | wall seconds, peak RSS, idle headroom from `vm_stat` |
| B: full matrix sequential | Loop the wrapper once per UDID (no backgrounding) under `/usr/bin/time -l` | wall seconds, peak RSS, swap activity |
| C: full matrix concurrent | `UDIDS=(UDID1 UDID2 UDID3) /usr/bin/time -l ./parallel-destinations.sh` | wall seconds, peak RSS, any swap activity |
| D: acceptance | C's wall time ≤ B's wall time and no swap in `vm_stat` during C | pass / change plan |

If C triggers swap or runs slower than B, drop a Simulator from the matrix or move to a Mac with more RAM. Common rules of thumb such as "two to four GB per Simulator" come from old anecdotes. Your tests, asset catalogs and UI automation move those numbers, so measure before you commit to the sizing.

## How do I merge, inspect and publish the results?

After the wrapper exits, inspect the merged bundle and export per-device artifacts for your CI:

```bash
# Use the get form your installed Xcode prints in `xcrun xcresulttool help`.
xcrun xcresulttool get test-results summary --path "$ROOT/merged.xcresult" | less

# Extract attachments (screenshots, logs) from a bundle:
brew install chargepoint/xcparse/xcparse
xcparse screenshots "$ROOT/merged.xcresult" "$ROOT/attachments"
```

[xcparse](https://github.com/ChargePoint/xcparse) exports attachments, coverage and screenshots from a bundle. It is not an HTML reporter. If you want a per-test HTML view, point [XCTestHTMLReport](https://github.com/XCTestHTMLReport/XCTestHTMLReport) at the merged bundle. Both read the same `.xcresult` format XCTest emits, and both run on the same Mac that ran the tests.

## How many Simulators can each plan run at once?

The Dedicated M4 Pro 48 GB (whole Mac, M4 Pro, 48GB RAM, 512GB SSD; $349 a month, or $299 a month on a 12-month term) is the fit for many simultaneous Simulators, because the whole machine's memory is yours. The Apple Silicon Mac VM (4 shared vCPUs, 4GB RAM; $39 a month, $6 a day) suits a matrix of one or two devices. The Intel Mac VM is not a good host for a wide matrix, since it has 4GB of RAM and runs macOS Sequoia with Xcode 26.3 or earlier. We have not measured a Simulator count on any plan, so use the worksheet above. Attach the Mac as a self-hosted GitHub Actions or Buildkite runner and the wrapper runs against your repository. See the [Mac hosting plans](/mac-hosting).

For market context, [CloudMac](https://cloudmac.org/pricing) publishes a dedicated Mac mini M4 (16 GB / 256 GB) at $99.99/month, with its 512 GB and 1 TB tiers marked "Fully reserved" at the time of writing. Its homepage advertises a $999/year option, about $83.25/month effective. [MacStadium](https://macstadium.com/pricing) lists the M4.S (M4, 16 GB / 256 GB) at $149/month with included support and a 99.99% uptime claim. For twelve months, the Apple Silicon Mac VM costs 12 × $39 = $468 and the Dedicated M4 Pro 48 GB $3,228 paid up front, against 12 × $99.99 = $1,199.88 for CloudMac's monthly M4.

**Related guides:**

- [Safari web push notification testing](/blog/mac-safari-web-push-notification-test)
- [Accessibility Inspector tree snapshot](/blog/mac-accessibility-inspector-tree-snapshot)
- [Self-hosted GitHub Actions runner on macOS](/blog/mac-github-actions-self-hosted-runner)
