Revert "[ios]Removed usage of iossim in ios/build/bots/scripts/*"

This reverts commit 16469ef3a53c5de12de5a86913fde00b95172b0e.

Reason for revert: The recipe change that stops setting iossim breaks the builder on the beta branch: https://ci.chromium.org/p/chromium/builders/ci-beta/ios-simulator/463

Original change's description:
> [ios]Removed usage of iossim in ios/build/bots/scripts/*
>
> Bug: 1011498
> Change-Id: Ie72335fb20a8ee5c47ba8edaf4ed8299068a7f40
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067325
> Commit-Queue: Maksym Onufriienko <[email protected]>
> Reviewed-by: Rohit Rao <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#744748}

[email protected],[email protected],[email protected],[email protected]


Bug: 1011498, 1056905
Change-Id: I45689abac093072e819b19d38ed6855309045725
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079521
Reviewed-by: Garrett Beaty <[email protected]>
Commit-Queue: Garrett Beaty <[email protected]>
Cr-Commit-Position: refs/heads/master@{#745312}
diff --git a/ios/build/bots/scripts/iossim_util_test.py b/ios/build/bots/scripts/iossim_util_test.py
index d2efd15..5b9253d 100644
--- a/ios/build/bots/scripts/iossim_util_test.py
+++ b/ios/build/bots/scripts/iossim_util_test.py
@@ -5,7 +5,6 @@
 
 import iossim_util
 import mock
-
 import test_runner
 import test_runner_test
 
@@ -15,21 +14,17 @@
 
   def setUp(self):
     super(GetiOSSimUtil, self).setUp()
-    self.mock(iossim_util, 'get_simulator_list',
-              lambda: test_runner_test.SIMULATORS_LIST)
 
   def test_get_simulator_runtime_by_version(self):
     """Ensures correctness of filter."""
     self.assertEqual(
         'com.apple.CoreSimulator.SimRuntime.iOS-13-2',
-        iossim_util.get_simulator_runtime_by_version(
-            test_runner_test.SIMULATORS_LIST, '13.2.2'))
+        iossim_util.get_simulator_runtime_by_version(SIMULATORS_LIST, '13.2.2'))
 
   def test_get_simulator_runtime_by_version_not_found(self):
     """Ensures that SimulatorNotFoundError raises if no runtime."""
     with self.assertRaises(test_runner.SimulatorNotFoundError) as context:
-      iossim_util.get_simulator_runtime_by_version(
-          test_runner_test.SIMULATORS_LIST, '13.2')
+      iossim_util.get_simulator_runtime_by_version(SIMULATORS_LIST, '13.2')
     expected_message = ('Simulator does not exist: Not found '
                         '"13.2" SDK in runtimes')
     self.assertTrue(expected_message in str(context.exception))
@@ -38,14 +33,14 @@
     """Ensures correctness of filter."""
     self.assertEqual(
         'com.apple.CoreSimulator.SimDeviceType.iPhone-11',
-        iossim_util.get_simulator_runtime_by_platform(
-            test_runner_test.SIMULATORS_LIST, 'iPhone 11'))
+        iossim_util.get_simulator_runtime_by_platform(SIMULATORS_LIST,
+                                                      'iPhone 11'))
 
   def test_get_simulator_runtime_by_platform_not_found(self):
     """Ensures that SimulatorNotFoundError raises if no platform."""
     with self.assertRaises(test_runner.SimulatorNotFoundError) as context:
-      iossim_util.get_simulator_runtime_by_platform(
-          test_runner_test.SIMULATORS_LIST, 'iPhone XI')
+      iossim_util.get_simulator_runtime_by_platform(SIMULATORS_LIST,
+                                                    'iPhone XI')
     expected_message = ('Simulator does not exist: Not found device '
                         '"iPhone XI" in devicetypes')
     self.assertTrue(expected_message in str(context.exception))
diff --git a/ios/build/bots/scripts/run.py b/ios/build/bots/scripts/run.py
index a6fd2d1..555a54cd 100755
--- a/ios/build/bots/scripts/run.py
+++ b/ios/build/bots/scripts/run.py
@@ -140,6 +140,7 @@
         tr = xcodebuild_runner.SimulatorParallelTestRunner(
             self.args.app,
             self.args.host_app,
+            self.args.iossim,
             self.args.version,
             self.args.platform,
             out_dir=self.args.out_dir,
@@ -153,6 +154,7 @@
         tr = wpr_runner.WprProxySimulatorTestRunner(
             self.args.app,
             self.args.host_app,
+            self.args.iossim,
             self.args.replay_path,
             self.args.platform,
             self.args.version,
@@ -165,9 +167,10 @@
             test_cases=self.args.test_cases,
             xctest=self.args.xctest,
         )
-      elif self.args.platform and self.args.version:
+      elif self.args.iossim and self.args.platform and self.args.version:
         tr = test_runner.SimulatorTestRunner(
             self.args.app,
+            self.args.iossim,
             self.args.platform,
             self.args.version,
             self.args.out_dir,
@@ -278,6 +281,12 @@
         metavar='host_app',
     )
     parser.add_argument(
+        '-i',
+        '--iossim',
+        help='Compiled iossim to run the app on.',
+        metavar='iossim',
+    )
+    parser.add_argument(
         '-j',
         '--args-json',
         default='{}',
@@ -411,12 +420,12 @@
       Runs argument validation
       """
       if (not (args.xcode_parallelization or args.xcodebuild_device_runner) and
-          (args.platform or args.version)):
-        # If --platform or --version are specified then
-        # they must all be specified.
-        if not (args.platform and args.version):
+          (args.iossim or args.platform or args.version)):
+        # If any of --iossim, --platform, or --version
+        # are specified then they must all be specified.
+        if not (args.iossim and args.platform and args.version):
           parser.error('must specify all or none of '
-                       '-p/--platform, -v/--version')
+                       '-i/--iossim, -p/--platform, -v/--version')
 
       if args.xcode_parallelization and not (args.platform and args.version):
         parser.error('--xcode-parallelization also requires '
diff --git a/ios/build/bots/scripts/run_test.py b/ios/build/bots/scripts/run_test.py
index c092aa04..a4cff30 100755
--- a/ios/build/bots/scripts/run_test.py
+++ b/ios/build/bots/scripts/run_test.py
@@ -31,6 +31,69 @@
     runner.parse_args(cmd)
     self.assertTrue(runner.args.app == './foo-Runner.app')
 
+  def test_parse_args_iossim_platform_version(self):
+    """
+    iossim, platforma and version should all be set.
+    missing iossim
+    """
+    test_cases = [
+        {
+            'error':
+                2,
+            'cmd': [
+                '--platform',
+                'iPhone X',
+                '--version',
+                '13.2.2',
+
+                # Required
+                '--xcode-build-version',
+                '123abc',
+                '--out-dir',
+                'some/dir'
+            ],
+        },
+        {
+            'error':
+                2,
+            'cmd': [
+                '--iossim',
+                'path/to/iossim',
+                '--version',
+                '13.2.2',
+
+                # Required
+                '--xcode-build-version',
+                '123abc',
+                '--out-dir',
+                'some/dir'
+            ],
+        },
+        {
+            'error':
+                2,
+            'cmd': [
+                '--iossim',
+                'path/to/iossim',
+                '--platform',
+                'iPhone X',
+
+                # Required
+                '--xcode-build-version',
+                '123abc',
+                '--out-dir',
+                'some/dir'
+            ],
+        },
+    ]
+
+    runner = run.Runner()
+    for test_case in test_cases:
+      with self.assertRaises(SystemExit) as ctx:
+        runner.parse_args(test_case['cmd'])
+        self.assertTrue(re.match('must specify all or none of *', ctx.message))
+        self.assertEqual(ctx.exception.code, test_case['error'])
+
   def test_parse_args_xcode_parallelization_requirements(self):
     """
     xcode parallelization set requires both platform and version
diff --git a/ios/build/bots/scripts/test_runner.py b/ios/build/bots/scripts/test_runner.py
index f8bbe2c..34e997c0 100644
--- a/ios/build/bots/scripts/test_runner.py
+++ b/ios/build/bots/scripts/test_runner.py
@@ -685,11 +685,12 @@
 
 
 class SimulatorTestRunner(TestRunner):
-  """Class for running tests on iOS Simulators."""
+  """Class for running tests on iossim."""
 
   def __init__(
       self,
       app_path,
+      iossim_path,
       platform,
       version,
       out_dir,
@@ -706,10 +707,11 @@
 
     Args:
       app_path: Path to the compiled .app or .ipa to run.
+      iossim_path: Path to the compiled iossim binary to use.
       platform: Name of the platform to simulate. Supported values can be found
-        by running "xcrun simctl list". e.g. "iPhone 5s", "iPad Retina".
+        by running "iossim -l". e.g. "iPhone 5s", "iPad Retina".
       version: Version of iOS the platform should be running. Supported values
-        can be found by running "xcrun simctl list". e.g. "9.3", "8.2", "7.1".
+        can be found by running "iossim -l". e.g. "9.3", "8.2", "7.1".
       out_dir: Directory to emit test data into.
       env_vars: List of environment variables to pass to the test itself.
       retries: Number of times to retry failed test cases.
@@ -736,7 +738,13 @@
         test_cases=test_cases,
         xctest=xctest,
     )
+
+    iossim_path = os.path.abspath(iossim_path)
+    if not os.path.exists(iossim_path):
+      raise SimulatorNotFoundError(iossim_path)
+
     self.homedir = ''
+    self.iossim_path = iossim_path
     self.platform = platform
     self.start_time = None
     self.version = version
diff --git a/ios/build/bots/scripts/test_runner_test.py b/ios/build/bots/scripts/test_runner_test.py
index 16e2353..fef4902d 100755
--- a/ios/build/bots/scripts/test_runner_test.py
+++ b/ios/build/bots/scripts/test_runner_test.py
@@ -161,6 +161,7 @@
     with self.assertRaises(test_runner.AppNotFoundError):
       test_runner.SimulatorTestRunner(
         'fake-app',
+        'fake-iossim',
         'platform',
         'os',
         'xcode-version',
@@ -168,10 +169,26 @@
         'out-dir',
       )
 
+  def test_iossim_not_found(self):
+    """Ensures SimulatorNotFoundError is raised."""
+    self.mock(os.path, 'exists', lambda p: not p.endswith('fake-iossim'))
+
+    with self.assertRaises(test_runner.SimulatorNotFoundError):
+      test_runner.SimulatorTestRunner(
+        'fake-app',
+        'fake-iossim',
+        'iPhone X',
+        '11.4',
+        'xcode-version',
+        'xcode-build',
+        'out-dir',
+      )
+
   def test_init(self):
     """Ensures instance is created."""
     tr = test_runner.SimulatorTestRunner(
         'fake-app',
+        'fake-iossim',
         'iPhone X',
         '11.4',
         'xcode-version',
@@ -200,6 +217,7 @@
 
     tr = test_runner.SimulatorTestRunner(
         'fake-app',
+        'fake-iossim',
         'iPhone X',
         '11.4',
         'xcode-version',
@@ -225,6 +243,7 @@
 
     tr = test_runner.SimulatorTestRunner(
       'fake-app',
+      'fake-iossim',
       'iPhone X',
       '11.4',
       'xcode-version',
@@ -249,6 +268,7 @@
     with self.assertRaises(test_runner.SystemAlertPresentError):
       tr = test_runner.SimulatorTestRunner(
         'fake-app',
+        'fake-iossim',
         'iPhone X',
         '11.4',
         'xcode-version',
@@ -265,6 +285,7 @@
       test_cases."""
     tr = test_runner.SimulatorTestRunner(
       'fake-app',
+      'fake-iossim',
       'iPhone X',
       '11.4',
       'xcode-version',
@@ -338,6 +359,7 @@
 
     tr = test_runner.SimulatorTestRunner(
         'fake-app',
+        'fake-iossim',
         'iPhone X',
         '11.4',
         'xcode-version',
diff --git a/ios/build/bots/scripts/wpr_runner.py b/ios/build/bots/scripts/wpr_runner.py
index c9408327..ec70eee 100644
--- a/ios/build/bots/scripts/wpr_runner.py
+++ b/ios/build/bots/scripts/wpr_runner.py
@@ -50,6 +50,7 @@
       self,
       app_path,
       host_app_path,
+      iossim_path,
       replay_path,
       platform,
       version,
@@ -67,11 +68,12 @@
     Args:
       app_path: Path to the compiled .app or .ipa to run.
       host_app_path: A path to the host app for EG2.
+      iossim_path: Path to the compiled iossim binary to use.
       replay_path: Path to the folder where WPR replay and recipe files live.
       platform: Name of the platform to simulate. Supported values can be found
-        by running "xcrun simctl list". e.g. "iPhone 5s", "iPad Retina".
+        by running "iossim -l". e.g. "iPhone 5s", "iPad Retina".
       version: Version of iOS the platform should be running. Supported values
-        can be found by running "xcrun simctl list". e.g. "9.3", "8.2", "7.1".
+        can be found by running "iossim -l". e.g. "9.3", "8.2", "7.1".
       wpr_tools_path: Path to pre-installed (from CIPD) WPR-related tools
       out_dir: Directory to emit test data into.
       env_vars: List of environment variables to pass to the test itself.
@@ -89,6 +91,7 @@
     """
     super(WprProxySimulatorTestRunner, self).__init__(
         app_path,
+        iossim_path,
         platform,
         version,
         out_dir,
diff --git a/ios/build/bots/scripts/wpr_runner_test.py b/ios/build/bots/scripts/wpr_runner_test.py
index bb2221f..2284b1a 100644
--- a/ios/build/bots/scripts/wpr_runner_test.py
+++ b/ios/build/bots/scripts/wpr_runner_test.py
@@ -51,6 +51,7 @@
       wpr_runner.WprProxySimulatorTestRunner(
           'fake-app',
           'bad-host-app-path',
+          'fake-iossim',
           'replay-path',
           'platform',
           'os',
@@ -69,6 +70,7 @@
       wpr_runner.WprProxySimulatorTestRunner(
           'fake-app',
           'fake-host-app',
+          'fake-iossim',
           'bad-replay-path',
           'platform',
           'os',
@@ -87,6 +89,7 @@
       wpr_runner.WprProxySimulatorTestRunner(
           'fake-app',
           'fake-host-app',
+          'fake-iossim',
           'replay-path',
           'platform',
           'os',
@@ -101,6 +104,7 @@
     tr = wpr_runner.WprProxySimulatorTestRunner(
         'fake-app',
         'fake-host-app',
+        'fake-iossim',
         'replay-path',
         'platform',
         'os',
@@ -156,6 +160,7 @@
     tr = wpr_runner.WprProxySimulatorTestRunner(
         'fake-app',
         'fake-host-app',
+        'fake-iossim',
         'replay-path',
         'platform',
         'os',
diff --git a/ios/build/bots/scripts/xcodebuild_runner.py b/ios/build/bots/scripts/xcodebuild_runner.py
index 3d1a3d71..f42bd66 100644
--- a/ios/build/bots/scripts/xcodebuild_runner.py
+++ b/ios/build/bots/scripts/xcodebuild_runner.py
@@ -260,6 +260,7 @@
   def __init__(self,
                app_path,
                host_app_path,
+               iossim_path,
                version,
                platform,
                out_dir,
@@ -274,6 +275,8 @@
     Args:
       app_path: (str) A path to egtests_app.
       host_app_path: (str) A path to the host app for EG2.
+      iossim_path: Path to the compiled iossim binary to use.
+                   Not used, but is required by the base class.
       version: (str) iOS version to run simulator on.
       platform: (str) Name of device.
       out_dir: (str) A directory to emit test data into.
@@ -294,6 +297,7 @@
     """
     super(SimulatorParallelTestRunner, self).__init__(
         app_path,
+        iossim_path,
         platform,
         version,
         out_dir,