コード例 #1
0
    def GenerateReportMessage(self, requested, executed):
        """Uploads the result to the web service.

        Requires the feature to be enabled; no-op otherwise.

        Args:
            requested: list, A list of test case records requested to run
            executed: list, A list of test case records that were executed

        Returns:
            binary string, serialized report message.
            None if web is not enabled.
        """
        if not self.enabled:
            return None

        # Handle case when runner fails, tests aren't executed
        if (not getattr(self, keys.ConfigKeys.RUN_AS_VTS_SELFTEST, False)
                and executed and executed[-1].test_name == "setup_class"):
            # Test failed during setup, all tests were not executed
            start_index = 0
        else:
            # Runner was aborted. Remaining tests weren't executed
            start_index = len(executed)

        for test in requested[start_index:]:
            msg = self.report_msg.test_case.add()
            msg.name = test.test_name
            msg.start_timestamp = feature_utils.GetTimestamp()
            msg.end_timestamp = msg.start_timestamp
            msg.test_result = ReportMsg.TEST_CASE_RESULT_FAIL

        self.report_msg.end_timestamp = feature_utils.GetTimestamp()

        build = getattr(self, keys.ConfigKeys.IKEY_BUILD)
        if keys.ConfigKeys.IKEY_BUILD_ID in build:
            build_id = str(build[keys.ConfigKeys.IKEY_BUILD_ID])
            self.report_msg.build_info.id = build_id

        logging.info("_tearDownClass hook: start (username: %s)",
                     getpass.getuser())

        if len(self.report_msg.test_case) == 0:
            logging.info("_tearDownClass hook: skip uploading (no test case)")
            return ''

        post_msg = ReportMsg.DashboardPostMessage()
        post_msg.test_report.extend([self.report_msg])

        self.rest_client.AddAuthToken(post_msg)

        message_b = base64.b64encode(post_msg.SerializeToString())

        logging.info('Result proto message generated. size: %s',
                     len(message_b))

        logging.info("_tearDownClass hook: status upload time stamp %s",
                     str(self.report_msg.start_timestamp))

        return message_b
コード例 #2
0
    def GenerateReportMessage(self, requested, executed):
        """Uploads the result to the web service.

        Requires the feature to be enabled; no-op otherwise.

        Args:
            requested: list, A list of test case records requested to run
            executed: list, A list of test case records that were executed

        Returns:
            binary string, serialized report message.
            None if web is not enabled.
        """
        if not self.enabled:
            return None

        for test in requested[len(executed):]:
            msg = self.report_msg.test_case.add()
            msg.name = test.test_name
            msg.start_timestamp = feature_utils.GetTimestamp()
            msg.end_timestamp = msg.start_timestamp
            msg.test_result = ReportMsg.TEST_CASE_RESULT_FAIL

        self.report_msg.end_timestamp = feature_utils.GetTimestamp()

        build = getattr(self, keys.ConfigKeys.IKEY_BUILD)
        if keys.ConfigKeys.IKEY_BUILD_ID in build:
            build_id = str(build[keys.ConfigKeys.IKEY_BUILD_ID])
            self.report_msg.build_info.id = build_id

        logging.debug("_tearDownClass hook: start (username: %s)",
                      getpass.getuser())

        if len(self.report_msg.test_case) == 0:
            logging.warn("_tearDownClass hook: skip uploading (no test case)")
            return ''

        post_msg = ReportMsg.DashboardPostMessage()
        post_msg.test_report.extend([self.report_msg])

        self.rest_client.AddAuthToken(post_msg)

        message_b = base64.b64encode(post_msg.SerializeToString())

        logging.debug('Result proto message generated. size: %s',
                      len(message_b))

        logging.debug("_tearDownClass hook: status upload time stamp %s",
                      str(self.report_msg.start_timestamp))

        return message_b
コード例 #3
0
    def Upload(self, requested, executed):
        """Uploads the result to the web service.

        Requires the feature to be enabled; no-op otherwise.

        Args:
            requested: list, A list of test case names requested to run
            executed: list, A list of test case names that were executed
        """
        if not self.enabled:
            return

        # Handle case when runner fails, tests aren't executed
        if (executed and executed[-1].test_name == "setup_class"):
            # Test failed during setup, all tests were not executed
            start_index = 0
        else:
            # Runner was aborted. Remaining tests weren't executed
            start_index = len(executed)

        for test in requested[start_index:]:
            msg = self.report_msg.test_case.add()
            msg.name = test
            msg.start_timestamp = feature_utils.GetTimestamp()
            msg.end_timestamp = msg.start_timestamp
            msg.test_result = ReportMsg.TEST_CASE_RESULT_FAIL

        self.report_msg.end_timestamp = feature_utils.GetTimestamp()

        build = getattr(self, keys.ConfigKeys.IKEY_BUILD)
        if keys.ConfigKeys.IKEY_BUILD_ID in build:
            build_id = str(build[keys.ConfigKeys.IKEY_BUILD_ID])
            self.report_msg.build_info.id = build_id

        logging.info("_tearDownClass hook: start (username: %s)",
                     getpass.getuser())

        if len(self.report_msg.test_case) > 0:
            post_msg = ReportMsg.DashboardPostMessage()
            post_msg.test_report.extend([self.report_msg])

            # Post new data to the dashboard
            self.rest_client.PostData(post_msg)

            logging.info("_tearDownClass hook: status upload time stamp %s",
                         str(self.report_msg.start_timestamp))
        else:
            logging.info("_tearDownClass hook: skip uploading (no test case)")
コード例 #4
0
    def __init__(self, user_params):
        """Initializes the web feature.

        Parses the arguments and initializes the web functionality.

        Args:
            user_params: A dictionary from parameter name (String) to parameter value.
        """
        self.ParseParameters(toggle_param_name=self._TOGGLE_PARAM,
                             required_param_names=self._REQUIRED_PARAMS,
                             optional_param_names=self._OPTIONAL_PARAMS,
                             user_params=user_params)
        if not self.enabled:
            return

        # Initialize the dashboard client
        post_cmd = getattr(self, keys.ConfigKeys.IKEY_DASHBOARD_POST_COMMAND)
        service_json_path = str(
            getattr(self, keys.ConfigKeys.IKEY_SERVICE_JSON_PATH))
        self.rest_client = dashboard_rest_client.DashboardRestClient(
            post_cmd, service_json_path)
        if not self.rest_client.Initialize():
            self.enabled = False

        self.report_msg = ReportMsg.TestReportMessage()
        self.report_msg.test = str(
            getattr(self, keys.ConfigKeys.KEY_TESTBED_NAME))

        if getattr(self, keys.ConfigKeys.IKEY_ENABLE_PROFILING, False):
            logging.info("Profiling test")
            self.report_msg.test += "Profiling"

        self.report_msg.test_type = ReportMsg.VTS_HOST_DRIVEN_STRUCTURAL
        self.report_msg.start_timestamp = feature_utils.GetTimestamp()
        self.report_msg.host_info.hostname = socket.gethostname()

        android_devices = getattr(self, keys.ConfigKeys.IKEY_ANDROID_DEVICE,
                                  None)
        if not android_devices or not isinstance(android_devices, list):
            logging.warn("android device information not available")
            return

        for device_spec in android_devices:
            dev_info = self.report_msg.device_info.add()
            for elem in [
                    keys.ConfigKeys.IKEY_PRODUCT_TYPE,
                    keys.ConfigKeys.IKEY_PRODUCT_VARIANT,
                    keys.ConfigKeys.IKEY_BUILD_FLAVOR,
                    keys.ConfigKeys.IKEY_BUILD_ID, keys.ConfigKeys.IKEY_BRANCH,
                    keys.ConfigKeys.IKEY_BUILD_ALIAS,
                    keys.ConfigKeys.IKEY_API_LEVEL, keys.ConfigKeys.IKEY_SERIAL
            ]:
                if elem in device_spec:
                    setattr(dev_info, elem, str(device_spec[elem]))
            # TODO: get abi information differently for multi-device support.
            setattr(dev_info, keys.ConfigKeys.IKEY_ABI_NAME,
                    str(getattr(self, keys.ConfigKeys.IKEY_ABI_NAME)))
            setattr(dev_info, keys.ConfigKeys.IKEY_ABI_BITNESS,
                    str(getattr(self, keys.ConfigKeys.IKEY_ABI_BITNESS)))
コード例 #5
0
    def ProcessAndUploadSystrace(self, test_name):
        """Stops and outputs the systrace data to configured path.

        Requires the feature to be enabled; no-op otherwise.

        Args:
            test_name: String, the name of the test
        """
        if not self.enabled:
            return

        controller = getattr(self, "controller", None)
        if not controller:
            logging.info("ProcessSystrace: missing systrace controller")
            return

        controller.Stop()

        if not controller.has_output:
            logging.info("ProcessSystrace: systrace controller has no output")
            return

        try:
            test_module_name = getattr(self, keys.ConfigKeys.KEY_TESTBED_NAME)
            process = controller.process_name
            time = feature_utils.GetTimestamp()
            report_path = getattr(self,
                                  keys.ConfigKeys.IKEY_SYSTRACE_REPORT_PATH)
            report_destination_file_name = '{module}_{test}_{process}_{time}.html'.format(
                module=test_module_name,
                test=test_name,
                process=process,
                time=time)
            report_destination_file_path = os.path.join(
                report_path, report_destination_file_name)
            if controller.SaveLastOutput(report_destination_file_path):
                logging.info('Systrace output saved to %s',
                             report_destination_file_path)
            else:
                logging.error('Failed to save systrace output.')

            report_url_prefix = getattr(
                self, keys.ConfigKeys.IKEY_SYSTRACE_REPORT_URL_PREFIX)
            report_url_prefix = str(report_url_prefix)
            report_destination_file_url = '%s%s' % (
                report_url_prefix, report_destination_file_name)

            if self.web and self.web.enabled:
                self.web.AddSystraceUrl(report_destination_file_url)
            logging.info('systrace result url %s .',
                         report_destination_file_url)
        except Exception as e:  # TODO(yuexima): more specific exceptions catch
            logging.exception('Failed to add systrace to report message %s', e)
        finally:
            if not controller.ClearLastOutput():
                logging.error('failed to clear last systrace output.')
コード例 #6
0
    def AddTestReport(self, test_name):
        """Creates a report for the specified test.

        Requires the feature to be enabled; no-op otherwise.

        Args:
            test_name: String, the name of the test
        """
        if not self.enabled:
            return
        self.current_test_report_msg = self.report_msg.test_case.add()
        self.current_test_report_msg.name = test_name
        self.current_test_report_msg.start_timestamp = feature_utils.GetTimestamp(
        )
コード例 #7
0
ファイル: profiling_utils.py プロジェクト: MIPS/test-vts
    def StartHostProfiling(self, name):
        """Starts a profiling operation.

        Args:
            name: string, the name of a profiling point

        Returns:
            True if successful, False otherwise
        """
        if not self.enabled:
            return False

        if not hasattr(self, _HOST_PROFILING_DATA):
            setattr(self, _HOST_PROFILING_DATA, {})

        host_profiling_data = getattr(self, _HOST_PROFILING_DATA)

        if name in host_profiling_data:
            logging.error("profiling point %s is already active.", name)
            return False
        host_profiling_data[name] = feature_utils.GetTimestamp()
        return True
コード例 #8
0
ファイル: profiling_utils.py プロジェクト: MIPS/test-vts
    def StopHostProfiling(self, name):
        """Stops a profiling operation.

        Args:
            name: string, the name of a profiling point
        """
        if not self.enabled:
            return

        if not hasattr(self, _HOST_PROFILING_DATA):
            setattr(self, _HOST_PROFILING_DATA, {})

        host_profiling_data = getattr(self, _HOST_PROFILING_DATA)

        if name not in host_profiling_data:
            logging.error("profiling point %s is not active.", name)
            return False

        start_timestamp = host_profiling_data[name]
        end_timestamp = feature_utils.GetTimestamp()
        if self.web and self.web.enabled:
            self.web.AddProfilingDataTimestamp(name, start_timestamp,
                                               end_timestamp)
        return True