Exemplo n.º 1
0
def discharge_battery(targetlevel, currlevel=None, model=None):
    if not model:
        model = get_default_phone_model()

    if not currlevel:
        currlevel = get_battery_level()

    model.disable_charging()  # In case it wasn't already disabled
    while currlevel != targetlevel:
        wait_for_drop()
        currlevel = get_battery_level()
        write_same_line("Discharging to {}, currently at {}".format(
            str(targetlevel), str(get_battery_level())))
    finish_same_line()
Exemplo n.º 2
0
def wait_for_drop():
    dropped = False
    level = parse_battery_info(get_battery_info())["level"]
    starttime = time.time()
    finish_same_line()
    while not dropped:
        currlevel = parse_battery_info(get_battery_info())["level"]
        if level != currlevel:
            dropped = True
            break
        time.sleep(5)
        currtime = time.time()
        write_same_line("Time elapsed waiting for drop: {} seconds".format(
            str(currtime - starttime)))
    finish_same_line()
Exemplo n.º 3
0
def charge_battery(targetlevel, model=None):
    if not model:
        model = get_default_phone_model()

    currlevel = get_battery_level()
    decrease = False
    if currlevel == targetlevel:
        discharge_battery(currlevel - 1, currlevel=currlevel, model=model)
        currlevel = get_battery_level()

    print("Started charging...")
    model.enable_charging()
    while currlevel < targetlevel:
        time.sleep(5)
        currlevel = get_battery_level()
        write_same_line("Charging to {}, curently at {}".format(
            str(targetlevel), str(currlevel)))
    finish_same_line()

    print("Finished charging, disabling it now...")
    model.disable_charging()
def main(args):
    OUTPUT = args.output

    print("Running OS baseline test.\n")
    print("Make sure you have no apps running in the background.")
    print("Make sure that there is a wakelock app running.")
    print("Charging is disabled at the beginning of the test")
    print("and then enabled when we reach 5%.")

    _ = input("Press enter when ready...")
    ds = DataSaver(OUTPUT)
    ds.start()

    print("Getting Phone Model...")
    model = get_phone_model()
    print("Is the model %s correct?" % model.model)
    input("Press Enter to confirm...")

    print("Disabling charging...")
    model.disable_charging()
    input("Is it disabled?")
    print("Start time: {}".format(datetime.datetime.utcnow()))

    try:
        level = 1000
        prevcharge = 0
        prevlevel = 0
        prevtemp = 0
        while level != FINALLEVEL:
            start = time.time()

            info = parse_battery_info(get_battery_info())
            info["timestamp"] = time.time()
            ds.add(info, "batterydata")
            level = int(info["level"])

            if (prevcharge != info["Charge counter"] or prevlevel != level
                    or prevtemp != info["temperature"]):
                finish_same_line()
            write_same_line("{} | Current capacity: {}%, {}, Temp: {}".format(
                datetime.datetime.utcnow(),
                str(level),
                info["Charge counter"],
                info["temperature"],
            ))

            prevlevel = level
            prevcharge = info["Charge counter"]
            prevtemp = info["temperature"]

            end = time.time()
            telapsed = end - start

            if telapsed < RESOLUTION:
                time.sleep(RESOLUTION - telapsed)
    except Exception as e:
        model.enable_charging()
        raise

    finish_same_line()

    print("Enabling charging...")
    model.enable_charging()

    print("Stopping data saver...")
    ds.stop_running()
    print("Done.")
def main(args):
    OUTPUT = args.output

    print("Running Android Pre/Post test.\n")
    print("Make sure you have no extra apps running in the background.")
    print("Make sure that there is a wakelock app running"
          "(if going passed 30 minutes of testing).")
    print("Charging is disabled before the test starts. It is")
    print("enabled automatically when we reach the end of the test.")

    _ = input("Press enter when ready...")
    ds = DataSaver(OUTPUT)
    ds.start()

    print("Getting Phone Model...")
    model = get_phone_model()
    print("Is the model %s correct?" % model.model)
    input("Press Enter to confirm...")

    print("Disabling charging...")
    model.disable_charging()
    input("Is it disabled?")

    input("When the test is ready, start the recording by pressing enter...")

    print("Waiting for a percentage drop...")
    #wait_for_drop()
    print("Drop detected, starting test")
    print("Start time: {}".format(datetime.datetime.utcnow()))

    info = parse_battery_info(get_battery_info())
    info["timestamp"] = time.time()
    starttime = info["timestamp"]
    ds.add(info, "batterydata")

    print("Starting values:")
    for k, v in info.items():
        print("{}: {}".format(k, v))

    currtime = 0
    testtime_seconds = TESTTIME * 60
    while currtime - starttime < testtime_seconds:
        time.sleep(5)
        currtime = time.time()
        write_same_line("Elapsed time (seconds): {}".format(
            str(currtime - starttime)))
    finish_same_line()

    info = parse_battery_info(get_battery_info())
    info["timestamp"] = time.time()
    ds.add(info, "batterydata")

    print("End time: {}".format(datetime.datetime.utcnow()))
    print("Final values:")
    for k, v in info.items():
        print("{}: {}".format(k, v))

    print("Enabling charging...")
    model.enable_charging()

    print("Stopping data saver...")
    ds.stop_running()
    print("Done.")
Exemplo n.º 6
0
def main(args):
    OUTPUT = args.output

    print("Running OS baseline (percent-split) test.\n")
    print("Make sure you have no apps running in the background.")
    print("Make sure that there is a wakelock app running.")
    print("Charging is disabled and enabled periodically throughout "
          "the tests to gather {} trials for {} percentage ranges.".format(
              str(TRIALS), str(len(PERCENT_INTERVALS))))

    _ = input("Press enter when ready...")
    ds = DataSaver(OUTPUT)
    ds.start()

    print("Getting Phone Model...")
    model = get_phone_model()
    print("Is the model %s correct?" % model.model)
    input("Press Enter to confirm...")

    print("Disabling charging...")
    model.disable_charging()
    input("Is it disabled?")

    for startpercent, endpercent in PERCENT_INTERVALS:
        print("\nOn percent interval: {} to {}".format(startpercent,
                                                       endpercent))
        trialtimes = []
        for trialnum in range(TRIALS):
            print("\nRunning trial {}, current times are {}".format(
                trialnum, str(trialtimes)))
            print("Start time: {}".format(datetime.datetime.utcnow()))
            info = parse_battery_info(get_battery_info())
            if int(info["level"]) <= startpercent:
                charge_battery(startpercent, model=model)
            elif int(info["level"]) > startpercent:
                discharge_battery(startpercent, model=model)

            dname = "pc_breakdown_{}-{}-{}".format(startpercent, endpercent,
                                                   trialnum)
            outputdir = os.path.join(ds.output, dname)
            os.mkdir(outputdir)

            starttime = time.time()

            try:
                level = 1000
                prevcharge = 0
                prevlevel = 0
                prevtemp = 0
                while level > endpercent:  # end percent is inclusive
                    start = time.time()

                    info = parse_battery_info(get_battery_info())
                    info["timestamp"] = time.time()
                    ds.add(info, os.path.join(dname, "batterydata"))
                    level = int(info["level"])

                    if (prevcharge != info["Charge counter"]
                            or prevlevel != level
                            or prevtemp != info["temperature"]):
                        finish_same_line()
                    write_same_line(
                        "{} | Current capacity: {}%, {}, Temp: {}".format(
                            datetime.datetime.utcnow(),
                            str(level),
                            info["Charge counter"],
                            info["temperature"],
                        ))

                    prevlevel = level
                    prevcharge = info["Charge counter"]
                    prevtemp = info["temperature"]

                    end = time.time()
                    telapsed = end - start

                    if telapsed < RESOLUTION:
                        time.sleep(RESOLUTION - telapsed)
            except Exception as e:
                model.enable_charging()
                raise

            endtime = time.time()
            trialtimes.append(endtime - starttime)

            finish_same_line()

        print("Trial times for {} to {}: {}".format(startpercent, endpercent,
                                                    str(trialtimes)))

        ds.add(
            {"trial-times": trialtimes},
            "ttimes_pc_breakdown_{}-{}".format(startpercent, endpercent),
        )

    print("Enabling charging...")
    model.enable_charging()

    print("Stopping data saver...")
    ds.stop_running()
    print("Done.")