class GLBenchmarkExtendImpl(GLBenchmarkImpl): """ GLBenchmarkExtendImpl """ # TEST_HD_ETC1 = 'C24Z16 ETC1' # EGYPT_HD = 'C24Z24MS4 Auto' CONFIG_FILE = 'tests.common.glbenchmark.conf' # PKG_NAME = "com.glbenchmark.glbenchmark25" PKG_NAME = "com.glbenchmark.glbenchmark27" # MAIN_ACTIVITY = "com.glbenchmark.activities.MainActivity" MAIN_ACTIVITY = "com.glbenchmark.activities.GLBenchmarkDownloaderActivity" # TEST_ACTIVITY = "com.glbenchmark.activities.GLBenchmarkActivity" TEST_ACTIVITY = "com.glbenchmark.activities.GLBRender" # RESULT_ACTIVITY = "com.glbenchmark.activities.ResultsActivity" RESULT_ACTIVITY = "com.glbenchmark.activities.GLBResults" RESULT_DIR = "/storage/emulated/legacy/Android/data/com.glbenchmark.glbenchmark27/cache/" RESULT_DIR2 = "/storage/emulated/0/Android/data/com.glbenchmark.glbenchmark27/cache/" RESULT_DIR3 = "/data/data/com.glbenchmark.glbenchmark27/cache/" BURSTFREQUENCY = "/d/mali_platform/pm_level" BURSTFREQUENCY2 = "/d/dri/0/i915_frequency_info | grep -i current | grep -Eo '[0-9]+'" BURSTFREQUENCY3 = "/sys/class/thermal/cooling_device0/cur_state" RESULT_KEYS = ['title', 'type', 'texture_type', 'score', 'fps', 'minfps', 'maxfps', 'uom', 'vsync_triggered', 'error', 'error_string'] class TestResult(object): pass class HomeUI(object): """Home UI""" def __init__(self, device): self.device = device @property def performance_test(self): return self.device(resourceId="com.glbenchmark.glbenchmark27:id/listView1") \ .child_by_text( "Performance Tests", allow_scroll_search=True, className="android.widget.TextView" ) class TestList(object): """v2.7 Performance Tests List UI""" TESTLIST = { "Performance Tests": { "test1": "Fill rate/C24Z16 Onscreen 888", "test2": "Fill rate/C24Z16 Offscreen 888", "test3": "Triangle throughput: Textured/C24Z16 Onscreen 888", "test4": "Triangle throughput: Textured/C24Z16 Offscreen 888", "test5": "Triangle throughput: Textured/C24Z16 Onscreen Vertex Lit 888", "test6": "Triangle throughput: Textured/C24Z16 Offscreen Vertex Lit 888", "test7": "Triangle throughput: Textured/C24Z16 Onscreen Fragment Lit 888", "test8": "Triangle throughput: Textured/C24Z16 Offscreen Fragment Lit 888", "test9": "GLBenchmark 2.7 T-Rex HD/C24Z16 Onscreen Auto", "test10": "GLBenchmark 2.7 T-Rex HD/C24Z16 Offscreen Auto", "test11": "GLBenchmark 2.7 T-Rex HD/C24Z16 Onscreen ETC1", "test12": "GLBenchmark 2.7 T-Rex HD/C24Z16 Offscreen ETC1", "test13": "GLBenchmark 2.7 T-Rex HD/C24Z16 Onscreen DXT1", "test14": "GLBenchmark 2.7 T-Rex HD/C24Z16 Offscreen DXT1", "test15": "GLBenchmark 2.7 T-Rex HD/C24Z16 Onscreen PVRTC4", "test16": "GLBenchmark 2.7 T-Rex HD/C24Z16 Offscreen PVRTC4", "test17": "GLBenchmark 2.7 T-Rex HD/C24Z16 Onscreen ETC1to565", "test18": "GLBenchmark 2.7 T-Rex HD/C24Z16 Offscreen ETC1to565", "test19": "GLBenchmark 2.7 T-Rex HD/C24Z24MS4 Onscreen Auto", "test20": "GLBenchmark 2.7 T-Rex HD/C24Z24MS4 Offscreen Auto", "test21": "GLBenchmark 2.7 T-Rex HD/C24Z16 Onscreen Fixed timestep Auto", "test22": "GLBenchmark 2.7 T-Rex HD/C24Z16 Offscreen Fixed timestep Auto", "test23": "GLBenchmark 2.5 Egypt HD/C24Z16 Onscreen Auto", "test24": "GLBenchmark 2.5 Egypt HD/C24Z16 Offscreen Auto", "test25": "GLBenchmark 2.5 Egypt HD/C24Z24MS4 Onscreen Auto", "test26": "GLBenchmark 2.5 Egypt HD/C24Z24MS4 Offscreen Auto", "test27": "GLBenchmark 2.5 Egypt HD/C24Z16 Onscreen Fixed timestep Auto", "test28": "GLBenchmark 2.5 Egypt HD/C24Z16 Offscreen Fixed timestep Auto" } } def __init__(self, device): self.device = device self.testlist = self.TESTLIST def clear_choose(self): if self.btn_all.exists: self.btn_all.click() if self.btn_none.exists: self.btn_none.click() @property def onscreen(self): return self.device(textContains="Onscreen") @property def offscreen(self): return self.device(textContains="Offscreen") @property def btn_all(self): return self.device(className="android.widget.Button", text="All") @property def btn_none(self): return self.device(className="android.widget.Button", text="None") @property def btn_start(self): return self.device(clickable=True, text="Start") def search_item(self, name): return self.device(resourceId="com.glbenchmark.glbenchmark27:id/listView1") \ .child_by_text( name, allow_scroll_search=True, className="android.widget.TextView" ) def select_performance_test(self, testid=None): def _seperate_testid(testid=None): import re return int(re.findall(r'\d+', testid)[0]) parent_text = str(self.testlist["Performance Tests"][testid]).split("/")[0] child_text = str(self.testlist["Performance Tests"][testid]).split("/")[1] if _seperate_testid(testid) > 22: self.device().scroll.toEnd() time.sleep(3) self.device(text=parent_text).down(text=child_text).click() time.sleep(.5) else: self.device().scroll.to(text=child_text) time.sleep(3) self.device(text=child_text).click() time.sleep(.5) def __init__(self): GLBenchmarkImpl.__init__(self) self.device = g_common_obj.get_device() self.home = GLBenchmarkExtendImpl.HomeUI(self.device) self.performc = GLBenchmarkExtendImpl.TestList(self.device) self.configer = TestConfig() self.config = self.configer.read(self.CONFIG_FILE, "GLBenchmark") config_handle = ConfigHandle() self.config["artifactory_location"] = config_handle.read_configuration('artifactory', 'location', '/etc/oat', 'sys.conf') self.arti = Artifactory(self.config.get('artifactory_location')) def setup(self): apk_path = self.arti.get(self.config.get("apk")) cmd = "install -r %s" % (apk_path) print g_common_obj.adb_cmd_common(cmd, 210) def clean(self): cmd = "rm -rf %s; sync;rm -rf %s; sync;" % (self.RESULT_DIR, self.RESULT_DIR2) uninstall_cmd = "pm uninstall %s" % self.PKG_NAME g_common_obj.adb_cmd_capture_msg(repr(cmd)) g_common_obj.adb_cmd_capture_msg(repr(uninstall_cmd)) def launch(self): g_common_obj.launch_app_am(self.PKG_NAME, self.MAIN_ACTIVITY) def resume(self): cmdstr = "am start %s" % (self.pkg_name) g_common_obj.adb_cmd(cmdstr) def run_performance_test_async(self, testid): orientation = self.device.orientation self.home.performance_test.click.wait(timeout=5000) self.performc.clear_choose() self.performc.select_performance_test(testid) self.performc.btn_start.click() time.sleep(5) _, current_activity = common.get_current_focus_window() assert current_activity == self.TEST_ACTIVITY, \ "[FAILURE] Tests failed to start" def run_performance_test(self, testid, timeout=1800): orientation = self.device.orientation self.home.performance_test.click.wait(timeout=5000) self.performc.clear_choose() # print self.performc.onscreen.info['checked'] # if onscreen != self.performc.onscreen.info['checked']: # self.performc.onscreen.click() # if offscreen != self.performc.offscreen.info['checked']: # self.performc.offscreen.click() # # for each in names.split(','): # print "[Debug] performance test: %s" % (each) # if self.performc.search_item(each).exists: # self.performc.search_item(each).click() # checked_count = self.device(className="android.widget.CheckBox", checked=True).count # # assert checked_count == len(names.split(',')), \ # "[FAILURE] Failed Choose Test item" self.performc.select_performance_test(testid) self.performc.btn_start.click() time.sleep(5) _, current_activity = common.get_current_focus_window() assert current_activity == self.TEST_ACTIVITY, \ "[FAILURE] Tests failed to start" # print "[Debug] start test: %s" % (names) start_time = time.time() is_completed = False while time.time() - start_time < timeout: g_common_obj.assert_exp_happens() _, current_activity = common.get_current_focus_window() if current_activity == self.RESULT_ACTIVITY: is_completed = True break time.sleep(10) self.device.orientation = orientation assert is_completed, \ "[FAILURE] Test time out: %s" % (timeout) def run_performance_check_burstfrequency(self, testid, timeout=1800): orientation = self.device.orientation self.home.performance_test.click() self.performc.clear_choose() msg_flag = self.check_burstfrequency() print "msg_flag is %s" % (msg_flag) # if onscreen != self.performc.onscreen.info['checked']: # self.performc.onscreen.click() # if offscreen != self.performc.offscreen.info['checked']: # self.performc.offscreen.click() # # for each in names.split(','): # print "[Debug] performance test: %s" % (each) # if self.performc.search_item(each).exists: # self.performc.search_item(each).click() # time.sleep(3) # checked_count = self.device(className="android.widget.CheckBox", checked=True).count # # assert checked_count == len(names.split(',')), \ # "[FAILURE] Failed Choose Test item" self.performc.select_performance_test(testid) self.performc.btn_start.click() time.sleep(5) _, current_activity = common.get_current_focus_window() assert current_activity == self.TEST_ACTIVITY, \ "[FAILURE] Tests failed to start" # print "[Debug] start test: %s" % (names) start_time = time.time() is_completed = False while time.time() - start_time < timeout: g_common_obj.assert_exp_happens() msg = self.check_burstfrequency() if msg != msg_flag: is_completed = True break time.sleep(3) self.device.orientation = orientation assert is_completed, \ "[FAILURE] Test burst frequency fail:msg is %s" % (msg) def check_all_results(self): cmd = "cat %slast_results_*" % (self.RESULT_DIR) cmd2 = "cat %slast_results_*" % (self.RESULT_DIR2) cmd3 = "cat %slast_results_*" % (self.RESULT_DIR3) msg = g_common_obj.adb_cmd_capture_msg(repr(cmd)) if msg.find("No such file or directory") != -1 or msg == '': msg = g_common_obj.adb_cmd_capture_msg(repr(cmd2)) if msg.find("No such file or directory") != -1 or msg == '': msg = g_common_obj.adb_cmd_capture_msg(repr(cmd3)) assert len(msg), \ "[FAILURE] Failed get result xml: %s" % (cmd) results = self.parse_reulsts(msg) def is_error(x): return x['error'] != '0' errors = [item for item in results if is_error(item)] assert len(errors) == 0, \ "[FAILURE] Error found in results: %s" % (msg) return results def parse_reulsts(self, str_xml): results = [] def parse_items(child): items = {} for item in child: items[item.tag] = item.text assert sorted(items.keys()) == sorted(self.RESULT_KEYS), \ "[FAILURE] Failed parsing result" return items parser = ET.XMLParser(encoding="utf-8") root = ET.fromstring(str_xml, parser=parser) for child in root: results.append(parse_items(child)) return results def check_burstfrequency(self): cmd = "cat %s" % (self.BURSTFREQUENCY) cmd2 = "cat %s" % (self.BURSTFREQUENCY2) cmd3 = "cat %s" % (self.BURSTFREQUENCY3) msg = g_common_obj.adb_cmd_capture_msg(repr(cmd)) if msg.find("No such file or directory") != -1 or msg == '': msg = g_common_obj.adb_cmd_capture_msg(repr(cmd2)) if msg.find("No such file or directory") != -1 or msg == '': msg = g_common_obj.adb_cmd_capture_msg(repr(cmd3)) print "cat msg is %s" % (msg) return msg
class Gfxbench(GLBenchmarkImpl): """ GfxbenchmarkImpl """ CONFIG_FILE = 'tests.common.gfxbench40.conf' PKG_NAME = "com.glbenchmark.glbenchmark27" ROOT_DIR = "/sdcard/Android/data/com.glbenchmark.glbenchmark27/" RESULT_DIR = ROOT_DIR + "files/results/" MAIN_ACTIVITY = "net.kishonti.app.MainActivity" TEST_ACTIVITY = "net.kishonti.benchui.BenchTestActivity" USERNAME = "******" PASSWORD = "******" TEST_GROUPS = ['High-Level Tests', 'Low-Level Tests', 'Special Tests'] def __init__(self): self.device = g_common_obj.get_device() self.configer = TestConfig() self.config = self.configer.read(self.CONFIG_FILE, "Gfxbench40Impl") self.config_handle = ConfigHandle() self.config[ "artifactory_location"] = self.config_handle.read_configuration( 'artifactory', 'location', '/etc/oat', 'sys.conf') self.arti = Artifactory(self.config.get('artifactory_location')) self.apk_path = self.arti.get(self.config.get("apk")) self.remote_apk_cache_path = self.config.get("apk_cache_dir") self.apk_cache_path = self.arti.get(self.config.get("apk_cache_files")) self.apk_cache_name = self.config.get("apk_cache_files").split('/')[-1] def setup(self): gfb = Gfxbench() def _wait_init(timeout=60): """wait app initialize""" start_time = time.time() is_completed = False while time.time() - start_time < timeout: _, current_activity = get_current_focus_window() if current_activity == gfb.MAIN_ACTIVITY: is_completed = True break if gfb.device(text='Accept').exists: gfb.device(text='Accept').click() if gfb.device(text='OK').exists: gfb.device(text='OK').click() if gfb.device(text='Retry').exists: gfb.device(text='Retry').click() time.sleep(5) assert is_completed, \ "[FAILURE] Server timeout: %s" % (timeout) def _clean_chooses(): """check off all checkbox""" def _search_item_checkbox(name): """scroll find checkbox""" if gfb.device(resourceId="com.glbenchmark.glbenchmark27:id/main_testSelectListView")\ .scroll.vert.to(text=name): return gfb.device(text=name).right( className="android.widget.CheckBox") for each in gfb.TEST_GROUPS: checkbox = _search_item_checkbox(each) if checkbox.exists: check = checkbox.info['checked'] if check == True: checkbox.click() else: checkbox.click() checkbox.click() # install apk if not pkgmgr._package_installed(pkgName=self.PKG_NAME): pkgmgr.apk_install(self.apk_path) # Push cache files if not any([ True for i in file_sys.get_file_list(self.remote_apk_cache_path + " -type d -print") if self.PKG_NAME in i ]): busybox_obj.setup() clean_cache_cmd = "rm -rf %s%s" % (self.remote_apk_cache_path, self.PKG_NAME) push_cmd = "push %s %s" % (self.apk_cache_path, self.remote_apk_cache_path) cmd = "busybox tar xvf %s%s -C %s" % (self.remote_apk_cache_path, self.apk_cache_name, self.remote_apk_cache_path) td_cmd = "rm -rf %s%s" % (self.remote_apk_cache_path, self.apk_cache_name) g_common_obj.adb_cmd_capture_msg(clean_cache_cmd) g_common_obj.adb_cmd_common(push_cmd) busybox_obj.adb_busybox_cmd(cmd) g_common_obj.adb_cmd_capture_msg(td_cmd) # Go to main menu g_common_obj.launch_app_am(self.PKG_NAME, self.MAIN_ACTIVITY) _wait_init(240) # Log in account for i in range(4): self.device(className="android.widget.RelativeLayout").swipe.left() time.sleep(1) if not self.device(text=self.USERNAME).exists: self.device(resourceId="com.glbenchmark.glbenchmark27:id/settings_editableUserName").\ set_text(self.USERNAME) time.sleep(1) if not self.device( resourceId= "com.glbenchmark.glbenchmark27:id/settings_editableUserPassword" ).exists: self.device.press.back() time.sleep(1) self.device(resourceId="com.glbenchmark.glbenchmark27:id/settings_editableUserPassword").\ set_text(self.PASSWORD) time.sleep(1) if not self.device( resourceId="com.glbenchmark.glbenchmark27:id/settings_login" ).exists: self.device.press.back() time.sleep(1) self.device( resourceId="com.glbenchmark.glbenchmark27:id/settings_login" ).click.wait() time.sleep(1) for i in range(4): self.device( className="android.widget.RelativeLayout").swipe.right() time.sleep(1) # Show test lists if self.device( resourceId='com.glbenchmark.glbenchmark27:id/main_circleControl' ).exists: bounds = self.device( resourceId='com.glbenchmark.glbenchmark27:id/main_circleControl' ).info['visibleBounds'] for i in range(10): self.device.click( bounds['left'] + (bounds['right'] - bounds['left']) * 0.75, bounds['bottom'] - 20 * i) if self.device(text='Test selection').exists: break assert self.device(text='Test selection').exists, \ "[FAILURE] Failed skip_guide" _clean_chooses() self.device( resourceId="com.glbenchmark.glbenchmark27:id/main_testSelectListView" ).scroll.toBeginning() time.sleep(3) def stop_gfxbenchmark(self): g_common_obj.adb_cmd_capture_msg("am force-stop %s" % self.PKG_NAME) cmd = "rm -rf %s*" % (self.RESULT_DIR) g_common_obj.adb_cmd_capture_msg(cmd) def set_workaround(self): pid = g_common_obj.adb_cmd_capture_msg( "ps | grep 'com.glbenchmark.glbenchmark27' |awk '{print $2}' ") print "PID is %s" % pid if pid: g_common_obj.adb_cmd_capture_msg("'echo -12>/proc/%s/oom_adj'" % pid) oom_adj = g_common_obj.adb_cmd_capture_msg("cat proc/%s/oom_adj" % pid) print oom_adj def clean(self): """uninstall apk""" cmd = "uninstall %s" % (self.PKG_NAME) g_common_obj.adb_cmd_common(cmd) def get_result(self, timeout, test_name): start_time = time.time() while time.time() - start_time < timeout: cmd = "ls %s*" % (self.RESULT_DIR) msg = g_common_obj.adb_cmd_capture_msg(repr(cmd)) if msg.find("No such file or directory") == -1: break time.sleep(10) assert msg.find("No such file or directory") == -1, "Test time out" cmd = "cat %s*/*.json" % (self.RESULT_DIR) result = g_common_obj.adb_cmd_capture_msg(repr(cmd)) assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( test_name, result) def run_test(self, names, timeout=1800): """run test""" for each in names.split(','): print "[Debug] test: %s" % (each) if self.device(resourceId="com.glbenchmark.glbenchmark27:id/main_testSelectListView")\ .scroll.vert.to(text=each): self.device(text=each).right( className="android.widget.CheckBox").click.wait() checked_count = self.device(className="android.widget.CheckBox", checked=True).count assert checked_count == len(names.split(',')),\ "[FAILURE] Failed Choose Test item" self.device(text='Start').click.wait() _, current_activity = get_current_focus_window() assert current_activity == self.TEST_ACTIVITY,\ "[FAILURE] Tests failed to start" print "[Debug] start test: %s" % (names) start_time = time.time() is_completed = False while time.time() - start_time < timeout: _, current_activity = get_current_focus_window() if current_activity == self.MAIN_ACTIVITY: is_completed = True break time.sleep(10) assert is_completed,\ "[FAILURE] Test time out: %s" % (timeout)
class VideoPPImpl: ''' classdocs ''' pkg_name = "com.androvid" activity_name = "com.androvid.videokit.HomeActivity" def __init__(self): self.d = g_common_obj.get_device() self._locator = Locator(self.d) def init_environment(self): """ Init the test environment """ config = TestConfig() cfg_file = 'tests.tablet.artifactory.conf' cfg_arti = config.read(cfg_file, 'artifactory') config_handle = ConfigHandle() cfg_arti["location"] = config_handle.read_configuration('artifactory', 'location', '/etc/oat/', 'sys.conf') cfg = config.read(cfg_file, 'content_androidvid') self.arti = Artifactory(cfg_arti.get('location')) apk_name = cfg.get("name") file_path = self.arti.get(apk_name) print "%s" % file_path result = config_handle.check_apps(self.pkg_name) if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) video_name = cfg.get("video_arti") video_path = self.arti.get(video_name) g_common_obj.adb_cmd_common('push ' + video_path + ' /sdcard/') cmd = "am broadcast -a \ android.intent.action.MEDIA_MOUNTED -d file:///sdcard/" g_common_obj.adb_cmd(cmd) self.video = cfg.get("filename") bench_files = config.read(cfg_file, 'gfxbench31_files') busybox_path = self.arti.get(bench_files.get("busybox")) busybox_tar_path = bench_files.get("busybox_path") print g_common_obj.push_file(busybox_path, busybox_tar_path) print g_common_obj.adb_cmd_capture_msg("chmod 777 " + busybox_tar_path) self.md5_id = config.read(cfg_file, 'md5_id') self.check_path = self.md5_id.get('check_path') def launch_androvid_am(self): """ Launch androvid via adb am command """ print "Launch androvid by adb am" g_common_obj.launch_app_am( VideoPPImpl.pkg_name, VideoPPImpl.activity_name) self._locator.wait_exist(self._locator.performance_tests) if self.d(text="OK").exists: self.d(text="OK").click() time.sleep(2) @staticmethod def stop_androvid_am(): """ Stop androvid via adb am command """ print "Stop androvid by adb am" g_common_obj.stop_app_am(VideoPPImpl.pkg_name) @staticmethod def uninstall_app(): """ uninstall the androvid """ print "Uninstall the androvid" cmd = 'uninstall %s' % VideoPPImpl.pkg_name g_common_obj.adb_cmd_common(cmd) def launch_photos_am(self): """ Launch Photos via adb am command """ print "Launch Photos by adb am" g_common_obj.launch_app_am( "com.google.android.apps.plus", "com.google.android.apps.photos.phone.PhotosHomeActivity") time.sleep(2) if self.d(text="Later").exists: self.d(text="Later").click() time.sleep(2) self._locator.wait_exist(self._locator.performance_tests) time.sleep(5) if self.d(text="No thanks").exists: self.d(text="No thanks").click() time.sleep(5) if self.d(text="Setting up...").exists: time.sleep(30) @staticmethod def stop_photos_am(): """ Stop Photos via adb am command """ print "Stop Photos by adb am" g_common_obj.stop_app_am("com.google.android.apps.plus") def delete_video(self): """ delete the video pushed """ print "delete the video pushed" cmd = "rm -rf /sdcard/%s" % self.video g_common_obj.adb_cmd(cmd) cmd = "rm -rf /sdcard/DCIM/AndroVid/" g_common_obj.adb_cmd(cmd) cmd = "am broadcast -a \ android.intent.action.MEDIA_MOUNTED -d file:///sdcard/" g_common_obj.adb_cmd(cmd) def save_video_as_720p(self): """ Modifie the resolution as 720P """ self.d(className="android.widget.FrameLayout", index=0 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) if self.d(resourceId="com.androvid:id/video_effects_spinner_progress").exists: self.d.press.back() time.sleep(2) self.d(className="android.widget.FrameLayout", index=0 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) self.d(resourceId="com.androvid:id/option_transcode").click() time.sleep(2) self.d(resourceId="android:id/text1").click() self.d(text="720p").click() self.d(resourceId="com.androvid:id/option_transcode").click() time.sleep(3) self.d(text="Continue").click() if self.d(text="Continue").exists: self.d(text="Continue").click() time.sleep(240) self.d(resourceId="com.androvid:id/ringtone_save_button").click() def save_video_as_sepia(self): """ Set Video color effect as Sepia """ self.d(className="android.widget.FrameLayout", index=5 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) if self.d(resourceId="com.androvid:id/video_effects_spinner_progress").exists: self.d.press.back() time.sleep(2) self.d(className="android.widget.FrameLayout", index=5 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) x = self.d.info["displayWidth"] y = self.d.info["displayHeight"] if x > y: self.d(scrollable=True).scroll.vert.to(text="Sepia") else: self.d(scrollable=True).scroll.horiz.to(text="Sepia") time.sleep(2) self.d(text="Sepia").up(resourceId="com.androvid:id/effect_galery_icon" ).click() self.d(description="Apply").click() time.sleep(180) self.d( resourceId="com.androvid:id/ringtone_name_edit").set_text("video") self.d(resourceId="com.androvid:id/ringtone_save_button").click() def save_video_as_vintage(self): """ Set Video color effect as Vintage """ self.d(className="android.widget.FrameLayout", index=5 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) if self.d(resourceId="com.androvid:id/video_effects_spinner_progress").exists: self.d.press.back() time.sleep(2) self.d(className="android.widget.FrameLayout", index=5 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) x = self.d.info["displayWidth"] y = self.d.info["displayHeight"] if x > y: self.d(scrollable=True).scroll.vert.to(text="Vintage") else: self.d(scrollable=True).scroll.horiz.to(text="Vintage") time.sleep(2) self.d(text="Vintage").up( resourceId="com.androvid:id/effect_galery_icon" ).click() self.d(description="Apply").click() time.sleep(180) self.d( resourceId="com.androvid:id/ringtone_name_edit").set_text("video") self.d(resourceId="com.androvid:id/ringtone_save_button").click() def save_video_as_original(self): """ Set Video color effect as Original """ self.d(className="android.widget.FrameLayout", index=5 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(3) if self.d(resourceId="com.androvid:id/video_effects_spinner_progress").exists: self.d.press.back() time.sleep(2) self.d(className="android.widget.FrameLayout", index=5 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(3) self.d(text="Mirror").up(resourceId="com.androvid:id/effect_galery_icon" ).click() self.d(description="Apply").click() time.sleep(5) self.d(text="Cancel").click() time.sleep(2) self.d(text="Original").up(resourceId="com.androvid:id/effect_galery_icon" ).click() self.d(description="Apply").click() cmd = "du /sdcard/DCIM/AndroVid/video/ |awk '{print $1}'" size = g_common_obj.adb_cmd_capture_msg(cmd) assert int(size) == 8, "No Warning!" def save_video_as_1080p(self): """ Modifie the resolution as 1080P """ self.d(className="android.widget.FrameLayout", index=0 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) if self.d(resourceId="com.androvid:id/video_effects_spinner_progress").exists: self.d.press.back() time.sleep(2) self.d(className="android.widget.FrameLayout", index=0 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) self.d(resourceId="com.androvid:id/option_transcode").click() time.sleep(2) self.d(resourceId="android:id/text1").click() self.d(text="1080p").click() self.d(resourceId="com.androvid:id/option_transcode").click() time.sleep(3) self.d(text="Continue").click() if self.d(text="Continue").exists: self.d(text="Continue").click() time.sleep(500) self.d(resourceId="com.androvid:id/ringtone_save_button").click() def save_video_as_160p(self): """ Modifie the resolution as 160P """ self.d(className="android.widget.FrameLayout", index=0 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) if self.d(resourceId="com.androvid:id/video_effects_spinner_progress").exists: self.d.press.back() time.sleep(2) self.d(className="android.widget.FrameLayout", index=0 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) self.d(resourceId="com.androvid:id/option_transcode").click() time.sleep(2) self.d(resourceId="android:id/text1").click() self.d(text="160p").click() self.d(resourceId="com.androvid:id/option_transcode").click() time.sleep(3) self.d(text="Continue").click() if self.d(text="Continue").exists: self.d(text="Continue").click() time.sleep(90) self.d(resourceId="com.androvid:id/ringtone_save_button").click() def save_video_as_rotation(self): """ Modifie the resolution as rotation """ self.d(resourceId="com.androvid:id/home_latest_video1").click() time.sleep(2) if self.d(resourceId="com.androvid:id/video_effects_spinner_progress").exists: self.d.press.back() time.sleep(2) self.d(resourceId="com.androvid:id/home_latest_video1").click() time.sleep(2) self.d( resourceId="com.androvid:id/video_player_menu_videoview").click() self.d(resourceId="com.androvid:id/scrolling_menu_bar").swipe.left() self.d(text="Rotate").click() self.d(textContains="CCW").click() self.d(text="True Rotation (Encode Video)").click() self.d(text="Continue").click() time.sleep(60) self.d( resourceId="com.androvid:id/ringtone_name_edit").set_text("video") self.d(resourceId="com.androvid:id/ringtone_save_button").click() self.d(resourceId="com.androvid:id/overlayPlayButton").click() time.sleep(10) assert self.d(resourceId="com.androvid:id/video_player_menu_videoview" ).exists, "Video didn't playing" def save_video_as_mirror_rotation(self): """ Set Video color effect as mirror and rotation """ self.d(className="android.widget.FrameLayout", index=5 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) if self.d(resourceId="com.androvid:id/video_effects_spinner_progress").exists: self.d.press.back() time.sleep(2) self.d(className="android.widget.FrameLayout", index=5 ).child(resourceId="com.androvid:id/home_scroll_menu_item_icon" ).click() time.sleep(2) if self.d(className="android.widget.ImageButton").exists: self.d(className="android.widget.ImageButton").click() time.sleep(2) self.d(text="Choose Video File").click() time.sleep(2) self.d(resourceId="com.androvid:id/photo_frame_photo").click() time.sleep(2) self.d(text="Mirror").up(resourceId="com.androvid:id/effect_galery_icon" ).click() self.d(description="Apply").click() time.sleep(120) garbage = self.d(resourceId="com.androvid:id/ringtone_name_edit").text self.d(resourceId="com.androvid:id/ringtone_save_button").click() assert self.d(textContains="Saved Successfully" ).exists, "Save video as Mirror not success" self.d.press.menu() self.d(text="Rotate").click() self.d(textContains="CCW").click() self.d(text="True Rotation (Encode Video)").click() self.d(text="Continue").click() time.sleep(60) self.d( resourceId="com.androvid:id/ringtone_name_edit").set_text("video") self.d(resourceId="com.androvid:id/ringtone_save_button").click() cmd = "rm -rf /sdcard/DCIM/AndroVid/video/%s.mp4" % garbage g_common_obj.adb_cmd(cmd) def diff_md5(self, id): """ diff the video's md5 """ self.id = self.arti.get(self.md5_id.get(id)) g_common_obj.adb_cmd_common('push ' + self.id + ' ' + self.check_path) cmd = '"cd /sdcard/DCIM/AndroVid/video/;/data/busybox md5sum -c %s|grep OK"' % id assert g_common_obj.adb_cmd(cmd) == 0, "The video not match"
def commonTest(self, config, section=None): print "[RunTest]: %s" % self.__str__() if not section: section = self.id().split('.')[-1] case_cfg = TestConfig() cfg = case_cfg.read(config, section) config_handle = ConfigHandle() cfg["artifactory_location"] = config_handle.read_configuration( 'artifactory', 'location', '/etc/oat', 'sys.conf') arti = Artifactory(cfg.get('artifactory_location')) stream_fullpath = arti.get(cfg.get("stream")) stream_folder, stream_file = os.path.split(stream_fullpath) stream_name = os.path.basename(stream_file).split('.')[0] local_temp = '%s/%s' % (self.conf.get("local_temp"), stream_name) base_screenshots_path = '%s/base' % (local_temp) down_screenshots_path = '%s/remote' % (local_temp) remote_path = self.conf.get("remote_temp") os.system("rm -rf %s; mkdir -p %s" % (local_temp, local_temp)) os.system("mkdir -p %s" % (base_screenshots_path)) os.system("mkdir -p %s" % (down_screenshots_path)) os.system("rm -rf %s/%s" % (stream_folder, stream_name)) os.system("tar -C %s -zxvf %s" % (stream_folder, stream_fullpath)) os.system("mv -v %s/%s/%s/* %s" \ % (stream_folder, stream_name,\ self.conf.get("screenshots_subpath"), base_screenshots_path)) check_points = [] for path, _, files in os.walk(base_screenshots_path): for _name in files: _point = int(re.findall('\d+', _name)[0]) _full_path = os.path.join(path, _name) _remote_path = '%s/%s/%s/%s'\ % (remote_path, stream_name,\ self.conf.get("screenshots_subpath"), _name) check_points.append((_point, _name, _full_path, _remote_path)) assert check_points, "check_points empty!" check_points = deque(sorted(check_points, key=lambda t: t[0])) print "Check Points\n%s" % ([p[0] for p in check_points]) g_common_obj.adb_cmd_capture_msg("rm -rf %s/%s; sync"\ % (remote_path, stream_name)) ret = g_common_obj.push_file("%s/%s" % (stream_folder, stream_name),\ "%s/%s" % (remote_path, stream_name)) assert ret, 'Failed push %s' % (stream_name) gits_player = self.conf.get("gits_player") while len(check_points) > 0: point1, name1, fullpath1, _remote_path1 = check_points.popleft() point2, name2, fullpath2, _remote_path2 =\ point1, name1, fullpath1, _remote_path1 if len(check_points) > 0: point2, name2, fullpath2, _remote_path2 =\ check_points.popleft() lenth = point2 - point1 if point2 - point1 > 0 else 1 cmd_play = '%s %s/%s --captureFrames %s-%s:%s'\ % (gits_player, remote_path, stream_name,\ point1, point2, lenth) g_common_obj.adb_cmd_capture_msg(cmd_play) pull_path1 = '%s/%s' % (down_screenshots_path, name1) ret = g_common_obj.pull_file(pull_path1, _remote_path1) assert ret, 'Failed get %s' % (_remote_path1) self._diff_imag_file(stream_name, fullpath1, pull_path1) if point1 == point2: continue pull_path2 = '%s/%s' % (down_screenshots_path, name2) ret = g_common_obj.pull_file(pull_path2, _remote_path2) assert ret, 'Failed get %s' % (_remote_path1) self._diff_imag_file(stream_name, fullpath2, pull_path2) g_common_obj.adb_cmd_capture_msg("rm -rf %s/%s; sync"\ % (remote_path, stream_name))
class GfxbenchmarkImpl(GLBenchmarkImpl): """ GfxbenchmarkImpl """ CONFIG_FILE = 'tests.common.gfxbench31.conf' PKG_NAME = "com.glbenchmark.glbenchmark27.corporate" MAIN_ACTIVITY = "net.kishonti.gfxbench.GfxMainActivity" TEST_ACTIVITY = "net.kishonti.gfxbench.TfwActivityEx" LOADING_ACTIVITY = "net.kishonti.benchui.corporate.TestActivityCorporate" TEST_NAME = [ "Manhattan", "T-Rex", "ALU", "Alpha Blending", "Driver Overhead", "Fill" ] TEST_Manhattan = 'Manhattan' TEST_Manhattan_Offscreen = "1080p Manhattan Offscreen" TEST_TRex = 'T-Rex' TEST_TRex_Offscreen = "1080p T-Rex Offscreen" TEST_RenderQuality_HighPrecision = "Render Quality (high precision)" TEST_RenderQuality = "Render Quality" TEST_DriverOverhead = "Driver Overhead" TEST_DriverOverhead_Offscreen = "1080p Driver Overhead Offscreen" TEST_ALU = "ALU" TEST_ALU_Offscreen = "1080p ALU Offscreen" TEST_Alpha_Blending = "Alpha Blending" TEST_Alpha_Blending_offscreen = "1080p Alpha Blending Offscreen" TEST_Fill = "Fill" TEST_Fill_Offscreen = "1080p Fill Offscreen" RESULT_DIR = "/storage/emulated/legacy/Android/data/com.glbenchmark.glbenchmark27.corporate/files/results/" RESULT_DIR2 = "/storage/emulated/0/Android/data/com.glbenchmark.glbenchmark27.corporate/files/results/" class HomeUI(object): """Home UI""" def __init__(self, device): self.device = device @property def main_circle_control(self): return self.device( resourceId='net.kishonti.gfxbench.gl:id/main_circleControl') def test_select(self): """skip selection guide""" self.device(text="Test select").click.wait() time.sleep(2) class TestList(object): """Tests List UI""" def __init__(self, device): self.device = device @property def btn_start(self): return self.device(text='Start') def search_checkbox(self, name): """scroll to find item checkbox""" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] self.device(scrollable=True).scroll.to(text=name) if self.device(text=name).right(text="Not supported") != None: assert not self.device(text=name).right(text="Not supported").exists,\ "[FAILURE] This item %s is not supported" % (name) self.device(text=name).drag.to(x / 2, y / 2) return self.device(text=name)\ .right(className="android.widget.RelativeLayout", index=1)\ .child(className="android.widget.ImageView") def search_item_onscreen_checkbox(self, name): """scroll to find item onscreen checkbox""" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] for _ in range(10): self.device.swipe(x / 2, y / 2, x / 2, y, steps=5) assert self.device(scrollable=True).scroll.to(text=name),\ "[FAILURE] Not found %s item" % (name) return self.device(text=name)\ .right(className="android.widget.RelativeLayout", index=1)\ .child(className="android.widget.ImageView") def search_item_offscreen_checkbox(self, name): """scroll to find item offscreen checkbox""" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] for _ in range(10): self.device.swipe(x / 2, y / 2, x / 2, y, steps=5) assert self.device(scrollable=True).scroll.to(text=name),\ "[FAILURE] Not found %s item" % (name) return self.device(text=name)\ .right(className="android.widget.RelativeLayout", index=2)\ .child(className="android.widget.ImageView") def search_item_special_checkbox(self, name): """scroll to find item offscreen checkbox""" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] for _ in range(10): self.device.swipe(x / 2, y / 2, x / 2, y, steps=5) assert self.device(scrollable=True).scroll.to(text=name),\ "[FAILURE] Not found %s item" % (name) return self.device(text=name)\ .right(className="android.widget.RelativeLayout")\ .child(className="android.widget.ImageView") def __init__(self): GLBenchmarkImpl.__init__(self) self.device = g_common_obj.get_device() self.home = GfxbenchmarkImpl.HomeUI(self.device) self.testlist = GfxbenchmarkImpl.TestList(self.device) self.configer = TestConfig() self.config = self.configer.read(self.CONFIG_FILE, "GfxbenchmarkImpl") config_handle = ConfigHandle() self.config["artifactory_location"] = config_handle.read_configuration( 'artifactory', 'location', '/etc/oat', 'sys.conf') self.arti = Artifactory(self.config.get('artifactory_location')) def setup(self): """install apk""" if not pkgmgr._package_installed(pkgName=self.PKG_NAME): file_path = self.config.get("apk") apk_path = self.arti.get(file_path) pkgmgr.apk_install(apk_path) def set_workaround(self): pid = g_common_obj.adb_cmd_capture_msg( "ps | grep 'com.glbenchmark.glbenchmark27.corporate' |awk '{print $2}' " ) print "PID is %s" % pid if pid is not None: g_common_obj.adb_cmd_capture_msg("'echo -12>/proc/%s/oom_adj'" % pid) oom_adj = g_common_obj.adb_cmd_capture_msg("cat proc/%s/oom_adj" % pid) print oom_adj def clean(self): """uninstall apk""" cmd = "rm -rf %s*.json" % (self.RESULT_DIR) cmd2 = "rm -rf %s*.json" % (self.RESULT_DIR2) g_common_obj.adb_cmd_capture_msg(cmd) g_common_obj.adb_cmd_capture_msg(cmd2) cmd = "uninstall %s" % (self.PKG_NAME) g_common_obj.adb_cmd_common(cmd) def launch_app_from_home_sc(self, appname, appgallery="Apps", inspection=None): """ Launch App from app gallery Parameter appname is the app's widget name in app gallery Parameter appgallery is the widget name of app in home screen Parameter inspection is the text to validate if given app launched Please be aware that this fucntion assumes: 1) There is a app gallery icon in home screen; 2) Your app widget could be found in home screen. If your app meets above 2 assumtions, then it could be a convenient function call for you. Otherwise you may consider write your own app launch steps or using launch_app_am function instead. """ iffind = False d = g_common_obj.get_device() g_common_obj.back_home() d(description="Apps").click.wait() if d(text="Widgets").exists: d(text="Widgets").click.wait() d(text="Apps").click.wait() if d(scrollable=True): d(scrollable=True).scroll.horiz.toBeginning(steps=20) for _ in range(5): if d(text=appname).exists: d(text=appname).click.wait() iffind = True break d(scrollable=True).scroll.horiz() if not iffind: for _ in range(5): if d(text=appname).exists: time.sleep(2) d(text=appname).click.wait() iffind = True break d(scrollable=True).scroll.horiz.backward() assert iffind == True if (inspection is not None): assert d(textMatches=inspection) def launch(self): """launch app""" self.launch_app_from_home_sc("GFXBench Corporate") time.sleep(3) self.home.test_select() def run_test(self, name, timeout=900, onscreen=False, offscreen=False, special=False, others=False): """run test""" print "[Debug] test: %s onscreen:%s offscreen:%s special:%s others:%s" % ( name, onscreen, offscreen, special, others) if onscreen: onscreen_checkbox = self.testlist.search_item_onscreen_checkbox( name) onscreen_checkbox.click.wait() if offscreen: offscreen_checkbox = self.testlist.search_item_offscreen_checkbox( name) offscreen_checkbox.click.wait() if special: special_checkbox = self.testlist.search_item_special_checkbox(name) special_checkbox.click.wait() if others: others_checkbox = self.testlist.search_checkbox(name) others_checkbox.click.wait() cmd = "sync; echo 3 > /proc/sys/vm/drop_caches" g_common_obj.adb_cmd_capture_msg(repr(cmd)) self.testlist.btn_start.click() time.sleep(5) _, current_activity = common.get_current_focus_window() assert current_activity == self.TEST_ACTIVITY or current_activity ==self.LOADING_ACTIVITY,\ "[FAILURE] Tests failed to start" print "[Debug] start test: %s" % (name) start_time = time.time() is_completed = False while time.time() - start_time < timeout: cmd = "ls %s*.json" % (self.RESULT_DIR) cmd2 = "ls %s*.json" % (self.RESULT_DIR2) msg = g_common_obj.adb_cmd_capture_msg(repr(cmd)) if msg.find("No such file or directory") != -1: msg = g_common_obj.adb_cmd_capture_msg(repr(cmd2)) if msg.find("No such file or directory") == -1: break time.sleep(10) assert msg.find("No such file or directory") == -1, "Test time out" def get_result(self): cmd = "cat %s*.json" % (self.RESULT_DIR) cmd2 = "cat %s*.json" % (self.RESULT_DIR2) msg = g_common_obj.adb_cmd_capture_msg(repr(cmd)) if msg.find("No such file or directory") != -1: msg = g_common_obj.adb_cmd_capture_msg(repr(cmd2)) return msg def run_test_trex_onscreen(self): """run_test_trex_onscreen""" print "run_test_trex_onscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_TRex, onscreen=True, offscreen=False) else: self.run_test(self.TEST_TRex, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_TRex, result) def run_test_trex_offscreen(self): """run_test_trex_offscreen""" print "run_test_trex_offscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_TRex, onscreen=False, offscreen=True) else: self.run_test(self.TEST_TRex_Offscreen, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_TRex_Offscreen, result) def run_test_manhattan_onscreen(self): """run_test_manhattan_onscreen""" print "run_test_manhattan_onscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_Manhattan, onscreen=True, offscreen=False) else: self.run_test(self.TEST_Manhattan, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_Manhattan, result) def run_test_manhattan_offscreen(self): print "run_test_manhattan_offscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_Manhattan, onscreen=False, offscreen=True) else: self.run_test(self.TEST_Manhattan_Offscreen, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_Manhattan_Offscreen, result) def run_test_renderquality_highprecision(self): print "run_test_renderquality_highprecision" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_RenderQuality_HighPrecision, special=True) else: self.run_test(self.TEST_RenderQuality_HighPrecision, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_RenderQuality_HighPrecision, result) def run_test_renderquality(self): print "run_test_renderquality" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_RenderQuality, special=True) else: self.run_test(self.TEST_RenderQuality, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_RenderQuality, result) def run_test_driveroverhead_onscreen(self): """run_test_driveroverhead_onscreen""" print "run_test_driveroverhead_onscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_DriverOverhead, onscreen=True, offscreen=False) else: self.run_test(self.TEST_DriverOverhead, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_DriverOverhead, result) def run_test_driveroverhead_offscreen(self): """run_test_driveroverhead_offscreen""" print "run_test_driveroverhead_offscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_DriverOverhead, onscreen=False, offscreen=True) else: self.run_test(self.TEST_DriverOverhead_Offscreen, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_DriverOverhead_Offscreen, result) def run_test_ALU_onscreen(self): """run_test_ALU_onscreen""" print "run_test_ALU_onscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_ALU, onscreen=True, offscreen=False) else: self.run_test(self.TEST_ALU, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_ALU, result) def run_test_ALU_offscreen(self): """run_test_ALU_offscreen""" print "run_test_ALU_offscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_ALU, onscreen=False, offscreen=True) else: self.run_test(self.TEST_ALU_Offscreen, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_ALU_Offscreen, result) def run_test_alphablending_onscreen(self): """run_test_alphablending_onscreen""" print "run_test_alphablending_onscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_Alpha_Blending, onscreen=True, offscreen=False) else: self.run_test(self.TEST_Alpha_Blending, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_Alpha_Blending, result) def run_test_alphablending_offscreen(self): """run_test_alphablending_offscreen""" print "run_test_alphablending_offscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_Alpha_Blending, onscreen=False, offscreen=True) else: self.run_test(self.TEST_Alpha_Blending_offscreen, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_Alpha_Blending_offscreen, result) def run_test_fill_onscreen(self): """run_test_fill_onscreen""" print "run_test_fill_onscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_Fill, onscreen=True, offscreen=False) else: self.run_test(self.TEST_Fill, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_Fill, result) def run_test_fill_offscreen(self): """run_test_fill_offscreen""" print "run_test_fill_offscreen" y = self.device.info["displayHeight"] x = self.device.info["displayWidth"] if x > y: self.run_test(self.TEST_Fill, onscreen=False, offscreen=True) else: self.run_test(self.TEST_Fill_Offscreen, others=True) result = self.get_result() match = re.search(r'("score":\d+.\d+)', result).group() score = match.split(":")[1].strip() print "score is %s" % score assert float(score) > 0, "get score failed,and score is %d" % score assert result.find( 'status":"OK"') != -1, "run %s failed,and result is %s" % ( self.TEST_Fill_Offscreen, result)
class SpecialActionsImpl(object): """SpecialAction""" config_file = 'tests.common.special_actions.conf' def __init__(self): self.device = g_common_obj.get_device() self.configer = TestConfig() self.config = self.configer.read(self.config_file, "SpecialActionsImpl") config_handle = ConfigHandle() self.config["artifactory_location"] = config_handle.read_configuration('artifactory', 'location', '/etc/oat', 'sys.conf') self.arti = Artifactory(self.config.get('artifactory_location')) self.dut_res_dir = self.config.get("dut_res_dir") self.actions = [] def setup(self): """resource setup""" cmd = "cd %s || mkdir -p %s" % (self.dut_res_dir, self.dut_res_dir) g_common_obj.adb_cmd_capture_msg(repr(cmd)) res_files = self.configer.read(self.config_file, "EventFiles") for key_name, value in res_files.iteritems(): print "[Debug] install %s" % (key_name) res_file = self.arti.get(value) ret = g_common_obj.push_file(res_file, self.dut_res_dir) assert ret, 'Failed push %s' % (res_file) self.actions.append(key_name) print "[Debug] installed actions\n%s" % (self.actions) def zoom_in(self): """send event for zoom in""" do = 'event_zoom_in' assert do in self.actions cmd = 'sh %s/%s.sh' % (self.dut_res_dir, do) g_common_obj.adb_cmd_capture_msg(repr(cmd)) def zoom_out(self): """send event for zoom out""" do = 'event_zoom_out' assert do in self.actions cmd = 'sh %s/%s.sh' % (self.dut_res_dir, do) g_common_obj.adb_cmd_capture_msg(repr(cmd)) def long_touch_on_1_1(self): """send event for long click on left top corner.""" def _get_eventId(): '''get the input equipment id''' temps=[] equipments = g_common_obj.adb_cmd_capture_msg("getevent -p") tmp = re.findall(r'(/dev/input/event\d+)|(input props:.*\n.*)', equipments) for i in range(len(tmp)): if i%2 == 0: continue else: n_equip = tmp[i-1][0] + '\n' + tmp[i][1].replace('input props:\n','').strip() temps.append(n_equip) for _ in temps: t = _.splitlines() if t[1] != "<none>": return re.findall(r'\d+', t[0])[0] do = 'long_touch_on_1_1' eventId = _get_eventId() assert do in self.actions assert eventId != '' cmd = 'sh %s/%s.sh %s' % (self.dut_res_dir, do, eventId) g_common_obj.adb_cmd_capture_msg(repr(cmd)) def clean(self): """clean resource""" cmd = "rm -rf %s; sync;" % (self.dut_res_dir) g_common_obj.adb_cmd_capture_msg(repr(cmd)) self.actions = []
def download_artifactory_content(option_file): from testlib.util.repo import Artifactory cfg = TestConfig().read(DEFAULT_CONFIG, "artifactory") arti_obj = Artifactory(cfg.get("location")) ret_file = arti_obj.get(cfg.get(option_file)) return ret_file
class Gfxbench30Impl(GLBenchmarkImpl): """ Gfxbenchmark30Impl """ CONFIG_FILE = 'tests.common.gfxbench30.conf' PKG_NAME = "com.glbenchmark.glbenchmark27" INIT_ACTIVITY = "net.kishonti.benchui.initialization.InitActivity" MAIN_ACTIVITY = "net.kishonti.gfxbench.GfxMainActivity" TEST_ACTIVITY = "net.kishonti.benchui.BenchTestActivity" TEST_GROUPS = ['High-Level Tests', 'Low-Level Tests', 'Special Tests'] TEST_Alpha_Blending = 'Alpha Blending' TEST_Alpha_Blending_Offscreen = '1080p Alpha Blending Offscreen' class HomeUI(object): """Home UI""" def __init__(self, device): self.device = device @property def main_circle_control(self): return self.device( resourceId='com.glbenchmark.glbenchmark27:id/main_circleControl' ) def skip_guide_selection(self): """skip selection guide""" for _ in range(10): if not self.device().scroll.horiz.backward(steps=5): break if self.main_circle_control.exists: bounds = self.main_circle_control.info['visibleBounds'] for i in range(10): self.device.click( bounds['left'] + (bounds['right'] - bounds['left']) * 0.75, bounds['bottom'] - 20 * i) if self.device(text='Test selection').exists: break assert self.device(text='Test selection').exists,\ "[FAILURE] Failed skip_guide" def go_category_testlist(self): """go to test list category""" self.device().scroll.horiz.to(text='Test selection') class TestList(object): """Performance Tests List UI""" def __init__(self, device): self.device = device @property def btn_start(self): return self.device(text='Start') def clean_chooses(self): """check off all checkbox""" for each in Gfxbench30Impl.TEST_GROUPS: checkbox = self.search_item_checkbox(each) if checkbox.exists: check = checkbox.info['checked'] if check == True: checkbox.click() else: checkbox.click() checkbox.click() def search_item_checkbox(self, name): """scroll find checkbox""" if self.device().scroll.vert.to(text=name): return self.device(text=name).right( className="android.widget.CheckBox") def __init__(self): GLBenchmarkImpl.__init__(self) self.device = g_common_obj.get_device() self.home = Gfxbench30Impl.HomeUI(self.device) self.testlist = Gfxbench30Impl.TestList(self.device) self.configer = TestConfig() self.config = self.configer.read(self.CONFIG_FILE, "Gfxbench30Impl") config_handle = ConfigHandle() self.config["artifactory_location"] = config_handle.read_configuration( 'artifactory', 'location', '/etc/oat', 'sys.conf') self.arti = Artifactory(self.config.get('artifactory_location')) self.apk_cache_dir = self.config.get("apk_cache_dir") self.dut_download = self.config.get("dut_download") def setup(self): """setup implement's resource file""" busybox_obj.setup() if not pkgmgr._package_installed(pkgName=self.PKG_NAME): file_path = self.config.get("apk") apk_path = self.arti.get(file_path) pkgmgr.apk_install(apk_path) cmd = "cd %s || mkdir -p %s" % (self.apk_cache_dir, self.apk_cache_dir) g_common_obj.adb_cmd_capture_msg(repr(cmd)) apk_cache_files = self.arti.get(self.config.get("apk_cache_files")) ret = g_common_obj.push_file(apk_cache_files, self.dut_download) assert ret, 'Failed push %s' % (apk_cache_files) files_name = os.path.basename(apk_cache_files) cmd = "busybox tar zxf %s/%s --directory %s > /dev/null 2>&1 && print UnzipComplete"\ % (self.dut_download, files_name, self.apk_cache_dir) output = busybox_obj.adb_busybox_cmd(repr(cmd), 60 * 10) assert 'UnzipComplete' in output,\ "[FAILURE] Failed unzip: %s" % (files_name) def clean(self): """clean implement's resource file""" busybox_obj.clean() cmd = "rm -rf %s; sync;" % (self.apk_cache_dir) g_common_obj.adb_cmd_capture_msg(repr(cmd)) files_name = os.path.basename(self.config.get("apk_cache_files")) cmd = "rm -f %s/%s; sync;" % (self.dut_download, files_name) g_common_obj.adb_cmd_capture_msg(repr(cmd)) cmd = "uninstall %s" % (self.PKG_NAME) print g_common_obj.adb_cmd_common(cmd) def launch(self): """launch app""" g_common_obj.launch_app_am(self.PKG_NAME, self.MAIN_ACTIVITY) self._wait_init() self.home.skip_guide_selection() def _wait_init(self, timeout=60 * 15): """wait app initialize""" start_time = time.time() is_completed = False while time.time() - start_time < timeout: _, current_activity = common.get_current_focus_window() if current_activity == self.MAIN_ACTIVITY: is_completed = True break if self.device(text='Accept').exists: self.device(text='Accept').click() if self.device(text='OK').exists: self.device(text='OK').click() if self.device(text='Retry').exists: self.device(text='Retry').click() time.sleep(5) assert is_completed,\ "[FAILURE] Server timeout: %s" % (timeout) def resume(self): """resume app""" cmdstr = "am start %s" % (self.PKG_NAME) g_common_obj.adb_cmd(cmdstr) def run_test(self, names, timeout=1800): """run test""" self.home.go_category_testlist() self.testlist.clean_chooses() for each in names.split(','): print "[Debug] test: %s" % (each) if self.testlist.search_item_checkbox(each).exists: self.testlist.search_item_checkbox(each).click() checked_count = self.device(className="android.widget.CheckBox", checked=True).count assert checked_count == len(names.split(',')),\ "[FAILURE] Failed Choose Test item" self.testlist.btn_start.click() _, current_activity = common.get_current_focus_window() assert current_activity == self.TEST_ACTIVITY,\ "[FAILURE] Tests failed to start" print "[Debug] start test: %s" % (names) start_time = time.time() is_completed = False while time.time() - start_time < timeout: _, current_activity = common.get_current_focus_window() if current_activity == self.MAIN_ACTIVITY: is_completed = True break time.sleep(10) assert is_completed,\ "[FAILURE] Test time out: %s" % (timeout) def get_result(self, name): """get test result""" result_text = '' try: text1 = self.device(text=name).right( className='android.widget.TextView') result_text = text1.info['text'] text2 = text1.down(className='android.widget.TextView') if isinstance(text2, AutomatorDeviceObject) and text2.exists: result_text += text2.info['text'] except JsonRPCError: assert False,\ "[FAILURE] Failed get result: %s" % (name) print "[Debug] Result test:%s, result:%s" % (name, result_text) return result_text def run_test_alpha_blending(self, retry=5): """run alpha blending test""" for i in range(1, retry + 1): self.run_test(self.TEST_Alpha_Blending) result = self.get_result(self.TEST_Alpha_Blending) if 'try again later' in result: print "[Debug] Retry test. count:%s" % (i) time.sleep(10) continue break match = re.compile(r'([,0-9]*)([\w+\/]*)').match(result) assert match,\ "[FAILURE] Case Failed: %s" % (result) return match.group(1), match.group(2) def run_test_alpha_blending_offscreen(self, retry=5): """run alpha blending offscreen test""" for i in range(1, retry + 1): self.run_test(self.TEST_Alpha_Blending_Offscreen) result = self.get_result(self.TEST_Alpha_Blending_Offscreen) if 'try again later' in result: print "[Debug] Retry test. count:%s" % (i) time.sleep(10) continue break match = re.compile(r'([,0-9]+)([\w+\/]+)').match(result) assert match,\ "[FAILURE] Case Failed: %s" % (result) return match.group(1), match.group(2)
from testlib.androidframework.common import EnvironmentUtils from testlib.graphics.compare_pic_impl import compare_pic try: import pyqrcode import qrtools except ImportError: pyqrcode = None qrtools = None LOG = Logger.getlogger(__name__) config_handle = ConfigHandle() artifactory_href = config_handle.read_configuration('artifactory', 'location', '/etc/oat/', 'sys.conf') artifactory = Artifactory(artifactory_href) # Sub settings activity list ACCESSIBILITY = 'AccessibilitySettingsActivity' class Logcat(object): """Device Logcat""" def get_device_time_mark(self): """get device time""" cmd = 'date +"%m-%d %H:%M:%S"' date = g_common_obj.adb_cmd_capture_msg(repr(cmd)) time.sleep(1) return date def get_device_log(self, time_mark=None, filters="", pid=None):
def testPushSytemResourceFiles(self): """ Push system resources files to devices """ self.flag = [] config = TestConfig() cfg_file = 'tests.tablet.artifactory.conf' cfg_arti = config.read(cfg_file, 'artifactory') config_handle = ConfigHandle() cfg_arti["location"] = config_handle.read_configuration( 'artifactory', 'location', '/etc/oat/', 'sys.conf') cfg = config.read(cfg_file, 'content_oglconform') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg.get("name") file_path = arti.get(binary_name) output = g_common_obj.push_file(file_path, "/data/app/oglconform") g_common_obj.adb_cmd_common('shell chmod 777 /data/app/oglconform') self.flag.append(output) egl_config = cfg.get("egl_config") egl_config_file_path = arti.get(egl_config) output = g_common_obj.push_file(egl_config_file_path, "/data/app/egl-config") g_common_obj.adb_cmd_common('shell chmod 777 /data/app/egl-config') self.flag.append(output) egl_config = cfg.get("binary_es3") egl_config_file_path = arti.get(egl_config) output = g_common_obj.push_file(egl_config_file_path, "/data/app/get-program-binary_es3") g_common_obj.adb_cmd_common( 'shell chmod 777 /data/app/get-program-binary_es3') self.flag.append(output) cfg = config.read(cfg_file, 'content_gits') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg.get("busybox") file_path = arti.get(binary_name) output = g_common_obj.push_file(file_path, "/data/busybox") g_common_obj.adb_cmd_common('shell chmod 777 /data/busybox') self.flag.append(output) cfg = config.read(cfg_file, 'content_GLCTS') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg.get("name") file_path = arti.get(binary_name) print "push android_standalone_x86/ to DUT" output = g_common_obj.push_file(file_path, "/data/app/") g_common_obj.adb_cmd_common( "shell /data/busybox tar xzvf /data/app/android_standalone_x86.tgz -C /data/app", 10) g_common_obj.shell_cmd("rm -rf android_standalone_x86*") g_common_obj.adb_cmd_common( 'shell rm /data/app/android_standalone_x86.tgz') g_common_obj.adb_cmd_common( 'shell chmod 777 /data/app/android_standalone_x86/glcts') g_common_obj.adb_cmd_common( 'shell chmod 777 /data/app/android_standalone_x86/test.sh') self.flag.append(output) cfg = config.read(cfg_file, 'content_conform') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg.get("name") file_path = arti.get(binary_name) output = g_common_obj.push_file(file_path, "/data/app/conform") g_common_obj.adb_cmd_common('shell chmod 777 /data/app/conform') self.flag.append(output) binary_name = cfg.get("covegl") file_path = arti.get(binary_name) output = g_common_obj.push_file(file_path, "/data/app/covegl") g_common_obj.adb_cmd_common('shell chmod 777 /data/app/covegl') self.flag.append(output) binary_name = cfg.get("covgl") file_path = arti.get(binary_name) output = g_common_obj.push_file(file_path, "/data/app/covgl") g_common_obj.adb_cmd_common('shell chmod 777 /data/app/covgl') self.flag.append(output) binary_name = cfg.get("primtest") file_path = arti.get(binary_name) output = g_common_obj.push_file(file_path, "/data/app/primtest") g_common_obj.adb_cmd_common('shell chmod 777 /data/app/primtest') self.flag.append(output) cfg = config.read(cfg_file, 'content_android_extension_pack') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg.get("name") file_path = arti.get(binary_name) output = g_common_obj.push_file(file_path, "/data/app/oglconform_x86") g_common_obj.adb_cmd_common('shell chmod 777 /data/app/oglconform_x86') self.flag.append(output) for i in range(0, len(self.flag)): if self.flag[i] is False: return False return True
class ImageProcessingImpl(object): """ ImageProcessingExtendImpl """ CONFIG_FILE = 'tests.common.imageprocessing.conf' PKG_NAME = "com.android.rs.image" MAIN_ACTIVITY = "com.android.rs.image.ImageProcessingActivity" SECTION_LEVELS_VEC3_RELAXED = 'Levels Vec3 Relaxed' OPTIONS_LEVELS_VEC3_RELAXED = [ 'Saturation', 'In Black', 'Out Black', 'Out White' ] SECTION_LEVELS_VEC4_RELAXED = 'Levels Vec4 Relaxed' OPTIONS_LEVELS_VEC4_RELAXED = [ 'Saturation', 'In Black', 'Out Black', 'Out White' ] class HomeUI(object): """Home UI""" def __init__(self, device): self.device = device @property def image_display(self): """scroll to image region and return ui object""" self.device(scrollable=True).scroll.toBeginning(steps=20) time.sleep(3) return self.device(resourceId='com.android.rs.image:id/display') def set_selection(self, name): """change setting's section ui""" print "[Debug] set_selection %s" % (name) if self.device().scroll.to(text=name): print "[Debug] skip set selection %s" % (name) return resourceId = "com.android.rs.image:id/filterselection" self.device(scrollable=True).scroll.to(resourceId=resourceId) self.device(resourceId=resourceId).click() self.device(className="android.widget.ListView") \ .child_by_text( name, allow_scroll_search=True, className="android.widget.TextView" ).click() assert self.device(text=name).exists, \ "[FAILURE] Failed set_selection %s" % (name) def set_option(self, name, percent): """change option SeekBar value""" print "[Debug] set_option %s %s" % (name, percent) pre_image = get_screenshot_region(self.image_display.bounds) self.device().scroll.to(text=name) bounds = self.device(text=name)\ .down(className='android.widget.SeekBar').info['bounds'] pre_bar = get_screenshot_region(bounds) self.device.click( bounds['left'] + (bounds['right'] - bounds['left']) * (percent / 100.00), (bounds['top'] + bounds['bottom']) / 2) time.sleep(1) end_bar = get_screenshot_region(bounds) g_common_obj.assert_exp_happens() end_image = get_screenshot_region(self.image_display.bounds) g_common_obj.assert_exp_happens() remove_temp_file(pre_bar) remove_temp_file(end_bar) remove_temp_file(pre_image) remove_temp_file(end_image) def __init__(self): self.device = g_common_obj.get_device() self.home = ImageProcessingImpl.HomeUI(self.device) self.configer = TestConfig() self.config = self.configer.read(self.CONFIG_FILE, "ImageProcessingExtendImpl") config_handle = ConfigHandle() self.config["artifactory_location"] = config_handle.read_configuration( 'artifactory', 'location', '/etc/oat', 'sys.conf') self.arti = Artifactory(self.config.get('artifactory_location')) def setup(self): """setup implement's resource file""" version_array = osversion.get_android_version() androidversion = version_array[0] if androidversion == 7: print "osversion is N" apk_path = self.arti.get(self.config.get("apk")) elif androidversion == 6: print "osversion is M" apk_path = self.arti.get(self.config.get("apk")) elif androidversion == 5: print "osversion is L" apk_path = self.arti.get(self.config.get("apk_l")) else: print "osversion is %s" % (androidversion) apk_path = self.arti.get(self.config.get("apk_l")) cmd = "install -r %s" % (apk_path) print g_common_obj.adb_cmd_common(cmd, 300) def clean(self): """clean implement's resource file""" cmd = "uninstall %s" % (self.PKG_NAME) print g_common_obj.adb_cmd_common(cmd) def launch(self): """launch app""" g_common_obj.launch_app_am(self.PKG_NAME, self.MAIN_ACTIVITY) time.sleep(3) def change_levels_vec3_relaxed_settings(self, options=None): """change levels_vec3_relaxed options""" if options: keys = [each[0] for each in options] for key in keys: assert key in self.OPTIONS_LEVELS_VEC3_RELAXED self._change_settings(self.SECTION_LEVELS_VEC3_RELAXED, options) def change_levels_vec4_relaxed_settings(self, options=None): """change levels_vec4_relaxed options""" if options: keys = [each[0] for each in options] for key in keys: assert key in self.OPTIONS_LEVELS_VEC4_RELAXED self._change_settings(self.SECTION_LEVELS_VEC4_RELAXED, options) def _change_settings(self, section, options=None): """change setting's section and set options""" print "[Debug] change to %s" % (section) self.home.set_selection(section) if options: for option in options: assert isinstance(option, tuple) key, value = option self.home.set_option(key, value) def verify_log_gen_gpu(self, time_mark): """verify keywords GPU in log""" logs = logcat.get_device_log(time_mark, "RenderScript:V *:S") assert len(logs) > 0, \ "[FAILURE] Failed Catch logs" msg = re.findall(r'.* GPU*', logs) assert len(msg) > 0, \ "[FAILURE] Failed verify_log_gen_gpu" print "[Debug] %s" % (''.join(msg)) def verify_log_core_cpu(self, time_mark): """verify keywords CPU in log""" logs = logcat.get_device_log(time_mark, "RenderScript:V *:S") assert len(logs) > 0, \ "[FAILURE] Failed Catch logs" msg = re.findall(r'.* CPU*', logs) assert len(msg) > 0, \ "[FAILURE] Failed verify_log_core_cpu" print "[Debug] %s" % (''.join(msg))
def setUpClass(cls): print "[setUpClass]: %s" % cls.__name__ super(DisplayAllAppsOnHomeScreen, cls).setUpClass() cls.d = g_common_obj.get_device() g_common_obj.root_on_device() g_common_obj.remount_device() config = TestConfig() cfg_file = 'tests.tablet.artifactory.conf' cfg_arti = config.read(cfg_file, 'artifactory') config_handle = ConfigHandle() cfg_arti["location"] = config_handle.read_configuration( 'artifactory', 'location', '/etc/oat/', 'sys.conf') # Change to photoGrid app since meitupic is not support for x86 cpu cfg_picasatool = config.read(cfg_file, 'content_photogrid') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_picasatool.get("name") file_path = arti.get(binary_name) print "[Setup]: install photogrid" result = config_handle.check_apps("com.roidapp.photogrid") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) cfg_picsart = config.read(cfg_file, 'content_picsart') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_picsart.get("name") file_path = arti.get(binary_name) print "[Setup]: install picsart" result = config_handle.check_apps("com.picsart.studio") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) cfg_picsay = config.read(cfg_file, 'content_picsay') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_picsay.get("name") file_path = arti.get(binary_name) print "[Setup]: install picsay" result = config_handle.check_apps("com.shinycore.picsayfree") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) cfg_sketchbook = config.read(cfg_file, 'content_sketchbook') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_sketchbook.get("name") file_path = arti.get(binary_name) print "[Setup]: install sketchbook" result = config_handle.check_apps("com.adsk.sketchbookhdexpress") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) cfg_skitch = config.read(cfg_file, 'content_skitch') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_skitch.get("name") file_path = arti.get(binary_name) print "[Setup]: install skitch" result = config_handle.check_apps("com.evernote.skitch") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path)
class HDMICaptureDecodeImpl(object): """HDMI_capture_decode_impl""" config_file = 'tests.common.display_cable_switch.conf' def __init__(self): configer = TestConfig() self.config = configer.read(self.config_file, "DisplayCableSwitch") config_handle = ConfigHandle() self.config["artifactory_location"] = config_handle.read_configuration('artifactory', 'location', '/etc/oat', 'sys.conf') self.arti = Artifactory(self.config.get('artifactory_location')) self.excuter_path = '' def setup(self): self.excuter_path = self.arti.get(self.config.get("bin_qrdecode")) assert self.excuter_path, \ "Download resource failed!" cmd = 'chmod 777 %s' % self.excuter_path code, msg = self.shell_command(cmd) assert code == 0, \ "[FAILURE] %s %s" % (cmd, msg) def capture_decode(self, QRstring): """Excute binary and camera will capture and decode photos.""" cmd = "%s Command Camera" % (self.excuter_path) _, msg = self.shell_command(cmd) # assert code == 0, \ # "[FAILURE] %s %s" % (cmd, msg) if not msg.find('QR string:') >= 0: return False, "capture failed" if not msg.find(QRstring) >= 0: return False, "decode failed" else: return True, "" def shell_command(self, cmd): print 'Execute command: %s' % cmd exit_code, stdout_log, stderr_log = shell_command_ext(cmd) message = stdout_log + stderr_log print 'Result exit:%s\n%s' % (exit_code, message) return exit_code, message def get_path(self): """To get the binary path""" self.binary_path = self.excuter_path.replace("QRdecode", "") print 'binary_path: %s' % (self.binary_path) return self.binary_path def capture_image_and_upload(self, casename): """Excute binary and camera will capture and upload photos.""" cmd = "%s Command Camera" % (self.excuter_path) _, msg = self.shell_command(cmd) # assert code == 0, \ # "[FAILURE] %s %s" % (cmd, msg) if not msg.find('SaveAs:fail_0_0.png') >= 0: assert False, "capture failed" pathlist = [self.get_path(), "saveimages/fail_0_0.png"] image_path = os.sep.join(pathlist) print image_path if not os.path.exists(image_path): assert False, "No images found" else: # copyfile(image_path, self._acs_params["report_path"] + "/PHONE1/DEBUG_LOGS/Capture.png") # copyfile(image_path, self._acs_params["report_path"] + "/PHONE1/DEBUG_LOGS/" + casename + "/Capture.png") live_report_log_path = g_common_obj.get_user_log_dir() copyfile(image_path, live_report_log_path + "/Capture.png") reportSemiAutoVerdict()