def recordHD_task_run(device, serialno, num_iter=1): log("record_HD_task_run++") package = "com.htc.audiofunctionsdemo" activity = ".activities.MainActivity" component = package + "/" + activity cmd = " ".join(["am", "force-stop", package]) trials = [] device.startActivity(component=component) time.sleep(1) log("dev_record_start") time.sleep(3) for i in range(num_iter): log("-------- record_task #{} --------".format(i + 1)) trial = Trial(taskname="recordHD") trial.put_extra(name="iter_id", value=i + 1) log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ)) AudioFunction.play_sound(out_freq=OUT_FREQ) # record HD start log("-> record HD start") AATApp.recordHD_start(device) time.sleep(10) # stop play log("AudioFunction.stop_audio()") AudioFunction.stop_audio() # stop record log("-> record HD stop") AATApp.record_stop(device) time.sleep(3) # analysis file pull_files(serialno, file_path) ret = judge_record(file_name) if ret: log("-> record HD function: pass") trial.put_extra(name="record HD", value="pass") else: log("-> record HD function: fail") trial.invalidate(errormsg="record HD fail") trials.append(trial) trials.append(trial) #delete_file(serialno, file_name, file_path) device.shell(cmd) log("record_task_run--") return trials
def phone_call_rx_task(): log("phone_call_task_rx_run++") trials = [] trial = Trial(taskname="phonecall_task_rx") change_soundcard_setting(1) log("change_soundcard_setting(1)") disable_Auto_Mute_Mode() playbackThread = PlaybackThread() recordThread = RecordThread() th = DetectionStateChangeListenerThread() th.start() ToneDetector.start_listen( target_freq=OUT_FREQ, cb=lambda event: th.tone_detected_event_cb(event), recordThread=recordThread) playbackThread.start() time.sleep(1) recordThread.start() log("-> phone call rx start:") if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate(errormsg="rx task fail") trials.append(trial) else: log("-> phone call rx: pass") trial.put_extra(name="phone call rx", value="pass") SINK_PORT recordThread.stopRecord() playbackThread.stopPlayback() trials.append(trial) time.sleep(1) if playbackThread.isrun: playbackThread.join() if recordThread.isrun: recordThread.join() ToneDetector.stop_listen() th.join() return trials
def phone_call_tx_task(device, serialno): log("phone_call_task_tx_run++") trials = [] trial = Trial(taskname="phonecall_task_tx") playbackThread = PlaybackThread() playbackThread.start() time.sleep(1) while True: if (not get_callDuration_id(device, serialno)): log("Detect phone has been cut off...") log("Stop music") playbackThread.stopPlayback() time.sleep(2) if playbackThread.isrun: playbackThread.join() return else: log("Phone call has not been cut off by target...")
def phone_call_rx_task(): trials = [] trial = Trial(taskname="phonecall_task_rx") recordThread = RecordThread() th = DetectionStateChangeListenerThread() th.start() ToneDetector.start_listen( target_freq=440, cb=lambda event: th.tone_detected_event_cb(event), recordThread=recordThread) recordThread.start() log("->Start detecting rx sound") if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=8) < 0: log("->the rx sound was not detected, abort the iteration this time..." ) trial.invalidate(errormsg="rx task fail") else: log("-> phone call rx: pass") trial.put_extra(name="phone call rx", value="pass") recordThread.stopRecord() trials.append(trial) time.sleep(1) if recordThread.isrun: recordThread.join() ToneDetector.stop_listen() th.join() return trials
def record_task_run(device, serialno, num_iter=1, num_freqs=1): log("record_task_run++") log("launch AAT app") AATApp.launch_app(device) time.sleep(2) trials = [] log("dev_record_start") AATApp.record_start(device) time.sleep(2) stm = DetectionStateListener() def gen_freq(): import random return 440. * 2**(random.randint(-12, 12) / 12.) for i in range(num_iter): log("-------- record_task #{} --------".format(i + 1)) trial = Trial(taskname="record", pass_check= \ lambda t: "result" in t.ds["extra"].keys() and t.ds["extra"]["result"] == "pass") trial.put_extra(name="iter_id", value=i + 1) AATApp.print_log(device, severity="i", tag=TAG, log="record_task #{}".format(i + 1)) result = "pass" freqs = [] for _ in range(num_freqs): stm.clear() target_freq = gen_freq() freqs.append(target_freq) log("ToneDetector.start_listen(serialno={}, target_freq={})". format(serialno, target_freq)) ToneDetector.start_listen( serialno=serialno, target_freq=target_freq, cb=lambda event: stm.tone_detected_event_cb(event)) time.sleep(2) log("AudioFunction.play_sound(out_freq={})".format(target_freq)) AudioFunction.play_sound(out_freq=target_freq) if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=10) < 0: log("The {}Hz tone is not detected".format(target_freq)) now = "_".join("{}".format(datetime.datetime.now()).split()) log("dump the recorded pcm to \"sdcard/PyAAT/dump_{}\"".format( now)) AATApp.record_dump(device, "sdcard/PyAAT/dump_{}".format(now)) log("start dumping the process during capturing the frequency..." ) ToneDetector.WORK_THREAD.dump() result = "failed" log("ToneDetectorForDeviceThread.adb-read-prop-max-elapsed: {} ms".format( \ ToneDetector.WORK_THREAD.extra["adb-read-prop-max-elapsed"])) log("ToneDetectorForDeviceThread.freq-cb-max-elapsed: {} ms".format( \ ToneDetector.WORK_THREAD.extra["freq-cb-max-elapsed"])) AudioFunction.stop_audio() ToneDetector.stop_listen() time.sleep(2) trial.put_extra(name="result", value=result) trial.put_extra(name="test_freqs", value=freqs) trials.append(trial) log("dev_record_stop") AATApp.record_stop(device) time.sleep(2) log("record_task_run--") return trials
def playback_task_run(num_iter, num_seek_test, gmhandler): log("playback_task_run++") if not gmhandler.cache_init: log("gmhandler.walk_through()") if not gmhandler.walk_through(): log("failed to walk through the UI of the google music") gmhandler.dump() return [] log("gmhandler.cache\n{}".format( json.dumps(gmhandler.cache, indent=4, ensure_ascii=False))) else: log("gmhandler.to_top()") gmhandler.to_top() if not gmhandler.to_control_panel(): log("failed to go to the control panel of the google music") gmhandler.dump() return [] trials = [] def gmplayback_pass_check(trial): subtasknames = ["pause", "resume", "next", "start", "seek"] for subtaskname in subtasknames: if not subtaskname in trial.ds["extra"].keys(): return False subtask_result = trial.ds["extra"][subtaskname] if isinstance(subtask_result, str) and subtask_result != "pass": return False if isinstance(subtask_result, dict) and subtask_result["result"] != "pass": return False return True stm = DetectionStateListener() for i in range(num_iter): log("-------- playback_task #{} --------".format(i + 1)) trial = Trial(taskname="playback", pass_check=gmplayback_pass_check) trial.put_extra(name="iter_id", value=i + 1) song = gmhandler.control_panel.get_current_song() log("the current song:\n{}".format( json.dumps(song, indent=4, ensure_ascii=False))) trial.put_extra(name="song_title", value=song["name"]) target_freq = int(song["name"].split("Hz")[0]) stm.clear() log("ToneDetector.start_listen(target_freq={})".format(target_freq)) ToneDetector.start_listen( target_freq=target_freq, cb=lambda event: stm.tone_detected_event_cb(event)) gmhandler.control_panel.play() time.sleep(1) if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=10) < 0: log("The {}Hz tone is not detected....".format(target_freq)) trial.put_extra("start", "failed") else: log("The {}Hz tone is detected".format(target_freq)) trial.put_extra("start", "pass") gmhandler.control_panel.play_pause() if stm.wait_for_event(DetectionStateListener.Event.INACTIVE, timeout=10) < 0: log("The {}Hz tone seems not to be stopped".format(target_freq)) trial.put_extra("pause", "failed") else: log("The {}Hz tone has been stopped".format(target_freq)) trial.put_extra("pause", "pass") gmhandler.control_panel.play_pause() if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=10) < 0: log("The {}Hz tone is not resumed....".format(target_freq)) trial.put_extra("resume", "failed") else: log("The {}Hz tone is resumed".format(target_freq)) trial.put_extra("resume", "pass") result = "pass" for _ in range(num_seek_test): import random v = random.uniform(0., 1.) * 0.9 log("seek to {}".format(v)) gmhandler.control_panel.seek(v) time.sleep(0.1) if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=10) < 0: log("seek failed: the {}Hz tone is not detected".format( target_freq)) result = "failed" trial.put_extra("seek", { "num_trials": num_seek_test, "result": result }) ToneDetector.stop_listen() stm.clear() gmhandler.control_panel.next() song = gmhandler.control_panel.get_current_song() log("the current song:\n{}".format( json.dumps(song, indent=4, ensure_ascii=False))) trial.put_extra(name="next_song_title", value=song["name"]) target_freq = int(song["name"].split("Hz")[0]) log("ToneDetector.start_listen(target_freq={})".format(target_freq)) ToneDetector.start_listen( target_freq=target_freq, cb=lambda event: stm.tone_detected_event_cb(event)) if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=10) < 0: log("The {}Hz tone is not detected....".format(target_freq)) trial.put_extra("next", "failed") else: log("The {}Hz tone is detected".format(target_freq)) trial.put_extra("next", "pass") gmhandler.control_panel.play_pause() ToneDetector.stop_listen() time.sleep(1) trials.append(trial) log("playback_task_run--") return trials
def voip_task_run(device, serialno, num_iter=1): log("voip_task_run++") trials = [] # AATApp.voip_use_speaker(device) time.sleep(2) stm = DetectionStateListener() out_freq = OUT_FREQ log("ToneDetector.start_listen(target_freq={})".format(serialno, out_freq)) ToneDetector.start_listen( target_freq=out_freq, cb=lambda event: stm.tone_detected_event_cb(event)) has_triggered_bugreport = False Adb.execute(cmd=["shell", "rm", "-f", "sdcard/AudioFunctionsDemo-record-prop.txt"], \ serialno=serialno) AATApp.voip_start(device) for i in range(num_iter): log("-------- dev_voip_rx_task #{} --------".format(i + 1)) trial = Trial(taskname="voip_rx", pass_check=lambda t: t.ds["extra"]["elapsed"] > 0) trial.put_extra(name="iter_id", value=i + 1) AATApp.print_log(device, severity="i", tag=GLOBAL["tag"], log="voip_rx_task #{}".format(i + 1)) time.sleep(1) stm.reset() if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=10) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate( errormsg="early return, possible reason: rx no sound") trials.append(trial) continue time.sleep(1) log("trigger_{}()".format(GLOBAL["test_config"])) if GLOBAL["test_config"] == "ssr": trigger_ssr(serialno) else: trigger_asr(serialno) log("Waiting for {} recovery".format("SSR" if GLOBAL["test_config"] == "ssr" else "ASR")) elapsed = stm.wait_for_event(DetectionStateListener.Event.RISING_EDGE, timeout=15) log("elapsed: {} ms".format(elapsed)) if elapsed < 0: log("Timeout in waiting for rising event, possibly caused by missing event not being caught" ) log("Waiting for the tone being detected") if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=10) < 0: log("The tone is not detected") if not has_triggered_bugreport: log("get bugreport...") p = trigger_bugreport(device) trial.put_extra("bugreport", p) has_triggered_bugreport = True else: log("The tone is detected, please also check the device log for confirming if it is a false alarm" ) trial.put_extra(name="msg", value="possible false alarm") AATApp.voip_stop(device) time.sleep(5) AATApp.voip_start(device) else: AATApp.voip_stop(device) time.sleep(30 - elapsed / 1000.) AATApp.voip_start(device) trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) log("-------- dev_voip_rx_task done --------") log("ToneDetector.stop_listen()") ToneDetector.stop_listen() stm = DetectionStateListener() time.sleep(2) AATApp.voip_mute_output(device) time.sleep(10) log("ToneDetector.start_listen(serialno={}, target_freq={})".format( serialno, out_freq)) listen_params = { "serialno": serialno, "target_freq": out_freq, "cb": lambda event: stm.tone_detected_event_cb(event), "dclass": ToneDetectorForDeviceThread } try: ToneDetector.start_listen(**listen_params) except: def voip_parse_detector(voip_info): import json info = voip_info[2] for chandle in info: info[chandle] = json.loads(info[chandle]) return info listen_params["params"] = { "detector_reg_func": AATApp.voip_detector_register, "detector_unreg_func": AATApp.voip_detector_unregister, "detector_setparams_func": AATApp.voip_detector_set_params, "info_func": AATApp.voip_info, "parse_detector_func": voip_parse_detector } ToneDetector.start_listen(**listen_params) has_triggered_bugreport = False for i in range(num_iter): log("-------- dev_voip_tx_task #{} --------".format(i + 1)) trial = Trial(taskname="voip_tx", pass_check=lambda t: t.ds["extra"]["elapsed"] > 0) trial.put_extra(name="iter_id", value=i + 1) AATApp.print_log(device, severity="i", tag=GLOBAL["tag"], log="voip_tx_task #{}".format(i + 1)) time.sleep(2) log("AudioFunction.play_sound(out_freq={})".format(out_freq)) AudioFunction.play_sound(out_freq=out_freq) stm.reset() if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=10) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate( errormsg="early return, possible reason: tx no sound") trials.append(trial) continue time.sleep(2) log("trigger_{}()".format(GLOBAL["test_config"])) if GLOBAL["test_config"] == "ssr": trigger_ssr(serialno) else: trigger_asr(serialno) log("waiting for inactive....") stm.wait_for_event(DetectionStateListener.Event.INACTIVE, timeout=10) Adb.execute(cmd=[ "shell", "rm", "-f", "sdcard/AudioFunctionsDemo-record-prop.txt" ], serialno=serialno) log("Waiting for {} recovery".format("SSR" if GLOBAL["test_config"] == "ssr" else "ASR")) elapsed = stm.wait_for_event(DetectionStateListener.Event.RISING_EDGE, timeout=15) log("elapsed: {} ms".format(elapsed)) if elapsed < 0: log("Timeout in waiting for rising event, possibly caused by missing event not being caught" ) log("Waiting for the tone being detected") if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=10) < 0: log("The tone is not detected") if not has_triggered_bugreport: AudioFunction.stop_audio() log("get bugreport...") p = trigger_bugreport(device) trial.put_extra("bugreport", p) has_triggered_bugreport = True now = "_".join("{}".format(datetime.datetime.now()).split()) log("dump the recorded pcm to \"sdcard/PyAAT/dump_{}\"".format( now)) AATApp.record_dump(device, "sdcard/PyAAT/dump_{}".format(now)) log("start dumping the process during capturing the frequency..." ) ToneDetector.WORK_THREAD.dump() else: log("The tone is detected, please also check the device log for confirming if it is a false alarm" ) trial.put_extra(name="msg", value="possible false alarm") log("AudioFunction.stop_audio()") AudioFunction.stop_audio() log("ToneDetectorForDeviceThread.adb-read-prop-max-elapsed: {} ms".format( \ ToneDetector.WORK_THREAD.extra["adb-read-prop-max-elapsed"])) log("ToneDetectorForDeviceThread.freq-cb-max-elapsed: {} ms".format( \ ToneDetector.WORK_THREAD.extra["freq-cb-max-elapsed"])) trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) import random out_freq = OUT_FREQ * 2**(random.randint(0, 12) / 12.) ToneDetector.set_target_frequency(target_freq=out_freq) log("ToneDetector.set_target_frequency(serialno={}, target_freq={})". format(serialno, out_freq)) if elapsed > 0: time.sleep(30 - elapsed / 1000.) log("-------- dev_voip_tx_task done --------") log("dev_voip_stop") AATApp.voip_stop(device) time.sleep(5) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() log("voip_task_run--") relaunch_app(device) return trials
def playback_task_run(device, serialno, num_iter=1, postfix=None): log("playback_task_run++") trials = [] stm = DetectionStateListener() log("ToneDetector.start_listen(target_freq={})".format(OUT_FREQ)) ToneDetector.start_listen( target_freq=OUT_FREQ, cb=lambda event: stm.tone_detected_event_cb(event)) funcs = { "nonoffload": AATApp.playback_nonoffload, "offload": AATApp.playback_offload } files = {"nonoffload": "440Hz_wav.wav", "offload": "440Hz_mp3.mp3"} has_triggered_bugreport = False for i in range(num_iter): log("-------- playback_task #{} --------".format(i + 1)) for name, func in funcs.items(): trial = Trial(taskname="playback_{}".format(name), pass_check=lambda t: t.ds["extra"]["elapsed"] > 0) trial.put_extra(name="iter_id", value=i + 1) AATApp.print_log(device, severity="i", tag=GLOBAL["tag"], log="playback_{}_task #{}".format(name, i + 1)) log("dev_playback_{}_start".format(name)) time.sleep(1) stm.reset() log("reset DetectionStateChangeListener") try: func(device, filename=files[name]) except: func(device, freq=float(files[name].split("Hz")[0])) if name == "offload": time.sleep(5) if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=60) < 0: log("the tone was not detected, abort the iteration this time..." ) AATApp.playback_stop(device) trial.invalidate( errormsg="early return, possible reason: rx no sound") trials.append(trial) continue time.sleep(1) log("trigger_{}()".format(GLOBAL["test_config"])) if GLOBAL["test_config"] == "ssr": trigger_ssr(serialno) else: trigger_asr(serialno) log("Waiting for {} recovery".format( "SSR" if GLOBAL["test_config"] == "ssr" else "ASR")) elapsed = stm.wait_for_event( DetectionStateListener.Event.RISING_EDGE, timeout=15) log("elapsed: {} ms".format(elapsed)) if elapsed < 0: log("Timeout in waiting for rising event, possibly caused by missing event not being caught" ) log("Waiting for the tone being detected") if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=5) < 0: log("The tone is not detected") screenshot_path = "{}-{}.png".format( postfix, int(time.time())) os.system( "python {}/tools-for-dev/dump-screen.py {}/{}_report-bugreport/{}/{}" .format(ROOT_DIR, ROOT_DIR, GLOBAL["test_config"], postfix, screenshot_path)) trial.put_extra("screenshot", screenshot_path) if not has_triggered_bugreport: AATApp.playback_stop(device) log("get bugreport...") p = trigger_bugreport(device) trial.put_extra("bugreport", "{}/{}".format(postfix, p)) has_triggered_bugreport = True else: log("The tone is detected, please also check the device log for confirming if it is a false alarm" ) trial.put_extra(name="msg", value="possible false alarm") trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) log("dev_playback_stop") AATApp.playback_stop(device) stm.wait_for_event(DetectionStateListener.Event.INACTIVE, timeout=5) if elapsed > 0: time.sleep(20 - elapsed / 1000.) log("-------- playback_task done --------") log("ToneDetector.stop_listen()") ToneDetector.stop_listen() log("playback_task_run--") relaunch_app(device) return trials
def playback_GoogleMusic_run(device, serialno, num_iter=1): # Google Music # play # pause # resume # seek # forward log("GoogleMusic playback++") packageGM = "com.google.android.music" activityGM = "com.android.music.activitymanagement.TopLevelActivity" componentGM = packageGM + "/" + activityGM cmd = " ".join(["am", "force-stop", packageGM]) freq = 440 trials = [] th = DetectionStateChangeListenerThread() th.start() for i in range(num_iter): trial = Trial(taskname="GoogleMusic playback") trial.put_extra(name="iter_id", value=i+1) # start google music device.wake() time.sleep(1) device.startActivity(componentGM) log("-> GoogleMusic start") # into Music list log("-> GoogleMusic into Music list") vc, key = get_MusicList_id(device, serialno) if vc is None: log("can't find Music list") trial.invalidate(errormsg="can't find Music list") trials.append(trial) device.shell(cmd) continue log("find the Music list") control_Btn(vc, key) # find 440Hz in list log("-> GoogleMusic find 440Hz in list") vc = ViewClient(device, serialno) view = get_fragment_list_view(device, serialno) uis = UiScrollable(view) for i in range(3): vc, key = get_File_id(device, serialno) if key is None: log("scroll") uis.flingForward() continue else: control_Btn(vc, key) break; # into art pager interface log("-> GoogleMusic into art pager") vc, key = get_ArtPager_id(device, serialno) if vc is None: log("can't find Art Pager") trial.invalidate(errormsg="GoogleMusic can't find Art Pager") trials.append(trial) device.shell(cmd) continue log("find the Art Pager") control_Btn(vc, key) log("ToneDetector.start_listen(target_freq={})".format(freq)) ToneDetector.start_listen(target_freq=freq, cb=lambda event: th.tone_detected_event_cb(event)) th.reset() # the music already start, so detect it... log("-> GoogleMusic start function:") if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate(errormsg="GoogleMusic start play fail") trials.append(trial) device.shell(cmd) continue else: log("-> GoogleMusic start function: pass") trial.put_extra(name="GoogleMusic start", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") # pause log("-> GoogleMusic pause function:") vc, key = get_play_pause_id(device, serialno) if vc is None: log("can't find pause btn") trial.invalidate(errormsg="can't find pause btn") trials.append(trial) device.shell(cmd) continue log("find the pause btn") control_Btn(vc, key) if th.wait_for_event(DetectionStateChangeListenerThread.Event.FALLING_EDGE, timeout=5) < 0: log("the tone was not pause...") trial.invalidate(errormsg="GoogleMusic pause fail") trials.append(trial) device.shell(cmd) continue else: log("-> GoogleMusic pause function: pass") trial.put_extra(name="GoogleMusic pause", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") # resume log("-> GoogleMusic resume function:") vc, key = get_play_pause_id(device, serialno) if vc is None: log("can't find resume btn") trial.invalidate(errormsg="can't find resume btn") trials.append(trial) device.shell(cmd) continue pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") log("find the resume btn") control_Btn(vc, key) if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not resume...") trial.invalidate(errormsg="GoogleMusic resume fail") trials.append(trial) device.shell(cmd) continue else: log("-> GoogleMusic resume function: pass") trial.put_extra(name="GoogleMusic resume", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") time.sleep(1) # seek log("-> GoogleMusic seek function:") vc, key = get_progress_id(device, serialno) if vc is None: log("can't find seek btn") trial.invalidate(errormsg="can't find seek btn") trials.append(trial) device.shell(cmd) continue log("find the seek btn") control_Btn(vc, key) if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("seek fail...") trial.invalidate(errormsg="GoogleMusic seek fail") trials.append(trial) device.shell(cmd) continue else: log("-> GoogleMusic seek function: pass") trial.put_extra(name="GoogleMusic seek", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") time.sleep(1) # next log("-> GoogleMusic next function:") vc, key = get_next_id(device, serialno) if vc is None: log("can't find next btn") trial.invalidate(errormsg="can't find next btn") trials.append(trial) device.shell(cmd) continue log("find the next btn") control_Btn(vc, key) if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("next fail...") trial.invalidate(errormsg="GoogleMusic next fail") trials.append(trial) device.shell(cmd) continue else: log("-> GoogleMusic next function: pass") trial.put_extra(name="GoogleMusic next", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") time.sleep(1) # pause log("-> GoogleMusic pause function:") vc, key = get_play_pause_id(device, serialno) if vc is None: log("can't find pause btn") trial.invalidate(errormsg="can't find pause btn") trials.append(trial) device.shell(cmd) continue log("find the pause btn") control_Btn(vc, key) if th.wait_for_event(DetectionStateChangeListenerThread.Event.FALLING_EDGE, timeout=5) < 0: log("pause fail...") trial.invalidate(errormsg="GoogleMusic pause fail") trials.append(trial) device.shell(cmd) continue else: log("-> GoogleMusic pause function: pass") trial.put_extra(name="GoogleMusic pause", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") time.sleep(1) device.shell(cmd) time.sleep(2) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() device.shell(cmd) th.join() log("GoogleMusic playback--") return trials
def playback_format_task_run(device, num_iter=1): log("playback_format_task_run++") package = "com.htc.audiofunctionsdemo" activity = ".activities.MainActivity" component = package + "/" + activity trials = [] device.startActivity(component=component) th = DetectionStateChangeListenerThread() th.start() funcs = { "nonoffload": AATApp.playback_nonoffload } formats = { "1k_Stereo_48k_16bits_aac.aac": 1000, "1k_Stereo_48k_16bits_wav.wav": 1000, "1k_Stereo_96k_24bits_flac.flac": 1000 } # force stop app string cmd = " ".join(["am", "force-stop", package]) for i in range(num_iter): log("-------- playback_format_task #{} --------".format(i+1)) for name, func in funcs.items(): log("dev_playback_{}_start".format(name)) for file, freq in formats.items(): trial = Trial(taskname="playback_{}_{}".format(name, file)) trial.put_extra(name="iter_id", value=i+1) log("playback_file_{}".format(file)) log("ToneDetector.start_listen(target_freq={})".format(freq)) ToneDetector.start_listen(target_freq=freq, cb=lambda event: th.tone_detected_event_cb(event)) time.sleep(1) th.reset() log("reset DetectionStateChangeListener") func(device, file) log("-> playback start function:") if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") AATApp.playback_stop(device) trial.invalidate(errormsg="start play fail") trials.append(trial) continue else: log("-> playback start function: pass") trial.put_extra(name="playback start", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") time.sleep(0.5) log("-> playback pause function:") th.reset() AATApp.playback_pause_resume(device) #time.sleep(1) if th.wait_for_event(DetectionStateChangeListenerThread.Event.INACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") AATApp.playback_stop(device) trial.invalidate(errormsg="pause fail") trials.append(trial) continue else: log("-> playback pause function: pass") trial.put_extra(name="playback pause", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") time.sleep(1) log("-> playback resume function:") th.reset() AATApp.playback_pause_resume(device) if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") AATApp.playback_stop(device) trial.invalidate(errormsg="resume fail") trials.append(trial) continue else: log("-> playback resume: pass") trial.put_extra(name="playback resume", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") time.sleep(1) log("-> playback seek function:") th.reset() AATApp.playback_seek(device) if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") AATApp.playback_stop(device) trial.invalidate(errormsg="seek fail") trials.append(trial) continue else: log("-> playback seek: pass") trial.put_extra(name="playback seek", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") time.sleep(2) log("-> playback forward function:") th.reset() AATApp.playback_forward(device) if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") AATApp.playback_stop(device) trial.invalidate(errormsg="forward fail") trials.append(trial) continue else: log("-> playback forward function: pass") trial.put_extra(name="playback forward", value="pass") pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") time.sleep(2) th.reset() AATApp.playback_stop(device) log("dev_playback_stop") elapsed = th.wait_for_event(DetectionStateChangeListenerThread.Event.INACTIVE, timeout=5) trial.put_extra(name="elapsed", value=elapsed) pop = AudioFunction.get_pop() if pop: log("pop detect") trial.put_extra(name="playback start", value="pop") trials.append(trial) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() device.shell(cmd) log("playback_task_run--") return trials
def record_task_run(device, serialno, num_iter=1): log("record_task_run++") trials = [] log("dev_record_start") AATApp.record_start(device) time.sleep(2) stm = DetectionStateListener() log("ToneDetector.start_listen(serialno={}, target_freq={})".format( serialno, OUT_FREQ)) ToneDetector.start_listen( serialno=serialno, target_freq=OUT_FREQ, cb=lambda event: stm.tone_detected_event_cb(event)) log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ)) AudioFunction.play_sound(out_freq=OUT_FREQ) time.sleep(3) for i in range(num_iter): log("-------- record_task #{} --------".format(i + 1)) trial = Trial(taskname="record", pass_check=lambda t: t.ds["extra"]["elapsed"] > 0) trial.put_extra(name="iter_id", value=i + 1) AATApp.print_log(device, severity="i", tag=TAG, log="record_task #{}".format(i + 1)) ToneDetector.WORK_THREAD.clear_dump() stm.reset() if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") log("ToneDetectorForDeviceThread.adb-read-prop-max-elapsed: {} ms".format( \ ToneDetector.WORK_THREAD.extra["adb-read-prop-max-elapsed"])) log("ToneDetectorForDeviceThread.freq-cb-max-elapsed: {} ms".format( \ ToneDetector.WORK_THREAD.extra["freq-cb-max-elapsed"])) trial.invalidate( errormsg="early return, possible reason: tx no sound") trials.append(trial) now = "_".join("{}".format(datetime.datetime.now()).split()) log("dump the recorded pcm to \"sdcard/PyAAT/dump_{}\"".format( now)) AATApp.record_dump(device, "sdcard/PyAAT/dump_{}".format(now)) continue log("trigger_ssr()") AATApp.trigger_ssr(device) if PARTIAL_RAMDUMP_ENABLED: handle_ssr_ui() log("Waiting for SSR recovery") elapsed = stm.wait_for_event(DetectionStateListener.Event.RISING_EDGE, timeout=10) if elapsed < 0: log("Timeout in waiting for rising event, possibly caused by missing event not being caught" ) log("Waiting for the tone being detected") if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=5) < 0: log("The tone is not detected") else: log("The tone is detected, please also check the device log for confirming if it is a false alarm" ) log("start dumping the process during capturing the frequency...") ToneDetector.WORK_THREAD.dump() log("elapsed: {} ms".format(elapsed)) if elapsed < 0: now = "_".join("{}".format(datetime.datetime.now()).split()) log("dump the recorded pcm to \"sdcard/PyAAT/dump_{}\"".format( now)) AATApp.record_dump(device, "sdcard/PyAAT/dump_{}".format(now)) log("ToneDetectorForDeviceThread.adb-read-prop-max-elapsed: {} ms".format( \ ToneDetector.WORK_THREAD.extra["adb-read-prop-max-elapsed"])) log("ToneDetectorForDeviceThread.freq-cb-max-elapsed: {} ms".format( \ ToneDetector.WORK_THREAD.extra["freq-cb-max-elapsed"])) if PARTIAL_RAMDUMP_ENABLED: log("Waiting for the partial ramdump completed") handle_ssr_ui() if elapsed >= 0 and not PARTIAL_RAMDUMP_ENABLED: time.sleep(10 - elapsed / 1000.0) trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) log("-------- record_task done --------") log("AudioFunction.stop_audio()") AudioFunction.stop_audio() log("dev_record_stop") AATApp.record_stop(device) time.sleep(5) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() log("record_task_run--") return trials
def playback_task_run(device, num_iter=1): log("playback_task_run++") trials = [] stm = DetectionStateListener() log("ToneDetector.start_listen(target_freq={})".format(OUT_FREQ)) ToneDetector.start_listen( target_freq=OUT_FREQ, cb=lambda event: stm.tone_detected_event_cb(event)) funcs = { "nonoffload": AATApp.playback_nonoffload, "offload": AATApp.playback_offload } files = {"nonoffload": "440Hz_wav.wav", "offload": "440Hz_mp3.mp3"} for i in range(num_iter): log("-------- playback_task #{} --------".format(i + 1)) for name, func in funcs.items(): trial = Trial(taskname="playback_{}".format(name), pass_check=lambda t: t.ds["extra"]["elapsed"] > 0) trial.put_extra(name="iter_id", value=i + 1) AATApp.print_log(device, severity="i", tag=TAG, log="playback_{}_task #{}".format(name, i + 1)) log("dev_playback_{}_start".format(name)) time.sleep(1) stm.reset() log("reset DetectionStateChangeListener") func(device, filename=files[name]) if stm.wait_for_event(DetectionStateListener.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time..." ) AATApp.playback_stop(device) trial.invalidate( errormsg="early return, possible reason: rx no sound") trials.append(trial) continue time.sleep(1) log("trigger_ssr()") AATApp.trigger_ssr(device) if PARTIAL_RAMDUMP_ENABLED: handle_ssr_ui() log("Waiting for SSR recovery") elapsed = stm.wait_for_event( DetectionStateListener.Event.RISING_EDGE, timeout=10) log("elapsed: {} ms".format(elapsed)) if PARTIAL_RAMDUMP_ENABLED: log("Waiting for the partial ramdump completed") handle_ssr_ui() if elapsed >= 0 and not PARTIAL_RAMDUMP_ENABLED: time.sleep(10 - elapsed / 1000.0) trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) log("dev_playback_stop") AATApp.playback_stop(device) stm.wait_for_event(DetectionStateListener.Event.INACTIVE, timeout=5) log("-------- playback_task done --------") log("ToneDetector.stop_listen()") ToneDetector.stop_listen() log("playback_task_run--") return trials
def record_VoiceRecord_run(device, serialno, num_iter=1): # Google Music # play # pause # resume # seek # forward # offload/non-offload log("VoiceReocrd record_task_run++") packageVR = "com.htc.soundrecorder" activityVR = ".SoundRecorderBG" componentVR = packageVR + "/" + activityVR cmd = " ".join(["am", "force-stop", packageVR]) trials = [] for i in range(num_iter): trial = Trial(taskname="VoiceRecord record") trial.put_extra(name="iter_id", value=i + 1) device.wake() log("wake") time.sleep(1) device.startActivity(componentVR) log("startActivity") time.sleep(1) # more option vc, key = get_menu_id(device=device, serialno=serialno) if vc is None: log("can't find more option") trial.invalidate(errormsg="can't find more option") trials.append(trial) device.shell(cmd) continue control_Btn(vc, key) # settings vc, key = get_setting_id(device=device, serialno=serialno) if vc is None: log("can't find setting") trial.invalidate(errormsg="can't find setting") trials.append(trial) device.shell(cmd) continue control_Btn(vc, key) # (ask to name check) # encoding format vc, key = get_encode_id(device=device, serialno=serialno) if vc is None: log("can't find encode") trial.invalidate(errormsg="can't find encode") trials.append(trial) device.shell(cmd) continue control_Btn(vc, key) # flac vc, key = get_flac_id(device=device, serialno=serialno) if vc is None: log("can't find .flac format") trial.invalidate(errormsg="can't find .flac format") trials.append(trial) device.shell(cmd) continue control_Btn(vc, key) # back vc, key = get_back_id(device=device, serialno=serialno) if vc is None: log("can't find back key") trial.invalidate(errormsg="can't find back key") trials.append(trial) device.shell(cmd) continue control_Btn(vc, key) # start record vc, key = get_record_id(device=device, serialno=serialno) if vc is None: log("can't find start record") trial.invalidate(errormsg="can't find start record") trials.append(trial) device.shell(cmd) continue control_Btn(vc, key) log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ)) AudioFunction.play_sound(out_freq=OUT_FREQ) time.sleep(10) # stop record vc, key = get_stop_id(device=device, serialno=serialno) if vc is None: log("can't find stop record") trial.invalidate(errormsg="can't find stop record") trials.append(trial) device.shell(cmd) continue control_Btn(vc, key) log("AudioFunction.stop_audio()") AudioFunction.stop_audio() # rename vc, key = get_rename_edit_id(device=device, serialno=serialno) if vc is None: log("can't find rename edit") trial.invalidate(errormsg="can't find rename edit") trials.append(trial) device.shell(cmd) continue control_Edit(vc, key, "VRecordHD") time.sleep(1) #save vc, key = get_save_id(device=device, serialno=serialno) if vc is None: log("can't find save file btn") trial.invalidate(errormsg="can't find save file btn") trials.append(trial) device.shell(cmd) continue control_Btn(vc, key) # pull file pull_files(serialno, voice_path_1) # judge_record ret = judge_recordV(voice_name, thresh=80) if ret: log("-> VoiceReocrd record HD function: pass") trial.put_extra(name="VoiceReocrd record HD", value="pass") else: log("-> VoiceReocrd record HD function: fail") trial.invalidate(errormsg="VoiceReocrd record HD fail") trials.append(trial) trials.append(trial) delete_file(serialno, voice_name, voice_path_2) device.shell(cmd) log("VoiceReocrd record_task_run--") return trials
def record_task_run(device, serialno, num_iter=1): log("record_task_run++") package = "com.htc.audiofunctionsdemo" activity = ".activities.MainActivity" component = package + "/" + activity trials = [] cmd = " ".join(["am", "force-stop", package]) device.startActivity(component=component) time.sleep(1) log("dev_record_start") AATApp.record_start(device) time.sleep(2) th = DetectionStateChangeListenerThread() th.start() log("ToneDetector.start_listen(serialno={}, target_freq={})".format( serialno, OUT_FREQ)) ToneDetector.start_listen( serialno=serialno, target_freq=OUT_FREQ, cb=lambda event: th.tone_detected_event_cb(event)) log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ)) AudioFunction.play_sound(out_freq=OUT_FREQ) time.sleep(3) for i in range(num_iter): log("-------- record_task #{} --------".format(i + 1)) trial = Trial(taskname="record") trial.put_extra(name="iter_id", value=i + 1) th.reset() if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate( errormsg="early return, possible reason: tx no sound") trials.append(trial) continue else: log("-> record function: pass") trial.put_extra(name="record", value="pass") log("AudioFunction.stop_audio()") AudioFunction.stop_audio() log("dev_record_stop") AATApp.record_stop(device) time.sleep(5) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() device.shell(cmd) log("record_task_run--") return trials
def playback_task_run(device, serialno, num_iter=1): log("playback_task_run++") trials = [] th = DetectionStateChangeListenerThread() th.start() log("ToneDetector.start_listen(target_freq={})".format(OUT_FREQ)) ToneDetector.start_listen( target_freq=OUT_FREQ, cb=lambda event: th.tone_detected_event_cb(event)) funcs = { "nonoffload": AATApp.playback_nonoffload, "offload": AATApp.playback_offload } for i in range(num_iter): log("-------- playback_task #{} --------".format(i + 1)) for name, func in funcs.items(): trial = Trial(taskname="playback_{}".format(name)) trial.put_extra(name="iter_id", value=i + 1) log("dev_playback_{}_start".format(name)) time.sleep(1) th.reset() log("trigger_asr() for idle") trigger_asr(serialno) #time.sleep(2) log("reset DetectionStateChangeListener") func(device) if th.wait_for_event( DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time..." ) AATApp.playback_stop(device) trial.invalidate( errormsg="early return, possible reason: rx no sound") trials.append(trial) continue time.sleep(1) log("trigger_asr()") #AATApp.trigger_ssr(device) trigger_asr(serialno) if PARTIAL_RAMDUMP_ENABLED: handle_ssr_ui() log("Waiting for SSR recovery") elapsed = th.wait_for_event( DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10) log("elapsed: {} ms".format(elapsed)) if PARTIAL_RAMDUMP_ENABLED: log("Waiting for the partial ramdump completed") handle_ssr_ui() if elapsed >= 0 and not PARTIAL_RAMDUMP_ENABLED: time.sleep(10 - elapsed / 1000.0) trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) log("dev_playback_stop") AATApp.playback_stop(device) th.wait_for_event( DetectionStateChangeListenerThread.Event.INACTIVE, timeout=5) log("-------- playback_task done --------") log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() log("playback_task_run--") return trials
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 voip_task_run(device, serialno, num_iter=1): log("voip_task_run++") trials = [] # AATApp.voip_use_speaker(device) time.sleep(2) th = DetectionStateChangeListenerThread() th.start() log("ToneDetector.start_listen(target_freq={})".format(serialno, OUT_FREQ)) ToneDetector.start_listen( target_freq=OUT_FREQ, cb=lambda event: th.tone_detected_event_cb(event)) AATApp.voip_start(device) for i in range(num_iter): log("-------- dev_voip_rx_task #{} --------".format(i + 1)) trial = Trial(taskname="voip_rx") trial.put_extra(name="iter_id", value=i + 1) time.sleep(1) th.reset() log("trigger_asr() for idle") trigger_asr(serialno) #time.sleep(2) if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate( errormsg="early return, possible reason: rx no sound") trials.append(trial) continue time.sleep(1) log("trigger_asr()") #AATApp.trigger_ssr(device) trigger_asr(serialno) if PARTIAL_RAMDUMP_ENABLED: handle_ssr_ui() log("Waiting for ASR recovery") elapsed = th.wait_for_event( DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10) log("elapsed: {} ms".format(elapsed)) if PARTIAL_RAMDUMP_ENABLED: log("Waiting for the partial ramdump completed") handle_ssr_ui() if elapsed >= 0 and not PARTIAL_RAMDUMP_ENABLED: time.sleep(10 - elapsed / 1000.0) trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) log("-------- dev_voip_rx_task done --------") log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() th = DetectionStateChangeListenerThread() th.start() time.sleep(2) AATApp.voip_mute_output(device) time.sleep(10) log("ToneDetector.start_listen(serialno={}, target_freq={})".format( serialno, None)) ToneDetector.start_listen( serialno=serialno, target_freq=None, cb=lambda event: th.tone_detected_event_cb(event)) for i in range(num_iter): log("-------- dev_voip_tx_task #{} --------".format(i + 1)) trial = Trial(taskname="voip_tx") trial.put_extra(name="iter_id", value=i + 1) time.sleep(2) log("trigger_asr() for idle") trigger_asr(serialno) #time.sleep(2) log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ)) AudioFunction.play_sound(out_freq=OUT_FREQ) th.reset() if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate( errormsg="early return, possible reason: tx no sound") trials.append(trial) continue time.sleep(2) log("trigger_asr()") #AATApp.trigger_ssr(device) trigger_asr(serialno) if PARTIAL_RAMDUMP_ENABLED: handle_ssr_ui() log("Waiting for ASR recovery") elapsed = th.wait_for_event( DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10) log("elapsed: {} ms".format(elapsed)) if PARTIAL_RAMDUMP_ENABLED: log("Waiting for the partial ramdump completed") handle_ssr_ui() if elapsed >= 0 and not PARTIAL_RAMDUMP_ENABLED: time.sleep(10 - elapsed / 1000.0) trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) log("AudioFunction.stop_audio()") AudioFunction.stop_audio() log("-------- dev_voip_tx_task done --------") log("dev_voip_stop") AATApp.voip_stop(device) time.sleep(5) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() log("voip_task_run--") return trials
def voip_task_run(device, serialno, num_iter=1): log("voip_task_run++") trials = [] AATApp.voip_use_speaker(device) time.sleep(2) th = DetectionStateChangeListenerThread() th.start() log("ToneDetector.start_listen(target_freq={})".format(serialno, OUT_FREQ)) ToneDetector.start_listen(target_freq=OUT_FREQ, cb=lambda event: th.tone_detected_event_cb(event)) AATApp.voip_start(device) for i in range(num_iter): log("-------- dev_voip_rx_task #{} --------".format(i+1)) trial = Trial(taskname="voip_rx") trial.put_extra(name="iter_id", value=i+1) time.sleep(1) th.reset() if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate(errormsg="early return, possible reason: rx no sound") trials.append(trial) continue else: log("--> VOIP: rx pass") time.sleep(1) trials.append(trial) log("-------- dev_voip_rx_task done --------") log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() th = DetectionStateChangeListenerThread() th.start() time.sleep(2) log("-> VOIP: mute output") AATApp.voip_mute_output(device) time.sleep(10) log("ToneDetector.start_listen(serialno={}, target_freq={})".format(serialno, None)) ToneDetector.start_listen(serialno=serialno, target_freq=None, cb=lambda event: th.tone_detected_event_cb(event)) for i in range(num_iter): log("-------- dev_voip_tx_task #{} --------".format(i+1)) trial = Trial(taskname="voip_tx") trial.put_extra(name="iter_id", value=i+1) time.sleep(2) log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ)) AudioFunction.play_sound(out_freq=OUT_FREQ) th.reset() if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate(errormsg="early return, possible reason: tx no sound") trials.append(trial) continue else: log("--> VOIP: tx pass") time.sleep(2) trials.append(trial) log("AudioFunction.stop_audio()") AudioFunction.stop_audio() log("-------- dev_voip_tx_task done --------") log("dev_voip_stop") AATApp.voip_stop(device) time.sleep(5) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() log("voip_task_run--") return trials