def __init__(self, tc_name, global_config):
        """
        Constructor

        :type tc_name: BaseConf
        :param tc_name: Configuration of the usecase

        :type global_config: Dictionary
        :param global_config: Global configuration of the campaign
        """

        # Call UseCase base constructor
        self._device = DeviceManager().get_device("PHONE1")

        self.__adbConnectionTimeout = self._device.get_config(
            "adbConnectTimeout", 30, float)
        self._device_uptime_begin = None
        self._sleep_duration = None

        # If the device was disconnected before due to an error
        # we must reconnect it explicitly at the beginning of the test
        # else some commands will not be executed and the test will be blocked
        self._system_api = self._device.get_uecmd("System")
        return_code = self._system_api.wait_for_device(
            self.__adbConnectionTimeout)
        if not return_code:
            time.sleep(30)

        if not self._device.is_available():
            self._device.connect_board()

        # Call SystemSleepBase base Init function
        SystemSleepBase.__init__(self, tc_name, global_config)

        self._report_tree = global_config.campaignConfig.get(
            "campaignReportTree")
        self._sysdebug_apis = self._device.get_uecmd("SysDebug")

        self._tc_name = os.path.basename(self.get_name())
        self._tc_date = ""
        attributes = {"id": self._tc_name, "date": self._tc_date}

        self.__results = PnPResults(self._report_tree,
                                    self._dut_config.get("Name"),
                                    self._failure_file, None, attributes)
Ejemplo n.º 2
0
    def __init__(self, tc_name, global_config):
        """
        Constructor

        :type tc_name: BaseConf
        :param tc_name: Configuration of the usecase

        :type global_config: Dictionnary
        :param global_config: Global configuration of the campaign
        """
        # Call power measurement base Init function
        UseCaseBase.__init__(self, tc_name, global_config)

        self._artifact_manager = self._em.get_artifact_manager(
            "ARTIFACT_MANAGER")

        self.__failure_file = os.path.join(
            self._execution_config_path,
            self._device.get_config("FailureFile"))
        self.__target_file = os.path.join(
            self._execution_config_path, self._device.get_config("TargetFile"))
        self._report_tree = global_config.campaignConfig.get(
            "campaignReportTree")
        self._tc_name = os.path.basename(self.get_name())
        self._tc_date = ""
        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())
        self._sysdebug_apis = self._device.get_uecmd("SysDebug")
        self.screen_off_time = 0
        attributes = {
            "id": self._tc_name,
            "date": self._tc_date,
            "verdict": "NOT EXECUTED"
        }

        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())

        self.__results = PnPResults(self._report_tree,
                                    self._dut_config.get("Name"),
                                    self.__failure_file, self.__target_file,
                                    attributes)
        self._results = {}
Ejemplo n.º 3
0
    def run(self, context):
        """
        Runs the test step
        """
        attributes = dict()
        attributes["date"] = time.strftime("%Y-%m-%d %H:%M:%S")
        attributes["id"] = os.path.basename(self._testcase_name)
        failure_file = os.path.join(Paths.EXECUTION_CONFIG,
                                    self._device.get_config("FailureFile"))
        target_file = os.path.join(Paths.EXECUTION_CONFIG,
                                   self._device.get_config("TargetFile"))

        iteration = False
        if self._tc_parameters.get_b2b_iteration() > 1:
            iteration = True

        # init pnp result object
        pnp_results = PnPResults(self._report_tree, self._dut_name,
                                 failure_file, target_file, attributes,
                                 iteration)
        # store object into the context
        context.set_info(self._pars.save_as, pnp_results)
Ejemplo n.º 4
0
    def _verdict(self):
        """
        Compute verdict for the test
        """
        attributes = {
            "id": self._tc_name,
            "date": self._tc_date,
            "residency_mode": self._sleep_mode_api.get_sleep_mode(),
            "duration": str(self._test_meas_duration),
            "verdict_rail": str(self._verdict_rail),
            "verdict": "UNDEFINED"
        }
        results = PnPResults(self._report_tree, self._dut_config.get("Name"),
                             self.__failure_file, self.__target_file,
                             attributes)

        raw_pat_file = None
        dat_pat_file = None
        js_out_file = None
        if self._is_raw_data_saved:
            raw_pat_file = os.path.join(
                self._report_tree.get_report_path(),
                "PowerMeasurementData_%s_%s.xml" % (self._tc_date.replace(
                    " ", "_").replace(":", ""), self._tc_name))
            dat_pat_file = os.path.join(
                self._report_tree.get_report_path(),
                "PowerMeasurementData_%s_%s" % (self._tc_date.replace(
                    " ", "_").replace(":", ""), self._tc_name),
                self._verdict_rail + ".dat")
            js_out_file = os.path.join(
                self._report_tree.get_report_path(),
                "PowerMeasurementData_%s_%s" % (self._tc_date.replace(
                    " ", "_").replace(":", ""), self._tc_name),
                "graph_values.js")

        # Add power measure only if test has finished
        if self.__finish_test:
            results.append(
                self._patlib.report(self._is_power_calculation_needed,
                                    raw_pat_file, dat_pat_file, js_out_file))

            # Add power_graph.html into folder
            if js_out_file:
                srcname = os.path.join(Paths.TEST_SUITES, "FT", "pnp",
                                       "REPORT", "power_graph.html")
                destname = os.path.join(
                    self._report_tree.get_report_path(),
                    "PowerMeasurementData_%s_%s" % (self._tc_date.replace(
                        " ", "_").replace(":", ""), self._tc_name))
                shutil.copy(srcname, destname)

        results.append(self._sysdebug_apis.report())

        ver_pwr, msg_pwr = results.get_power_verdict(self._verdict_rail)
        ver_res, msg_res = results.get_residency_verdict(
            self._sleep_mode_api.get_sleep_mode(), self._sleep_duration,
            self._test_meas_duration)

        if Global.FAILURE in [ver_pwr, ver_res]:
            results.update({"verdict": "FAIL"})
        else:
            results.update({"verdict": "PASS"})

        results.write()

        if Global.FAILURE in [ver_pwr, ver_res]:
            return Global.FAILURE, msg_pwr + ";" + msg_res
        else:
            return Global.SUCCESS, msg_pwr + ";" + msg_res
class CameraToCamcorderSwitching(UseCaseBase):

    """
    Class live to run benchmarks application
    """

    def __init__(self, tc_name, global_config):
        """
        Constructor

        :type tc_name: BaseConf
        :param tc_name: Configuration of the usecase

        :type global_config: Dictionnary
        :param global_config: Global configuration of the campaign
        """
        # Call power measurement base Init function
        UseCaseBase.__init__(self, tc_name, global_config)

        self._artifact_manager = self._em.get_artifact_manager("ARTIFACT_MANAGER")

        self.__failure_file = os.path.join(self._execution_config_path,
                                           self._device.get_config("FailureFile"))
        self.__target_file = os.path.join(self._execution_config_path,
                                          self._device.get_config("TargetFile"))
        self._report_tree = global_config.campaignConfig.get("campaignReportTree")
        self._tc_name = os.path.basename(self.get_name())
        self._tc_date = ""
        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())
        self._sysdebug_apis = self._device.get_uecmd("SysDebug")
        self.screen_off_time = 0
        attributes = {"id": self._tc_name,
                      "date": self._tc_date,
                      "verdict": "NOT EXECUTED"}

        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())

        self.__results = PnPResults(self._report_tree,
                                    self._dut_config.get("Name"),
                                    self.__failure_file,
                                    self.__target_file,
                                    attributes)
        self._results = {}

    def get_score(self, stat_type="MEDIAN"):
        """
        Get the score of the application
        """
        if stat_type == "ARITHMETIC_MEAN":
            functor = numpy.mean
        elif stat_type == "GEOMETRIC_MEAN":
            functor = scipy.stats.mstats.gmean
        else:
            stat_type = "MEDIAN"
            functor = numpy.median

        xmlresult = etree.Element("scores")
        keys = sorted(self._results.keys())
        if "score" in keys:
            keys.remove("score")
            keys.insert(0, "score")

        for key in keys:
            value = self._results[key]

            xmlnode = etree.Element("item")
            result = str(functor(value))
            runs = ";".join([str(x) for x in value])
            xmlnode.attrib["name"] = key
            xmlnode.attrib["value"] = str(result)
            xmlnode.attrib["runs"] = runs
            self._device.get_logger().debug("%s: %s => %s" % (key, str(value), result))

            xmlresult.append(xmlnode)

            if key == "score":
                self._device.get_logger().info("Result Contacts score : %s (%s)"% (result, stat_type))
        return xmlresult

    def runBashCommand(self, command):
        '''
        Brief:
        Runs a bash command and waits for it
        Param:
        command - the command to be executed

        Atention!: Take care to escape properly the special characters
        '''

        p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        retval = p.wait()
        return p.stdout.readlines()

    def set_up(self):
        """
        Set up the test configuration

        :rtype: tuple
        :return: tuple of Verdict and comment
        """

       #Download and push uiautomator jar on the device
        arguments = self._tc_parameters.get_param_value("ARGUMENTS")

        local_artifact = self._artifact_manager.get_artifact(artifact_name=arguments, transfer_timeout=3600)

        if os.path.isfile(local_artifact):
            result, output = self._device.push(local_artifact, "/data/local/tmp/", 60)
            if result != Global.SUCCESS:
                return result, output
        else:
            return Global.BLOCKED, "Cannot find {0}".format(local_artifact)

        return Global.SUCCESS, "No errors"

    def run_test(self):
        """
        Run the test

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        ITERATIONS = 3
        CtoCCavg = 0
        self.runBashCommand("adb shell uiautomator runtest Performance.jar -c other.StartCamera")

        for x in range(0, ITERATIONS):
            self.runBashCommand("adb shell uiautomator runtest Performance.jar -c other.CameraCamcorderSwitch")

            time.sleep(3)

            out = self.runBashCommand("adb logcat -d -v time | grep \"startDevice\\|camera_cancel_auto_focus\\|closeCamera\"")
            rawtimestamps = []


            for line in out:
                res = re.findall( r'[0-9]+:[0-9]+:[0-9]+.[0-9]+', line)

                rawtimestamps.append(res[0])


            numericTimestamp = re.findall( r'[0-9]+', rawtimestamps[0])

            initialTimestamp = 3600 * 1000 * int(numericTimestamp[0]) + 60 * 1000 * int(numericTimestamp[1]) + 1000 * int(numericTimestamp[2]) + int(numericTimestamp[3]);

            numericTimestamp = re.findall( r'[0-9]+', rawtimestamps[1])

            finalTimestamp = 3600 * 1000 * int(numericTimestamp[0]) + 60 * 1000 * int(numericTimestamp[1]) + 1000 * int(numericTimestamp[2]) + int(numericTimestamp[3]);

            CtoCCavg += (finalTimestamp - initialTimestamp)


        self._device.get_logger().info("Result Camera to preview launch time : %s MEDIAN", str(CtoCCavg/ITERATIONS))
        stat_type = self._tc_parameters.get_param_value("STAT_TYPE")
        scores = self.get_score(stat_type)
        xmltree = self._sysdebug_apis.report()

        self.__results.append(scores)
        self.__results.append(xmltree)

        try:
            ilb = True
            verdict, output = self.__results.get_performance_verdict(scores, ilb,
                                                                     self._secondary_report,
                                                                     self.tc_order)
            self._device.get_logger().info(output)
        finally:
            self.__results.write()

        return verdict, output


    def tear_down(self):
        """
        Tear down

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        self._device.run_cmd("adb shell input keyevent KEYCODE_ESCAPE", 5)
        self._device.run_cmd("adb shell input keyevent KEYCODE_ESCAPE", 5)
        return Global.SUCCESS, "No errors"
class BrowserLaunchTime(UseCaseBase):

    """
    Class live to run benchmarks application
    """

    def __init__(self, tc_name, global_config):
        """
        Constructor

        :type tc_name: BaseConf
        :param tc_name: Configuration of the usecase

        :type global_config: Dictionnary
        :param global_config: Global configuration of the campaign
        """
        # Call power measurement base Init function
        UseCaseBase.__init__(self, tc_name, global_config)


        self.__failure_file = os.path.join(self._execution_config_path,
                                           self._device.get_config("FailureFile"))
        self.__target_file = os.path.join(self._execution_config_path,
                                          self._device.get_config("TargetFile"))
        self._report_tree = global_config.campaignConfig.get("campaignReportTree")
        self._tc_name = os.path.basename(self.get_name())
        self._tc_date = ""
        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())
        self._sysdebug_apis = self._device.get_uecmd("SysDebug")
        self.screen_off_time = 0
        attributes = {"id": self._tc_name,
                      "date": self._tc_date,
                      "verdict": "NOT EXECUTED"}

        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())

        self.__results = PnPResults(self._report_tree,
                                    self._dut_config.get("Name"),
                                    self.__failure_file,
                                    self.__target_file,
                                    attributes)
        self._results = {}

    def __fetch_artifactory_file(self, appuri):
        """
        Retrieve a file from artifactory
        """
        artifact_url_base = "https://mcg-depot.intel.com/artifactory/acs_test_artifacts/"
        artifact_url = artifact_url_base + appuri

        local_path = os.path.join(self._execution_config_path, "EMBD")
        local_filename = os.path.join(local_path, os.path.basename(appuri))
        local_filename = local_filename.split(";")[0]

        if not os.path.exists(local_path):
            os.mkdir(local_path)

        if os.path.exists(local_filename):
            return local_filename

        self._device.get_logger().info("Download %s => %s" % (artifact_url, local_filename))

        start = time.time()
        r = requests.get(artifact_url, proxies={'http': ''})
        r.raise_for_status()

        length = float(r.headers['content-length'])
        progressize = 0

        with open(local_filename, "wb") as f:
            for chunk in r.iter_content(chunk_size=1024000):
                if chunk:
                    progressize += len(chunk)
                    percent = int(progressize / length * 100)
                    self._logger.debug("progress of downloading %s file: %d%%" %
                                       (appuri, percent))
                    f.write(chunk)

        dlduration = time.time() - start
        self._device.get_logger().info("Download %s in %f seconds (birate: %d MiO/s)" %
                          (appuri, dlduration, length / (dlduration * 8000000)))

        return local_filename


    def get_score(self, stat_type="MEDIAN"):
        """
        Get the score of the application
        """
        if stat_type == "ARITHMETIC_MEAN":
            functor = numpy.mean
        elif stat_type == "GEOMETRIC_MEAN":
            functor = scipy.stats.mstats.gmean
        else:
            stat_type = "MEDIAN"
            functor = numpy.median

        xmlresult = etree.Element("scores")
        keys = sorted(self._results.keys())
        if "score" in keys:
            keys.remove("score")
            keys.insert(0, "score")

        for key in keys:
            value = self._results[key]

            xmlnode = etree.Element("item")
            result = str(functor(value))
            runs = ";".join([str(x) for x in value])
            xmlnode.attrib["name"] = key
            xmlnode.attrib["value"] = str(result)
            xmlnode.attrib["runs"] = runs
            self._device.get_logger().debug("%s: %s => %s" % (key, str(value), result))

            xmlresult.append(xmlnode)

            if key == "score":
                self._device.get_logger().info("Result Browser score : %s (%s)"% (result, stat_type))
        return xmlresult


    def set_up(self):
        """
        Set up the test configuration

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        #Download and push uiautomator jar on the device
        arguments = self._tc_parameters.get_param_value("ARGUMENTS")
        addr = self.__fetch_artifactory_file(arguments.split("artifact://")[1])

        result, output = self._device.push(addr.split(";")[0], "/data/local/tmp/", 60)

        res, output = self._device.run_cmd("adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db\
                                           \"select value from system where name='screen_off_timeout'\"", 5)
        if not res == Global.SUCCESS:
            return Global.FAILURE, "No output detected"

        self.screen_off_time = int(output)

        #Set screen off timeout to 30 min
        self._device.run_cmd("adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db\
                             \"update system set value='1800000' where name='screen_off_timeout'\"", 5)


        #Cold measurement, reboot before measure
        self._device.reboot()

        #unlock screen
        self._device.run_cmd("adb shell input keyevent 82", 5)
        return Global.SUCCESS, "No errors"

    def run_test(self):
        """
        Run the test

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        #Launch Browser as user
        self._device.run_cmd("adb shell uiautomator runtest Performance.jar -c other.BrowserLaunch", 120)

        #Filter the output
        res, out = self._device.run_cmd("adb logcat -d | \
                        grep \"Displayed com.android.browser/.BrowserActivity\" | cut -d ' ' -f5-", 5)

        if not res == Global.SUCCESS:
            return Global.FAILURE, "No output detected"
        out = out.replace("\r\n", "\n")

        err = re.search( r'Exception', out)
        if not err == None:
            return Global.FAILURE, "uiautomator test faield"

        #Get raw result
        out = re.search( r'[0-9]+', out)
        if out == None:
            return Global.FAILURE, "No answer detected"

        #Compare result with the target file's entry
        self._device.get_logger().info("Result Settings score : %s MEDIAN", out.group(0))
        stat_type = self._tc_parameters.get_param_value("STAT_TYPE")
        scores = self.get_score(stat_type)
        xmltree = self._sysdebug_apis.report()

        self.__results.append(scores)
        self.__results.append(xmltree)

        try:
            ilb = True
            verdict, output = self.__results.get_performance_verdict(scores, ilb,
                                                                     self._secondary_report,
                                                                     self.tc_order)
            self._device.get_logger().info(output)
        finally:
            self.__results.write()

        return verdict, output


    def tear_down(self):
        """
        Tear down

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        self._device.run_cmd("adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db\
                             \"update system set value='"+ str(self.screen_off_time) + "' where name='screen_off_timeout'\"", 5)
        return Global.SUCCESS, "No errors"
    def __init__(self, tc_name, global_config):
        """
        Constructor

        :type tc_name: BaseConf
        :param tc_name: Configuration of the usecase

        :type global_config: Dictionnary
        :param global_config: Global configuration of the campaign
        """
        # Call power measurement base Init function
        UseCaseBase.__init__(self, tc_name, global_config)

        # Call verdict management instance
        self.__failure_file = os.path.join(
            self._execution_config_path,
            self._device.get_config("FailureFile"))
        self.__target_file = os.path.join(
            self._execution_config_path, self._device.get_config("TargetFile"))
        self.__application = None
        self._global_config = global_config
        self.__adbConnectionTimeout = self._device.get_config(
            "adbConnectTimeout", 30, float)

        # If the device was disconnected before due to an error
        # we must reconnect it explicitly at the beginning of the test
        # else the commands will fail and the test will be blocked
        self._system_api = self._device.get_uecmd("System")
        return_code = self._system_api.wait_for_device(
            self.__adbConnectionTimeout)
        if not return_code:
            time.sleep(30)

        if not self._device.is_available():
            self._device.connect_board()

        self._phonesystem_api = self._device.get_uecmd("PhoneSystem")
        self._networking_api = self._device.get_uecmd("Networking")
        self._localconnectivity_api = self._device.get_uecmd(
            "LocalConnectivity")
        self._localization_api = self._device.get_uecmd("Location")
        self._sensor_api = self._device.get_uecmd("Sensor")
        self._sysdebug_apis = self._device.get_uecmd("SysDebug")
        self._system_apis = self._device.get_uecmd("System")

        self._report_tree = global_config.campaignConfig.get(
            "campaignReportTree")
        self._tc_name = os.path.basename(self.get_name())
        self._tc_date = ""
        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())

        attributes = {
            "id": self._tc_name,
            "date": self._tc_date,
            "verdict": "NOT EXECUTED"
        }

        self.__results = PnPResults(self._report_tree,
                                    self._dut_config.get("Name"),
                                    self.__failure_file, self.__target_file,
                                    attributes)
class LivePerfMeasApplication(UseCaseBase):
    """
    Class live to run benchmarks application
    """
    def __init__(self, tc_name, global_config):
        """
        Constructor

        :type tc_name: BaseConf
        :param tc_name: Configuration of the usecase

        :type global_config: Dictionnary
        :param global_config: Global configuration of the campaign
        """
        # Call power measurement base Init function
        UseCaseBase.__init__(self, tc_name, global_config)

        # Call verdict management instance
        self.__failure_file = os.path.join(
            self._execution_config_path,
            self._device.get_config("FailureFile"))
        self.__target_file = os.path.join(
            self._execution_config_path, self._device.get_config("TargetFile"))
        self.__application = None
        self._global_config = global_config
        self.__adbConnectionTimeout = self._device.get_config(
            "adbConnectTimeout", 30, float)

        # If the device was disconnected before due to an error
        # we must reconnect it explicitly at the beginning of the test
        # else the commands will fail and the test will be blocked
        self._system_api = self._device.get_uecmd("System")
        return_code = self._system_api.wait_for_device(
            self.__adbConnectionTimeout)
        if not return_code:
            time.sleep(30)

        if not self._device.is_available():
            self._device.connect_board()

        self._phonesystem_api = self._device.get_uecmd("PhoneSystem")
        self._networking_api = self._device.get_uecmd("Networking")
        self._localconnectivity_api = self._device.get_uecmd(
            "LocalConnectivity")
        self._localization_api = self._device.get_uecmd("Location")
        self._sensor_api = self._device.get_uecmd("Sensor")
        self._sysdebug_apis = self._device.get_uecmd("SysDebug")
        self._system_apis = self._device.get_uecmd("System")

        self._report_tree = global_config.campaignConfig.get(
            "campaignReportTree")
        self._tc_name = os.path.basename(self.get_name())
        self._tc_date = ""
        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())

        attributes = {
            "id": self._tc_name,
            "date": self._tc_date,
            "verdict": "NOT EXECUTED"
        }

        self.__results = PnPResults(self._report_tree,
                                    self._dut_config.get("Name"),
                                    self.__failure_file, self.__target_file,
                                    attributes)

    def _verdict(self):
        """
        Get verdict
        """
        stat_type = self._tc_parameters.get_param_value("STAT_TYPE")
        scores = self.__application.get_score(stat_type)
        sysreport = self._sysdebug_apis.report()

        self.__results.append(scores)
        self.__results.append(sysreport)

        try:
            ilb = self.__application.is_lower_better
            verdict, output = self.__results.get_performance_verdict(
                scores, ilb, self._secondary_report, self.tc_order)
            self._logger.info(output)
        finally:
            self.__results.write()

        return verdict, output

    def set_up(self):
        """
        Set up the test configuration

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        # Call power measurement base setup function
        UseCaseBase.set_up(self)

        sysdbg_modules_config = self._tc_parameters.get_param_value(
            "SYSDEBUG_MODULES")
        self._sysdebug_apis.init(sysdbg_modules_config)

        self._networking_api.set_wifi_power("off")
        self._localconnectivity_api.set_bt_power("off")
        self._localization_api.set_gps_power("off")
        self._networking_api.set_flight_mode("on")

        application_name = self._tc_parameters.get_param_value(
            "APPLICATION_NAME")
        # appuri contains the app name to retrieve in pnp module config
        app_key = self._tc_parameters.get_param_value("APP_NAME")
        main_app_full_name = self.__retrieve_value_from_module_config(app_key)
        if not main_app_full_name:
            # specified key is not in config, it could be a real app name
            main_app_full_name = app_key
        # additional contains additional app name to install to retrieve in pnp module config
        additionnals = self._tc_parameters.get_param_value("ADDITIONALS")
        additional_app_full_name = self.__retrieve_value_from_module_config(
            additionnals)
        if not additional_app_full_name:
            # specified key is not in config, it could be a real app name
            additional_app_full_name = additionnals

        arguments = self._tc_parameters.get_param_value("ARGUMENTS")
        arguments_full_name = self.__retrieve_value_from_module_config(
            arguments)
        if not arguments_full_name:
            arguments_full_name = arguments
        self.__loop_mode = self._tc_parameters.get_param_value("LOOP_MODE")
        url = self._tc_parameters.get_param_value("URL")
        self.__application = self._device.get_application_instance(
            application_name)

        self.__application.pre_install(self._execution_config_path,
                                       self._global_config, self._dut_config,
                                       self._sysdebug_apis)
        self.__application.install(main_app_full_name,
                                   additional_app_full_name,
                                   arguments_full_name, url)
        self.__application.post_install()

        self._system_apis.clear_cache()
        self._phonesystem_api.display_on()
        stabilization_time = 5
        self._logger.debug("Wait for %s seconds after display_on." %
                           str(stabilization_time))
        time.sleep(stabilization_time)

        return Global.SUCCESS, "No errors"

    def __retrieve_value_from_module_config(self, app_key):
        """
        Retrieve the apk to install from PnpModule configuration
        """
        if app_key is None:
            return None
        # get all configuration for pnp module
        apk_full_name = None
        module_name = "PnpModule"
        module_configs = [
            module.configuration
            for module in self._device.get_device_modules(module_name)
        ]
        for module_config in module_configs:
            if app_key.strip() in module_config:
                apk_full_name = module_config.get(app_key.strip())
        return apk_full_name

    def run_test(self):
        """
        Run the test

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        UseCaseBase.run_test(self)

        self._tc_date = time.strftime("%Y-%m-%d %H:%M:%S")
        self.__results.update({"date": self._tc_date})

        self._sysdebug_apis.reset()
        self._sysdebug_apis.start()
        self.__application.run(self._tc_parameters)
        self._sysdebug_apis.fetch()
        self._sysdebug_apis.stop()

        return self._verdict()

    def tear_down(self):
        """
        Tear down

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        UseCaseBase.tear_down(self)

        if self.__application is not None:
            self.__application.uninstall()
        #some application may have change the brightness value
        brightness = int(self._dut_config.get("displayBrightness"))
        if brightness is not None:
            new_brightness = int(
                self._phonesystem_api.set_display_brightness(brightness))
            if abs(new_brightness - brightness) > 1:
                self._logger.warning(
                    "Requested brightness was %s, brightness has been set to %s"
                    % (brightness, new_brightness))
        self._phonesystem_api.display_off()

        return Global.SUCCESS, "No errors"
class LiveSystemSleepResidencyMeasurement(SystemSleepBase):
    """
    Sleep mode residency measurement class.
    """
    def __init__(self, tc_name, global_config):
        """
        Constructor

        :type tc_name: BaseConf
        :param tc_name: Configuration of the usecase

        :type global_config: Dictionary
        :param global_config: Global configuration of the campaign
        """

        # Call UseCase base constructor
        self._device = DeviceManager().get_device("PHONE1")

        self.__adbConnectionTimeout = self._device.get_config(
            "adbConnectTimeout", 30, float)
        self._device_uptime_begin = None
        self._sleep_duration = None

        # If the device was disconnected before due to an error
        # we must reconnect it explicitly at the beginning of the test
        # else some commands will not be executed and the test will be blocked
        self._system_api = self._device.get_uecmd("System")
        return_code = self._system_api.wait_for_device(
            self.__adbConnectionTimeout)
        if not return_code:
            time.sleep(30)

        if not self._device.is_available():
            self._device.connect_board()

        # Call SystemSleepBase base Init function
        SystemSleepBase.__init__(self, tc_name, global_config)

        self._report_tree = global_config.campaignConfig.get(
            "campaignReportTree")
        self._sysdebug_apis = self._device.get_uecmd("SysDebug")

        self._tc_name = os.path.basename(self.get_name())
        self._tc_date = ""
        attributes = {"id": self._tc_name, "date": self._tc_date}

        self.__results = PnPResults(self._report_tree,
                                    self._dut_config.get("Name"),
                                    self._failure_file, None, attributes)

    def run_test(self):
        """
        Execute the test
        """

        sysdbg_modules_config = self._tc_parameters.get_param_value(
            "SYSDEBUG_MODULES")
        self._sysdebug_apis.init(sysdbg_modules_config)

        sleep_parameter = self._tc_parameters.get_param_value("SLEEP_DURATION")
        if sleep_parameter is not None and sleep_parameter != "" and sleep_parameter.isdigit(
        ):
            self._sleep_duration = int(sleep_parameter)

        # Call live sleep use case base
        SystemSleepBase.run_test(self)

        self._tc_date = time.strftime("%Y-%m-%d %H:%M:%S")
        self.__results.update({"date": self._tc_date})

        while not self._sysdebug_apis.synchronize():
            time.sleep(10)

        adbConnectTimeout = self._device.get_config("adbConnectTimeout", 10,
                                                    float)
        usbReplugRetries = self._device.get_config("usbReplugRetries", 1, int)

        if self._io_card is not None:
            self._device.disconnect_board()
            self._sysdebug_apis.reset()  # will clear mid_pmu_states
            self._residency_api.clear(
                self._sleep_duration)  # will also clear mid_pmu_states
            # but this is needed to do the fetch on this instance
            self._io_card.usb_host_pc_connector(False)
            # Unplug wall charger only if it is AC_CHGR
            if self._device.get_default_wall_charger(
            ) == self._io_card.AC_CHGR:
                self._io_card.wall_charger_connector(False)

        # Update device uptime
        updated, self._device_uptime_begin = self._device._update_device_up_state(
            0)
        if not updated:
            self._device_uptime_begin = None

        if self._sleep_duration:
            self._logger.info(
                "Wait for %s s before measurement (sleep duration before %s)" %
                (str(self._sleep_duration), self._sleep_mode))
            time.sleep(self._sleep_duration)

        self._sysdebug_apis.start()
        self._logger.info("Wait for %s s to enter in %s" %
                          (str(self._duration), self._sleep_mode))
        time.sleep(self._duration)
        self._sysdebug_apis.stop()

        residency_spent = 0
        ret_code = None

        if self._io_card is not None:
            for cnt in range(0, usbReplugRetries + 1):
                self._logger.debug("Loop Iteration: %d" % cnt)
                # plug wall charger only if it is AC_CHGR
                if self._device.get_default_wall_charger(
                ) == self._io_card.AC_CHGR:
                    self._io_card.wall_charger_connector(True)
                self._io_card.usb_host_pc_connector(True)

                self._logger.debug("Wait for device %s seconds" %
                                   self.__adbConnectionTimeout)
                ret_code = self._system_api.wait_for_device(
                    self.__adbConnectionTimeout)
                self._logger.debug("Wait for device return code: %s" %
                                   ret_code)
                if not ret_code:
                    if cnt < usbReplugRetries:
                        self._logger.warning(
                            "timeout on wait-for-device, trying to unplug/replug (try %s/%s)"
                            % (str(cnt + 1), str(usbReplugRetries)))
                        self._io_card.usb_host_pc_connector(False)
                        # Unplug wall charger only if it is AC_CHGR
                        if self._device.get_default_wall_charger(
                        ) == self._io_card.AC_CHGR:
                            self._io_card.wall_charger_connector(False)
                        time.sleep(10)
                    continue

                residency_spent = self._residency_api.get_value(
                    "residency", self._sleep_mode_api.get_sleep_mode())
                self._sysdebug_apis.fetch()
                self._device.connect_board()
                self._logger.debug("device retrieved after %s tries" %
                                   str(cnt + 1))
                break

            if not ret_code:
                raise DeviceException(
                    DeviceException.OPERATION_FAILED,
                    "Could not retrieve the device after %s plug/unplug cycles"
                    % str(usbReplugRetries))

        if residency_spent is None:
            raise DeviceException(
                DeviceException.INVALID_PARAMETER,
                "There is no %s sleep mode for this device model" %
                self._sleep_mode_api.get_sleep_mode())

        # Get device uptime and raise an exception if the device rebooted
        if self._device_uptime_begin:
            updated, uptime = self._device._update_device_up_state(
                self._device_uptime_begin)
            if updated and not self._device.is_up:
                self._logger.warning(
                    "the device uptime was %s before the measurement, %s now !"
                    % (str(self._device_uptime_begin), str(uptime)))
                raise DeviceException(
                    DeviceException.OPERATION_FAILED,
                    "Device rebooted during the measurement")

        sysreport = self._sysdebug_apis.report()
        self.__results.append(sysreport)
        self.__results.write()

        return self._residency_verdict(residency_spent)
Ejemplo n.º 10
0
class VideoRecordingFPS(UseCaseBase):
    """
    Class live to run benchmarks application
    """
    def __init__(self, tc_name, global_config):
        """
        Constructor

        :type tc_name: BaseConf
        :param tc_name: Configuration of the usecase

        :type global_config: Dictionnary
        :param global_config: Global configuration of the campaign
        """
        # Call power measurement base Init function
        UseCaseBase.__init__(self, tc_name, global_config)

        self._artifact_manager = self._em.get_artifact_manager(
            "ARTIFACT_MANAGER")

        self.__failure_file = os.path.join(
            self._execution_config_path,
            self._device.get_config("FailureFile"))
        self.__target_file = os.path.join(
            self._execution_config_path, self._device.get_config("TargetFile"))
        self._report_tree = global_config.campaignConfig.get(
            "campaignReportTree")
        self._tc_name = os.path.basename(self.get_name())
        self._tc_date = ""
        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())
        self._sysdebug_apis = self._device.get_uecmd("SysDebug")
        self.screen_off_time = 0
        attributes = {
            "id": self._tc_name,
            "date": self._tc_date,
            "verdict": "NOT EXECUTED"
        }

        self._secondary_report = SecondaryTestReport(
            self._device.get_report_tree().get_report_path())

        self.__results = PnPResults(self._report_tree,
                                    self._dut_config.get("Name"),
                                    self.__failure_file, self.__target_file,
                                    attributes)
        self._results = {}

    def get_score(self, stat_type="MEDIAN"):
        """
        Get the score of the application
        """
        if stat_type == "ARITHMETIC_MEAN":
            functor = numpy.mean
        elif stat_type == "GEOMETRIC_MEAN":
            functor = scipy.stats.mstats.gmean
        else:
            stat_type = "MEDIAN"
            functor = numpy.median

        xmlresult = etree.Element("scores")
        keys = sorted(self._results.keys())
        if "score" in keys:
            keys.remove("score")
            keys.insert(0, "score")

        for key in keys:
            value = self._results[key]

            xmlnode = etree.Element("item")
            result = str(functor(value))
            runs = ";".join([str(x) for x in value])
            xmlnode.attrib["name"] = key
            xmlnode.attrib["value"] = str(result)
            xmlnode.attrib["runs"] = runs
            self._device.get_logger().debug("%s: %s => %s" %
                                            (key, str(value), result))

            xmlresult.append(xmlnode)

            if key == "score":
                self._device.get_logger().info(
                    "Result Contacts score : %s (%s)" % (result, stat_type))
        return xmlresult

    def runBashCommand(self, command):
        '''
        Brief:
        Runs a bash command and waits for it
        Param:
        command - the command to be executed

        Atention!: Take care to escape properly the special characters
        '''

        p = subprocess.Popen(command,
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        retval = p.wait()
        return p.stdout.readlines()

    def set_up(self):
        """
        Set up the test configuration

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        #Download and push uiautomator jar on the device
        arguments = self._tc_parameters.get_param_value("ARGUMENTS")

        local_artifact = self._artifact_manager.get_artifact(
            artifact_name=arguments, transfer_timeout=3600)

        if os.path.isfile(local_artifact):
            result, output = self._device.push(local_artifact,
                                               "/data/local/tmp/", 60)
            if result != Global.SUCCESS:
                return result, output
        else:
            return Global.BLOCKED, "Cannot find {0}".format(local_artifact)

        return Global.SUCCESS, "No errors"

    def run_test(self):
        """
        Run the test

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        #Removes all videos recorded previously
        res, out = self._device.run_cmd(
            "adb shell rm /sdcard/DCIM/Camera/* 2> /dev/null", 30)
        #print "xxxxxxxxxxxxxxxxx" + out
        #Record new video
        self._device.run_cmd(
            "adb shell uiautomator runtest Performance.jar -c other.VideoRecording",
            330)
        self._device.run_cmd("sleep 3", 5)

        #Removes all previous videos from /tmp
        self.runBashCommand("rm /tmp/VID*")

        #pull the video
        self._device.pull("/sdcard/DCIM/Camera/", "/tmp/", 120)

        #analyze the video
        command = "mediainfo " + "/tmp/VID*" + " 2> /dev/null | grep 'Frame rate  ' | tr -d ' ' | cut -d ':' -f2-2"
        out = self.runBashCommand(command)

        print out
        if out == []:
            return Global.FAILURE, "mediainfo is not installed,\
             please install mediainfo(sudo apt-get install mediainfo)"

        #extract the result
        out = re.search(r'[0-9]+(\.[0-9][0-9]?)?', out[0])

        self._device.get_logger().info(
            "Result VideoRecording score : %s MEDIAN", out.group(0))

        stat_type = self._tc_parameters.get_param_value("STAT_TYPE")
        scores = self.get_score(stat_type)
        xmltree = self._sysdebug_apis.report()

        self.__results.append(scores)
        self.__results.append(xmltree)

        try:
            ilb = True
            verdict, output = self.__results.get_performance_verdict(
                scores, ilb, self._secondary_report, self.tc_order)
            self._device.get_logger().info(output)
        finally:
            self.__results.write()

        return verdict, output

    def tear_down(self):
        """
        Tear down

        :rtype: tuple
        :return: tuple of Verdict and comment
        """
        self._device.run_cmd("adb shell rm /sdcard/DCIM/Camera/* 2> /dev/null",
                             30)
        self._device.run_cmd("adb shell input keyevent KEYCODE_ESCAPE", 2)
        self._device.run_cmd("adb shell input keyevent KEYCODE_ESCAPE", 2)
        return Global.SUCCESS, "No errors"