def net_monitor_setup(root_path): if not myadb.verify_adb_devices_connect(): print 'Error, no adb devices connected!' exit(1) init_path_vars(root_path) mutils.g_create_report_dir(root_path)
def loop_run_test(during): i = 0 cmd = build_instrument_cmd_v2() start_time = int(time.clock()) while 1: if not AdbUtils.verify_adb_devices_serialno(): if not AdbUtils.adb_connect_to_device(g_device_ip): logging.error('device is disconnect!') exit(1) run_instrument_tests_v2(cmd) time.sleep(3) i += 1 logging.info('run ui test %d times.' % i) cur_run_time = int(time.clock()) - start_time logging.info('current run time: %d minutes %d seconds' % (cur_run_time / 60, cur_run_time % 60)) if ((cur_run_time - start_time) > during): break # END LOOP global g_total_run_times g_total_run_times = i
def connect_to_device_with_root(): if not AdbUtils.adb_connect_to_device(g_target_device_ip): print 'Failed adb connect to %s' % g_target_device_ip exit(1) if not AdbUtils.adb_connect_with_root(g_target_device_ip): print 'Failed adb root and connect to %s' % g_target_device_ip exit(1)
def adb_connect_with_root(device_ip): if not AdbUtils.adb_connect_to_device(device_ip): # adb connect print 'Error, when adb connect to the device!' exit(1) # fix pending issue when run adb root command # if not run_cmd_adb_root_from_subprocess(): # print 'Error, when run adb as root!' # exit(1) run_cmd_adb_root_from_subprocess_and_kill() if not AdbUtils.adb_connect_to_device(device_ip): # adb connect as root print 'Error, when adb connect to the device with root!' exit(1)
def cpu_monitor_top_setup(): if not AdbUtils.verify_adb_devices_connect(): print 'Error, no adb devices connected!' exit(1) init_path_vars(g_report_root_path) MUtils.g_create_report_dir(g_report_root_path)
def dump_logcat_for_app_main(pkg_name, file_path): if not AdbUtils.verify_adb_devices_connect(): print 'Error, no adb devices connected!' exit(1) filter_str = get_pids_filter_string(pkg_name) dump_logcat_by_process_id(filter_str, file_path)
def mem_monitor_procrank_setup(): if not AdbUtils.verify_adb_devices_connect(): print 'Error, no adb devices connected!' exit(1) init_path_vars(g_report_root_path) MUtils.g_create_report_dir(g_report_root_path)
def main_instument_setup(): if not AdbUtils.verify_adb_devices_serialno(): print 'Error, No adb devices connected, and exit!' exit(1) if not os.path.exists(REPORT_DIR_PATH): os.makedirs(REPORT_DIR_PATH) delete_old_instrument_run_listener_logs()
def run_cmd_adb_root_from_subprocess_and_reconnect(): cmd = 'adb root' print 'run adb root and reconnect.' p = subprocess.Popen(cmd, shell=True) time.sleep(1) p.kill() # no return back for 'adb root' and kill instead return AdbUtils.adb_connect_to_device(target_device_ip)
def connect_to_device_with_root(): if not AdbUtils.adb_connect_to_device(target_device_ip): print 'Failed adb connect to ' + target_device_ip exit(1) if not run_cmd_adb_root_from_subprocess_and_reconnect(): print 'Failed adb root and reconnect to ' + target_device_ip exit(1)
def run_test_setup(during): init_local_report_paths() LogUtils.init_log_config(logging.DEBUG, logging.INFO, g_local_test_logging_file_path) if not AdbUtils.adb_connect_with_root(g_device_ip): logging.error('adb is NOT run with root!') exit(1) rm_old_captures_on_remote() test_case = g_test_class[(g_test_class.rindex('.') + 1) : ] logging.info('----- START run test %s for %s minutes' % (test_case, during / 60))
def pull_all_testing_logs(): # the adb connection maybe disconnect when running the monkey if not AdbUtils.verify_adb_devices_connect(): print 'Warn, no devices connected, NO files pulled!' return cmd_pull_logcat_log = 'adb pull %s %s' % (g_logcat_log_path_for_shell, g_log_dir_path_for_win) run_system_command(cmd_pull_logcat_log) cmd_pull_whitelist = 'adb pull %s %s' % (g_whitelist_file_path_for_shell, g_log_dir_path_for_win) run_system_command(cmd_pull_whitelist) run_system_command(build_command_pull_anr_file()) run_system_command(build_command_pull_tombstone_file())
def connect_device(device_ip): if not AdbUtils.adb_connect_with_root(device_ip): raise Exception('Adb connect with root failed!')
def stop_logcat_log(p): if p is not None: p.kill() AdbUtils.adb_stop()
def mem_monitor_dumpsys_setup(): if not AdbUtils.verify_adb_devices_connect(): print 'No adb devices connected!' exit(1) init_path_vars(g_report_root_path)
def stop_logcat_log(p): AdbUtils.adb_stop() if p is not None: p.kill()
def remount_system_partition(): if not AdbUtils.adb_remount(): print 'Failed to remount /system partition!' exit(1)
def pull_captures(): if not AdbUtils.verify_adb_devices_connect(): print 'Warn, no devices connected, NO captures pulled!' return cmd = 'adb pull %s %s' % (g_captures_dir_path_for_shell, g_captures_dir_path_for_win) run_system_command(cmd)
def stop_logcat(p): if p is not None: p.kill() time.sleep(1) AdbUtils.adb_stop()
def start_logcat_log(): p = AdbUtils.adb_logcat_by_tag_and_ret_process( g_inst_runner_logcat_tag, g_local_logcat_log_file_path) return p