From f86975f78e12a034235094bb7ebfa37501dd3f62 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Thu, 4 Aug 2016 11:11:32 -0700 Subject: [PATCH] wipe simulators between runs --- scripts/reset-simulators.sh | 59 +++++++++++++++++++++++++++++++++++++ scripts/test.sh | 12 +------- 2 files changed, 60 insertions(+), 11 deletions(-) create mode 100755 scripts/reset-simulators.sh diff --git a/scripts/reset-simulators.sh b/scripts/reset-simulators.sh new file mode 100755 index 00000000..3404b145 --- /dev/null +++ b/scripts/reset-simulators.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +set -o pipefail +set -e + +while pgrep -q Simulator; do + # Kill all the current simulator processes as they may be from a + # different Xcode version + pkill Simulator 2>/dev/null || true + # CoreSimulatorService doesn't exit when sent SIGTERM + pkill -9 Simulator 2>/dev/null || true + done + +# Shut down simulators until there's no booted ones left +# Only do one at a time because devices sometimes show up multiple times +while xcrun simctl list | grep -q Booted; do + xcrun simctl list | grep Booted | sed 's/.* (\(.*\)) (Booted)/\1/' | head -n 1 | xargs xcrun simctl shutdown +done + +# Clean up all available simulators +( + previous_device='' + IFS=$'\n' # make newlines the only separator + for LINE in $(xcrun simctl list); do + if [[ $LINE =~ unavailable || $LINE =~ disconnected ]]; then + # skip unavailable simulators + continue + fi + + if [[ $LINE =~ "--" ]]; then + # Reset the last seen device so we won't consider devices with the same name to be duplicates + # if they appear in different sections. + previous_device="" + continue + fi + + regex='^(.*) [(]([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})[)]' + if [[ $LINE =~ $regex ]]; then + device="${BASH_REMATCH[1]}" + guid="${BASH_REMATCH[2]}" + + # Delete the simulator if it's a duplicate of the last seen one + # Otherwise delete all contents and settings for it + if [[ $device == $previous_device ]]; then + xcrun simctl delete $guid + else + xcrun simctl erase $guid + previous_device="$device" + fi + fi + done +) + +if [[ -a "${DEVELOPER_DIR}/Applications/iOS Simulator.app" ]]; then + open "${DEVELOPER_DIR}/Applications/iOS Simulator.app" +elif [[ -a "${DEVELOPER_DIR}/Applications/Simulator.app" ]]; then + open "${DEVELOPER_DIR}/Applications/Simulator.app" +fi + diff --git a/scripts/test.sh b/scripts/test.sh index 049ef86e..a6c7cc36 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -30,16 +30,6 @@ cleanup() { rm -f "$PACKAGER_OUT" "$LOGCAT_OUT" } -kill_ios_simulator() { - while pgrep -q Simulator; do - # Kill all the current simulator processes as they may be from a - # different Xcode version - pkill Simulator 2>/dev/null || true - # CoreSimulatorService doesn't exit when sent SIGTERM - pkill -9 Simulator 2>/dev/null || true - done -} - open_chrome() { local dir for dir in "$HOME/Applications" "/Applications"; do @@ -65,7 +55,7 @@ start_packager() { } xctest() { - kill_ios_simulator + ${SRCROOT}/scripts/reset-simulators.sh local dest="$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')" xcodebuild -scheme "$1" -configuration "$CONFIGURATION" -sdk iphonesimulator -destination id="$dest" build test