示例#1
0
class ChargingLongTime(UIATestBase):
    """
    Connecting CDP charger in MOS and wait one night for 12 hours, check battery increase.
    """
    def setUp(self):
        self._test_name = __name__
        print "[Setup]: %s" % self._test_name
        self.emImpl = EMImpl()
        self.emImpl.set_screen_status("on")
        self.emImpl.unlock_screen()
        g_common_obj.close_background_apps()
        super(ChargingLongTime, self).setUp()

    def tearDown(self):
        super(ChargingLongTime, self).tearDown()
        print "[Teardown]: %s" % self._test_name

    def check_charging_12h(self, charger_type, device_mode=MOS):
        level = self.emImpl.get_battery_level()
        if device_mode == COS:
            self.emImpl.power_off_device()
        else:
            self.emImpl.set_screen_status("off")
            time.sleep(5)
        # charge 12h
        if charger_type == CDP:
            self.emImpl.enable_cdp_charging()
        elif charger_type == DCP:
            self.emImpl.enable_dcp_charging()
        print "Sleep 12h."
        time.sleep(12 * 3600)
        if charger_type != SDP:
            self.emImpl.enable_sdp_charging()
            time.sleep(30)

        if device_mode == COS:
            self.emImpl.boot_up_device()
            self.emImpl.adb_root()
        level = self.emImpl.get_battery_level()
        assert level >= FULL, "charging for 12 hours is not full."

    def check_charging_1h(self, charger_type):
        level1 = self.emImpl.get_battery_level()
        self.emImpl.set_screen_status("off")
        time.sleep(5)
        if charger_type == CDP:
            self.emImpl.enable_cdp_charging()
        elif charger_type == DCP:
            self.emImpl.enable_dcp_charging()
        print "Sleep 1h."
        time.sleep(36)
        if charger_type != SDP:
            self.emImpl.enable_sdp_charging()
        level2 = self.emImpl.get_battery_level()
        assert level2 >= min(FULL, level1 + 10)

    def test_charging_CDP_MOS_12_hours(self):
        self.check_charging_12h(CDP, MOS)

    def test_charging_CDP_COS_12_hours(self):
        self.check_charging_12h(CDP, COS)

    def test_charging_DCP_MOS_12_hours(self):
        self.check_charging_12h(DCP, MOS)

    def test_charging_DCP_COS_12_hours(self):
        self.check_charging_12h(DCP, COS)

    def test_charging_SDP_MOS_12_hours(self):
        self.check_charging_12h(SDP, MOS)

    def test_charging_SDP_COS_12_hours(self):
        self.check_charging_12h(SDP, COS)

    def test_CDP_charging_1_hour(self):
        self.check_charging_1h(CDP)

    def test_DCP_charging_1_hour(self):
        self.check_charging_1h(DCP)

    def test_SDP_charging_1_hour(self):
        self.check_charging_1h(SDP)
class ChargerWakeupSystem(UIATestBase):
    def setUp(self):
        self._test_name = __name__
        print "[Setup]: %s" % self._test_name
        self.emImpl = EMImpl()
        self.suspend_time = int(self.emImpl.get_config_value("s0ix", "suspend_time"))
        self.emImpl.adb_root()
        self.emImpl.set_screen_status("on")
        self.emImpl.unlock_screen()
        self.emImpl.setSleepMode("30 minutes")
        self.emImpl.install_em_tools()
        super(ChargerWakeupSystem, self).setUp()

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        self.emImpl.three_way_cutter_reconnect_sdp(3, 2, 5)
        super(ChargerWakeupSystem, self).tearDown()

    def charger_wakeup_system_in_S0i3(self, charger_type):
        s3_pre = self.emImpl.get_s0i3_suspend_stat()
        self.emImpl.set_screen_status("on")
        self.emImpl.unlock_screen()
        self.emImpl.start_monitor_screen_on_off()
        self.emImpl.set_screen_status("off")
        time.sleep(2)
        if charger_type == SDP:
            self.emImpl.enable_sdp_charging(self.suspend_time, 5)
        elif charger_type == CDP:
            self.emImpl.enable_cdp_charging(self.suspend_time, 5)
        else:
            self.emImpl.enable_dcp_charging(self.suspend_time, 5)
        # wait screen off
        time.sleep(15)
        self.emImpl.three_way_cutter_reconnect_sdp(3, 2, 5)
        self.emImpl.unlock_screen()
        history = self.emImpl.get_screen_on_off_history().split()
        result = True
        if history.count("ON") < 3:
            result = False
        if history.count("OFF") < 3:
            result = False
        s3_post = self.emImpl.get_s0i3_suspend_stat()
        if s3_pre == s3_post:
            result = False
        return result

    def test_DCP_wakeup_system_in_S0i3(self):
        print "[RunTest]: %s" % self.__str__()
        assert self.charger_wakeup_system_in_S0i3(DCP)

    def test_DCP_wakeup_system_in_s0i3_10_times(self):
        print "[RunTest]: %s" % self.__str__()
        fail_num = 0
        cycles = 10
        for i in range(1, 1 + cycles):
            print "[info]--- Cycle: %s/%s" % (i, cycles)
            if not self.charger_wakeup_system_in_S0i3(DCP):
                fail_num += 1
            assert fail_num <= 2, "Failed times: %s" % fail_num

    def test_SDP_CDP_wakeup_system_in_s0i3_10_times(self):
        print "[RunTest]: %s" % self.__str__()
        fail_num = 0
        cycles = 10
        chargers = [SDP, CDP]
        for i in range(1, 1 + cycles):
            print "[info]--- Cycle: %s/%s" % (i, cycles)
            if not self.charger_wakeup_system_in_S0i3(chargers[i % 2]):
                fail_num += 1
            assert fail_num <= 2, "Failed times: %s" % fail_num
class LowBatteryPerformance(UIATestBase):
    def setUp(self):
        self._test_name = __name__
        print "[Setup]: %s" % self._test_name
        self.emImpl = EMImpl()
        self.emImpl.adb_root()
        self.emImpl.set_screen_status("on")
        self.emImpl.unlock_screen()
        self.emImpl.set_sleep_mode("30 minutes")
        self.enable_wifi_adb()
        super(LowBatteryPerformance, self).setUp()

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        self.emImpl.three_way_cutter_reconnect_sdp(3, 2, 5)
        super(LowBatteryPerformance, self).tearDown()

    def enable_wifi_adb(self):
        ssid, passwd = self.emImpl.read_wifi_conf()
        self.emImpl.connect_wifi(ssid, passwd)
        serial_wifi = self.emImpl.enable_wifi_adb()
        self.emImpl_wifi = EMImpl(serial_wifi)

    def prepare_battery_level(self, target_level):
        actual_level = self.emImpl.get_battery_level()
        if actual_level < target_level - 1:
            self.emImpl.set_screen_status("off")
            self.emImpl.enable_dcp_charging(2, 2)
            cycles = 20
            for i in range(1, 1 + cycles):
                wait_time = 60 * (target_level - actual_level)
                print "Cycle: %d/%d, wait %ds" % (i, cycles, wait_time)
                time.sleep(wait_time)
                actual_level = self.emImpl_wifi.get_battery_level()
                if actual_level >= target_level:
                    break
            else:
                assert False
            self.emImpl.three_way_cutter_reconnect_sdp(3, 2, 5)
            self.emImpl.set_screen_status("on")
            self.emImpl.unlock_screen()

        elif actual_level > target_level + 1:
            video_file = self.emImpl.push_artifactory_resource(
                "video", "/mnt/sdcard/Movies")
            self.emImpl.play_media_file("video/*", "file://" + video_file)
            time.sleep(5)
            self.emImpl.set_three_way_cutter_usb(0)
            cycles = 20
            for i in range(1, 1 + cycles):
                wait_time = 60 * (actual_level - target_level)
                print "Cycle: %d/%d, wait %ds" % (i, cycles, wait_time)
                time.sleep(wait_time)
                actual_level = self.emImpl_wifi.get_battery_level()
                if actual_level <= target_level:
                    break
            else:
                assert False
            self.emImpl.three_way_cutter_reconnect_sdp(3, 2, 5)
            self.emImpl.stop_focused_activity()

    def check_low_battery_warning(self, low_level):
        cycles = 20
        for i in range(1, 1 + cycles):
            print "Check low battery warning: %d/%d" % (i, cycles)
            time.sleep(60)
            if self.emImpl_wifi.get_battery_level() <= low_level:
                break
        else:
            assert False, "battery level higher than 15%"
        assert self.emImpl_wifi.check_lowbattery_notification()

    def test_low_battery_warning_15_play_video(self):
        """
        Test low battery warning 15% play video
        """
        print "[RunTest]: %s" % self.__str__()
        self.prepare_battery_level(17)
        video_file = self.emImpl.push_artifactory_resource(
            "video", "/mnt/sdcard/Movies")
        self.emImpl.play_media_file("video/*", "file://" + video_file)
        time.sleep(5)
        self.emImpl.set_three_way_cutter_usb(0)
        self.check_low_battery_warning(15)
        self.emImpl.stop_focused_activity()

    def test_low_battery_warning_15(self):
        """
        Test low battery warning 15
        """
        print "[RunTest]: %s" % self.__str__()
        self.prepare_battery_level(17)
        self.emImpl.set_three_way_cutter_usb(0)
        self.check_low_battery_warning(15)

    def test_low_battery_warning_5(self):
        """
        Test low battery warning 5
        """
        print "[RunTest]: %s" % self.__str__()
        self.prepare_battery_level(7)
        self.emImpl.set_three_way_cutter_usb(0)
        time.sleep(5)
        self.emImpl_wifi.clean_notification()
        self.check_low_battery_warning(5)

    def test_battery_20_discharge_util_shutdown(self):
        print "[RunTest]: %s" % self.__str__()
        self.prepare_battery_level(20)
        video_file = self.emImpl.push_artifactory_resource(
            "video", "/mnt/sdcard/Movies")
        self.emImpl.play_media_file("video/*", "file://" + video_file)
        time.sleep(5)
        self.emImpl.set_three_way_cutter_usb(0)
        for _ in range(20):
            if not self.emImpl_wifi.get_state():
                break
            try:
                level = self.emImpl_wifi.get_battery_level()
            except:
                break
            wait_time = 60 * level + 5
            print "Wait %ds" % wait_time
            time.sleep(wait_time)
        else:
            assert False
        self.emImpl.enable_dcp_charging(2, 2)
        time.sleep(600)
        self.emImpl.enable_sdp_charging(2, 2)
        time.sleep(60)
        self.emImpl.boot_up_device()
        self.emImpl.adb_root()