def get_default_addr(self): """ Get the default BD address (persistant address) :rtype: str :return: default BD address. format: 12:34:56:78:9A:BC otherwise return empty str """ BDADDR_PATH_PROPERTY = "ro.bt.bdaddr_path" PERSIST_BDROID_ADDR = "persist.service.bdroid.bdaddr" device_properties = DeviceManager().get_device_properties( self._device.get_name()) # 1. Default from bd_addr.conf file if it exists and not null if BDADDR_PATH_PROPERTY in device_properties: bdconf_path = device_properties.get(BDADDR_PATH_PROPERTY) cmd = "adb shell cat %s" % bdconf_path bdconf = self._exec(cmd) bdconf = str(bdconf).upper().strip() if bdconf.find("NO SUCH FILE OR DIRECTORY"): bdconf = "" if bdconf not in ["", "00:00:00:00:00:00"]: self._logger.debug("Default BD Address from %s is <%s>" % (bdconf_path, bdconf)) if NetworkingUtil.is_valid_mac_address(bdconf): return bdconf else: return "" # 2. Default from persist.service.bdroid.bdaddr property if PERSIST_BDROID_ADDR in device_properties: bdaddr = device_properties.get(PERSIST_BDROID_ADDR) else: bdaddr = "" bdaddr = str(bdaddr).upper().strip() self._logger.debug( "Default BD Address from persist.service.bdroid.bdaddr is <%s>" % bdaddr) if NetworkingUtil.is_valid_mac_address(bdaddr): return bdaddr else: return ""
class PatLibBase(EquipmentTestStepBase): """ Manage PatLib """ def __init__(self, tc_conf, global_conf, ts_conf, factory): """ Constructor """ EquipmentTestStepBase.__init__(self, tc_conf, global_conf, ts_conf, factory) self._dut_config = DeviceManager().get_device_config("PHONE1") self._patlib = None self._report_tree = global_conf.campaignConfig.get( "campaignReportTree") self._patlib_util = None def update_report(self, pnp_verdict, result_name, measure): """ Hack to add test step comment in AWR database for now Test steps result are not yet available in AWR database (and not planned...) """ device = DeviceManager._device_instances.get("PHONE1") external_tc_report = SecondaryTestReport( device.get_report_tree().get_report_path()) if pnp_verdict == Global.FAILURE: verdict = external_tc_report.verdict.FAIL else: verdict = external_tc_report.verdict.PASS external_tc_report.add_result(result_name, verdict, measure, self._testcase_name, self._conf.tc_order) def _run(self): """ Specific run for test step """ raise AcsToolException(AcsToolException.FEATURE_NOT_IMPLEMENTED, "_run is not implemented for this test step") def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ EquipmentTestStepBase.run(self, context) self._patlib_util = PatLibUtil(self._equipment_parameters, self._dut_config.get("Name"), os.path.basename(self._conf.get_name()), self._logger) #self._patlib = self._context.get_info(self._pars.stored_pat_lib_instance) self._patlib = self._equipment_manager.get_power_analyzer_tool( self._pars.eqt) self._run()
class Thermals(SysDebug): """ Read thermals (zone and cpu) on the device """ def __init__(self, device, config=None): """ Constructor. :type device: Device :param device: The DUT :type config: dictionary :param config: Configuration of the module. Unused for this module """ SysDebug.__init__(self, device) self._sys_debug_infos = {} self.__thermals = {} self.__thermal_cpu_path = "/sys/devices/platform/coretemp.0" self.__thermal_soc_file = "soc_temp_input" self.__thermal_core_file_temp = "temp[0-9]*_input" self.__thermal_core_file_label = "temp[0-9]*_label" self.__force_thermal_cooling = False self.__thermal_zones_path = "/sys/devices/virtual/thermal" self.__campaign_config = DeviceManager().get_global_config( ).campaignConfig self.__config = {} if config: self.__config = config if "waitForCoolDown" in self.__campaign_config: self.__force_thermal_cooling = self.__campaign_config.get( "waitForCoolDown").lower() == "true" def __fill_thermal(self, zone, filename, value): """ Fill sysdebug structure :type zone: str :param zone: thermal zone defined in the DUT :type filename: str :param filename: filename of thermal information :type value: str :param value: thermal information (file content) """ if zone not in self.__thermals.keys(): self.__thermals[zone] = {} if filename == self.__thermal_soc_file: self.__thermals[zone]['name'] = "soc" self.__thermals[zone]['value'] = value elif re.search(".*_label", filename) or filename == "type": self.__thermals[zone]["name"] = value elif re.search(".*_input", filename) or filename == "temp": self.__thermals[zone]["value"] = value def __get_thermals_data(self, lines): """ Get dictionnary of thermals: zone : { name : thermal_name, value : thermal_value } :type lines: str :param lines: measure of a thermal. The line looks like : "filepath/filename:value" """ self.__thermals = {} for item in lines: data = item.split(":") if len(data) != 2: self._logger.warning("Thermal entry error : '%s'" % item) continue filename = os.path.basename(data[0]) dirname = os.path.basename(os.path.dirname(data[0])) if dirname.find("coretemp") != -1: zone = ("coretemp", filename.split("_")[0]) else: zone = ("thermal", dirname.split("_")[-1]) self.__fill_thermal(zone, filename, data[1]) def __merge_sys_debug_infos(self): """ Add thermals in _sys_debug_infos structure. """ for item in self.__thermals.values(): if "value" not in item: continue name = item["name"] value = str(float(item["value"]) / 1000) if name in self._sys_debug_infos: value = self._sys_debug_infos[name] + ";" + value self._sys_debug_infos[name] = value else: self._sys_debug_infos[name] = value def _retrieve_sysinfo(self): """ Retrieve informations """ sysinfo = self._retrieve_sysdebug_message() self.__get_thermals_data(sysinfo) def _retrieve_sysdebug_message(self): """ Retrieve triggered message in aplog :rtype: list :return: list of lines of thermal informations """ cmd = "find %s -name type -o -name temp|xargs grep -e '^.*$';" % \ self.__thermal_zones_path cmd += "find %s -name '%s' -o -name '%s' -o -name '%s'|xargs grep '^.*$';" % \ (self.__thermal_cpu_path, self.__thermal_core_file_temp, self.__thermal_core_file_label, self.__thermal_soc_file) _, thermals = self._device.run_cmd("adb shell " + cmd, self._uecmd_default_timeout, force_execution=True, silent_mode=True) return thermals.splitlines() def synchronize(self): """ Synchronize :rtype: Boolean :return: True if module is synchronized with the DUT, False otherwise """ self._retrieve_sysinfo() if self.__force_thermal_cooling is True: self._logger.debug( "thermal_cooling is forced in the global config with waitForCoolDown=true" ) blocking = True elif "level" in self.__config.keys() and self.__config["level"].lower( ) == "blocking": blocking = True else: blocking = False for item2 in self.__config.keys(): for item in self.__thermals.values(): if "value" not in item: continue name = item["name"] if str(item2).lower() in name.lower(): value = float(item["value"]) / 1000 if blocking and value > float(self.__config[item2]): self._logger.warning( "Wait requested as thermal %s has too high " "temperature : %s > %s" % (name, str(value), self.__config[item2])) return False elif value > float(self.__config[item2]): self._logger.warning( "Thermal %s has too high temperature : %s > %s" % (name, str(value), self.__config[item2])) return True def fetch(self): """ Fetch sysdebug information on a connected device """ self._retrieve_sysinfo() self.__merge_sys_debug_infos() def init(self): self._retrieve_sysinfo() self.__merge_sys_debug_infos() return True def stats(self, start, stop): """ Return representation of lss changes :type start: Integer :param start: The timestamp of the beginning of the measure :type stop: Integer :param stop: The timestamp of the end of the measure :rtype: etree.Element :return: The Xml tree vue of statistic results of the module """ SysDebug.stats(self, start, stop) xmltree = etree.Element("thermals") for name, value in self._sys_debug_infos.items(): thermal = etree.Element("thermal") thermal.attrib["name"] = name thermal.attrib["value"] = value xmltree.append(thermal) self._logger.debug("Thermal stats : %s" % str(self._sys_debug_infos)) return xmltree
class UseCaseBase(TestStepEngine): """ Base class for all use case implementation """ def __init__(self, tc_conf, global_config): """ Constructor """ TestStepEngine.__init__(self, tc_conf, global_config) # Get Device Instance self._device = DeviceManager().get_device("PHONE1") self._dut_config = DeviceManager().get_device_config("PHONE1") self._device.inject_device_log("i", "ACS_TESTCASE", "INIT: %s" % self._name) # Get a reference of equipment manager self._em = EquipmentManager() # Get IO card instance. Default value is 'IO_CARD' io_card_name = self._dut_config.get("IoCard", "IO_CARD") self._io_card = self._em.get_io_card(io_card_name) # Get Global TC Parameters self._wait_btwn_cmd = float(self._dut_config.get("waitBetweenCmd")) # UECmd type self._uecmd_types = UECmdTypes def _run_test_steps(self, path, optional_step=True): return TestStepEngine._run_test_steps(self, path, optional_step=True) def initialize(self): verdict, msg = TestStepEngine.initialize(self) self._device.inject_device_log("i", "ACS_TESTCASE", "INITIALIZE: %s" % self._name) return verdict, msg def set_up(self): """ Initialize the test """ verdict, msg = TestStepEngine.set_up(self) self._device.inject_device_log("i", "ACS_TESTCASE", "SETUP: %s" % self._name) return verdict, msg def run_test(self): """ Execute the test """ verdict, msg = TestStepEngine.run_test(self) self._device.inject_device_log("i", "ACS_TESTCASE", "RUNTEST: %s" % self._name) return verdict, msg def tear_down(self): """ End and dispose the test """ verdict, msg = TestStepEngine.tear_down(self) self._device.inject_device_log("i", "ACS_TESTCASE", "TEARDOWN: %s" % self._name) return verdict, msg def finalize(self): verdict, msg = TestStepEngine.finalize(self) self._device.inject_device_log("i", "ACS_TESTCASE", "FINALIZE: %s" % self._name) return verdict, msg
class LabWifiDirectBase(UseCaseBase): """ Lab Wifi Direct class. """ DEFAULT_REGULATORY_DOMAIN = "US" def __init__(self, tc_name, global_config): """ Constructor """ UseCaseBase.__init__(self, tc_name, global_config) self._device1_name = self._tc_parameters.get_param_value( "DEVICE1_NAME", "") self._device2_name = self._tc_parameters.get_param_value( "DEVICE2_NAME", "") # Get P2p interface name self._device1_p2pinterface = str(self._dut_config.get("p2pInterface")) self._device1_supplicant = None self._device1_client = None self._device1_mac = None self._device2_supplicant = None self._device2_client = None self._device2_mac = None self._phone2 = None self._networking2_api = None self._device2_p2pinterface = None if self._device2_name.startswith("PHONE"): self.dut_config2 = DeviceManager().get_device_config("PHONE2") self._device2_p2pinterface = str( self.dut_config2.get("p2pInterface")) # Get Device 2 Instance self._phone2 = DeviceManager().get_device(self._device2_name) self._networking2_api = self._phone2.get_uecmd("Networking") self._networking_api = self._device.get_uecmd("Networking") self._dut1_wlan_iface = str(self._dut_config.get("wlanInterface")) self._dut2_wlan_iface = str(self.dut_config2.get("wlanInterface")) def set_up(self): """ Initialize the test """ UseCaseBase.set_up(self) self.__check_tc_parameters() if self._phone2 is not None and not self._phone2.is_available(): DeviceManager().boot_device(self._device2_name) # set wifi On on the DUT to allow regulatory domain to change self._networking_api.set_wifi_power("on") if self._networking2_api is not None: self._networking2_api.set_wifi_power("on") # set the regulatory domain self._networking_api.set_regulatorydomain( LabWifiDirectBase.DEFAULT_REGULATORY_DOMAIN, self._dut1_wlan_iface) if self._networking2_api is not None: self._networking2_api.set_regulatorydomain( LabWifiDirectBase.DEFAULT_REGULATORY_DOMAIN, self._dut2_wlan_iface) # set wifi Off on the DUT self._networking_api.set_wifi_power("off") if self._networking2_api is not None: self._networking2_api.set_wifi_power("off") return Global.SUCCESS, "No error" #------------------------------------------------------------------------------ def _get_supplicant_instance(self, device_name): """ Get the p2p supplicant instance for the device :rtype: UECmd Object or Equipement Object :return: The p2p supplicant instance for the device """ device_instance = self.__get_device_instance(device_name) if device_name.startswith("PHONE"): return device_instance.get_uecmd("P2PSupplicantCLI") if device_name.startswith("COMPUTER"): return device_instance.get_p2p("P2pSupplicant") msg = "device not found " + device_name self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) def _get_client_instance(self, device_name): """ return the p2p client instance for the device """ device_instance = self.__get_device_instance(device_name) if device_name.startswith("PHONE"): return device_instance.get_uecmd("P2PClientCLI") if device_name.startswith("COMPUTER"): return device_instance.get_p2p("P2pClient") msg = "device not found " + device_name self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) def __get_device_instance(self, device_name): """ retrieve the device instance """ if device_name.startswith("COMPUTER"): return self._em if device_name == "PHONE1": return self._device if device_name.startswith("PHONE"): if not self._phone2.is_available(): DeviceManager().boot_device(device_name) return self._phone2 msg = "device not found " + device_name self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) def __check_tc_parameters(self): """ Checks all TC parameters """ if not self._device1_name: msg = "undefined device name 1." self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) if not self._device2_name: msg = "undefined device name 2." self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)