Пример #1
0
    def Run(self, device_id, sdk, derived_data_dir, startup_timeout_sec):
        """Runs the test with generated xctestrun file in the specific device.

    Args:
      device_id: ID of the device.
      sdk: shared.ios_constants.SDK, sdk of the device.
      derived_data_dir: path of derived data directory of this test session.
      startup_timeout_sec: seconds until the xcodebuild command is deemed stuck.

    Returns:
      A value of type runner_exit_codes.EXITCODE.
    """
        logging.info('Running test-without-building with device %s', device_id)
        command = [
            'xcodebuild', 'test-without-building', '-xctestrun',
            self._xctestrun_file_path, '-destination',
            'id=%s' % device_id, '-derivedDataPath', derived_data_dir
        ]
        exit_code, _ = xcodebuild_test_executor.XcodebuildTestExecutor(
            command,
            succeeded_signal=_SIGNAL_TEST_WITHOUT_BUILDING_SUCCEEDED,
            failed_signal=_SIGNAL_TEST_WITHOUT_BUILDING_FAILED,
            sdk=sdk,
            test_type=self.test_type,
            device_id=device_id,
            app_bundle_id=self._aut_bundle_id,
            startup_timeout_sec=startup_timeout_sec).Execute(
                return_output=False)
        return exit_code
Пример #2
0
  def RunXcTest(self, device_id, built_products_dir, derived_data_dir,
                startup_timeout_sec):
    """Runs `xcodebuild test` with the dummy project.

    If app under test or test bundle are not in built_products_dir, will copy
    the file into built_products_dir.

    Args:
      device_id: string, id of the device.
      built_products_dir: path of the built products dir in this build session.
      derived_data_dir: path of the derived data dir in this build session.
      startup_timeout_sec: Seconds until the xcodebuild command is deemed stuck.

    Returns:
      A value of type runner_exit_codes.EXITCODE.

    Raises:
      IllegalArgumentError: when test type is not xctest.
    """
    if self._test_type != ios_constants.TestType.XCTEST:
      raise ios_errors.IllegalArgumentError(
          'Only xctest dummy project is supported to run `xcodebuild test`. '
          'The test type %s is not supported.' % self._test_type)
    self.GenerateDummyProject()
    # In Xcode 7.3+, the folder structure of app under test is changed.
    if xcode_info_util.GetXcodeVersionNumber() >= 730:
      app_under_test_plugin_path = os.path.join(self._app_under_test_dir,
                                                'PlugIns')
      if not os.path.exists(app_under_test_plugin_path):
        os.mkdir(app_under_test_plugin_path)
      test_bundle_under_plugin_path = os.path.join(
          app_under_test_plugin_path, os.path.basename(self._test_bundle_dir))
      if not os.path.exists(test_bundle_under_plugin_path):
        shutil.copytree(self._test_bundle_dir, test_bundle_under_plugin_path)
    self._PrepareBuildProductsDir(built_products_dir)

    logging.info('Running `xcodebuild test` with dummy project.\n'
                 'device_id= %s\n'
                 'built_product_dir = %s\nderived_data_path = %s\n',
                 device_id,
                 built_products_dir,
                 derived_data_dir)
    command = ['xcodebuild', 'test',
               'BUILT_PRODUCTS_DIR=' + built_products_dir,
               '-project', self._xcodeproj_dir_path,
               '-scheme', self._test_scheme,
               '-destination', 'id=' + device_id,
               '-derivedDataPath', derived_data_dir]
    app_bundle_id = bundle_util.GetBundleId(self._app_under_test_dir)
    exit_code, _ = xcodebuild_test_executor.XcodebuildTestExecutor(
        command,
        succeeded_signal=_SIGNAL_XCODEBUILD_TEST_SUCCEEDED,
        failed_signal=_SIGNAL_XCODEBUILD_TEST_FAILED,
        sdk=self._sdk,
        test_type=self._test_type,
        device_id=device_id,
        app_bundle_id=app_bundle_id,
        startup_timeout_sec=startup_timeout_sec).Execute(return_output=False)
    return exit_code
Пример #3
0
    def Run(self,
            device_id,
            sdk,
            derived_data_dir,
            startup_timeout_sec,
            destination_timeout_sec=None,
            os_version=None):
        """Runs the test with generated xctestrun file in the specific device.

    Args:
      device_id: ID of the device.
      sdk: shared.ios_constants.SDK, sdk of the device.
      derived_data_dir: path of derived data directory of this test session.
      startup_timeout_sec: seconds until the xcodebuild command is deemed stuck.
      destination_timeout_sec: Wait for the given seconds while searching for
          the destination device.
      os_version: os version of the device.

    Returns:
      A value of type runner_exit_codes.EXITCODE.
    """
        # When running tests on iOS 12.1 or earlier simulator under Xcode 11 or
        # later, it is required to add swift5 fallback libraries to environment
        # variable.
        # See https://github.com/bazelbuild/rules_apple/issues/684 for context.
        if (xcode_info_util.GetXcodeVersionNumber() >= 1100
                and sdk == ios_constants.SDK.IPHONESIMULATOR and os_version
                and version_util.GetVersionNumber(os_version) < 1220):
            new_env_var = {
                'DYLD_FALLBACK_LIBRARY_PATH':
                xcode_info_util.GetSwift5FallbackLibsDir()
            }
            self.SetTestEnvVars(new_env_var)
        logging.info('Running test-without-building with device %s', device_id)
        command = [
            'xcodebuild', 'test-without-building', '-xctestrun',
            self._xctestrun_file_path, '-destination',
            'id=%s' % device_id, '-derivedDataPath', derived_data_dir
        ]
        if destination_timeout_sec:
            command.extend(
                ['-destination-timeout',
                 str(destination_timeout_sec)])
        exit_code, _ = xcodebuild_test_executor.XcodebuildTestExecutor(
            command,
            succeeded_signal=_SIGNAL_TEST_WITHOUT_BUILDING_SUCCEEDED,
            failed_signal=_SIGNAL_TEST_WITHOUT_BUILDING_FAILED,
            sdk=sdk,
            test_type=self.test_type,
            device_id=device_id,
            app_bundle_id=self._aut_bundle_id,
            startup_timeout_sec=startup_timeout_sec).Execute(
                return_output=False)
        return exit_code