def run(): AudioFunction.init() Logger.init(Logger.Mode.STDOUT) Adb.init() package = "com.htc.audiofunctionsdemo" activity = ".activities.MainActivity" component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno, autodump=False) if not device.isScreenOn(): device.wake() vc.dump() import StringIO as sio so = sio.StringIO() vc.traverse(stream=so) if "lockscreen" in so.getvalue(): device.unlock() # keymap reference: # https://github.com/dtmilano/AndroidViewClient/blob/master/src/com/dtmilano/android/adb/androidkeymap.py device.press("HOME") time.sleep(1) device.startActivity(component=component) time.sleep(1) playback_task_run(device) record_task_run(device, serialno) AudioFunction.finalize() Logger.finalize()
def run(): Logger.init(Logger.Mode.STDOUT) log("Hello, test.") device, serialno = ViewClient.connectToDeviceOrExit(serialno=None) gmhandler = GoogleMusicApp(device, serialno) gmhandler.walk_through() gmhandler.dump() log(json.dumps(gmhandler.cache, indent=2)) Logger.finalize()
def run(num_iter=1): AudioFunction.init() Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() os.system("mkdir -p {}/ssr_report > /dev/null".format(ROOT_DIR)) t = datetime.datetime.now() filename = "report_{}{:02d}{:02d}_{:02d}{:02d}{:02d}.json".format( t.year, t.month, t.day, t.hour, t.minute, t.second) package = "com.htc.audiofunctionsdemo" activity = ".activities.MainActivity" component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit(serialno=None) wake_device(device, serialno) SSRDumpListener.init(device, serialno) # keymap reference: # https://github.com/dtmilano/AndroidViewClient/blob/master/src/com/dtmilano/android/adb/androidkeymap.py device.press("HOME") time.sleep(1) device.startActivity(component=component) time.sleep(1) trials = [] batch_count = 1 while num_iter > 0: log("-------- batch_run #{} --------".format(batch_count)) trials_batch = [] trials_batch += playback_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) trials_batch += record_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) trials_batch += voip_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) map(lambda trial: trial.put_extra(name="batch_id", value=batch_count), trials_batch) trials += trials_batch with open("{}/ssr_report/{}".format(ROOT_DIR, filename), "w") as f: f.write(TrialHelper.to_json(trials)) num_iter -= BATCH_SIZE batch_count += 1 AudioFunction.finalize() Logger.finalize() SSRDumpListener.finalize() device.press("HOME")
def run(num_iter=1): # initail componet AudioFunction.init() Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() if PLATFORM == WINDOWS: os.system("mkdir {}/{} ".format(ROOT_DIR, REPORT_DIR)) elif PLATFORM == LINUX: os.system("mkdir -p {}/{} ".format(ROOT_DIR, REPORT_DIR)) t = datetime.datetime.now() filename = "report_{}{:02d}{:02d}_{:02d}{:02d}{:02d}.json".format( t.year, t.month, t.day, t.hour, t.minute, t.second) device, serialno = ViewClient.connectToDeviceOrExit(serialno=None) wake_device(device, serialno) # keymap reference: # https://github.com/dtmilano/AndroidViewClient/blob/master/src/com/dtmilano/android/adb/androidkeymap.py device.press("HOME") time.sleep(0.5) trials = [] batch_count = 1 while num_iter > 0: log("-------- batch_run #{} --------".format(batch_count)) trials_batch = [] trials_batch += record_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) #trials_batch += recordHD_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) trials_batch += record_VoiceRecord_run(device, serialno, num_iter=min( [num_iter, BATCH_SIZE])) map(lambda trial: trial.put_extra(name="batch_id", value=batch_count), trials_batch) trials += trials_batch with open("{}/{}/{}".format(ROOT_DIR, REPORT_DIR, filename), "w") as f: f.write(TrialHelper.to_json(trials)) num_iter -= BATCH_SIZE batch_count += 1 device.press("HOME") AudioFunction.finalize() Logger.finalize()
def run(num_iter=1): # initail componet AudioFunction.init() Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() os.system("mkdir -p {}/ssr_report > /dev/null".format(ROOT_DIR)) t = datetime.datetime.now() filename = "report_{}{:02d}{:02d}_{:02d}{:02d}{:02d}.json".format( t.year, t.month, t.day, t.hour, t.minute, t.second) package = "com.htc.audiofunctionsdemo" activity = ".activities.MainActivity" component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit(serialno=None) wake_device(device, serialno) #push_files_if_needed(serialno) # keymap reference: # https://github.com/dtmilano/AndroidViewClient/blob/master/src/com/dtmilano/android/adb/androidkeymap.py device.press("HOME") #time.sleep(1) #push_files_if_needed(serialno) time.sleep(1) #device.startActivity(component=component) #time.sleep(1) for i in range(1): #swith_effect_ui(device, serialno) #device.press("HOME") playback_task_run(device, num_iter=num_iter) #AATApp.playback_nonoffload(device, "pop.wav") #time.sleep(5) #device.press("HOME") #playback_task2_run(device, num_iter=num_iter) #device.press("HOME") #control_GoogleMusic(device, serialno, num_iter=num_iter) AudioFunction.finalize() Logger.finalize()
def run(num_iter=1, serialno=None): num_iter = int(num_iter) Adb.init() Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT, prefix="quick-start") check_props = { "Device name": "ro.product.model", "Project": "ro.build.product", "ROM": "ro.product.build.fingerprint", } passed = True for tag, prop in check_props.items(): out, err = Adb.execute(["shell", "getprop {}".format(prop)], serialno=serialno) passed &= len(err) == 0 out = out.strip() Logger.log(LOGGER_TAG, "{}: {}".format(tag, out)) Logger.log(LOGGER_TAG, "result: {}".format("passed" if passed else "failed")) Logger.finalize()
def run(num_iter, serialno1, phoneno1, serialno2, phoneno2): Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) # Logger.init(Logger.Mode.STDOUT) Adb.init() for serialno in [serialno1, serialno2]: Adb.execute(["root"], serialno=serialno) Adb.execute(["shell", "'echo \'related\' > msm_subsys'"], serialno=serialno) Adb.execute(["shell", "svc", "power", "stayon", "true"], serialno=serialno) out, err = Adb.execute(["shell", "getprop", "ro.vendor.build.fingerprint"], serialno=serialno) out = out.strip() log("build number: '{}'".format(out)) latest_dmesg1 = fetch_dmesg(serialno=serialno1) latest_dmesg2 = fetch_dmesg(serialno=serialno2) latest_dmesg1 = latest_dmesg1[0] if len(latest_dmesg1) > 0 else None latest_dmesg2 = latest_dmesg2[0] if len(latest_dmesg2) > 0 else None phone_dict = { serialno1: phoneno1, serialno2: phoneno2 } last_dmesg_dict = { serialno1: latest_dmesg1, serialno2: latest_dmesg2 } mt_serialno = serialno1 mo_serialno = serialno2 pass_trial_cnt = 0 total_trial_cnt = 0 invalid_trial_cnt = 0 failed_trial_cnt = 0 try: for i in range(int(num_iter)): log("-------------------- Dual-CS-call-test #{} --------------------".format(i+1)) log("{} makes call to {} ({})".format(mo_serialno, mt_serialno, phone_dict[mt_serialno])) start_cs_call(tel=phone_dict[mt_serialno], serialno=mo_serialno) if not wait_for_phone_state(state=1, timeout=30, serialno=mt_serialno): log("There is no incoming call to {}, next trial".format(mt_serialno)) end_cs_call(serialno=mo_serialno) end_cs_call(serialno=mt_serialno) invalid_trial_cnt += 1 continue log("{} picks up the call".format(mt_serialno)) pick_cs_call(serialno=mt_serialno) if not wait_for_phone_state(state=2, timeout=10, serialno=mo_serialno): log("{} is not in phone state 'MODE_INCALL', next trial".format(mo_serialno)) end_cs_call(serialno=mo_serialno) end_cs_call(serialno=mt_serialno) invalid_trial_cnt += 1 continue if not wait_for_phone_state(state=2, timeout=10, serialno=mt_serialno): log("{} is not in phone state 'MODE_INCALL', next trial".format(mt_serialno)) end_cs_call(serialno=mo_serialno) end_cs_call(serialno=mt_serialno) invalid_trial_cnt += 1 continue log("To check if ADSP crashes during the CS call") is_passed = True pass_trial_cnt += 1 total_trial_cnt += 1 retry = 15 while retry > 0: for serialno in [mt_serialno, mo_serialno]: latest_dmesg = last_dmesg_dict[serialno] new_dmesgs = fetch_dmesg(latest_dmesg, serialno=serialno) if len(new_dmesgs) > 0: last_dmesg_dict[serialno] = new_dmesgs[-1] adsp_ssr_demsgs = filter(lambda x: "Restart sequence requested for adsp" in x.raw, new_dmesgs) if len(adsp_ssr_demsgs) > 0: for dmesg in adsp_ssr_demsgs: log("SSR log detected in {}: '{}'".format(serialno, dmesg.raw)) is_passed = False break phone_state = get_phone_state(serialno=serialno) if phone_state == None: log("the phone state of {} is unobtainable, something wrong".format(serialno)) is_passed = False break if phone_state == 0: log("the phone state of {} is in idle, the call might be dropped".format(serialno)) is_passed = False break if not is_passed: for serialno in [mt_serialno, mo_serialno]: out, err = Adb.execute(["bugreport"], serialno) log("bugreport to '{}'".format(out.strip())) pass_trial_cnt -= 1 failed_trial_cnt += 1 for serialno in [mt_serialno, mo_serialno]: end_cs_call(serialno=serialno) break if retry % 5 == 0: log("{} switches path to '{}'".format(mo_serialno, "speaker" if retry/5 % 2 == 1 else "receiver")) Adb.execute(["shell", "input", "tap", "1000", "1000"], tolog=False, serialno=mo_serialno) retry -= 1 time.sleep(1) log("result: {} ({}/{})".format("pass" if retry == 0 else "fail", pass_trial_cnt, total_trial_cnt)) log("pass: {}% ({}/{}), fail: {}% ({}/{}), invalid: {}% ({}/{})".format( pass_trial_cnt*100.0/total_trial_cnt, pass_trial_cnt, total_trial_cnt, failed_trial_cnt*100.0/total_trial_cnt, failed_trial_cnt, total_trial_cnt, invalid_trial_cnt*100.0/(i+1), invalid_trial_cnt, i+1)) for serialno in [mo_serialno, mt_serialno]: end_cs_call(serialno=serialno) wait_for_phone_state(state=0, timeout=10, serialno=serialno) time.sleep(5) except: pass for serialno in [serialno1, serialno2]: end_cs_call(serialno=serialno) Adb.execute(["shell", "svc", "power", "stayon", "false"], serialno=serialno) Logger.finalize()
def main(): Logger.init(Logger.Mode.STDOUT) Adb.init() trial_num = 1 pass_trial_num = 0 try: while True: Adb.execute(["shell", "input", "keyevent", "POWER"]) Adb.execute([ "shell", AATApp.INTENT_PREFIX, AATApp.HTC_INTENT_PREFIX + "record.start" ]) time.sleep(2) log("play 220Hz_44100Hz_15secs_2ch.wav") os.system( "adb shell tinyplay /data/220Hz_44100Hz_15secs_2ch.wav > /dev/null &" ) retry = 5 detected = False while retry > 0: out, err = Adb.execute([ "shell", "cat", "/storage/emulated/0/AudioFunctionsDemo-record-prop.txt" ], tolog=False) try: out = float(out.split(",")[0]) except: out = 0.0 if out > 200.0 and out < 240.0: log("detected tones.") detected = True break time.sleep(0.1) time.sleep(1) log("turn off the screen.") Adb.execute(["shell", "input", "keyevent", "POWER"]) time.sleep(2) retry = 5 detected = False detected_cnt = 0 while retry > 0: out, err = Adb.execute([ "shell", "cat", "/storage/emulated/0/AudioFunctionsDemo-record-prop.txt" ], tolog=False) try: out = float(out.split(",")[0]) except: out = 0.0 if out > 200.0 and out < 240.0: log("detected tones.") detected_cnt += 1 if detected_cnt == 10: log("detected for a sufficient times.") detected = True break time.sleep(0.1) if detected: pass_trial_num += 1 log("trial #{}: passed. ({}/{})".format( trial_num, pass_trial_num, trial_num)) else: log("trial #{}: failed. ({}/{})".format( trial_num, pass_trial_num, trial_num)) trial_num += 1 time.sleep(15) except: pass Logger.finalize()
def run(num_iter=1): AudioFunction.init() Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() os.system("mkdir -p {}{}{} > {}".format(ROOT_DIR, SEP, REPORT_DIR, STDNUL)) t = datetime.datetime.now() filename = "report_{}{:02d}{:02d}_{:02d}{:02d}{:02d}.json".format( t.year, t.month, t.day, t.hour, t.minute, t.second) device, serialno = ViewClient.connectToDeviceOrExit(serialno=None) device.press("HOME") time.sleep(1) gmhandler = GoogleMusicApp(device, serialno) log("gmhandler.to_top()") gmhandler.to_top() clear_and_update_music_files(serialno) time.sleep(10) trials = [] batch_count = 1 while num_iter > 0: log("-------- batch_run #{} --------".format(batch_count)) trials_batch = [] trials_batch += playback_task_run(num_iter=min([num_iter, BATCH_SIZE]), num_seek_test=5, gmhandler=gmhandler) trials_batch += record_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE]), num_freqs=5) map(lambda trial: trial.put_extra(name="batch_id", value=batch_count), trials_batch) trials += trials_batch with open( "{}{}{}{}{}".format(ROOT_DIR, SEP, REPORT_DIR, SEP, filename), "w") as f: f.write(TrialHelper.to_json(trials)) for taskname, tasktrials in TrialHelper.categorize_in( trials, lambda t: t.ds["task"]).items(): valid_trials = zip( tasktrials, TrialHelper.pass_fail_list( tasktrials, lambda t: t.ds["status"] == "valid")) valid_trials = [ trial for trial, isvalid in valid_trials if isvalid ] num_valid = len(valid_trials) num_pass = len( filter(lambda x: x, TrialHelper.pass_fail_list(valid_trials))) log("task[{}] valid trials: {}/{}, pass trials: {}/{}".format( taskname, num_valid, len(tasktrials), num_pass, num_valid)) num_iter -= BATCH_SIZE batch_count += 1 AudioFunction.finalize() Logger.finalize()
def run(num_iter=1): AudioFunction.init() Logger.init(Logger.Mode.STDOUT) Logger.log(TAG, "delete the existed dump folder...") subprocess.Popen(["rm", "-rf", "./record-dump"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() audiodump = AudioSignalFrameLogger() databuff = queue.Queue() th_tictoc = TicToc() push_tictoc = TicToc() push_tictoc.extra = { "initialized": False, "max_period": -1, "avg_period": -1, "push_count": 0, "max_snr": None, "min_snr": None, "avg_snr": -1 } def process_buff(): th_tictoc.tic() try: data = databuff.get(timeout=FRAMEMILLIS*.1/1000.) if push_tictoc.extra["initialized"]: elapsed = push_tictoc.toc() push_tictoc.extra["max_period"] = max([push_tictoc.extra["max_period"], elapsed]) push_tictoc.extra["avg_period"] *= push_tictoc.extra["push_count"] push_tictoc.extra["avg_period"] += elapsed push_tictoc.extra["avg_period"] /= float(push_tictoc.extra["push_count"]+1) else: push_tictoc.tic() push_tictoc.extra["initialized"] = True push_tictoc.extra["push_count"] += 1 audiodump.push(name="signal", fs=FS, values=data) nfft = np.ceil(np.log2(data.shape[0])) nfft = int(2**nfft) spectrum = np.abs(fft(data.flatten(), nfft)) audiodump.push(name="spectrum", fs=-1, values=spectrum) spectrum = spectrum[:nfft/2] unit_freq = FS*1./nfft spectrum = map(lambda x: (x[0]*unit_freq, -x[1]), sort_values(-spectrum)) signal_spectrum = filter(lambda x: target_detected(freq=x[0], target_freq=FREQ), spectrum) noise_spectrum = filter(lambda x: not target_detected(freq=x[0], target_freq=FREQ), spectrum) if len(signal_spectrum) > 0 and len(noise_spectrum) > 0: snr = np.mean(map(lambda x: x[1], signal_spectrum)) / np.mean(map(lambda x: x[1], noise_spectrum)) snr = 20*np.log10(snr) if target_detected(freq=spectrum[0][0], target_freq=FREQ): if push_tictoc.extra["max_snr"] == None or push_tictoc.extra["max_snr"][0] < snr: push_tictoc.extra["max_snr"] = [snr, push_tictoc.extra["push_count"]-1] if push_tictoc.extra["min_snr"] == None or push_tictoc.extra["min_snr"][0] > snr: push_tictoc.extra["min_snr"] = [snr, push_tictoc.extra["push_count"]-1] push_tictoc.extra["avg_snr"] *= (push_tictoc.extra["push_count"]-1) push_tictoc.extra["avg_snr"] += snr push_tictoc.extra["avg_snr"] /= float(push_tictoc.extra["push_count"]) sleeptime = max([FRAMEMILLIS - th_tictoc.toc(), 0]) time.sleep(sleeptime * .99/1000.) except queue.Empty: pass def threadloop(): while True: process_buff() def record_cb(indata): databuff.put(indata) record_cmd = RawRecordCommand(config=AudioConfig(fs=FS, ch=1, dtype="float32", cb=record_cb), framemillis=FRAMEMILLIS) AudioFunction.COMMAND.cmd = record_cmd AudioFunction.WORK_THREAD.push(AudioFunction.COMMAND.cmd) Logger.log(TAG, "start recording on the server...") time.sleep(1) Logger.log(TAG, "start processing the data buffers...") th = threading.Thread(target=threadloop) th.daemon = True th.start() time.sleep(10) AudioFunction.stop_audio() Logger.log(TAG, "stop recording on the server...") audiodump.dump(path="./record-dump") Logger.log(TAG, "------------------------ profiling in process_buff ------------------------") Logger.log(TAG, "max period: {}".format(push_tictoc.extra["max_period"])) Logger.log(TAG, "avg period: {}".format(push_tictoc.extra["avg_period"])) Logger.log(TAG, "push count: {}".format(push_tictoc.extra["push_count"])) Logger.log(TAG, "max SNR : {}".format(push_tictoc.extra["max_snr"])) Logger.log(TAG, "min SNR : {}".format(push_tictoc.extra["min_snr"])) Logger.log(TAG, "avg SNR : {}".format(push_tictoc.extra["avg_snr"])) AudioFunction.finalize() Logger.finalize()
def run(test_type, num_iter=1, serialno=None): num_iter = int(num_iter) GLOBAL["test_config"] = test_type GLOBAL["tag"] = GLOBAL["tag"].format(GLOBAL["test_config"]) AudioFunction.init() Adb.init() os.system("mkdir -p {}{}{}_report > {}".format(ROOT_DIR, SEP, GLOBAL["test_config"], STDNUL)) os.system("mkdir -p {}{}{}_report-bugreport > {}".format( ROOT_DIR, SEP, GLOBAL["test_config"], STDNUL)) t = datetime.datetime.now() postfix = "{}{:02d}{:02d}_{:02d}{:02d}{:02d}".format( t.year, t.month, t.day, t.hour, t.minute, t.second) filename = "report_{}.json".format(postfix) os.system("mkdir -p {}{}{}_report-bugreport/{} > {}".format( ROOT_DIR, SEP, GLOBAL["test_config"], postfix, STDNUL)) device, serialno = ViewClient.connectToDeviceOrExit(serialno=serialno) Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT, prefix="{}-{}".format(GLOBAL["test_config"], serialno)) push_files(serialno) Adb.execute(["shell", "svc", "power", "stayon", "true"], serialno=serialno) Adb.execute(["root"], serialno=serialno) out, _ = Adb.execute(["shell", "getprop", "ro.vendor.build.fingerprint"], serialno=serialno) out = out.strip() log("build number: '{}'".format(out)) # keymap reference: # https://github.com/dtmilano/AndroidViewClient/blob/master/src/com/dtmilano/android/adb/androidkeymap.py # device.press("HOME") # time.sleep(1) relaunch_app(device) # time.sleep(5) function_items = [ lambda x: playback_task_run( device, serialno, num_iter=x, postfix=postfix), lambda x: record_task_run(device, serialno, num_iter=x), lambda x: voip_task_run(device, serialno, num_iter=x) ] trials = [] batch_count = 1 temp = num_iter while num_iter > 0: log("-------- batch_run #{} --------".format(batch_count)) AATApp.print_log( device, severity="i", tag=GLOBAL["tag"], log="-------- batch_run #{} --------".format(batch_count)) trials_batch = [] # trials_batch += playback_task_run(device, num_iter=min([num_iter, BATCH_SIZE])) # trials_batch += record_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) # trials_batch += voip_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) need_to_reboot = False for test_item in function_items: test_results = test_item(min([num_iter, BATCH_SIZE])) trials_batch += test_results if len(filter(lambda t: t.ds["status"] == "valid", test_results)) == 0: log("Function failed after {} trials...".format(temp - num_iter)) need_to_reboot = True for trial in trials_batch: trial.put_extra(name="batch_id", value=batch_count) trials += trials_batch with open( "{}{}{}_report{}{}".format(ROOT_DIR, SEP, GLOBAL["test_config"], SEP, filename), "w") as f: f.write(TrialHelper.to_json(trials)) for taskname, tasktrials in TrialHelper.categorize_in( trials, lambda t: t.ds["task"]).items(): valid_trials = zip( tasktrials, TrialHelper.pass_fail_list( tasktrials, lambda t: t.ds["status"] == "valid")) valid_trials = [ trial for trial, isvalid in valid_trials if isvalid ] num_valid = len(valid_trials) num_pass = len( filter(lambda x: x, TrialHelper.pass_fail_list(valid_trials))) log("task[{}] valid trials: {}/{}, pass trials: {}/{}".format( taskname, num_valid, len(tasktrials), num_pass, num_valid)) if need_to_reboot: AudioFunction.stop_audio() log("No valid trials, might be some problems!") log("trigger bugreport!") trigger_bugreport(device) log("Try to reboot the device") if not try_to_reboot_device(serialno, timeout=300): log("reboot failed!") os.system( "mv bugreport*.zip {}{}{}_report-bugreport{}{}{}".format( ROOT_DIR, SEP, GLOBAL["test_config"], SEP, postfix, SEP)) os.system("mv {}-*.png {}{}{}_report-bugreport{}{}{}".format( postfix, ROOT_DIR, SEP, GLOBAL["test_config"], SEP, postfix, SEP)) break else: time.sleep(5) device, serialno = ViewClient.connectToDeviceOrExit( serialno=serialno) os.system("mv bugreport*.zip {}{}{}_report-bugreport{}{}{}".format( ROOT_DIR, SEP, GLOBAL["test_config"], SEP, postfix, SEP)) num_iter -= BATCH_SIZE batch_count += 1 time.sleep(5) AudioFunction.finalize() Logger.finalize()
def run(num_iter, serialno): Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() out, err = Adb.execute(["shell", "getprop", "ro.vendor.build.fingerprint"], serialno=serialno) log("build number: '{}'".format(out.strip())) report_file_name = "./log/test_report_{}.json".format(serialno) try: trials = TrialHelper.load(report_file_name) except: trials = [] if len(trials) > 0: pass_cnt = len( filter( lambda x: x, TrialHelper.pass_fail_list( trials, check_func=lambda x: not x.ds["error-msg"]))) fail_cnt = len(trials) - pass_cnt else: pass_cnt, fail_cnt = 0, 0 try: for i in range(int(num_iter)): log("-------------------- reboot-snd-card-test #{} --------------------" .format(i + 1)) trial = Trial(taskname="reboot-snd-card-test", pass_check=lambda x: not x.ds["error-msg"]) log("reboot the device") _, err = Adb.execute(["reboot"], serialno=serialno) if len(err) > 0: log("adb error: '{}'".format(err.strip())) time.sleep(5) continue time.sleep(5) try: wait_for_device(serialno=serialno) except: break log("now checking the snd card") elapsed = wait_for_snd_card(serialno=serialno, timeout=30) if elapsed < 0: fail_cnt += 1 trial.invalidate(errormsg="no sound card") error_handle(serialno=serialno, trial=trial) else: pass_cnt += 1 log("elapsed: {} ms".format(elapsed)) trial.put_extra("elapsed", elapsed) trials.append(trial) with open(report_file_name, "w") as f: f.write(TrialHelper.to_json(trials)) log("pass/fail/total: {}/{}/{}".format(pass_cnt, fail_cnt, pass_cnt + fail_cnt)) time.sleep(20) except: pass Logger.finalize()
def run(num_iter=1): AudioFunction.init() Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() os.system("mkdir -p {}{}ssr_report > {}".format(ROOT_DIR, SEP, STDNUL)) t = datetime.datetime.now() filename = "report_{}{:02d}{:02d}_{:02d}{:02d}{:02d}.json".format( t.year, t.month, t.day, t.hour, t.minute, t.second) device, serialno = ViewClient.connectToDeviceOrExit(serialno=None) push_files(serialno) wake_device(device, serialno) SSRDumpListener.init(device, serialno) # keymap reference: # https://github.com/dtmilano/AndroidViewClient/blob/master/src/com/dtmilano/android/adb/androidkeymap.py device.press("HOME") time.sleep(1) AATApp.launch_app(device) time.sleep(1) trials = [] batch_count = 1 while num_iter > 0: log("-------- batch_run #{} --------".format(batch_count)) AATApp.print_log( device, severity="i", tag=TAG, log="-------- batch_run #{} --------".format(batch_count)) trials_batch = [] trials_batch += playback_task_run(device, num_iter=min([num_iter, BATCH_SIZE])) trials_batch += record_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) trials_batch += voip_task_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) map(lambda trial: trial.put_extra(name="batch_id", value=batch_count), trials_batch) trials += trials_batch with open("{}{}ssr_report{}{}".format(ROOT_DIR, SEP, SEP, filename), "w") as f: f.write(TrialHelper.to_json(trials)) for taskname, tasktrials in TrialHelper.categorize_in( trials, lambda t: t.ds["task"]).items(): valid_trials = zip( tasktrials, TrialHelper.pass_fail_list( tasktrials, lambda t: t.ds["status"] == "valid")) valid_trials = [ trial for trial, isvalid in valid_trials if isvalid ] num_valid = len(valid_trials) num_pass = len( filter(lambda x: x, TrialHelper.pass_fail_list(valid_trials))) log("task[{}] valid trials: {}/{}, pass trials: {}/{}".format( taskname, num_valid, len(tasktrials), num_pass, num_valid)) num_iter -= BATCH_SIZE batch_count += 1 AudioFunction.finalize() Logger.finalize() SSRDumpListener.finalize()
def run(num_iter=1, is_MO=False): # initail componet Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() if PLATFORM == WINDOWS: os.system("mkdir {}/{} ".format(ROOT_DIR, REPORT_DIR)) elif PLATFORM == LINUX: os.system("mkdir -p {}/{} ".format(ROOT_DIR, REPORT_DIR)) t = datetime.datetime.now() filename = "report_{}{:02d}{:02d}_{:02d}{:02d}{:02d}.json".format( t.year, t.month, t.day, t.hour, t.minute, t.second) trials = [] device, serialno = ViewClient.connectToDeviceOrExit(serialno=None) log(serialno) time.sleep(1) wake_device(device, serialno) time.sleep(1) device.press("HOME") if is_MO: log("This test is running as MO call") notAnsweredTimes = 0 test_count = 0 while num_iter > 0 and notAnsweredTimes <= 5: num_iter -= 1 test_count += 1 # target control_MO_phone out phone log("start target MO") ret = control_MO_phone(device, serialno, True) if ret is False: log("can't out phone call") control_Stop_Call(device, serialno) continue else: log("phone call out: TX test") time.sleep(1) # phone call start timeout = 30 isCallAnswered = False log("Waiting target answer our call in {} secs".format(timeout)) while (timeout > 0): if (get_callDuration_id(device, serialno)): log("Target has answered our call!") isCallAnswered = True break else: log("Target not yet answered... {}".format(timeout)) timeout -= 3 if (isCallAnswered): log("-------- batch_run #{} --------".format(test_count)) phone_call_tx_task(device, serialno) else: log("Timeout: 30 secs") log("Target didn't answer our call...") control_Stop_Call(device, serialno) notAnsweredTimes += 1 if not detect_DQ_stop(device, serialno): log("can't detect DQ log stop") continue else: log("This test is running as MT call") batch_count = 0 while True: trials_batch = [] # test control_MT_phone then recive phone ret = control_MT_phone(device, serialno) if ret is False: log("Timeout: no phone call comming") Logger.finalize() return else: log("Detected: answer the call") log("Phone call start: RX test") batch_count += 1 # phone call start log("-------- batch_run #{} --------".format(batch_count)) log("phone_call_task_rx_run++") trials_batch += phone_call_rx_task() map( lambda trial: trial.put_extra(name="batch_id", value=batch_count), trials_batch) trials += trials_batch with open("{}/{}/{}".format(ROOT_DIR, REPORT_DIR, filename), "w") as f: f.write(TrialHelper.to_json(trials)) control_Stop_Call(device, serialno) log("phone_call_task_rx_run--") Logger.finalize()
def run(num_iter=1, serialno1=None, serialno2=None): ''' # initail componet AudioFunction.init() Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() os.system("mkdir -p {}/{} > /dev/null".format(ROOT_DIR, REPORT_DIR)) # windows need modified t = datetime.datetime.now() filename = "report_{}{:02d}{:02d}_{:02d}{:02d}{:02d}.json".format(t.year, t.month, t.day, t.hour, t.minute, t.second) device, serialno = ViewClient.connectToDeviceOrExit(serialno=None) wake_device(device, serialno) # keymap reference: # https://github.com/dtmilano/AndroidViewClient/blob/master/src/com/dtmilano/android/adb/androidkeymap.py device.press("HOME") time.sleep(0.5) trials = [] batch_count = 1 while num_iter > 0: log("-------- batch_run #{} --------".format(batch_count)) trials_batch = [] trials_batch += playback_task_run(device, num_iter=min([num_iter, BATCH_SIZE])) trials_batch += playback_format_task_run(device, num_iter=min([num_iter, BATCH_SIZE])) trials_batch += playback_GoogleMusic_run(device, serialno, num_iter=min([num_iter, BATCH_SIZE])) map(lambda trial: trial.put_extra(name="batch_id", value=batch_count), trials_batch) trials += trials_batch with open("{}/{}/{}".format(ROOT_DIR, REPORT_DIR, filename), "w") as f: f.write(TrialHelper.to_json(trials)) num_iter -= BATCH_SIZE batch_count += 1 AudioFunction.finalize() Logger.finalize() ''' # initail componet Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() if PLATFORM == WINDOWS: os.system("mkdir {}/{} ".format(ROOT_DIR, REPORT_DIR)) elif PLATFORM == LINUX: os.system("mkdir -p {}/{} ".format(ROOT_DIR, REPORT_DIR)) t = datetime.datetime.now() filename = "report_{}{:02d}{:02d}_{:02d}{:02d}{:02d}.json".format( t.year, t.month, t.day, t.hour, t.minute, t.second) trials = [] if serialno1: device1, serialno1 = ViewClient.connectToDeviceOrExit( serialno=serialno1) target_sn = serialno1 log(serialno1) if serialno2: device2, serialno2 = ViewClient.connectToDeviceOrExit( serialno=serialno2) test_sn = serialno2 log(serialno2) if serialno1 is None or serialno2 is None: log("please input 2 phone serialno") return time.sleep(1) wake_device(device1, serialno1) time.sleep(1) wake_device(device2, serialno2) time.sleep(1) device1.press("HOME") device2.press("HOME") time.sleep(1) original = get_Auto_Mute_Mode() #disable_Auto_Mute_Mode() batch_count = 1 while num_iter > 0: trials_batch = [] # target control_MO_phone out phone log("start target MO") ret = control_MO_phone(device1, serialno1, True) if ret is False: log("can't out phone call") control_Stop_Call(device1, serialno1) continue else: log("phone call out: TX test") # test control_MT_phone then recive phone ret = control_MT_phone(device2, serialno2) if ret is False: log("can't answer phone call") control_Stop_Call(device1, serialno1) continue else: log("phone call start: TX test") if not detect_DQ_start(device1, serialno1): log("can't detect DQ log start") # add trials for DQ continue log("-------- batch_run #{} --------".format(batch_count)) # phone call start trials_batch += phone_call_tx_task() time.sleep(2) trials_batch += phone_call_rx_task() control_Stop_Call(device1, serialno1) if not detect_DQ_stop(device1, serialno1): log("can't detect DQ log stop") continue map(lambda trial: trial.put_extra(name="batch_id", value=batch_count), trials_batch) trials += trials_batch with open("{}/{}/{}".format(ROOT_DIR, REPORT_DIR, filename), "w") as f: f.write(TrialHelper.to_json(trials)) num_iter -= BATCH_SIZE batch_count += 1 ####### change_soundcard_setting(0) set_Auto_Mute_Mode(original) log("-------- set_Auto_Mute_Mode --------") Logger.finalize()
def run(num_iter, serialno): Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) # Logger.init(Logger.Mode.STDOUT) Adb.init() Adb.execute(["root"], serialno=serialno) Adb.execute(["shell", "'echo \'related\' > msm_subsys'"], serialno=serialno) Adb.execute(["shell", "svc", "power", "stayon", "true"], serialno=serialno) out, err = Adb.execute(["shell", "getprop", "ro.vendor.build.fingerprint"], serialno=serialno) out = out.strip() log("build number: '{}'".format(out)) latest_dmesg = fetch_dmesg(serialno=serialno) latest_dmesg = latest_dmesg[0] if len(latest_dmesg) > 0 else None pass_trial_cnt = 0 try: for i in range(num_iter): log("-------------------- CS call test #{} --------------------". format(i + 1)) events = fetch_setmode_events(serialno=serialno) latest_event = events[-1] if len(events) > 0 else None log("The latest setMode event: '{}'".format( latest_event.raw if latest_event else "None")) log("Make call to 0988102544") start_cs_call(tel="0988102544", serialno=serialno) log("Waiting to the mode 'MODE_IN_CALL'") if not wait_for_phone_state(state=2, timeout=10, serialno=serialno): log("The phone state never turns in 'MODE_IN_CALL', ignore this trial" ) continue log("To check if ADSP crashes during the CS call") is_passed = True pass_trial_cnt += 1 retry = 15 while retry > 0: new_dmesgs = fetch_dmesg(latest_dmesg, serialno=serialno) if len(new_dmesgs) > 0: latest_dmesg = new_dmesgs[-1] adsp_ssr_demsgs = filter( lambda x: "Restart sequence requested for adsp" in x. raw, new_dmesgs) if len(adsp_ssr_demsgs) > 0: for dmesg in adsp_ssr_demsgs: log("SSR log detected: '{}'".format(dmesg.raw)) is_passed = False phone_state = get_phone_state(serialno=serialno) if phone_state == None: log("the phone state is unobtainable, something wrong") is_passed = False if phone_state == 0: log("the phone state is in idle, the call might be dropped" ) is_passed = False if not is_passed: out, err = Adb.execute(["bugreport"]) log("bugreport to '{}'".format(out.strip())) pass_trial_cnt -= 1 break if retry % 5 == 0: log("switch path to '{}'".format("speaker" if retry / 5 % 2 == 1 else "receiver")) Adb.execute(["shell", "input", "tap", "1000", "1000"], tolog=False, serialno=serialno) retry -= 1 time.sleep(1) log("result: {} ({}/{})".format("pass" if retry == 0 else "fail", pass_trial_cnt, i + 1)) end_cs_call(serialno=serialno) time.sleep(10) except: pass Adb.execute(["shell", "svc", "power", "stayon", "false"], serialno=serialno) Logger.finalize()
def run(num_iter=1, is_MO=False): # initail componet Logger.init(Logger.Mode.BOTH_FILE_AND_STDOUT) Adb.init() if PLATFORM == WINDOWS: os.system("mkdir {}/{} ".format(ROOT_DIR, REPORT_DIR)) elif PLATFORM == LINUX: os.system("mkdir -p {}/{} ".format(ROOT_DIR, REPORT_DIR)) t = datetime.datetime.now() filename = "report_{}{:02d}{:02d}_{:02d}{:02d}{:02d}.json".format( t.year, t.month, t.day, t.hour, t.minute, t.second) trials = [] device, serialno = ViewClient.connectToDeviceOrExit(serialno=None) log(serialno) time.sleep(1) wake_device(device, serialno) time.sleep(1) device.press("HOME") if is_MO: log("This test is running as MO call") notAnsweredTimes = 0 test_count = 0 #start to test MO call tx log("===== Now is running as MO tx test for {} times =====".format( num_iter)) while test_count < num_iter and notAnsweredTimes <= 5: # MO start to call target log("MO start to call target ({})".format(test_count + 1)) ret = control_MO_phone(device, serialno, True) if ret is False: log("control_MO_phone failed: cannot dial out") control_Stop_Call(device, serialno) continue else: log("MO call: dial out success!") time.sleep(1) # Waiting target answer the call timeout = 30 isCallAnswered = False log("Waiting target answer our call in {} secs".format(timeout)) while (timeout > 0): if (get_callDuration_id(device, serialno)): log("Target has answered our call!") isCallAnswered = True break else: log("Target not yet answered... {}".format(timeout)) timeout -= 3 if (isCallAnswered): test_count += 1 log("-------- batch_run #{} --------".format(test_count)) play_sound_and_wait_cut(device, serialno) else: log("Timeout: 30 secs") log("Target didn't answer our call...") control_Stop_Call(device, serialno) notAnsweredTimes += 1 if not detect_DQ_stop(device, serialno): log("can't detect DQ log stop") continue #start to test MO call rx #reset test_count test_count = 0 log("===== Now is running as MO rx test for {} times =====".format( num_iter)) while test_count < num_iter and notAnsweredTimes <= 5: trials_batch = [] # MO start to call target log("MO start to call target ({})".format(test_count + 1)) ret = control_MO_phone(device, serialno, True) if ret is False: log("control_MO_phone failed: cannot dial out") control_Stop_Call(device, serialno) continue else: log("MO call: dial out success") time.sleep(1) # phone call start timeout = 30 isCallAnswered = False log("Waiting target answer our call in {} secs".format(timeout)) while (timeout > 0): if (get_callDuration_id(device, serialno)): log("Target has answered our call!") isCallAnswered = True break else: log("Target not yet answered... {}".format(timeout)) timeout -= 3 if (isCallAnswered): test_count += 1 log("-------- batch_run #{} --------".format(test_count)) trials_batch += detect_sound_task() map( lambda trial: trial.put_extra(name="batch_id", value=test_count), trials_batch) trials += trials_batch with open("{}/{}/{}".format(ROOT_DIR, REPORT_DIR, filename), "w") as f: f.write(TrialHelper.to_json(trials)) log("MO hang up the call...") control_Stop_Call(device, serialno) else: log("Timeout: 30 secs") log("Target didn't answer our call...") control_Stop_Call(device, serialno) notAnsweredTimes += 1 if not detect_DQ_stop(device, serialno): log("can't detect DQ log stop") continue else: log("This test is running as MT call") log("===== Now is running as MT rx test for {} times =====".format( num_iter)) test_count = 0 #start to test MT call rx while test_count < num_iter: trials_batch = [] # test control_MT_phone then recive phone ret = control_MT_phone(device, serialno) if ret is False: log("Timeout: no phone call comming") Logger.finalize() return # phone call start log("Detected: answer the call") log("Phone call start: MT detect sound") test_count += 1 log("-------- batch_run #{} --------".format(test_count)) log("phone_call_task_rx_run++") trials_batch += detect_sound_task() map( lambda trial: trial.put_extra(name="batch_id", value=test_count), trials_batch) trials += trials_batch with open("{}/{}/{}".format(ROOT_DIR, REPORT_DIR, filename), "w") as f: f.write(TrialHelper.to_json(trials)) log("MT hang up the call...") control_Stop_Call(device, serialno) log("phone_call_task_rx_run--") #start to test MT call tx #reset test_count test_count = 0 log("===== Now is running as MT tx test for {} times =====".format( num_iter)) while test_count < num_iter: # test control_MT_phone then recive phone ret = control_MT_phone(device, serialno) if ret is False: log("Timeout: no phone call comming") Logger.finalize() return # phone call start log("Detected: answer the call") log("Phone call start: MT play sound") test_count += 1 log("-------- batch_run #{} --------".format(test_count)) log("MT_call_play_sound_task++") play_sound_and_wait_cut(device, serialno) log("MT_call_play_sound_task--") Logger.finalize()