예제 #1
0
 def _BuildGenericTestSetup(self):
   """Build an IosTestSetup for an iOS test."""
   additional_ipas = [
       self._BuildFileReference(os.path.basename(additional_ipa))
       for additional_ipa in getattr(self._args, 'additional_ipas', []) or []
   ]
   directories_to_pull = []
   for directory in getattr(self._args, 'directories_to_pull', []) or []:
     if ':' in directory:
       bundle, path = directory.split(':')
       directories_to_pull.append(
           self._messages.IosDeviceFile(bundleId=bundle, devicePath=path))
     else:
       directories_to_pull.append(
           self._messages.IosDeviceFile(devicePath=directory))
   device_files = []
   other_files = getattr(self._args, 'other_files', None) or {}
   for device_path in other_files.keys():
     # Device paths are be prefixed by the bundle ID if they refer to an app's
     # sandboxed filesystem, separated with the device path by ':'
     idx = device_path.find(':')
     bundle_id = device_path[:idx] if idx != -1 else None
     path = device_path[idx + 1:] if idx != -1 else device_path
     device_files.append(
         self._messages.IosDeviceFile(
             content=self._BuildFileReference(
                 util.GetRelativeDevicePath(path), use_basename=False),
             bundleId=bundle_id,
             devicePath=path))
   return self._messages.IosTestSetup(
       networkProfile=getattr(self._args, 'network_profile', None),
       additionalIpas=additional_ipas,
       pushFiles=device_files,
       pullDirectories=directories_to_pull)
예제 #2
0
    def _BuildGenericTestSpec(self):
        """Build a generic TestSpecification without test-type specifics."""
        device_files = []
        for obb_file in self._args.obb_files or []:
            obb_file_name = os.path.basename(obb_file)
            device_files.append(
                self._messages.DeviceFile(obbFile=self._messages.ObbFile(
                    obbFileName=obb_file_name,
                    obb=self._BuildFileReference(obb_file_name))))
        other_files = getattr(self._args, 'other_files', None) or {}
        for device_path in other_files.keys():
            device_files.append(
                self._messages.DeviceFile(
                    regularFile=self._messages.RegularFile(
                        content=self._BuildFileReference(
                            util.GetRelativeDevicePath(device_path)),
                        devicePath=device_path)))
        environment_variables = []
        if self._args.environment_variables:
            for key, value in six.iteritems(self._args.environment_variables):
                environment_variables.append(
                    self._messages.EnvironmentVariable(key=key, value=value))

        directories_to_pull = self._args.directories_to_pull or []

        account = None
        if self._args.auto_google_login:
            account = self._messages.Account(
                googleAuto=self._messages.GoogleAuto())

        additional_apks = [
            self._messages.Apk(location=self._BuildFileReference(
                os.path.basename(additional_apk))) for additional_apk in
            getattr(self._args, 'additional_apks', []) or []
        ]

        grant_permissions = getattr(self._args, 'grant_permissions',
                                    'all') == 'all'

        setup = self._messages.TestSetup(
            filesToPush=device_files,
            account=account,
            environmentVariables=environment_variables,
            directoriesToPull=directories_to_pull,
            networkProfile=getattr(self._args, 'network_profile', None),
            additionalApks=additional_apks,
            dontAutograntPermissions=not grant_permissions)

        return self._messages.TestSpecification(
            testTimeout=matrix_ops.ReformatDuration(self._args.timeout),
            testSetup=setup,
            disableVideoRecording=not self._args.record_video,
            disablePerformanceMetrics=not self._args.performance_metrics)
예제 #3
0
    def Run(self, args):
        """Run the 'firebase test ios run' command to invoke a test in Test Lab.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation (i.e. group and command arguments combined).

    Returns:
      One of:
        - a list of TestOutcome tuples (if ToolResults are available).
        - a URL string pointing to the user's results in ToolResults or GCS.
    """
        # TODO(b/79369595): expand libs to share more code with android run command.
        if args.async_ and not args.IsSpecified('format'):
            args.format = """
          value(format('Final test results will be available at [{0}].', []))
      """
        log.status.Print(
            '\nHave questions, feedback, or issues? Get support by '
            'emailing:\n  [email protected]\n')

        arg_manager.IosArgsManager().Prepare(args)

        project = util.GetProject()
        tr_client = self.context['toolresults_client']
        tr_messages = self.context['toolresults_messages']
        storage_client = self.context['storage_client']

        bucket_ops = results_bucket.ResultsBucketOps(project,
                                                     args.results_bucket,
                                                     args.results_dir,
                                                     tr_client, tr_messages,
                                                     storage_client)
        if getattr(args, 'app', None):
            bucket_ops.UploadFileToGcs(args.app, _IPA_MIME_TYPE)
        if args.test:
            bucket_ops.UploadFileToGcs(args.test, 'application/zip')
        if args.xctestrun_file:
            bucket_ops.UploadFileToGcs(args.xctestrun_file, 'text/xml')
        additional_ipas = getattr(args, 'additional_ipas', None) or []
        for additional_ipa in additional_ipas:
            bucket_ops.UploadFileToGcs(additional_ipa, _IPA_MIME_TYPE)
        other_files = getattr(args, 'other_files', {}) or {}
        for device_path, file_to_upload in six.iteritems(other_files):
            path = device_path
            if ':' in path:
                path = path[path.find(':') + 1:]
            bucket_ops.UploadFileToGcs(
                file_to_upload,
                None,
                destination_object=util.GetRelativeDevicePath(path))
        bucket_ops.LogGcsResultsUrl()

        tr_history_picker = history_picker.ToolResultsHistoryPicker(
            project, tr_client, tr_messages)
        history_name = PickHistoryName(args)
        history_id = tr_history_picker.GetToolResultsHistoryId(history_name)

        matrix = matrix_creator.CreateMatrix(
            args, self.context, history_id, bucket_ops.gcs_results_root,
            six.text_type(self.ReleaseTrack()))
        monitor = matrix_ops.MatrixMonitor(matrix.testMatrixId, args.type,
                                           self.context)

        with ctrl_c_handler.CancellableTestSection(monitor):
            supported_executions = monitor.HandleUnsupportedExecutions(matrix)
            tr_ids = tool_results.GetToolResultsIds(matrix, monitor)

            url = tool_results.CreateToolResultsUiUrl(project, tr_ids)
            log.status.Print('')
            if args.async_:
                return url
            log.status.Print(
                'Test results will be streamed to [{0}].'.format(url))

            # If we have exactly one testExecution, show detailed progress info.
            if len(supported_executions
                   ) == 1 and args.num_flaky_test_attempts == 0:
                monitor.MonitorTestExecutionProgress(
                    supported_executions[0].id)
            else:
                monitor.MonitorTestMatrixProgress()

        log.status.Print('\nMore details are available at [{0}].'.format(url))
        # Fetch the per-dimension test outcomes list, and also the "rolled-up"
        # matrix outcome from the Tool Results service.
        summary_fetcher = results_summary.ToolResultsSummaryFetcher(
            project, tr_client, tr_messages, tr_ids, matrix.testMatrixId)
        self.exit_code = exit_code.ExitCodeFromRollupOutcome(
            summary_fetcher.FetchMatrixRollupOutcome(),
            tr_messages.Outcome.SummaryValueValuesEnum)
        return summary_fetcher.CreateMatrixOutcomeSummaryUsingEnvironments()