Пример #1
0
def voip_task_run(device, serialno, num_iter=1):
    log("voip_task_run++")

    trials = []

    # AATApp.voip_use_speaker(device)
    time.sleep(2)

    stm = DetectionStateListener()

    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))

    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=TAG,
                         log="voip_rx_task #{}".format(i + 1))

        time.sleep(1)
        stm.reset()

        if stm.wait_for_event(DetectionStateListener.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_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_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, None))
    ToneDetector.start_listen(
        serialno=serialno,
        target_freq=None,
        cb=lambda event: stm.tone_detected_event_cb(event))

    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=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=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_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("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()

    log("voip_task_run--")
    return trials
Пример #2
0
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
Пример #3
0
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)

    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("--> ssr test record: active pass")

        log("trigger_ssr()")
        AATApp.trigger_ssr(device)

        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 elapsed >= 0:
            log("--> ssr test record: rising pass")

        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()
    th.join()

    log("record_task_run--")
    return trials
Пример #4
0
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
Пример #5
0
def playback_task_run(device, 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("reset DetectionStateChangeListener")

            log("trigger_ssr() for idle")
            AATApp.trigger_ssr(device)

            if PARTIAL_RAMDUMP_ENABLED:
                handle_ssr_ui()
            time.sleep(1)

            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
            else:
                log("--> ssr test playback: active pass")
            time.sleep(1)

            log("trigger_ssr()")
            AATApp.trigger_ssr(device)

            if PARTIAL_RAMDUMP_ENABLED:
                handle_ssr_ui()

            log("Waiting for SSR recovery")
            elapsed = th.wait_for_event(
                DetectionStateChangeListenerThread.Event.RISING_EDGE,
                timeout=5)
            log("elapsed: {} ms".format(elapsed))

            if elapsed >= 0:
                log("--> ssr test playback: rising pass")

            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