def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ TestStepBase.run(self, context) self._logger.info("CheckFPS: Run") file_to_check = self._pars.file_to_check fps_value = self._pars.fps_value margin = self._pars.margin # Detect the right column in the file cmd = "gawk \"BEGIN{FS=\\\" \\\"}; END{print NF}\" " + file_to_check try: (return_code, first_output) = internal_shell_exec(cmd, 5) except Exception as e: message = "Error while running gawk command: {0}.\n{1}".format( cmd, e.message) self._logger.warning(message) # The command to execute is version dependent. cmd = "gawk" if int(first_output) == 7: cmd += " " + "\"BEGIN{frames=0;} /postFramebuffer/{if (frames == 0) first = $5; frames += 1;timestamp = $5 } END{printf(\\\"%.3f\\\", (frames - 1) / (timestamp - first))}\"" elif int(first_output) == 8: cmd += " " + "\"BEGIN{frames=0;} /postFramebuffer/{if (frames == 0) first = $6; frames += 1;timestamp = $6 } END{printf(\\\"%.3f\\\", (frames - 1) / (timestamp - first))}\"" else: self._logger.warning("Unknown platform, authorized") return Global.FAILURE cmd += " " + file_to_check # Run gawk to compute FPS self._logger.info("Run command : " + ' '.join(cmd)) try: (return_code, output) = internal_shell_exec(cmd, 5) except Exception as e: message = "Error while running gawk command: {0}.\n{1}".format( cmd, e.message) output = message self._logger.warning(message) if return_code != Global.SUCCESS: return Global.FAILURE # check FPS min_fps = fps_value * (100 - margin) / 100 max_fps = fps_value * (100 + margin) / 100 if float(min_fps) <= float(output) <= float(max_fps): self._logger.info("CheckFPS OK with %f fps", float(output)) return Global.SUCCESS else: # CheckFPS is non blocking now self._logger.error("CheckFPS Value ot reach with %f fps", float(output)) return Global.SUCCESS
def bt_fota(self, mac_address, files_to_flash, timeout=300): """ Do a FOTA (Flash Over The Air) using Bluetooth. The FOTA is not donne directly by the host computer. Instead it is done by the BLE test app of the android device connected to the host computer An exception is raised if an error occurs during the FOTA process (i.e. if this method ends, the FOTA has been done correctly). :type mac_address: str :param mac_address: MAC address of the device on which the FOTA shall be done :type files_to_flash: list :param files_to_flash: list of files to flash with FOTA. NOt used for clark because files to flash are predefined :type timeout: int :param timeout: FOTA timeout value :return: None """ self._logger.info("Do FOTA on device {0} with files : {1}".format( mac_address, files_to_flash)) # Remove all potential previous files on the android device internal_shell_exec(cmd="adb shell rm /sdcard/Pictures/*", timeout=10, silent_mode=True) # Copy files to flash on android device for file_tmp in files_to_flash: self._logger.info("Treating {0}".format(file_tmp)) internal_shell_exec( cmd="adb push {0} /sdcard/Pictures/".format(file_tmp), timeout=10, silent_mode=True) # Launch FOTA using clark test app self._logger.info("Launch FOTA using clark test app") cmd = "-a com.acs.action.fota -e DEVICE_ADDRESS {0}".format( mac_address) if len(files_to_flash) > 1: cmd += " -e PARTITION all" self._logger.debug("Flash all partition") elif "sdbootreco" in files_to_flash[0]: cmd += " -e PARTITION sdbootreco" self._logger.debug("Flash sdbootreco only") elif "application" in files_to_flash[0]: cmd += " -e PARTITION application" self._logger.debug("Flash app only") else: cmd = "-a com.acs.action.fw_update -e DEVICE_ADDRESS {0}".format( mac_address) self._logger.debug( "Warning: unknwon partition to flash. Using fw_update intent instead of fota intent" ) self._internal_exec(cmd=cmd, timeout=timeout)
def run_test(self): """ Execute the test """ # Run UC base run_test UseCaseBase.run_test(self) # Initialize the return code and message of the test return_code = Global.FAILURE return_message = "An error occurred." for device in DeviceManager().get_all_devices(): device_name = device.whoami().get("device", "") if not device_name: error_msg = "Device name cannot be found from device instances!" raise AcsConfigException( AcsConfigException.INSTANTIATION_ERROR, error_msg) # Check current state of the phone and act accordingly # We expect the phone to be booted before going any further in our test if not device.is_available(): DeviceManager().boot_device(device_name) dut_serial_number = device.get_serial_number() # ADB disable-verity cmd_verity = "adb -s %s disable-verity" % dut_serial_number (_exit_status, output) = internal_shell_exec(cmd_verity, 10) if (_exit_status is Global.FAILURE): return_msg = "Command %s has failed" % cmd_verity raise DeviceException(DeviceException.OPERATION_FAILED, return_msg) # Restart the phone in MOS rebooted = device.reboot(transition_timeout=self._boot_timeout) if rebooted: cmd_remount = "adb -s %s remount" % dut_serial_number (_exit_status, output) = internal_shell_exec(cmd_remount, 5) # pylint: disable=W0212 if _exit_status is Global.FAILURE: return_code = Global.FAILURE return_message = "Remount failed" else: return_code = Global.SUCCESS return_message = "Board rebooted successfully." else: return_code = Global.FAILURE return_message = "An error occurred when rebooting the board." # Return the verdict and the message return return_code, return_message
def _start_acs_service(self): # Kill apk before to avoid concurrent access cmd = "adb shell am force-stop " + self._app_package internal_shell_exec(cmd=cmd, timeout=self._device.get_uecmd_timeout(), silent_mode=True) self._logger.debug("Starting AcsService ...") return internal_shell_exec( cmd=self._acs_service_command.format("start"), timeout=self._device.get_uecmd_timeout(), silent_mode=True)
def stop_adb_server(self): try: cmd_line = "adb kill-server" if self._logger: self._logger.debug("[ADB-SERVER] Stopping ADB server ...") status, status_msg = internal_shell_exec(cmd_line, 5) if status == Global.SUCCESS: self._adb_server_is_running = False else: if self._logger: self._logger.error( "[ADB-SERVER] Stopping failure (status: %s)" % str(status_msg)) if not self._adb_server_is_running: if self._logger: self._logger.debug("[ADB-SERVER] ADB server stopped") except Exception as error: # pylint: disable=W0703 if self._logger: self._logger.error( "[ADB-SERVER] Stopping failure; adb not found (cmd: %s, error: %s)" % (str(cmd_line), str(error))) raise
def run_test(self): """ Execute the CTS test Compute result based on CTS xml result output :rtype: tuple :return: ACS verdict and msg output """ LiveWifiBase.run_test(self) cts_results = {} result = Global.SUCCESS for test_cmd_line in self._test_cmd_lines.split(";"): test_cmd_line = "%s %s" % (self._cts_exec_path, test_cmd_line.strip()) result, output = internal_shell_exec(test_cmd_line, self._test_timeout) # pylint: disable=W0212 if result != Global.SUCCESS: return Global.FAILURE, output else: self._logger.debug("CTS - run_test completed") for root, _, filenames in os.walk(self._cts_path): for file_ in filenames: if CTS_RESULT_FILENAME in file_: cts_results = self._extract_cts_results_from_cts_report(os.path.join(root, file_), cts_results, publishInExternalReport=True) acs_cts_results = os.path.join(self._device.get_report_tree().get_report_path(), "cts_results") if not os.path.exists(acs_cts_results): os.makedirs(acs_cts_results) self._logger.info("Move CTS results into ACS result dir") shutil.move(root, acs_cts_results) result, output = self._compute_cts_results(cts_results) return result, output
def run_test(self): """ Execute the gfx tests """ UseCaseBase.run_test(self) crt_dir = os.getcwd() test_dir = os.path.dirname(self._gfx_fwk_test) test_file = os.path.basename(self._gfx_fwk_test) result = Global.FAILURE # Execute GFX test framework os.chdir(test_dir) cmd = "%s %s %s" % (sys.executable, test_file, self._cmd_params) # GFX framework always ends with a success return code result, output = internal_shell_exec(cmd, self._timeout) os.chdir(crt_dir) # so, parse the output to compute a results ... result, output = self.extract_results(output) self._device.get_logger().info("Move GFX results into ACS result, as zipfile %s" % (os.path.basename(self.acs_gfx_results))) if not os.path.isdir(self.original_results_gfx_location): self._device.get_logger().warning( "%s directory does not exist, cannot copy GFX results" % (self.original_results_gfx_location,)) else: # zip results self.zip_results() return result, output
def __run_command(self, command): """ Runs the given I{shell} command on the I{DUT} and raises an exception if the exit status indicates an error. :param command: the command to run :type command: str :raise AcsBaseException: if the exit status of the command indicates an error :rtype: str :return: the command output """ exit_status = Global.FAILURE try: # We have no choice but call a protected method # so we disable the corresponding Pylint warning. # pylint: disable=W0212 cmd = self.__device.format_cmd(command) (exit_status, output) = internal_shell_exec( cmd, int(self.__command_timeout)) # We want to trap any kind of error/exception so # we use an empty exception clause and disable the # corresponding Pylint warning. # pylint: disable=W0702 except: exit_status = Global.FAILURE traceback.print_exc() if exit_status != Global.SUCCESS: raise DeviceException(DeviceException.OPERATION_FAILED, "Command execution failed (command: '%s')." % command) return output
def stop_at_proxy_from_pos(self): """ Stops the I{AT proxy} tool on the device. We assume that the device is booted in I{POS} mode when this method is called. :rtype: None :raise DeviceException: if the command failed. """ # Inform user that the next command will fail # but that is what we expect. self._logger.info( "The command that stops AT proxy always fail. The coming error is expected." ) # Run Intel's OEM hooks to flash the modem's NVM _exec_status, stdout = internal_shell_exec("fastboot oem proxy stop", 30) # pylint: disable=W0212 # We expect a failure but let's check the # output content just to make sure that the # error is actually the one we expect. expected_error = "FAILED (status read failed (No such device))" if stdout.find(expected_error) == -1: message = "Unexpected failure cause when starting AT proxy: %s" % \ stdout self._logger.error(message) raise DeviceException(DeviceException.INTERNAL_EXEC_ERROR, message)
def _check_flash_tool_availability(self): """ Check if Dediprog Flash Tool is installed over current ACS bench :rtype: str :return: string containing flash tool name to use for flash execution """ cmd_name = "" # Check the dediprog flash tool installation over ACS bench if platform.system() == "Windows": cmd_name = "dpcmd" else: cmd_name = "flashrom" flash_tool_cmd_path = CommandLine.which(cmd_name) if flash_tool_cmd_path is None: error_msg = "DEDIPROG: Check if DEDIPROG is installed on ACS bench (Command %s not found !)" % cmd_name if platform.system() == "Windows": error_msg += " - Check also if DEDIPROG folder is referenced on ACS bench in PATH environment variable" self._logger.error(error_msg) raise AcsConfigException(AcsConfigException.EXTERNAL_LIBRARY_ERROR, error_msg) else: # DEDIPROG software is installed try: # Try to launch DEDIPROG flash tool # Analyze for LINUX and WINDOWS, return code to see if DEDIPROG flash tool is launchable if platform.system() == "Windows": cmd = cmd_name + " -d" else: cmd = cmd_name + " --version" return_code, return_message = internal_shell_exec( cmd, 1, silent_mode=True) except Exception as ex: err_msg = "DEDIPROG: Flash tool (%s) execution issue over ACS bench - error: %s" % ( cmd, str(ex)) self._logger.error(err_msg) raise AcsConfigException( AcsConfigException.EXTERNAL_LIBRARY_ERROR, err_msg) if return_code == 0: # DEDIPROG flash tool is installed and available # Print the flash tool version self._logger.info( "DEDIPROG: Flash tool is installed and running over ACS bench - version : %s" % str(return_message)) else: # DEDIPROG flash tool issue when launching it err_msg = "DEDIPROG: Flash tool (command= %s) execution issue over ACS bench - " % (cmd) + \ " - error: %s" % (str(return_message)) self._logger.error(err_msg) raise AcsConfigException( AcsConfigException.EXTERNAL_LIBRARY_ERROR, err_msg) return cmd_name
def _execute_at_command(self, at_command): """ Executes the given at_command. :type at_command: str :param at_command: the AT command to execute :rtype: tuple :return: the verdict and the message in a tuple """ # Check parameter if not at_command: return (Global.FAILURE, "Invalid input parameter") self._logger.debug("Sending AT command: %s " % str(at_command)) # Escape quotes in AT command at_command = at_command.replace('\"', '\\"') # Build the adb command adb_command = "adb -s %s shell %s %s %s \"%s\"" % ( self._device.get_serial_number(), "teltbox", "mdm_acm", "/dev/gsmtty20", at_command) # Execute the AT command (status, output) = internal_shell_exec(adb_command, 5) # pylint: disable=W0212 # Check the command output if "-ERROR-" in output: message = "Error during AT command execution: %s" % output raise AcsToolException( AcsToolException.OPERATION_FAILED, message) #Sleep arbitrary time time.sleep(1) # Return a status and a message return (status, output)
def flash_fw(self, fw_flash_file_path, flash_timeout, flash_app_path): """ Flashes the device modem's firmware when in I{MOS} (Main OS) mode. :param fw_flash_file_path: the path to the flash file :type fw_flash_file_path: str :param flashing_app_path: the absolute path the the flashing application. :type flashing_app_path: str :param flash_timeout: the flash timeout :type flash_timeout: int :rtype: list :return: operation status & output log & stdout & stderr """ # Flash the modem command = "adb shell %s -f %s" % (str(flash_app_path), str(fw_flash_file_path)) exec_status, stdout = internal_shell_exec(command, flash_timeout) # pylint: disable=W0212 # Check whether previous step completed successfully if exec_status == Global.FAILURE: message = "Could not flash modem's firmware: %s" % stdout self._logger.error("%s" % message) raise DeviceException(DeviceException.INTERNAL_EXEC_ERROR, message) # Return the result # When using _internal_shell_exec_command the stderr # is concatenated to sdtout. We simply return stdout. return exec_status, stdout
def _delete_file_if_exists(self, file_path, fail_on_error=True): """ Deletes the given file on DUT if it exists. :type file_path: str :param file_path: the absolute path of the file to delete. :type fail_on_error: bool :param fail_on_error: [optional] a boolean indicating whether we want to raise an exception on error or not. Defaults to C{True}. """ # Force file path to a str value file_path = str(file_path) rm_cmd = "adb shell rm %s" % file_path # We go on only if the file exists on the DUT if not self._phone_system_api.check_file_exist_from_shell(file_path): self._logger.debug("No such file to delete.") return # We try to delete the file try: # Run the command to remove the file, we give it 10 seconds to run self._logger.debug("Deleting file %s." % file_path) (exit_status, _output) = internal_shell_exec(rm_cmd, 10) except (KeyboardInterrupt, SystemExit): raise # We want to trap any kind of error/exception so # we use an empty exception clause and disable the # corresponding Pylint warning. # pylint: disable=W0702 except: exit_status = Global.FAILURE traceback.print_exc() # Check the status of the command execution if exit_status != Global.SUCCESS: # Build an error message error_message = "Command execution failed (command: '%s')." % rm_cmd # Handle the error case as expected if fail_on_error: # If we have to fail, raise an exception raise DeviceException(DeviceException.OPERATION_FAILED, error_message) else: # Otherwise simply log a warning self._logger.warning(error_message) # We double-check that the file has been deleted if self._phone_system_api.check_file_exist_from_shell(file_path): # Build an error message error_message = "File deletion failed (file: '%s')." % file_path # Handle the error case as expected if fail_on_error: # If we have to fail, raise an exception raise DeviceException(DeviceException.OPERATION_FAILED, error_message) else: # Otherwise simply log a warning self._logger.warning(error_message) else: self._logger.info("File %s deleted successfully." % file_path)
def flash_nvm_pos(self, nvm_config_file_path, target_directory): """ Flashes the device modem's I{NVM} when in I{POS} (Provisioning OS) mode. In order to flash the modem's {NVM} we need to provide a raw text file containing the commands to send. :param nvm_config_file_path: the path to the raw text file :type nvm_config_file_path: str :param target_directory: the absolute path to the temporary directory where the flash file will be uploaded before the flash operation. :type target_directory: str :rtype: tuple :return: operation status & output log & stdout & stderr """ # Compute the file to the NVM config file on the device file_name = os.path.basename(nvm_config_file_path) target_file_path = "%s/%s" % (target_directory, file_name) # Push the configuration file to the target # (adb not available in POS) # pylint: disable=W0212 exec_status, output = internal_shell_exec( "fastboot flash %s %s" % (target_file_path, nvm_config_file_path), 10) # pylint: enable=W0212 # Check whether previous step completed successfully if exec_status != NvmFastbootResult.NVM_ERR_SUCESS: message = "Could not push configuration file to target: %s" % output self._logger.error("%s" % message) raise DeviceException(DeviceException.INTERNAL_EXEC_ERROR, message) # Run Intel's OEM hooks to flash the modem's NVM exec_status, stdout = internal_shell_exec("fastboot oem nvm apply %s" % target_file_path, 30) # pylint: disable=W0212 # Return the result # When using _internal_shell_exec_command the stderr # is concatenated to sdtout. We simply return stdout. return exec_status, stdout
def set_up(self): """ Initialize the test """ # Run inherited set_up method LabModemNvmReadbackBase.set_up(self) # Check that the phone is in POS # Check the state of the phone as returned by adb # We do not want to use the 'get_state' method # of the device as it adds some post processing # on the state value (_exit_status, output) = internal_shell_exec("adb get-state", 5) # pylint: disable=W0212 state = output.strip() self._logger.debug("Initial phone state '%s'" % state) if state not in ("device", "alive"): message = "Unexpected phone state: %s. expected 'device' or 'alive'." % state self._logger.error(message) raise DeviceException(DeviceException.PROHIBITIVE_BEHAVIOR, message) # Start AT proxy in tunneling mode self._logger.debug("Starting AT proxy") try: self._at_proxy_tty = self._modem_flashing_api.start_at_proxy_from_mos( ModemFlashing.AT_PROXY_TUNNELING_MODE) except AcsBaseException as ex: message = ex.get_error_message() error_code = ex.get_error_code() self._logger.error(message) return error_code, message # Open the tty to talk to the modem time.sleep(20) self._logger.debug("Opening serial port to %s" % self._at_proxy_tty) self._at_proxy_serial = serial.Serial( port=self._at_proxy_tty, baudrate=self._at_proxy_baud_rate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1) self._at_proxy_serial.open() # Check that the modem is available time.sleep(10) modem_available = self._modem_flashing_api.ping_modem_from_serial( self._at_proxy_serial) if not modem_available: return Global.FAILURE, "Failed to contact the modem." # Return the status return Global.SUCCESS, "No error."
def _exec(self, cmd, timeout=None, force_execution=False, wait_for_response=True): """ Internal method that execute std command on device :type cmd: str :param cmd: cmd to be executed :type timeout: integer :param timeout: Script execution timeout in ms :type force_execution: Boolean :param force_execution: Force execution of command without check phone connected (dangerous) :type wait_for_response: Boolean :param wait_for_response: Wait response from adb before statuing on command :return: output str :rtype: string """ silent_mode = False if timeout is None: timeout = self._uecmd_default_timeout # (result, output) = self._device.run_cmd(cmd, timeout, force_execution, wait_for_response) if wait_for_response: return_code, output = internal_shell_exec(cmd=cmd, timeout=timeout, silent_mode=silent_mode) else: # Async operation is going to be started, we cannot provide a return_code # Return SUCCESS by default return_code = Global.SUCCESS output = "" run_local_command(args=cmd, get_stdout=not silent_mode) if return_code == Global.SUCCESS: if output is not None: return output else: raise DeviceException(DeviceException.PHONE_OUTPUT_ERROR, "\"" + cmd + "\" returned null output !") else: raise DeviceException(DeviceException.PHONE_OUTPUT_ERROR, output)
def test_power_gating2(self, time_to_sleep, what_to_read, cmd_to_run, timeout): f_stdout = tempfile.TemporaryFile() self.power_states_api.clear_mid_pmu_states() cmd = [] message = "" cmd = str(cmd_to_run).split() proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) state_dic = defaultdict(list) # time.sleep(10) self._logger.debug("PROC IS %s" % proc.poll()) while (proc.poll() is None and timeout > 0): t0 = time.time() verdict, mid_pmu_states = internal_shell_exec( ["adb", "shell", "cat", "/d/mid_pmu_states"], 100) if not verdict == Global.SUCCESS: return Global.BLOCKED, "Did not receive mid_pmu_states back from device" for driver_entry in DriverStates[what_to_read]: state, D0_count, D0_residency = self.get_readings_from_given_mid_pmu_states2( driver_entry, mid_pmu_states) self._logger.debug("State: %s D0_count: %s D0_res %s" % (state, D0_count, D0_residency)) self.process_readings(state, D0_count, D0_residency, state_dic, message, driver_entry) if state_dic is None: return Global.BLOCKED, message t1 = time.time() timeout -= (t1 - t0) power_gating = True result_out = "" self._logger.debug(f_stdout.read()) for driver_entry in DriverStates[what_to_read]: if int(state_dic[driver_entry][3]) > 0: result_out = result_out + "%s power gated %d times\n" % ( driver_entry, int(state_dic[driver_entry][3])) self._logger.debug(result_out) else: power_gating = False result_out = result_out + "%s power gated %d times\n" % ( driver_entry, int(state_dic[driver_entry][3])) self._logger.debug(result_out) if power_gating is False: self._logger.debug(result_out) return Global.FAILURE, result_out else: self._logger.debug(result_out) return Global.SUCCESS, result_out
def change_at_proxy_property_value(self, mode=1): """ Change the at proxy property value and check the result Possible modes: 1 Normal Mode ; 2 Tunneling Mode We assume that the device is booted in I{MOS} mode when this method is called. @type mode: int @param mode: the at proxy mode (normal or tunneling). Defaults to 1 (normal). @rtype: None @raise DeviceException: if the command failed. """ # Change the AT proxy property value command = "adb -s %s shell setprop %s %s" % ( self._serial_number, ModemFlashing.AT_PROXY_PROPERTY_NAME, str(mode)) internal_shell_exec(command, 5) # pylint: disable=W0212 # ADB shell always exits with 0, # so we check the AT proxy property value # to make sure our command succeeded. time.sleep(10) property_value = self._device.get_property_value( ModemFlashing.AT_PROXY_PROPERTY_NAME) property_value = str(property_value) if property_value != str(mode): message = "Property value %s was not changed. Expected %s, got %s." % ( ModemFlashing.AT_PROXY_PROPERTY_NAME, str(mode), property_value) raise DeviceException(DeviceException.OPERATION_FAILED, message) else: return
def force_dut_ssh_key_generation(self, ip_address, timeout=10): """ Clean user known host file. (Linux benches) To ensure better compatibility in case of StrictHostKeyChecking=yes on PC. And avoid ssh connection aborting after a flash (server keys should change) """ if 'posix' in sys.builtin_module_names: cmd = "ssh-keyscan -T {0} {1}".format(timeout, ip_address) status, value = internal_shell_exec(cmd=cmd, timeout=5, silent_mode=False) if status == Global.SUCCESS: self._logger.warning("ssh-keyscan successfully returned.") else: self._logger.debug("Not a linux bench")
def get_mode_duration(self, mode): """ Get the duration passed in the given mode (up time, idle time, ...) since device startup :type mode: str :param mode: mode we want to retrieve the duration. Accepted value: - up (for time) - idle (for idle time) - sleep (for deep sleep :rtype: int :return: time (in seconds) passed in the given mode. """ allowed_mode = ["up", "idle", "sleep"] self._logger.debug( "get_mode_duration: mode to treat {0}.".format(mode)) if mode not in allowed_mode: msg = "get_mode_duration : invalid mode {0}. Allowed values: {1}".format( mode, allowed_mode) self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) # Extract state duration from uptime command result and converts it into an operation evaluable # by python (uptime result in human readable format: hh:mm:ss) cmd_extract = "adb shell uptime | sed -e 's/.*{0} time:[^:]*\(..\):\(..\):\(..\).*$/\\1*3600+\\2*60+\\3/' |"\ .format(mode) cmd_extract += "sed 's/+0/+/g'" self._logger.debug( "get_mode_duration: extraction command: {0}".format(cmd_extract)) verdict, str_time = internal_shell_exec(cmd_extract, timeout=60, silent_mode=True) if verdict == Global.FAILURE: raise DeviceException( DeviceException.OPERATION_FAILED, "get_mode_duration: unable to run extraction command") # Evaluate generated operation to get the duration in seconds instead of human readable format self._logger.debug( "get_mode_duration: string to eval: {0}".format(str_time)) duration_result = eval(str_time) self._logger.info("get_mode_duration: mode: {0}, duration: {1}".format( mode, duration_result)) return duration_result
def set_up(self): """ Initialize the test """ # Run inherited set_up method LabModemNvmReadbackBase.set_up(self) # Check that the phone is in POS # Check the state of the phone as returned by adb # We do not want to use the 'get_state' method # of the device as it adds some post processing # on the state value (_exit_status, output) = internal_shell_exec("adb get-state", 5) # pylint: disable=W0212 state = output.strip() self._logger.debug("Initial phone state '%s'" % state) if state not in ("bootloader", "unknown"): message = "Unexpected phone state: %s. expected 'bootloader' or 'unknown'." % state self._logger.error(message) return Global.FAILURE, message # Start AT proxy in tunneling mode self._logger.debug("Starting AT proxy") try: self._at_proxy_tty = self._modem_flashing_api.start_at_proxy_from_pos() except AcsBaseException as ex: message = ex.get_error_message() error_code = ex.get_errorcode() self._logger.error(message) return error_code, message # Open the tty to talk to the modem self._logger.debug("Opening serial port to %s" % self._at_proxy_tty) self._at_proxy_serial = serial.Serial( port=self._at_proxy_tty, baudrate=self._at_proxy_baud_rate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1) self._at_proxy_serial.open() # Return the status return Global.SUCCESS, "No error."
def adb_start(self, timeout=10): """Start adb server """ self.__lock.acquire() cmd_line = "adb start-server" self._adb_server_is_running = False try: # WA to integrate the patch until all server are killed # self._adb_host_port = self.get_adb_server_port(port=self._adb_host_port, # retry=5) os.environ["ANDROID_ADB_SERVER_PORT"] = str(self._adb_host_port) self.stop_adb_server() if self._logger: self._logger.debug( "[ADB-SERVER] Starting ADB server on {0}...".format( self._adb_host_port)) # below sleep time gives some time for adb to respond after # "stop_adb_server()" time.sleep(1) status, status_msg = internal_shell_exec(cmd_line, timeout) if status == Global.SUCCESS: self._adb_server_is_running = True if self._logger: self._logger.debug("[ADB-SERVER] ADB server started") else: if self._logger: self._logger.error( "[ADB-SERVER] Starting failure (status: %s)" % str(status_msg)) except Exception as error: # pylint: disable=W0703 if self._logger: self._logger.error( "[ADB-SERVER] Starting failure; adb not found (cmd: %s, error: %s)" % (str(cmd_line), str(error))) raise finally: self.__lock.release()
def clean_user_known_host_file(self, ip_address): """ Clean user known host file. (Linux benches) To ensure better compatibility in case of StrictHostKeyChecking=yes on PC. And avoid ssh connection aborting after a flash (server keys should change) """ if 'posix' in sys.builtin_module_names: self._logger.warning( "Clean user know_host file to ensure better ssh compatibility") known_host_file = path.expanduser("~/.ssh/known_hosts") cmd = "ssh-keygen -f {0} -R {1}".format(known_host_file, ip_address) status, value = internal_shell_exec(cmd=cmd, timeout=5, silent_mode=False) if status == Global.SUCCESS: self._logger.warning("known_host clean done.") else: self._logger.debug( "Not a linux bench, no known_hosts file to clean")
def _run_crashtooluploader_cmd(self, cmd): """ Run sync cmd line of CrashToolUploader :return: """ if self._device_serial_number != "not_set": cmd = "{0}{1} {2}".format(cmd, self.SSN_OPTION, self._device_serial_number) try: # Timeout is high here because sometimes, we need to upload a modem panic event + BP log (~600MB) result, output = internal_shell_exec( cmd, 900, log_stdout=False, silent_mode=(not self._debug_mode)) except Exception as e: message = "Error while running CrashToolUploader command: {0}.\n{1}".format( cmd, e) result = Global.FAILURE output = message self.logger.warning(message) return result, output
def _parse_application_data(self): """ Parse application data package to collect information on the application """ if self._path.endswith(self._app_ext): # TODO: if aapt is missing ,this should be clearly indicated aapt_cmd_str = "aapt dump badging \"{0}\"".format(self._path) if os.name in ['posix']: aapt_cmd_str = "./{0}".format(aapt_cmd_str) # remove the silent mode to log the error reasons status, status_msg = internal_shell_exec(aapt_cmd_str, self._default_timeout, log_stdout=False, silent_mode=False) if status == Global.SUCCESS: if status_msg: self._extract_application_data(status_msg) else: self._log("aapt command failed: {0}".format(status_msg)) else: self._log("Android application extensions should be .apk")
def run_test(self): """ Execute the test """ # Run UC base run_test UseCaseBase.run_test(self) # Initialize the return code and message of the test return_code = Global.FAILURE return_message = "An error occurred." # Check the state of the phone as returned by adb # We do not want to use the 'get_state' method # of the device as it adds some post processing # on the state value (_exit_status, output) = internal_shell_exec("adb get-state", 5) # pylint: disable=W0212 state = output.strip() self._logger.debug("Initial phone state '%s'" % state) if state not in ("unknown", "bootloader"): message = "Unexpected phone state: %s. expected 'unknown' or 'bootloader'." % state self._logger.error(message) raise DeviceException(DeviceException.PROHIBITIVE_BEHAVIOR, message) # Restart the phone in MOS rebooted = self._device.reboot(mode="MOS", transition_timeout=self._boot_timeout) if rebooted: return_code = Global.SUCCESS return_message = "Board rebooted successfully." else: return_code = Global.FAILURE return_message = "An error occurred when rebooting the board." # Return the verdict and the message return return_code, return_message
def take_power_gate_reading(self, what_to_read): self._logger.debug("Looking for: %s" % what_to_read) verdict, grep_output = internal_shell_exec([ "adb", "shell", "cat", "/d/mid_pmu_states", "|", "grep", what_to_read ], 100) if not verdict == Global.SUCCESS: return None, None, None for line in grep_output.split("\n"): self._logger.debug("Line %s:" % line) line_array = line.split() self._logger.debug(len(line_array)) if len(line_array) == 11: return line_array[7], line_array[8], line_array[9] elif len(line_array) == 10: return line_array[6], line_array[7], line_array[8] elif len(line_array) == 9: return line_array[8], None, None elif len(line_array) == 6: return line_array[2], line_array[3], line_array[4] elif len(line_array) == 3: return line_array[2], None, None
def bool_power_gating2(self, timeout, what_to_read, stimulated=True): start_time = time.time() end_time = start_time + timeout state_dic = defaultdict(list) power_gating = True message = "" while start_time < end_time: verdict, mid_pmu_states = internal_shell_exec( ["adb", "shell", "cat", "/d/mid_pmu_states"], 100) if not verdict == Global.SUCCESS: return None, "Could not find mid_pmu_states" for driver_entry in DriverStates[what_to_read]: state, D0_count, D0_residency = self.get_readings_from_given_mid_pmu_states2( driver_entry, mid_pmu_states) self._logger.debug("State: %s D0_count: %s D0_res %s" % (state, D0_count, D0_residency)) self.process_readings(state, D0_count, D0_residency, state_dic, message, driver_entry) if state_dic is None: return Global.BLOCKED, message time.sleep(10.00) start_time = time.time() result_out = "" for driver_entry in DriverStates[what_to_read]: if stimulated and state_dic[driver_entry][3] > 0: result_out = result_out + "%s power gated %d times\n" % ( driver_entry, int(state_dic[driver_entry][3])) elif not stimulated and state_dic[driver_entry][3] < 20: result_out = result_out + "%s power gated %d times\n" % ( driver_entry, int(state_dic[driver_entry][3])) else: power_gating = False result_out = result_out + "%s power gated %d times\n" % ( driver_entry, int(state_dic[driver_entry][3])) return power_gating, result_out
def adb_ethernet_stop(self, ip_address, port, timeout=10): """ Stop adb server and disconnect from adbd """ is_disconnected = False if self._logger: self._logger.debug( "[ADB-SERVER] stopping and disconnecting over ETHERNET (IP: %s, Port: %s)..." % (ip_address, port)) try: cmd_line = "adb disconnect %s:%s" % (ip_address, port) status, return_msg = internal_shell_exec(cmd_line, timeout) if status == Global.SUCCESS: if return_msg.startswith("") or return_msg.startswith( "No such"): msg = "[ADB-SERVER] stopped and disconnected from DUT (%s)" % return_msg is_disconnected = True else: msg = "[ADB-SERVER] stopped but connection to DUT status is unknown (%s)" % return_msg else: msg = "[ADB-SERVER] Stop failure (status: %s)" % str( return_msg) if self._logger: self._logger.debug(msg) except Exception as error: # pylint: disable=W0703 if self._logger: self._logger.debug( "[ADB-SERVER] fail to stop over ETHERNET (%s)" % str(error)) return is_disconnected
def _run_fastboot_cmds(self): android_dir = str(os.environ['ANDROID_PRODUCT_OUT']) self._logger.info( "Waiting for the device to Power On and stabilize for 100 seconds") time.sleep(100) timeout = 10 command = "adb connect " + self._serial self._logger.info(command) return_code, output = internal_shell_exec(command, timeout) if return_code == Global.SUCCESS: try: tree = etree.parse(self._flash_file) for df in tree.xpath('//file'): conf_type = df.attrib['TYPE'] sf = df.getchildren() if conf_type == "FASTBOOT": fastboot_file = sf[0].text print(conf_type + "::" + fastboot_file) elif conf_type == "KERNEL": kernel_file = sf[0].text print(conf_type + "::" + kernel_file) elif conf_type == "RECOVERY": recovery_file = sf[0].text print(conf_type + "::" + recovery_file) elif conf_type == "SYSTEM": system_file = sf[0].text print(conf_type + "::" + system_file) except Exception as ex: return_code = Global.FAILURE self.error_message = "FastbootTool: Error in parsing xml %s" % str( ex) else: self.error_message = "FastbootTool: ADB connect has failed" % str( output) if return_code == Global.SUCCESS: # assume that device is now in POS, so we can release the pos line if self._flash_tool_state == "FLASH_MODE_START": # Deactivate provisionning line as PFT start the flashing. if self._switch_device_state_fct( "POS_MODE_OFF") == Global.SUCCESS: self._flash_tool_state = "FLASH_MODE" else: return_code = Global.FAILURE self._flash_tool_state = "UNKNOW" self.error_message = "FastbootTool: Issue can not disable provisionning line on the device" if self._flash_tool_state == "FLASH_MODE": command = "fastboot devices" timeout = 2 return_code, output = internal_shell_exec(command, timeout) if return_code == Global.SUCCESS: for df in tree.xpath('//command'): sf = df.getchildren() command = df.find('string').text timeout = df.find('timeout').text flash_time = int(timeout) if command.find("$fastboot_file") > -1: command = command.replace( "$fastboot_file", android_dir + "/" + fastboot_file) elif command.find("$recovery_file") > -1: command = command.replace( "$recovery_file", android_dir + "/" + recovery_file) elif command.find("$system_file") > -1: command = command.replace( "$system_file", android_dir + "/" + system_file) elif command.find("$kernel_file") > -1: command = command.replace( "$kernel_file", android_dir + "/" + kernel_file) else: print command command = command.replace( "fastboot", "fastboot -t " + self._pos_serial, 1) if command.find("system") > -1: return_code, output = internal_shell_exec( command, flash_time) else: return_code, output = internal_shell_exec( command, flash_time) if return_code != Global.SUCCESS: self.error_message = "Fastboot flash commands fail" % str( output) else: self.error_message = "Fastboot devices has failed" % str( output) else: self.error_message = "FastbootTool: unable to switch to flash mode" return return_code