diff --git a/engine/src/flutter/testing/run_tests.py b/engine/src/flutter/testing/run_tests.py index 1a6ad24550..53881719e3 100755 --- a/engine/src/flutter/testing/run_tests.py +++ b/engine/src/flutter/testing/run_tests.py @@ -605,25 +605,53 @@ def RunObjcTests(ios_variant='ios_debug_sim_unopt', test_filter=None): ios_out_dir = os.path.join(out_dir, ios_variant) EnsureIosTestsAreBuilt(ios_out_dir) - ios_unit_test_dir = os.path.join( - buildroot_dir, 'flutter', 'testing', 'ios', 'IosUnitTests' - ) + new_simulator_name = 'IosUnitTestsSimulator' - # Avoid using xcpretty unless the following can be addressed: - # - Make sure all relevant failure output is printed on a failure. - # - Make sure that a failing exit code is set for CI. - # See https://github.com/flutter/flutter/issues/63742 - command = [ - 'xcodebuild ' - '-sdk iphonesimulator ' - '-scheme IosUnitTests ' - "-destination platform='iOS Simulator,name=iPhone 11' " - 'test ' - 'FLUTTER_ENGINE=' + ios_variant + # Delete simulators with this name in case any were leaked + # from another test run. + DeleteSimulator(new_simulator_name) + + create_simulator = [ + 'xcrun ' + 'simctl ' + 'create ' + '%s com.apple.CoreSimulator.SimDeviceType.iPhone-11' % new_simulator_name ] - if test_filter != None: - command[0] = command[0] + " -only-testing:%s" % test_filter - RunCmd(command, cwd=ios_unit_test_dir, shell=True) + RunCmd(create_simulator, shell=True) + + try: + ios_unit_test_dir = os.path.join( + buildroot_dir, 'flutter', 'testing', 'ios', 'IosUnitTests' + ) + # Avoid using xcpretty unless the following can be addressed: + # - Make sure all relevant failure output is printed on a failure. + # - Make sure that a failing exit code is set for CI. + # See https://github.com/flutter/flutter/issues/63742 + test_command = [ + 'xcodebuild ' + '-sdk iphonesimulator ' + '-scheme IosUnitTests ' + "-destination name='" + new_simulator_name + "' " + 'test ' + 'FLUTTER_ENGINE=' + ios_variant + ] + if test_filter != None: + test_command[0] = test_command[0] + " -only-testing:%s" % test_filter + RunCmd(test_command, cwd=ios_unit_test_dir, shell=True) + finally: + DeleteSimulator(new_simulator_name) + + +def DeleteSimulator(simulator_name): + # Will delete all simulators with this name. + delete_simulator = [ + 'xcrun', + 'simctl', + 'delete', + simulator_name, + ] + # Let this fail if the simulator was never created. + RunCmd(delete_simulator, expect_failure=True) def GatherDartTests(build_dir, filter, verbose_dart_snapshot):