def pid_of(self, process_name): """ Get the pid of a process by its name. :rtype: str :return: the pid of the process or empty str if process as not been found. """ cmd = "pidof " + str(process_name) cmd = self._internal_exec(cmd) self._logger.info("Getting the pid of the process with name: %s" % process_name) (_result, pid) = Util.internal_shell_exec(cmd, 10) if not pid.isdigit() and not pid == "": raise DeviceException(DeviceException.INTERNAL_EXEC_ERROR, "The pid should be a int. Is: %s" % str(pid)) self._logger.debug("PID of %s is: %s" % (process_name, pid)) return pid
def run_cts(self): ''' This function will deal with running CTS ''' current_time = time.time() test_cmd_line = "%s %s" % (self._cts_exec_path, self._test_cmd_lines) result, output = Utils.internal_shell_exec(test_cmd_line, self._test_timeout) if result != Global.SUCCESS: return Global.FAILURE for root, _, filenames in os.walk(self._cts_path): for file_ in filenames: if CTS_RESULT_FILENAME in file_: cts_results = os.path.join(root, file_) left_time = time.time() - current_time self._test_timeout = self._test_timeout - left_time xml_file = open(cts_results, 'r') xml_cont = xml_file.read() xml_file.close() if 'result="notExecuted"' in xml_cont: if self._test_timeout > 0: self._test_cmd_lines = CTS_CONTINUE_SESSION_COMMAND self._logger.debug("CTS - Not Executed retry") self.run_cts() elif 'result="fail"' in xml_cont: if self._test_timeout > 600 and self._test_failed_retry_no > 0: self._test_failed_retry_no -= 1 x_res = os.path.join( os.path.dirname(cts_results), 'backup_cts_res_' + str(self._test_failed_retry_no)) shutil.copyfile(cts_results, x_res) xml_cont = xml_cont.replace('result="fail"', \ 'result="notExecuted"') xml_file = open(cts_results, 'w') xml_file.write(xml_cont) xml_file.close() #self.motc_library.reboot_device() self._test_cmd_lines = CTS_CONTINUE_SESSION_COMMAND self._logger.debug("CTS - Failed retry:%s" % self._test_failed_retry_no) self.run_cts()