also looking at this
fix(mobile-e2e): launch iOS apps without a pty, so a cold simulator cannot eat the budget
#212
5 files
+74
-23
| @@ -22,6 +22,9 @@ echo "==> building the craft iOS simulator library" | ||
| 22 | 22 | SDK="$(xcrun --sdk iphonesimulator --show-sdk-path)" |
| 23 | 23 | APP="$OUT/CraftSlice.app" |
| 24 | 24 | rm -rf "$OUT"; mkdir -p "$APP" |
| 25 | # Absolute, because the app writes its console to paths under here and resolves | |
| 26 | # them from its own working directory, not this script's. | |
| 27 | OUT="$(cd "$OUT" && pwd)"; APP="$OUT/CraftSlice.app" | |
| 25 | 28 | |
| 26 | 29 | echo "==> compiling the fixture" |
| 27 | 30 | # The ObjC translation units first, then swiftc drives the link. swiftc is the |
| @@ -117,9 +120,22 @@ xcrun simctl location "$UDID" set 37.3317,-122.0307 | ||
| 117 | 120 | # i=68 assertion below fails loudly, which is the right way round. |
| 118 | 121 | xcrun simctl privacy "$UDID" grant kTCCServiceSpeechRecognition "$BUNDLE_ID" 2>/dev/null || true |
| 119 | 122 | |
| 123 | # The app's stdout and stderr, each to a file, gathered into $LOG as it runs. | |
| 124 | # | |
| 125 | # Not `simctl launch --console-pty`, for the reason scripts/mobile-e2e/ios.ts | |
| 126 | # gives: the first pty launch after a cold boot took about 200 seconds to start | |
| 127 | # the app, against 10 for a plain launch, and that wait came out of this | |
| 128 | # script's budget. `NSUnbufferedIO=YES` is what lets a file see the output | |
| 129 | # while the app runs; without it nothing arrives. And no pty means no CRLF, so | |
| 130 | # the lines grepped below end where they appear to. | |
| 131 | STDOUT_LOG="$OUT/app-stdout.log" | |
| 132 | STDERR_LOG="$OUT/app-stderr.log" | |
| 120 | 133 | LOG="$OUT/console.log" |
| 121 | xcrun simctl launch --console-pty "$UDID" "$BUNDLE_ID" > "$LOG" 2>&1 & | |
| 122 | LAUNCH_PID=$! | |
| 134 | : > "$LOG" | |
| 135 | SIMCTL_CHILD_NSUnbufferedIO=YES xcrun simctl launch --terminate-running-process \ | |
| 136 | --stdout="$STDOUT_LOG" --stderr="$STDERR_LOG" "$UDID" "$BUNDLE_ID" | |
| 137 | ||
| 138 | gather_log() { cat "$STDOUT_LOG" "$STDERR_LOG" > "$LOG" 2>/dev/null || true; } | |
| 123 | 139 | |
| 124 | 140 | # The round trip is fast, but a cold simulator is not. Poll rather than sleep a |
| 125 | 141 | # fixed amount, so a slow boot does not read as a failure. |
| @@ -141,6 +157,7 @@ DEADLINE=$(( $(date +%s) + SLICE_TIMEOUT )) | ||
| 141 | 157 | |
| 142 | 158 | missing_ids() { |
| 143 | 159 | local missing="" |
| 160 | gather_log | |
| 144 | 161 | for id in $AWAITED_IDS; do |
| 145 | 162 | # ERE with an explicit boundary rather than \b, which is a GNU |
| 146 | 163 | # extension this script cannot count on, and rather than a bare |
| @@ -159,12 +176,13 @@ while :; do | ||
| 159 | 176 | echo "FAIL: timed out after ${SLICE_TIMEOUT}s waiting for:$MISSING" |
| 160 | 177 | echo " The app never got that far — this is a timeout, not a wrong answer." |
| 161 | 178 | echo " Raise CRAFT_SLICE_TIMEOUT if the machine is simply slow." |
| 162 | kill "$LAUNCH_PID" 2>/dev/null || true | |
| 179 | xcrun simctl terminate "$UDID" "$BUNDLE_ID" 2>/dev/null || true | |
| 163 | 180 | exit 1 |
| 164 | 181 | fi |
| 165 | 182 | sleep 1 |
| 166 | 183 | done |
| 167 | kill "$LAUNCH_PID" 2>/dev/null || true | |
| 184 | xcrun simctl terminate "$UDID" "$BUNDLE_ID" 2>/dev/null || true | |
| 185 | gather_log | |
| 168 | 186 | |
| 169 | 187 | echo "==> console" |
| 170 | 188 | cat "$LOG" || true |
| @@ -200,7 +218,12 @@ echo "==> assertions" | ||
| 200 | 218 | PLAIN="$OUT/console.plain" |
| 201 | 219 | sed -e $'s/\x1b\[[0-9;]*m//g' -e 's/\r$//' "$LOG" > "$PLAIN" |
| 202 | 220 | |
| 203 | count() { grep -cE "craft-bridge dispatch t=mobile a=[A-Za-z]+ i=$1\$" "$PLAIN" || true; } | |
| 221 | # The same boundary missing_ids waits on. This used to demand the id end the | |
| 222 | # line, while the wait accepted any non-digit after it, so a line the loop had | |
| 223 | # already counted as arrived could fail its assertion here: on main, run | |
| 224 | # 35094828558 waited for i=76, found it, and then reported that | |
| 225 | # getCurrentPosition "did not return the simulated coordinate". | |
| 226 | count() { grep -cE "craft-bridge dispatch t=mobile a=[A-Za-z]+ i=$1(\$|[^0-9])" "$PLAIN" || true; } | |
| 204 | 227 | |
| 205 | 228 | C1="$(count 1)"; C2="$(count 2)"; C3="$(count 3)" |
| 206 | 229 | |