class BatterySaver(UIATestBase): def setUp(self): self._test_name = __name__ print "[Setup]: %s" % self._test_name self.emImpl = EMImpl() self.emImpl.adb_root() self.result_dir = self.emImpl.get_tmp_dir() self.wait_time = int( self.emImpl.get_config_value("battery_saver", "wait_time")) self.emImpl.set_screen_status("on") self.emImpl.unlock_screen() self.emImpl.setSleepMode("30 minutes") self.emImpl.set_brightness_level(255) g_common_obj.close_background_apps() super(BatterySaver, self).setUp() def tearDown(self): print "[Teardown]: %s" % self._test_name self.emImpl.check_adb_or_reconnect() self.emImpl.remove_tmp_dir(self.result_dir) super(BatterySaver, self).tearDown() def check_battery_history(self, name=None, data=None): # connect WIFI_ADB ssid, passwd = self.emImpl.read_wifi_conf() self.emImpl.connect_wifi(ssid, passwd) wifi_serial = self.emImpl.enable_wifi_adb() self.emImpl_wifi = EMImpl(wifi_serial) self.emImpl.enable_full_wake_history() self.emImpl.reset_batterystats() self.emImpl.launch_settings("Battery saver") self.emImpl.disconnect_adb() self.emImpl_wifi.open_battery_saver() if name == "record_video": self.emImpl_wifi.grant_permissions_for_camera_app() self.emImpl_wifi.launch_camera("Video") self.emImpl_wifi.click_shutter_button() elif name == "chrome": self.emImpl_wifi.chrome_open_url(data) if data.endswith("mp3"): self.emImpl_wifi.play_audio_chrome() elif data.endswith("mp4"): self.emImpl_wifi.play_video_chrome() elif name == "audio": self.emImpl_wifi.play_media_file("audio/*", data) elif name == "video": self.emImpl_wifi.play_media_file("video/*", data) elif name == "templerun": self.emImpl_wifi.launch_templerun() time.sleep(60) self.emImpl_wifi.play_templerun() elif name == "glbenchmark": self.emImpl_wifi.run_glbenchmark27() time.sleep(self.wait_time) self.emImpl.connect_adb() bugreport_file = self.emImpl.save_bugreport(self.result_dir) html_file = self.emImpl.generate_battery_history_html(bugreport_file) self.emImpl.parse_battery_history_html(html_file) def test_battery_life_compared_record_video(self): """ Test battery life compared record 1080P video max backlight """ print "[RunTest]: %s" % self.__str__() self.check_battery_history(name="record_video") def test_battery_life_compared_chrome_web_browser(self): """ Test battery life compared chrome web browser """ print "[RunTest]: %s" % self.__str__() url = "http://" + self.emImpl.get_server_ip( ) + self.emImpl.get_config_value("webpage", "webgl") self.check_battery_history(name="chrome", data=url) def test_battery_life_compared_chrome_audio_play(self): """ Test battery life compared chrome audio play """ print "[RunTest]: %s" % self.__str__() self.emImpl.close_chrome_tabs() url = "http://" + self.emImpl.get_server_ip( ) + self.emImpl.get_config_value("webpage", "audio_play") self.check_battery_history(name="chrome", data=url) def test_battery_life_compared_chrome_video_play(self): """ Test battery life compared chrome video play """ print "[RunTest]: %s" % self.__str__() self.emImpl.close_chrome_tabs() url = "http://" + self.emImpl.get_server_ip( ) + self.emImpl.get_config_value("webpage", "video_play") self.check_battery_history(name="chrome", data=url) def test_battery_life_compared_audio_play(self): """ Test battery life compared audio play """ print "[RunTest]: %s" % self.__str__() self.emImpl.grant_music_app_permissions() music_file = self.emImpl.push_artifactory_resource( "long_music", "/mnt/sdcard/Music") self.check_battery_history(name="audio", data="file://" + music_file) def test_battery_life_compared_video_play(self): """ Test battery life compared video play """ print "[RunTest]: %s" % self.__str__() video_file = self.emImpl.push_artifactory_resource( "video", "/mnt/sdcard/Movies") self.check_battery_history(name="video", data="file://" + video_file) def test_battery_life_compared_play_3D_game(self): """ Test battery life compared play 3D game """ print "[RunTest]: %s" % self.__str__() temple_run_package = "com.imangi.templerun2" self.emImpl.install_artifactory_app("templerun", temple_run_package) self.check_battery_history(name="templerun") def test_battery_historian_tool(self): """ Test battery historian tool """ print "[RunTest]: %s" % self.__str__() self.check_battery_history() def test_battery_life_compared_glbenchmark27(self): """ Test battery life compared glbenchmark27 """ print "[RunTest]: %s" % self.__str__() app_package = 'com.glbenchmark.glbenchmark27' self.emImpl.install_artifactory_app("glbenchmark", app_package) self.check_battery_history(name="glbenchmark")
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()