#!/bin/bash set -euo pipefail cd "$(dirname "$0")/.." source Scripts/trace-common.sh usage() { printf 'Usage: %s [--seconds N] [--installed-template]\n' "$0" >&2; exit 2; } [[ $# -ge 1 ]] || usage scenario=$1 shift case "$scenario" in swap-2-windows|layout-change-10|layout-change-30|hotkey-focus-move|slow-neighbour|new-window-to-tile) ;; *) printf 'Unknown smoothness scenario: %s\n' "$scenario" >&2; exit 2 ;; esac seconds=120 installed=0 while (( $# )); do case "$1" in --seconds) [[ $# -ge 2 && $2 =~ ^[1-9][0-9]*$ ]] || usage; seconds=$2; shift 2 ;; --installed-template) installed=1; shift ;; *) usage ;; esac done template=$(trace_template smoothness "$installed") process_status=0 pgrep -x Parcel > /dev/null || process_status=$? case "$process_status" in 0) printf 'Quit your running Parcel first; trace-e2e only launches the harness-owned bundle.\n' >&2; exit 2 ;; 1) ;; *) printf 'Could not inspect running Parcel processes.\n' >&2; exit "$process_status" ;; esac configuration=${PARCEL_TRACE_CONFIGURATION:-release} case "$configuration" in debug|release) ;; *) printf 'Trace configuration must be debug or release.\n' >&2; exit 2 ;; esac Scripts/bundle.sh "$configuration" Scripts/swift-build.sh -c "$configuration" --product FixtureApp Scripts/swift-build.sh -c "$configuration" --build-tests -Xswiftc -enable-testing bin_dir=$(swift build -c "$configuration" --show-bin-path) runner="$bin_dir/ParcelPackageTests.xctest/Contents/MacOS/ParcelPackageTests" [[ -f $runner ]] || { printf 'Swift Testing bundle missing: %s\n' "$runner" >&2; exit 2; } swift_path=$(xcrun --find swift) helper="$(dirname "$swift_path")/../libexec/swift/pm/swiftpm-testing-helper" [[ -x $helper ]] || { printf 'SwiftPM bundle-loading test helper missing: %s\n' "$helper" >&2; exit 2; } platform=$(xcrun --sdk macosx --show-sdk-platform-path) output=$(trace_output_path "e2e-$scenario") xcrun xctrace record --template "$template" --time-limit "${seconds}s" --output "$output" \ --target-stdout "${output%.trace}.test.log" \ --env PARCEL_E2E=1 --env PARCEL_TRACE=1 \ --env "PARCEL_APP_PATH=$PWD/build/Parcel.app" --env "PARCEL_FIXTURE_PATH=$bin_dir/FixtureApp" \ --env "PARCEL_SMOOTHNESS_SCENARIO=$scenario" \ --env "DYLD_FRAMEWORK_PATH=$platform/Developer/Library/Frameworks" \ --env "DYLD_LIBRARY_PATH=$platform/Developer/usr/lib" \ --launch -- "$helper" --test-bundle-path "$runner" --testing-library swift-testing --filter 'ParcelE2ETests.*(SmoothnessTests|LatencyTests)' \ --xunit-output "${output%.trace}.xunit.xml" [[ -d $output ]] || { printf 'Recorder succeeded without writing a trace.\n' >&2; exit 2; } Scripts/parcel-dev.sh trace-verdict "${output%.trace}.xunit.xml" || { printf 'Scenario failed, did not run, or was terminated before its test verdict; inspect %s.\n' "${output%.trace}.test.log" >&2 exit 1 } printf 'E2E trace: %s; test log: %s\n' "$output" "${output%.trace}.test.log"