Exemple #1
0
def shutdown_appium(port,device):
    line = cmd('netstat -aon | findstr %d' % port).stdout.readline()
    pid = line.strip().split(' ')[-1]
    cmd('taskkill /f /pid {}'.format(pid))
    L.success("killed appium %s" % port)
    clean_logcat(device)
    reconnect_device(device)
Exemple #2
0
def main():
    try:
        time_start = time.time()

        sig_addr = "GPIB0::19::INSTR"
        sigen = hd_sig(sig_addr)

        cmw_addr = "GPIB0::20::INSTR"
        cmw = hd_cmw(cmw_addr)
        if sigen and cmw:
            res_list = []
            try:
                lte_test_list = lte_test_list_build(cfg_lte)
                cmw.main_lte_setup(lte_test_list)

                for band_ch in lte_test_list:
                    cmw.LTE_ch_redirection(band_ch)
                    for s_amp in amp_range:
                        for s_freq in freq_range:
                            # begin loop
                            try:
                                res = loop_sig(sigen, cmw, s_amp, s_freq,
                                               "sensm_cloop")
                                print(res)
                                res_list.append(
                                    (band_ch.BAND + str(band_ch.CH_UL) +
                                     band_ch.BW, *res))
                            except ConnectionError:
                                for i in range(5):
                                    try:
                                        cmd("taskkill /f /im adb.exe")
                                        print("kill adb process")
                                        time.sleep(5)
                                        cmd("adb reboot")
                                        time.sleep(30)
                                        cmw.main_lte_setup([
                                            band_ch,
                                        ])
                                        res = loop_sig(sigen, cmw, s_amp,
                                                       s_freq, "sensm_cloop")
                                        print(res)
                                        res_list.append(
                                            (band_ch.BAND +
                                             str(band_ch.CH_UL) + band_ch.BW,
                                             *res))
                                        break
                                    except:
                                        pass
            finally:
                # datetime.today().strftime("_%Y_%m_%d_%H_%M")
                sig_data_output(
                    res_list, "sense" +
                    datetime.today().strftime("_%Y_%m_%d_%H_%M") + ".txt")
                sigen.instr_close()
                cmw.instr_rm_close()
    finally:
        time_end = time.time()
        print("time elaped {0}:{1}".format(
            int(time_end - time_start) // 60,
            int(time_end - time_start) % 60))
def meminfo(serial):
    result = {}
    for line in adb.cmd(['-s', serial, 'shell', 'cat', '/proc/meminfo'])['stdout'].splitlines():
        item = [i.strip() for i in line.split(':')]
        if len(item) == 2:
            values = item[1].split()
            result[item[0]] = int(values[0])*1024 if len(values) == 2 and values[1] == 'kB' else int(values[0])
    return result
Exemple #4
0
def get_device_name():
    devices = cmd('adb devices').stdout.readlines()
    device_list = []
    for device in devices:
        if 'device' in device and 'devices' not in device:
            device = device.split('\t')[0]
            device_list.append(device)
    return device_list
def top(serial):
    result = {"processes": []}
    out = adb.cmd(['-s', serial, 'shell', 'top', '-n', '1'])['stdout']
    m = re.search(r'User\s*(\d+)%,\s*System\s*(\d+)%,\s*IOW\s*(\d+)%,\s*IRQ\s*(\d+)%', out)
    if m:
        result["CPU"] = {"User": int(m.group(1))/100., "System": int(m.group(2))/100., "IOW": int(m.group(3))/100., "IRQ": int(m.group(4))/100.}
    for item in re.findall(r'(\d+)\s+(\d+)\s+(\d+)%\s+(\w+)\s+(\d+)\s+(\d+)K\s+(\d+)K\s+(fg|bg)?\s+(\S+)\s+(\S+)', out):
        pid, pr, cpu, s, thr, vss, rss, pcy, uid, name = item
        result["processes"].append({"pid": int(pid), "pr": int(pr), "cpu": int(cpu)/100., "s": s, "thr": int(thr), "vss": int(vss)*1024, "rss": int(rss)*1024, "pcy": pcy, "uid": uid, "name": name})
    return result
Exemple #6
0
 def __start_appium(self,aport,bport):
     if platform.system() == 'Windows':
         subprocess.Popen("appium -p %s -bp %s -U %s" %
                         (aport,bport,self.device),shell=True)
     else:
         appium = cmd('appium -p %s -bp %s -U %s' %
                        (aport, bpport, self.device))
         while True:
             appium_line = appium.stdout.readline().strip()
             L.Logging.debug(appium_line)
             if 'listener started' in appium_line:
                 break
Exemple #7
0
 def start_appium(self):
     aport = random.randint(4700, 4900)
     bport = random.randint(4700, 4900)
     self.__start_appium(aport,bport)
     count = 20
     for i in range(count):
         appium = cmd('netstat -aon | findstr %d' % aport).stdout.readline()
         if appium:
             L.info('start appium :p %s bp %s device: %s' %
                 (aport,bport,self.device))
             return aport
         else:
             L.info('waiting start appium 3 seconds!')
             sleep(3)
def adb_cmd(serial, cmds):
    return adb.cmd(['-s', serial] + cmds.split("/"), timeout=request.params.get("timeout", 10))
Exemple #9
0
def get_android_version():
    for version in cmd('adb shell getprop').stdout.readlines():
        if 'ro.build.version.release' in version:
            version = version.split(':')[1].strip().strip('[]')
            return version
Exemple #10
0
def clean_logcat(device):
    pid = cmd('netstat -aon | findstr %s' % device).stdout.readline().strip().split(' ')[-1]
    cmd('taskkill /f /pid %s' % pid)
    sleep(2)
    L.success('stop logcat %s' % device)