From d23d29b6967f0310478eaa1f33180d02b6780a89 Mon Sep 17 00:00:00 2001 From: thomasvl Date: Wed, 29 Oct 2014 15:33:04 +0000 Subject: After switching to Xcode 6, the Simulator sometimes fails to open causing the tests to fail. The projects that have more test targets are more vulnerable to the issue. When the simulator fails to open, we should reset it and try again. --- UnitTesting/RuniOSUnitTestsUnderSimulator.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/UnitTesting/RuniOSUnitTestsUnderSimulator.sh b/UnitTesting/RuniOSUnitTestsUnderSimulator.sh index 20efc45..6f71f04 100755 --- a/UnitTesting/RuniOSUnitTestsUnderSimulator.sh +++ b/UnitTesting/RuniOSUnitTestsUnderSimulator.sh @@ -130,6 +130,13 @@ GTMKillSimulator() { GTMKillNamedAndWait "${SimulatorProcessName}" } +GTMResetSimulator() { + GTMKillSimulator + device_id=`xcrun simctl list | grep "${GTM_DEVICE_TYPE} (" | sed -n 2p | \ + cut -d "(" -f2 | cut -d ")" -f1` + xcrun simctl erase $device_id || true +} + # Honor TEST_AFTER_BUILD if requested. if [[ "$GTM_USE_TEST_AFTER_BUILD" == 1 && "$TEST_AFTER_BUILD" == "NO" ]]; then GTMXcodeNote ${LINENO} "Skipping running of unittests since TEST_AFTER_BUILD=NO." @@ -265,6 +272,17 @@ set -e GTMKillSimulator GTMKillNamedAndWait "${GTM_TEST_APP_NAME}" +# If the simulator fails to open with error FBSOpenApplicationErrorDomain:4, +# reset the sim and try again (Known simulator issue for Xcode 6). +if [ ${TEST_HOST_RESULT} -eq 4 ] && [ ${XCODE_VERSION_MINOR} -ge "0600" ]; then + GTMFakeUnitTestingMsg ${LINENO} "Simulator failed to open" "$TEST_HOST_RESULT, trying again." + GTMResetSimulator + set +e + "${GTM_TEST_COMMAND[@]}" + TEST_HOST_RESULT=$? + set -e +fi + if [[ ${TEST_HOST_RESULT} -ne 0 ]]; then GTMXcodeError ${LINENO} "Tests failed." exit 1 -- cgit v1.2.3