Commit 2accaa0ea7
Unsigned
Layout: unified · split
Scripts/test.sh +46 −16
| @@ -23,6 +23,7 @@ cd "$(dirname "$0")/.." | |||
| 23 | PROJECT="DomainDig.xcodeproj" | 23 | PROJECT="DomainDig.xcodeproj" |
| 24 | SCHEME="DomainDig" | 24 | SCHEME="DomainDig" |
| 25 | TIER="${1:-both}" | 25 | TIER="${1:-both}" |
| 26 | MAX_LAUNCH_ATTEMPTS=3 | ||
| 26 | 27 | ||
| 27 | # shellcheck source=lib/simulators.sh | 28 | # shellcheck source=lib/simulators.sh |
| 28 | source "$(dirname "$0")/lib/simulators.sh" | 29 | source "$(dirname "$0")/lib/simulators.sh" |
| @@ -42,6 +43,7 @@ echo " deployment target: $DEPLOYMENT_TARGET (rank $FLOOR_RANK)" | |||
| 42 | run_tier() { | 43 | run_tier() { |
| 43 | local which="$1" | 44 | local which="$1" |
| 44 | local sim udid label | 45 | local sim udid label |
| 46 | local attempt=1 | ||
| 45 | 47 | ||
| 46 | sim=$(select_sim "$which") | 48 | sim=$(select_sim "$which") |
| 47 | if [[ -z "$sim" ]]; then | 49 | if [[ -z "$sim" ]]; then |
| @@ -61,22 +63,50 @@ run_tier() { | |||
| 61 | echo " deployment target, so this is not true floor coverage." | 63 | echo " deployment target, so this is not true floor coverage." |
| 62 | fi | 64 | fi |
| 63 | 65 | ||
| 64 | # Boot and wait before handing the destination to xcodebuild. Left to | 66 | local log |
| 65 | # xcodebuild, a cold device races its own boot: the test host fails to launch | 67 | log=$(mktemp -t "domaindig-test-$which") |
| 66 | # with "Application launch did not return a process handle" (NSPOSIXErrorDomain | 68 | |
| 67 | # Code=3), no test reports, and the run stalls about 380 seconds before it | 69 | while :; do |
| 68 | # calls that a failure. `bootstatus -b` boots if needed and blocks until the | 70 | # Boot and wait rather than letting xcodebuild race its own boot. |
| 69 | # device is ready, which is the whole fix. | 71 | xcrun simctl bootstatus "$udid" -b > /dev/null 2>&1 || true |
| 70 | echo " booting and waiting for the device" | 72 | |
| 71 | xcrun simctl bootstatus "$udid" -b > /dev/null 2>&1 || true | 73 | set +e |
| 72 | 74 | xcodebuild test \ | |
| 73 | set -o pipefail | 75 | -project "$PROJECT" \ |
| 74 | xcodebuild test \ | 76 | -scheme "$SCHEME" \ |
| 75 | -project "$PROJECT" \ | 77 | -destination "id=$udid" \ |
| 76 | -scheme "$SCHEME" \ | 78 | -only-testing:DomainDigTests > "$log" 2>&1 |
| 77 | -destination "id=$udid" \ | 79 | local code=$? |
| 78 | -only-testing:DomainDigTests 2>&1 \ | 80 | set -e |
| 79 | | grep -E 'Executed [0-9]+ test|\*\* TEST (SUCCEEDED|FAILED)|error:|malloc: \*\*\*|^Test Case .* failed' | 81 | |
| 82 | grep -E 'Executed [0-9]+ test|\*\* TEST (SUCCEEDED|FAILED)|error:|malloc: \*\*\*|^Test Case .* failed|failed to launch|did not return a process handle' "$log" || true | ||
| 83 | |||
| 84 | xcrun simctl shutdown "$udid" > /dev/null 2>&1 || true | ||
| 85 | |||
| 86 | if [[ "$code" -eq 0 ]] || ! launch_failed "$log" || [[ "$attempt" -ge "$MAX_LAUNCH_ATTEMPTS" ]]; then | ||
| 87 | rm -f "$log" | ||
| 88 | return "$code" | ||
| 89 | fi | ||
| 90 | |||
| 91 | echo " launch failed before any test ran; retrying ($attempt/$((MAX_LAUNCH_ATTEMPTS - 1)))" | ||
| 92 | attempt=$((attempt + 1)) | ||
| 93 | done | ||
| 94 | } | ||
| 95 | |||
| 96 | # A CoreSimulator flake, not a test result. The device accepts the install and | ||
| 97 | # then the test host never starts: sometimes with "Application launch ... did | ||
| 98 | # not return a process handle nor launch error", sometimes with no diagnostic | ||
| 99 | # at all beyond "** TEST FAILED **", and left alone xcodebuild can sit ~380s | ||
| 100 | # before saying so. Seen on roughly a third of invocations here, on several | ||
| 101 | # devices and both runtimes, and not fixed by booting and waiting first. | ||
| 102 | # | ||
| 103 | # Retrying is a workaround for that, so the test is what makes it safe rather | ||
| 104 | # than the error text, which varies: a run that executed no tests at all did | ||
| 105 | # not get far enough to have a test result, and a compile failure is excluded | ||
| 106 | # so a broken build is not retried three times. | ||
| 107 | launch_failed() { | ||
| 108 | local log="$1" | ||
| 109 | ! grep -qE 'Executed [0-9]+ test' "$log" && ! grep -qE ': error:' "$log" | ||
| 80 | } | 110 | } |
| 81 | 111 | ||
| 82 | status=0 | 112 | status=0 |