def test_long_loop_read_of_memtrack(self): null_pipe = open(os.devnull, 'w') AdbUtils._run_adb_cmd("dmesg -c", add_ticks=False) long_loop_read_proc_cmd = 'for i in 1 2 3 4 5 6 7 8 9 10; do while :; ' \ 'do cat /sys/class/drm/card0/gfx_memtrack/* > /dev/null; done & done' long_loop_proc = subprocess.Popen(long_loop_read_proc_cmd, shell=True, stdout=null_pipe, stderr=subprocess.STDOUT) try: # launch youtube and watch a video UiAutomatorUtils.launch_activity_with_data_uri( MemTrack.youtube_sample_video) if self.d(text=OS_OPEN_JUST_ONCE_TXT).wait.exists(timeout=3000): self.d(text=OS_OPEN_JUST_ONCE_TXT).click() self.assertTrue( self.d(packageName=YOUTUBE_PACKAGE_NAME).wait.exists( timeout=10000)) # let the youtube play for some time time.sleep(10) # check for potential errors error_msgs_cmd = "dmesg" output = AdbUtils._run_adb_cmd(error_msgs_cmd, add_ticks=False) self.assertTrue(" trace " not in output) self.assertTrue(" bug " not in output) self.assertTrue(" stack " not in output) finally: long_loop_proc.terminate() os.kill(long_loop_proc.pid, signal.SIGTERM) ShellUtils.kill_processes_containing_string("gfx_memtrack")
def setUp(self): super(Messaging, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self.d = g_common_obj.get_device() UiAutomatorUtils.unlock_screen() resource.disable_app_verification() _apk_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "GCM", "gcm_listener") g_common_obj.adb_cmd_common("install -r %s" % _apk_path) self._jar_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "GCM", "gcm_sender") self._proxy_file = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "Proxy", "http_proxy") with open(self._proxy_file) as pf: self._proxy = pf.read().strip('\n') """ Get Android version: adb shell getprop | grep ro.build.version.sdk """ cmd = 'getprop | grep ro.build.version.sdk' sdk_string = g_common_obj.adb_cmd_capture_msg(cmd) if '24' in sdk_string: self.android_version = "N" elif '23' in sdk_string: self.android_version = "M" elif '22' in sdk_string: self.android_version = "L"
def setUp(self): super(Bug_Report, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self.d = g_common_obj.get_device() self.func = Func_New() self.conf = TestConfig().read(section='google_account') self.username = self.conf.get("user_name") self.passwd = self.conf.get("password") UiAutomatorUtils.unlock_screen()
def setUp(self): super(DataUsage, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self._cts_test = CTS_Impl() UiAutomatorUtils.unlock_screen() resource.disable_app_verification() _apk_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "SDK_API", "api_test") g_common_obj.adb_cmd_common("install -r %s" % _apk_path)
def setUp(self): super(SystemTimeUpdate, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self.d = g_common_obj.get_device() UiAutomatorUtils.unlock_screen() resource.disable_app_verification() self.screenshooter = ScreenshotUtils() _apk_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "SDK_API", "system_api") g_common_obj.adb_cmd_common("install -r %s" % _apk_path)
def setUp(self): super(Recents_20, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self.d = g_common_obj.get_device() UiAutomatorUtils.unlock_screen() resource.disable_app_verification() for i in range(1, 21): _apk_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "20recents", str(i)) g_common_obj.adb_cmd_common("install -r %s" % _apk_path)
def setUp(self): super(Clock_Alarm_Reboot, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self.d = g_common_obj.get_device() UiAutomatorUtils.unlock_screen() resource.disable_app_verification() for i in ["api_test", "system_api"]: _apk_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "SDK_API", i) g_common_obj.adb_cmd_common("install -r %s" % _apk_path)
def setUp(self): super(Calendar_Reminder, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self.c = Calendar() self.d = g_common_obj.get_device() UiAutomatorUtils.unlock_screen() resource.disable_app_verification() _apk_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "SDK_API", "api_test") g_common_obj.adb_cmd_common("install -r %s" % _apk_path)
def setUp(self): super(ImmersiveMode, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self.d = g_common_obj.get_device() UiAutomatorUtils.unlock_screen() resource.disable_app_verification() self.screenshooter = ScreenshotUtils() for i in ["temple_run", "immersive_ui"]: _apk_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "ImmersiveMode", i) g_common_obj.adb_cmd_common("install -r %s" % _apk_path)
def setUp(self): super(MemTrack, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self.d = g_common_obj.get_device() UiAutomatorUtils.unlock_screen() for i in ["device_ui", "jank_test"]: _apk_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "CTS_APKS", i) g_common_obj.adb_cmd_common("install -r %s" % _apk_path) _bin_path = resource.get_resource_from_atifactory\ ("tests.tablet.artifactory.conf", "BIN", "memtrack") g_common_obj.adb_cmd_common("push %s /data/" % _bin_path)
def test_screenshot_video_playback(self): UiAutomatorUtils.launch_activity_with_data_uri( Screenshot.youtube_sample_video) if self.d(text=OS_OPEN_JUST_ONCE_TXT).wait.exists(timeout=3000): self.d(text=OS_OPEN_JUST_ONCE_TXT).click() self.assertTrue( self.d(packageName=YOUTUBE_PACKAGE_NAME).wait.exists( timeout=10000)) # wait for the video to start time.sleep(10) self.screenshooter.take_screenshot() # wait for misc error messages to appear time.sleep(2) self.assertTrue( self.d(packageName=YOUTUBE_PACKAGE_NAME).wait.exists(timeout=1000))
def test_immersive_mode(self): UiAutomatorUtils.launch_app_from_apps_menu( SYSTEM_OS_IMMERSIVE_APP_SHORTCUT_NAME) # enter immersive mode self.assertTrue( self.d(text=SYSTEM_OS_ENTER_IMMERSIVE_MODE_TXT).wait.exists( timeout=4000)) self.d(text=SYSTEM_OS_ENTER_IMMERSIVE_MODE_TXT).click() # wait for immersive mode time.sleep(3) self.screenshooter.take_screenshot() StatusBar.open_notifications(nr_of_swipes=2) time.sleep(1) self.screenshooter.take_screenshot() # check if status bar is showing after swipe self.assertFalse(self.screenshooter.same_screenshots(-1, -2))
def test_alarm_after_reboot(self): hh, mm, ss = Calendar.get_current_dut_time() result = SystemApiTestsInterface.run_instrumentation( class_name="CommonTestsDriver", method_name="testDisableAutoTime", instrumentation_args=None, runner_name="GenericArgumentPassingTestRunner") self.assertTrue( SystemApiTestsInterface.was_instrumentation_test_successful( result), "Could not disable auto time sync") try: # set an alarm at least 250 seconds into the future alarm_time = Clock.set_new_alarm(hh, mm, offset=120) hh, mm, ss = Calendar.get_current_dut_time() current_time = datetime.datetime(1, 1, 1, int(hh), int(mm), int(ss)) time.sleep(5) reboot_time = UiAutomatorUtils.reboot_device() UiAutomatorUtils.unlock_screen() time_delta = alarm_time - current_time sleep_time = time_delta.seconds - reboot_time if sleep_time > 0: LOG.info("sleeping for %s seconds" % time_delta.seconds) time.sleep(sleep_time) self.d.open.notification() self.assertTrue(self.d(text="Alarm").wait.exists(timeout=3000)) if EnvironmentUtils.get_android_version() == "N": self.assertTrue( self.d(text=CLOCK_SNOOZE_ALARM_TXT_N).wait.exists( timeout=3000)) self.assertTrue( self.d(textContains=CLOCK_DISMISS_ALARM_TXT_N).wait.exists( timeout=3000)) self.d(text=CLOCK_DISMISS_ALARM_TXT_N).click() else: self.assertTrue( self.d(text=CLOCK_SNOOZE_ALARM_TXT).wait.exists( timeout=3000)) self.assertTrue( self.d(textContains=CLOCK_DISMISS_ALARM_TXT).wait.exists( timeout=3000)) self.d(text=CLOCK_DISMISS_ALARM_TXT).click() finally: Clock.delete_all_alarms()
def test_show_GPU_view_updates(self): def get_gpu_update_pixels(x, y, color): return color[0] >= 245 and color[1] <= 150 and color[2] <= 150 Settings.enable_gpu_show_updates() time.sleep(3) try: for i in range(5): self.screenshooter.take_screenshot() show_update_pixels = self.screenshooter.search_for_pixels( get_gpu_update_pixels) pixels_percent = 1.0 * len(show_update_pixels) / ( self.screenshooter.screen_width * self.screenshooter.screen_height) * 100 LOG.info("Percent of update pixels: " + str(pixels_percent)) if pixels_percent >= 60: return # Number of update pixels greater than 60%. Test passed. ScreenSwiper.swipe_up() self.assertTrue(False, "Could not find any update pixels") finally: UiAutomatorUtils.close_all_tasks() Settings.enable_gpu_show_updates()
def test_verify_20_recent_apps(self): activity_string_template = "com.example.test$NR$/.MainActivity" app_string_template = "com.example.test$NR$" UiAutomatorUtils.close_all_tasks() for i in range(1, 21): package_name = app_string_template.replace("$NR$", str(i)) activity_string = activity_string_template.replace("$NR$", str(i)) AdbUtils.start_activity_from_shell(activity_string) self.d(packageName=package_name).wait.exists(timeout=3000) AdbUtils.force_stop_app(package_name) # wait a little for the tasks to be registered with the visual manager component nr_of_dismissed_tasks = 0 # hack to count a large number of dismissed tasks while True: task_dismissed_at_current_step = UiAutomatorUtils.close_all_tasks() nr_of_dismissed_tasks += task_dismissed_at_current_step if task_dismissed_at_current_step == 0: break print nr_of_dismissed_tasks LOG.info("dismissed " + str(nr_of_dismissed_tasks) + " tasks") self.assertTrue(nr_of_dismissed_tasks >= 20, "test was not able to dismiss 20 recent tasks")
def test_system_time_update(self): result = SystemApiTestsInterface.run_instrumentation(class_name="CommonTestsDriver", method_name="testDisableAutoTime", instrumentation_args=None, runner_name="GenericArgumentPassingTestRunner") self.assertTrue(SystemApiTestsInterface.was_instrumentation_test_successful(result), "Could not disable auto time sync") initial_system_time = SystemUtils.get_system_time() LOG.info("initial time: " + str(initial_system_time)) initial_hour_format = SystemUtils.get_hour_format() LOG.info("initial hour format: " + str(initial_hour_format)) new_system_time = initial_system_time.copy() new_system_time.min = 0 new_system_time.day = 2 new_system_time.time_zone = "Cuba" hour_format_toggle = {12: 24, 24: 12} new_hour_format = hour_format_toggle[initial_hour_format] try: self.assertTrue(SystemUtils.set_hour_format(new_hour_format), "could not set new hour format") self.assertTrue(SystemUtils.set_system_time(new_system_time), "could not set new System time") reboot_time = UiAutomatorUtils.reboot_device() LOG.info("reboot time was: " + str(reboot_time)) UiAutomatorUtils.unlock_screen() system_time_after_reboot = SystemUtils.get_system_time() LOG.info("after reboot time: " + str(system_time_after_reboot)) hour_format_after_reboot = SystemUtils.get_hour_format() LOG.info("after reboot hour format: " + str(hour_format_after_reboot)) self.assertTrue(system_time_after_reboot.time_zone == new_system_time.time_zone, "timezone did not persist after reboot") self.assertTrue(abs(system_time_after_reboot.day - new_system_time.day) < 2, "system day did not persist after reboot") self.assertTrue(system_time_after_reboot.min <= new_system_time.min + 2 * reboot_time / 60 + 5, "system minute was affected by the reboot") self.assertTrue(hour_format_after_reboot == new_hour_format, "system hour format was affected by the reboot") finally: SystemUtils.set_hour_format(initial_hour_format) SystemUtils.set_system_time(initial_system_time)
def test_safe_mode_by_property(self): g_common_obj.root_on_device() set_safemode_cmd = "setprop persist.sys.safemode 1" g_common_obj.adb_cmd(set_safemode_cmd) AdbUtils.reboot_device() UiAutomatorUtils.unlock_screen() g_common_obj.root_on_device() try: UiAutomatorUtils.launch_app_from_apps_menu("API Demos") except: print "Pass" else: assert None, "The 3rd party app is still visible in all apps menu when DUT in safe mode!" AdbUtils.reboot_device() UiAutomatorUtils.unlock_screen() g_common_obj.root_on_device() try: UiAutomatorUtils.launch_app_from_apps_menu("API Demos") except: assert None, "The 3rd party app is invisible in all apps menu when DUT is not in safe mode!" else: print "Pass"
def test_memtrack_effect_framerate(self): def run_memtrack(): global memtrack_proc MemTrack.memtrack_proc = AdbUtils.get_adb_cmd_process( MemTrack.memtrack_loop_cmd) def run_jank_test(): jank_runner = InstrumentationInterface() MemTrack.jank_test_output = jank_runner.run_instrumentation( "android.cts.jank.ui.CtsDeviceJankUi", "", "android.cts.jank/android.support.test.runner.AndroidJUnitRunner" ) # must stop python uiautomator in order to run the jank test AdbUtils.kill_python_uiautomator_rpc_server_on_dut() # initial run of jank test run_jank_test() LOG.info("initial run of the jank test yielded: " + MemTrack.jank_test_output) self.assertTrue( InstrumentationInterface.was_instrumentation_test_successful( MemTrack.jank_test_output), "initial run of the jank test was not successful") fps_values = re.findall("\|fps\|(\d+\.\d+)", MemTrack.jank_test_output) self.assertTrue( len(fps_values) > 0, "could not find fps information in jank test output") initial_fps_value = float(fps_values[0]) UiAutomatorUtils.close_all_tasks() # must stop python uiautomator in order to run the jank test AdbUtils.kill_python_uiautomator_rpc_server_on_dut() # subsequent run of the jank test, with memtrack running along side memtrack_thread = Thread(target=run_memtrack) jank_thread = Thread(target=run_jank_test) LOG.info("Starting memtrack") memtrack_thread.start() time.sleep(0.5) # allow memtrack to start before running the jank test LOG.info("Starting jank ui on dut") jank_thread.start() jank_thread.join() MemTrack.memtrack_proc.kill() # kill memtrack so the thread will join memtrack_thread.join() LOG.info("second run of the jank test yielded: " + MemTrack.jank_test_output) self.assertTrue( InstrumentationInterface.was_instrumentation_test_successful( MemTrack.jank_test_output), "second run of the jank test was not successful") fps_values = re.findall("\|fps\|(\d+\.\d+)", MemTrack.jank_test_output) self.assertTrue( len(fps_values) > 0, "could not find fps information in jank test output") second_fps_value = float(fps_values[0]) LOG.info("initial fps value: %s, second fps value: %s" % (initial_fps_value, second_fps_value)) self.assertTrue( second_fps_value < initial_fps_value, "fps when running memtrack was not smaller than " "fps without running memtrack")
def test_SmartLock_TrustedLocation(self): trusted_place = "Havana, Cuba" try: # Enable location LOG.info("Enabling location") Settings.enable_location() # Enable screen lock pin and add a trusted place (current location) LOG.info("Enabling PIN screen lock") Settings.enable_pin() LOG.info("Adding trusted place - current location") Settings.add_trusted_place() self.d.press.home() # Lock the screen LOG.info("Locking the screen") self.d.press.power() time.sleep(5) # Unlock the device LOG.info("Unlocking the screen") UiAutomatorUtils.unlock_screen() LOG.info("Checking the PIN keyguard in NOT present") assert not self.d( resourceId=ANDROID_KEYGUARD_PIN_VIEW_RESID ).wait.exists( timeout=5000 ), "The keyguard should not be present in the current trusted place" time.sleep(3) #Below "if" codes is to handle an info window of trusted unlocking. if self.d(resourceId=SETTINGS_TRUSTED_FIRST_TIME_RESID).exists: self.d(resourceId=SETTINGS_TRUSTED_FIRST_TIME_RESID).click() # Remove the current trusted place LOG.info("Removing the current trusted place") Settings.remove_trusted_place() # Add a trusted place in another location LOG.info("Adding trusted place - {0}".format(trusted_place)) Settings.add_trusted_place(trusted_place) self.d.press.home() # Lock the screen LOG.info("Locking the screen") self.d.press.power() time.sleep(2) # Unlock the device LOG.info("unlocking the screen") UiAutomatorUtils.unlock_screen() LOG.info( "Checking the PIN keyguard is present in a non-trusted place") assert self.d( resourceId=ANDROID_KEYGUARD_PIN_VIEW_RESID).wait.exists( timeout=5000 ), "The keyguard should appear when not in a trusted location" # Input the PIN via shell AdbUtils.input_text(TEST_PIN) time.sleep(1) self.d.press.enter() time.sleep(3) # Remove the trusted place LOG.info("Removing the trusted place - {0}".format(trusted_place)) Settings.remove_trusted_place(trusted_place) except Exception, e: AdbUtils.input_text(TEST_PIN) time.sleep(3) self.d.press.enter() time.sleep(5) raise e
def tearDown(self): # UiAutomatorUtils.close_all_tasks() # Settings.disable_location() Settings.disable_pin() UiAutomatorUtils.close_all_tasks()
def setUp(self): super(SmartLockTrustedLocation, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name self.d = g_common_obj.get_device() UiAutomatorUtils.unlock_screen()
def setUp(self): super(AutomotiveProfile, self).setUp() self.__test_name = __name__ LOG.debug("Setup: %s" % self.__test_name) UiAutomatorUtils.unlock_screen()
def tearDown(self): UiAutomatorUtils.close_all_tasks()
def test_safe_mode_by_ui(self): """Test case to start DUT in safe mode through UI. :return: None """ unlock_screen() g_common_obj.root_on_device() # Below command will work in Android release above 'M' for longpress # POWER # longpress_power = "input keyevent --longpress POWER" # g_common_obj.adb_cmd(longpress_power) # simulating longpress POWER through sendevent cmd1 = 'sendevent /dev/input/event0 1 116 1' cmd2 = 'sendevent /dev/input/event0 0 0 0' cmd3 = 'sendevent /dev/input/event0 1 116 0' while [0-3]: g_common_obj.adb_cmd(cmd1) g_common_obj.adb_cmd(cmd2) time.sleep(2) g_common_obj.adb_cmd(cmd3) g_common_obj.adb_cmd(cmd2) if g_common_obj.d(text="Power off").exists: g_common_obj.d(text="Power off").long_click() g_common_obj.d(text="OK").click() break timeout = 300 count = 6 sleep_time = 5 time.sleep(sleep_time) while count < timeout: time.sleep(sleep_time) prop_val = g_common_obj.adb_cmd_capture_msg('getprop ' 'sys.boot_completed') if '1' in prop_val: LOG.debug("dut booted in safe mode successfully") break count += sleep_time g_common_obj.root_on_device() unlock_screen() failed = False try: UiAutomatorUtils.launch_app_from_apps_menu("API Demos") except: LOG.debug("3rd party apps are not seen in Safe mode") else: LOG.error("3rd party app is still visible in all apps menu when " "DUT is in safe mode!") # below is added to not exit code failed = True AdbUtils.reboot_device() time.sleep(sleep_time+sleep_time) g_common_obj.root_on_device() unlock_screen() if failed == False: try: UiAutomatorUtils.launch_app_from_apps_menu("API Demos") except: LOG.error("3rd party app is invisible in all apps menu when " "DUT is not in safe mode!") assert False, "3rd party app is invisible in all apps menu " \ "when DUT is not in safe mode!" else: LOG.debug("3rd party apps are visible in all apps menu when " "DUT is not in safe mode") assert True else: assert False, "3rd party app is still visible in all apps menu " \ "when DUT is in safe mode!"
def setUp(self): super(ScreenRecording, self).setUp() self.__test_name = __name__ print "Setup: %s" % self.__test_name UiAutomatorUtils.unlock_screen()