Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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")
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
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()