Example #1
0
  def test_move_runtime_remove_from_dst(self, mock_glob, mock_rmtree,
                                        mock_move):

    mock_glob.side_effect = [['test/path/Runtime/iOS.simruntime'],
                             [('test/path/Xcode.app/Contents/Developer/'
                               'Platforms/iPhoneOS.platform/Library/Developer/'
                               'CoreSimulator/Profiles/Runtimes/iOS.simruntime')
                             ]]

    xcode_util.move_runtime(self.runtime_cache_folder, self.xcode_app_path,
                            True)

    xcode_runtime_path = ('test/path/Xcode.app/Contents/Developer/'
                          'Platforms/iPhoneOS.platform/Library/Developer/'
                          'CoreSimulator/Profiles/Runtimes/iOS.simruntime')
    calls = [
        mock.call('test/path/Runtime/*.simruntime'),
        mock.call(('test/path/Xcode.app/Contents/Developer/'
                   'Platforms/iPhoneOS.platform/Library/Developer/'
                   'CoreSimulator/Profiles/Runtimes/*.simruntime'))
    ]
    mock_glob.assert_has_calls(calls)
    mock_rmtree.assert_called_with(xcode_runtime_path)
    mock_move.assert_called_with('test/path/Runtime/iOS.simruntime',
                                 xcode_runtime_path)
Example #2
0
  def test_move_runtime_multiple_in_src(self, mock_glob, mock_rmtree,
                                        mock_move):
    mock_glob.side_effect = [[
        'test/path/Runtime/iOS.simruntime',
        'test/path/Runtime/iOS 13.4.simruntime'
    ], []]

    with self.assertRaises(test_runner_errors.IOSRuntimeHandlingError):
      xcode_util.move_runtime(self.runtime_cache_folder, self.xcode_app_path,
                              True)
    mock_glob.assert_called_with('test/path/Runtime/*.simruntime')
    self.assertFalse(mock_rmtree.called)
    self.assertFalse(mock_move.called)
Example #3
0
    def test_move_runtime_remove_from_dst(self, mock_glob, mock_exists,
                                          mock_rmtree, mock_move):
        mock_glob.return_value = ['test/path/Runtime/iOS.simruntime']
        mock_exists.return_value = True

        xcode_util.move_runtime(self.runtime_cache_folder, self.xcode_app_path,
                                True)

        xcode_runtime_path = ('test/path/Xcode.app/Contents/Developer/'
                              'Platforms/iPhoneOS.platform/Library/Developer/'
                              'CoreSimulator/Profiles/Runtimes/iOS.simruntime')
        mock_glob.assert_called_with('test/path/Runtime/*.simruntime')
        mock_exists.assert_called_with(xcode_runtime_path)
        mock_rmtree.assert_called_with(xcode_runtime_path)
        mock_move.assert_called_with('test/path/Runtime/iOS.simruntime',
                                     xcode_runtime_path)
Example #4
0
    def test_move_runtime_outside_xcode(self, mock_glob, mock_exists,
                                        mock_rmtree, mock_move):
        xcode_runtime_folder = (
            'test/path/Xcode.app/Contents/Developer/'
            'Platforms/iPhoneOS.platform/Library/Developer/'
            'CoreSimulator/Profiles/Runtimes')
        mock_glob.return_value = [xcode_runtime_folder + '/iOS.simruntime']
        mock_exists.return_value = False

        xcode_util.move_runtime(self.runtime_cache_folder, self.xcode_app_path,
                                False)

        mock_glob.assert_called_with(xcode_runtime_folder + '/*.simruntime')
        mock_exists.assert_called_with('test/path/Runtime/iOS.simruntime')
        self.assertFalse(mock_rmtree.called)
        mock_move.assert_called_with(xcode_runtime_folder + '/iOS.simruntime',
                                     'test/path/Runtime/iOS.simruntime')
Example #5
0
  def test_move_runtime_outside_xcode(self, mock_glob, mock_rmtree, mock_move):
    xcode_runtime_folder = ('test/path/Xcode.app/Contents/Developer/'
                            'Platforms/iPhoneOS.platform/Library/Developer/'
                            'CoreSimulator/Profiles/Runtimes')
    mock_glob.side_effect = [[xcode_runtime_folder + '/iOS.simruntime'], []]

    xcode_util.move_runtime(self.runtime_cache_folder, self.xcode_app_path,
                            False)

    calls = [
        mock.call(('test/path/Xcode.app/Contents/Developer/'
                   'Platforms/iPhoneOS.platform/Library/Developer/'
                   'CoreSimulator/Profiles/Runtimes/*.simruntime')),
        mock.call('test/path/Runtime/*.simruntime')
    ]
    mock_glob.assert_has_calls(calls)
    self.assertFalse(mock_rmtree.called)
    mock_move.assert_called_with(xcode_runtime_folder + '/iOS.simruntime',
                                 'test/path/Runtime/iOS.simruntime')
Example #6
0
    def run(self, args):
        """
    Main coordinating function.
    """
        self.parse_args(args)

        # This logic is run by default before the otool command is invoked such that
        # otool has the correct Xcode selected for command line dev tools.
        install_success, is_legacy_xcode = self.install_xcode()
        if not install_success:
            raise test_runner.XcodeVersionNotFoundError(
                self.args.xcode_build_version)

        self.resolve_test_cases()

        summary = {}
        tr = None

        if not os.path.exists(self.args.out_dir):
            os.makedirs(self.args.out_dir)

        try:
            if self.args.xcode_parallelization:
                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,
                    release=self.args.release,
                    repeat_count=self.args.gtest_repeat,
                    retries=self.args.retries,
                    shards=self.args.shards,
                    test_cases=self.args.test_cases,
                    test_args=self.test_args,
                    use_clang_coverage=self.args.use_clang_coverage,
                    env_vars=self.args.env_var)
            elif self.args.variations_seed_path != 'NO_PATH':
                tr = variations_runner.VariationsSimulatorParallelTestRunner(
                    self.args.app,
                    self.args.host_app,
                    self.args.iossim,
                    self.args.version,
                    self.args.platform,
                    self.args.out_dir,
                    self.args.variations_seed_path,
                    release=self.args.release,
                    test_cases=self.args.test_cases,
                    test_args=self.test_args,
                    env_vars=self.args.env_var)
            elif self.args.replay_path != 'NO_PATH':
                tr = wpr_runner.WprProxySimulatorTestRunner(
                    self.args.app,
                    self.args.host_app,
                    self.args.iossim,
                    self.args.replay_path,
                    self.args.platform,
                    self.args.version,
                    self.args.wpr_tools_path,
                    self.args.out_dir,
                    env_vars=self.args.env_var,
                    retries=self.args.retries,
                    shards=self.args.shards,
                    test_args=self.test_args,
                    test_cases=self.args.test_cases,
                    xctest=self.args.xctest,
                )
            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,
                    env_vars=self.args.env_var,
                    repeat_count=self.args.gtest_repeat,
                    retries=self.args.retries,
                    shards=self.args.shards,
                    test_args=self.test_args,
                    test_cases=self.args.test_cases,
                    use_clang_coverage=self.args.use_clang_coverage,
                    wpr_tools_path=self.args.wpr_tools_path,
                    xctest=self.args.xctest,
                )
            elif self.args.xcodebuild_device_runner and self.args.xctest:
                tr = xcodebuild_runner.DeviceXcodeTestRunner(
                    app_path=self.args.app,
                    host_app_path=self.args.host_app,
                    out_dir=self.args.out_dir,
                    release=self.args.release,
                    repeat_count=self.args.gtest_repeat,
                    retries=self.args.retries,
                    test_cases=self.args.test_cases,
                    test_args=self.test_args,
                    env_vars=self.args.env_var)
            else:
                tr = test_runner.DeviceTestRunner(
                    self.args.app,
                    self.args.out_dir,
                    env_vars=self.args.env_var,
                    repeat_count=self.args.gtest_repeat,
                    restart=self.args.restart,
                    retries=self.args.retries,
                    test_args=self.test_args,
                    test_cases=self.args.test_cases,
                    xctest=self.args.xctest,
                )

            logging.info("Using test runner %s" % type(tr).__name__)
            return 0 if tr.launch() else 1
        except test_runner.DeviceError as e:
            sys.stderr.write(traceback.format_exc())
            summary['step_text'] = '%s%s' % (e.__class__.__name__, ': %s' %
                                             e.args[0] if e.args else '')

            # Swarming infra marks device status unavailable for any device related
            # issue using this return code.
            return 3
        except test_runner.TestRunnerError as e:
            sys.stderr.write(traceback.format_exc())
            summary['step_text'] = '%s%s' % (e.__class__.__name__, ': %s' %
                                             e.args[0] if e.args else '')

            # test_runner.Launch returns 0 on success, 1 on failure, so return 2
            # on exception to distinguish between a test failure, and a failure
            # to launch the test at all.
            return 2
        finally:
            if tr:
                summary['logs'] = tr.logs

            with open(os.path.join(self.args.out_dir, 'summary.json'),
                      'w') as f:
                json.dump(summary, f)
            if tr:
                with open(os.path.join(self.args.out_dir, 'full_results.json'),
                          'w') as f:
                    json.dump(tr.test_results, f)

                # The value of test-launcher-summary-output is set by the recipe
                # and passed here via swarming.py. This argument defaults to
                # ${ISOLATED_OUTDIR}/output.json. out-dir is set to ${ISOLATED_OUTDIR}

                # TODO(crbug.com/1031338) - the content of this output.json will
                # work with Chromium recipe because we use the noop_merge merge script,
                # but will require structural changes to support the default gtest
                # merge script (ref: //testing/merge_scripts/standard_gtest_merge.py)
                output_json_path = (self.args.test_launcher_summary_output
                                    or os.path.join(self.args.out_dir,
                                                    'output.json'))
                with open(output_json_path, 'w') as f:
                    json.dump(tr.test_results, f)

            # Move the iOS runtime back to cache dir if the Xcode package is not
            # legacy (i.e. Xcode program & runtimes are in different CIPD packages.)
            # and it's a simulator task.
            if not is_legacy_xcode and self.args.version:
                runtime_cache_folder = xcode.construct_runtime_cache_folder(
                    self.args.runtime_cache_prefix, self.args.version)
                xcode.move_runtime(runtime_cache_folder, self.args.xcode_path,
                                   False)

            test_runner.defaults_delete('com.apple.CoreSimulator',
                                        'FramebufferServerRendererPolicy')