Beispiel #1
0
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 record_task_run(device, serialno):
    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)

    def stop_then_play():
        log("thread stops the playback")
        AudioFunction.stop_audio()
        time.sleep(4)
        log("thread starts the playback")
        AudioFunction.play_sound(out_freq=OUT_FREQ)
        log("thread returns")

    threading.Thread(target=stop_then_play).start()
    log("Waiting for {} Hz pure tone detected".format(OUT_FREQ))
    elapsed = th.wait_for_event(
        DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10)
    log("elapsed: {} ms".format(elapsed))

    time.sleep(1)

    log("Trying to wait a timeout event")
    elapsed = th.wait_for_event(
        DetectionStateChangeListenerThread.Event.FALLING_EDGE, timeout=10)
    log("elapsed: {} ms".format(elapsed))

    log("dev_record_stop")
    AATApp.record_stop(device)

    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()
    th.join()

    AudioFunction.stop_audio()
Beispiel #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()
        log("trigger_asr() for idle")
        trigger_asr(serialno)
        #time.sleep(5)

        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

        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("-------- 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
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
Beispiel #5
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
Beispiel #6
0
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