def get(self, file_path=None): if file_path is None: return None if self._remote: local_path = None md5_str = self._get_remote_md5(file_path) old_path, local_path = self._cache.fetch(file_path, md5_str) if local_path: LOG.debug('%s is found in local cache !' % file_path) return local_path LOG.debug('start to download %s from artifactory !' % file_path) local_path = join(ARTI_LOCAL_REPO, gen_short(file_path)) if not exists(local_path): os.mkdir(local_path) local_path_file = join(local_path, basename(file_path)) if old_path is not None: old_path_file = join(old_path, basename(file_path)) if _download_file(self.__makeUrl(file_path), local_path_file): LOG.debug('complete to download %s !' % file_path) if md5_str and _checksum_md5(local_path_file) != md5_str: LOG.debug('check MD5 value failed on file: %s !' % file_path) shell_command('rm -rf %s' % local_path) return None self._cache.refresh(file_path, local_path_file) if old_path is not None: shell_command('ln -sf %s %s' % (local_path_file, old_path_file)) return local_path_file else: LOG.debug('failed to download %s!' % file_path) return None else: return self.__makeUrl(file_path)
def _adb_reboot_fastboot(self): adbcmdstr = "adb reboot fastboot" LOG.debug('Execute adb reboot fastboot') ret, _ = shell_command(adbcmdstr) fastbootcmdstr = "fastboot wait-for-device" LOG.debug('Waiting for device online') ret, _ = shell_command(fastbootcmdstr, timeout_second=90) return ret
def check_package_download(self): art_package_root = os.path.join(self.dirname, self.art_package) if not os.path.exists(art_package_root): from testlib.util.repo import Artifactory arti_obj = Artifactory("https://mcg-depot.intel.com/artifactory/acs_test_artifacts/OTC_Android_Auto_Test_Suite/resources") ret_file = arti_obj.get("ART/%s" % self.art_package_zip) cmd = "unzip -q %s -d %s" % (ret_file, self.dirname) print cmd shell_command(cmd, 180) assert os.path.exists(art_package_root), "Download ART package failed!"
def reboot_device(self): """ android root on """ adbcmdstr = self.adb_prefix + "reboot" LOG.debug('Execute adb reboot') ret, _ = shell_command(adbcmdstr) adbcmdstr = self.adb_prefix + "wait-for-device" LOG.debug('Waiting for device online') ret, _ = shell_command(adbcmdstr, timeout_second=90) return ret
def check_if_wifi_connected(self): _cmd = "adb shell dumpsys connectivity | grep 'CONNECTED/CONNECTED'" n = 3 try: while shell_command(_cmd)[0] and n > 0: self.func.connect_AP(self.ssid, self.passwd, self.security) n = n - 1 time.sleep(10) except: print "WiFi reconnection ERROR!" assert not shell_command(_cmd)[0], "WiFi is not connected!"
def _remount_result(self): # return exit code, 0 for succeed, 1 for error g_common_obj.root_on_device() time.sleep(3) LOG.debug('Execute adb remount') ret = [i.strip() for i in shell_command('adb remount')[1]] LOG.debug('Got remount result: %s' % ret) return ret
def run_art(self, test_case, timeout_second = 3 * 3600): self.check_package_download() script_path = os.path.join(self.dirname, "common_run.sh") cmd = "%s %s %s | grep PASSED" % (script_path, self.art_package, test_case) print cmd exit_code_int, result_array = shell_command(cmd, timeout_second) #print exit_code_int, result_array[0] assert exit_code_int == 0 assert result_array
def root_on_device(self): """ android root on """ adbcmdstr = self.adb_prefix + "root" LOG.debug('Execute adb root on') ret, _ = shell_command(adbcmdstr) time.sleep(5) return ret
def root_off_device(self): """ android root off """ adbcmdstr = self.adb_prefix + "root off" LOG.debug('adb root off') ret, _ = shell_command(adbcmdstr) time.sleep(3) return ret
def detect_device(self, model): re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) result = g_common_obj.adb_cmd_common('devices') devices = re_device.findall(result) for serial in sorted(devices): _cmd = "adb -s %s shell getprop ro.product.model" % (serial) msgs = shell_command(_cmd)[1] ret = ''.join(msgs).strip('\r\n') if ret == model: return serial assert False, 'There is no %s device' % model
def fastboot_flash_vbmeta(self, vbmeta_img=""): if "vbmeta_disable_verity.img" not in vbmeta_img: return False else: fastbootcmdstr = "fastboot flashing unlock" LOG.debug('Execute fastboot flashing unlock') ret, _ = shell_command(fastbootcmdstr) fastbootcmdstr = "fastboot flash vbmeta %s" % vbmeta_img LOG.debug('Execute fastboot flash vbmeta') ret, _ = shell_command(fastbootcmdstr) fastbootcmdstr = "fastboot flashing lock" LOG.debug('Execute fastboot flashing lock') ret, _ = shell_command(fastbootcmdstr) fastbootcmdstr = "fastboot reboot" LOG.debug('Execute fastboot reboot') ret, _ = shell_command(fastbootcmdstr) adbcmdstr = "adb wait-for-device" LOG.debug('Waiting for device online') ret, _ = shell_command(adbcmdstr, timeout_second=90) return ret
def push_file(self, local_path, remote_path): """upload file to device""" adbcmdstr = "%s push %s %s" % (self.adb_prefix, local_path, remote_path) exit_code, ret = shell_command(adbcmdstr, timeout_second=300) if exit_code != 0: error = ret[0].strip('\r\n') if len(ret) else "adb shell timeout" LOG.info("[ Push file \"%s\" failed, error: %s ]" % (local_path, error)) return False else: return True
def adb_cmd_capture_msg(self, cmdstr, time_out=15): """ Lightweight wrapper for adb command call. Return adb command line's message output parameter cmdstr is the command line string run in adb shell """ adbcmdstr = "%s shell %s" % (self.adb_prefix, cmdstr) LOG.debug('Execute adb command: %s' % adbcmdstr) _, msgs = shell_command(adbcmdstr, time_out) return ''.join(msgs).strip('\r\n')
def Install_Test_Apps(self, *args): _cmdstr_disable = "settings put global package_verifier_enable 0" _cmdstr_get_status = "settings get global package_verifier_enable" _status = shell_command( "adb shell settings get global package_verifier_enable" )[1][0].strip() if int(_status): g_common_obj.adb_cmd(_cmdstr_disable) config = TestConfig() cfg_file = 'tests.tablet.gps.conf' cfg_arti = config.read(cfg_file, 'artifactory') config_handle = ConfigHandle() cfg_arti["location"] = config_handle.read_configuration( 'artifactory', 'location', '/etc/oat/', 'sys.conf') cfg = config.read(cfg_file, 'CWS_GPS') arti = Artifactory(cfg_arti.get('location')) for i in args: apk_name = cfg.get(i) apk_path = arti.get(apk_name) g_common_obj.adb_cmd_common("install -r %s" % apk_path)
def setUp(self): self._test_name = __name__ print print "[Setup]: %s" % self._test_name self.data_files = shell_command("ls Thermal_data_*.csv")[1]
def adb_shell(self, cmd): _cmd = "adb -s %s shell %s" % (self.serial, cmd) msgs = shell_command(_cmd)[1] return ''.join(msgs).strip('\r\n')
def shell_cmd(cmd, timeout = 90): LOG.debug("Exec cmd: " + cmd) shell_command(cmd)
def shell_cmd(self, cmdstr, time_out=30): return shell_command(cmdstr, time_out)[0]
def remount_device(self): """remount device """ adbcmdstr = self.adb_prefix + "remount" LOG.debug('Execute adb remount') _, _ = shell_command(adbcmdstr)
def kill_uiautomator(self): _uiautomator_pid = shell_command( "adb shell ps | grep -i uiautomator | awk '{print $2}'")[1][0] g_common_obj.adb_cmd("kill %s" % _uiautomator_pid)
def getAllSerial(): """get all device serials found by command adb devices""" _, msgs = shell_command("adb devices") devices = [line for line in msgs if "\tdevice\n" in line] serials = sorted([dev.split()[0] for dev in devices], key=len) return serials