From: Sanghoon Lee Date: Mon, 13 May 2019 08:48:09 +0000 (+0900) Subject: [tools][non-acr][Updated config device] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=19af9329bbef0677a1fa1d5ddcbc14f827a575a9;p=test%2Ftct%2Fcsharp%2Fapi.git [tools][non-acr][Updated config device] Change-Id: Ie17d71844b8c3e728010852d813d20be9dfcaefb --- diff --git a/release/csharp-tct_5.5_dotnet/csharp-tct_5.5_dotnet/tools/tct-config-device.py b/release/csharp-tct_5.5_dotnet/csharp-tct_5.5_dotnet/tools/tct-config-device.py index d573c94d5..9c510774d 100755 --- a/release/csharp-tct_5.5_dotnet/csharp-tct_5.5_dotnet/tools/tct-config-device.py +++ b/release/csharp-tct_5.5_dotnet/csharp-tct_5.5_dotnet/tools/tct-config-device.py @@ -1,745 +1,745 @@ -#!/usr/bin/python - -"""Usage: - tct-config-device.py [--install [--deviceid ]] - tct-config-device.py --purge [--deviceid ] - tct-config-device.py --check [--deviceid ][--procid ] - tct-config-device.py --bhtest - -Options: - -h, --help show this help message and exit - --install Install tct resources to TIZEN device,it can be omitted - --purge Clean up tct resources from TIZEN device - --check Check test resource on device - --bhtest Install tct behavior test - --deviceid Set the device serial number - --procid Set the check process name - -""" -import os -import sys -import time -import ConfigParser -import threading -import subprocess - - -from optparse import OptionParser -from devicemanager import DeviceManager -from sdbmanager import SdbManager - -JOIN = os.path.join -EXISTS = os.path.exists -DIRNAME = os.path.dirname -BASENAME = os.path.basename -ABSPATH = os.path.abspath -SPLIT = os.path.split - -CURENT_DIR = SPLIT(DIRNAME(ABSPATH(__file__)))[0] - -TOOLS_DIR = JOIN(CURENT_DIR, "tools") -RESRC_DIR = JOIN(CURENT_DIR, "resource") -PKGS_DIR = JOIN(CURENT_DIR, "package") - -DEVID = "" - -TIZENV = "tizen_5.5" - -DLOG_CLEAR = "dlogutil -c" -DLOG_UTIL = "sdb -s %s shell dlogutil -v time" - -TCT_CONFIG_FILE = "/opt/tools/TCT_CONFIG" -tct_parser = ConfigParser.ConfigParser() -tct_parser.read(TCT_CONFIG_FILE) - -DEVICE_SUITE_TARGET_24 = tct_parser.get('DEVICE', 'DEVICE_SUITE_TARGET_24') -DEVICE_SUITE_TARGET_30 = tct_parser.get('DEVICE', 'DEVICE_SUITE_TARGET_30') -DEVICE_EXECUTION_MODE_30 = tct_parser.get('DEVICE', 'DEVICE_EXECUTION_MODE_30') - -if TIZENV.find('tizen_5.5') > -1: - DEVICE_SUITE_TARGET = DEVICE_SUITE_TARGET_30 -else: - DEVICE_SUITE_TARGET = DEVICE_SUITE_TARGET_24 - -def LS(root, file_name, extension=None): - import glob - - file_path = "" - if extension: - file_path = JOIN(root, file_name) + "*." + extension - else: - file_path = JOIN(root, file_name) + "*" - files = glob.iglob(r'' + file_path + '') - for f in files: - return BASENAME(f) - -def get_device_arch(): - global DEV_ARCH - #ARCHCMD = SDB_SERNO + " shell \"cat /etc/products.d/tizen.prod |grep \armv7 - result = SdbManager.sdbShell(DEVID, arch_cmd) - if result and len(result) > 0: - arch_str = result.split('\n')[0] - if arch_str and arch_str.find('armv7') > -1: - DEV_ARCH = "arm" - print "info: [* Arch Type : arm *]" - elif arch_str and arch_str.find("aarch64") > -1: - DEV_ARCH = "aarch64" - print "info: [* Arch Type : aarch64 *]" - elif arch_str and arch_str.find('x86_64') > -1: - DEV_ARCH = "ia64" - print "info: [* Arch Type : ia64 *]" - elif arch_str and (arch_str.find("i686") > -1 or arch_str.find("x86") > -1 or arch_str.find("i386") > -1): - DEV_ARCH = "ia" - print "info: [* Arch Type : ia *]" - else: - print "info: [* Arch Type : None *]" - return False - return True - else: - print "#ERROR#: Failed to get device cpu_arch type" - return False - - -def kill_process(process_name): - proc_cmd = "ps aux | grep " + process_name + " | grep -v grep | awk '{print $2}'" - result = SdbManager.sdbShell(DEVID, proc_cmd) - if result and len(result) > 0: - kill_cmd = "kill -9 " + str(result).strip() + " > /dev/null 2>&1" - SdbManager.sdbShell(DEVID, kill_cmd) - print "info: %s process has been killed" % process_name - else: - print "info: No process of %s activated" % process_name - -def remove_tinyweb(): - SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/server.pem > /dev/null 2>&1") - SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/tinyweb > /dev/null 2>&1") - SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/cgi-getcookie > /dev/null 2>&1") - SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/cgi-getfield > /dev/null 2>&1") - SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/libmongoose.so > /dev/null 2>&1") - SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/echo.so > /dev/null 2>&1") - SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/libssl.so > /dev/null 2>&1") - SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/libcrypto.so > /dev/null 2>&1") - -def remove_stub(): - SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/testkit-stub") - - -def uninstall_testconfig(): - if TIZENV.find('tizen_5.5') > -1: - inst_path = RESRC_DIR + os.sep + 'tct-testconfig' + os.sep + 'inst.py' - SdbManager.hostCommand("python %s -s %s -u" % (inst_path, DEVID)) - else: - RPMPKG = LS(RESRC_DIR, "tct-testconfig") - if not RPMPKG: - sys.exit("#ERROR#: cannot found tct-testconfig.zip file in resource dir") - uninst_cmd = JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-testconfig/inst.sh') + ' -u' - SdbManager.sdbShell(DEVID, uninst_cmd) - rm_cmd = 'rm -f ' + JOIN(DEVICE_SUITE_TARGET, 'tct/', RPMPKG) - SdbManager.sdbShell(DEVID, rm_cmd) - - -def uninstall_behavior(): - print "info: Uninstall behavior tool." - if TIZENV.find('tizen_5.5') > -1: - pass - else: - uninst_cmd = JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-behavior-tests/inst.sh') + ' -u' - SdbManager.sdbShell(DEVID, uninst_cmd) - - -def check_resource_dir(): - print "info: check resource directory." - if os.path.exists(RESRC_DIR): - SdbManager.sdbShell(DEVID, 'mkdir -p ' + JOIN(DEVICE_SUITE_TARGET, 'tct/')) - SdbManager.sdbShell(DEVID, 'mkdir -p ' + JOIN(DEVICE_SUITE_TARGET, 'Documents/')) - return True - else: - print "#WARNING#: The directory resource does not exists. Please copy test resources to %s " % RESRC_DIR - return False - -def check_tinyweb(): - print "info: Check tinyweb." - result = SdbManager.sdbShell(DEVID, "ls /opt/home/developer/ | grep tinyweb") - if result and result.find('tinyweb'): - remove_tinyweb() - install_tinyweb() - launch_tinyweb() - else: - install_tinyweb() - launch_tinyweb() - - -def port_manager(): - print "info: Check the tinyweb port" - result = SdbManager.sdbShell('fuser -n tcp 80 8080 8081 8082 8083 8443') - if result and len(result) > 0: - check_port = SdbManager.sdbShell('su "netstat -nap |grep tinyweb"') - if len(check_port) > 0: - print "info: tinyweb on" - else: - print "info: Port is available" - - -def launch_tinyweb(): - dpath_cmd = "printenv PATH" - dpath = SdbManager.sdbShell(DEVID, dpath_cmd) - - launch_cmd = 'sdb -s ' + DEVID + ' shell ' + '"env LD_LIBRARY_PATH=/opt/home/developer PATH=' + dpath.strip() + \ - ':/opt/home/developer/ tinyweb -ssl_certificate /opt/home/developer/server.pem -document_root ' + \ - JOIN(DEVICE_SUITE_TARGET, 'tct') + ' -listening_ports 80,8080,8081,8082,8083,8443s; sleep 3s" 0> /dev/null' - - SdbManager.sdbCommand(launch_cmd, 10) - - check_tinyweb_cmd = '\"ps aux | grep tinyweb | grep -v grep\"' - result = SdbManager.sdbShell(DEVID, check_tinyweb_cmd) - if result and result.find('tinyweb') > -1: - print "info: Active process tinyweb successfully." - return True - else: - print "#ERROR#: Active process tinyweb failed." - return False - -def install_tinyweb(): - print "info: Install tinyweb" - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'tinyweb'), '/opt/home/developer/') - SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/tinyweb") - - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'cgi-getcookie'), '/opt/home/developer/') - SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/cgi-getcookie") - - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'cgi-getfield'), '/opt/home/developer/') - SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/cgi-getfield") - - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'libmongoose.so'), '/opt/home/developer/') - SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/libmongoose.so") - - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'echo.so'), '/opt/home/developer/') - SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/echo.so") - - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'server.pem'), '/opt/home/developer/') - SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/server.pem") - if DEV_ARCH == "arm": - SdbManager.sdbShell(DEVID, "ln -s /usr/lib/libssl.so.1.0.0 /opt/home/developer/libssl.so") - SdbManager.sdbShell(DEVID, "ln -s /usr/lib/libcrypto.so.1.0.0 /opt/home/developer/libcrypto.so") - elif DEV_ARCH == "ia": - SdbManager.sdbShell(DEVID, "ln -s /usr/lib/libssl.so.1.0.0 /opt/home/developer/libssl.so") - SdbManager.sdbShell(DEVID, "ln -s /usr/lib/libcrypto.so.1.0.0 /opt/home/developer/libcrypto.so") - elif DEV_ARCH == "aarch64": - SdbManager.sdbShell(DEVID, "ln -s /usr/lib64/libssl.so.1.0.0 /opt/home/developer/libssl.so") - SdbManager.sdbShell(DEVID, "ln -s /usr/lib64/libcrypto.so.1.0.0 /opt/home/developer/libcrypto.so") - elif DEV_ARCH == "ia64": - SdbManager.sdbShell(DEVID, "ln -s /usr/lib64/libssl.so.1.0.0 /opt/home/developer/libssl.so") - SdbManager.sdbShell(DEVID, "ln -s /usr/lib64/libcrypto.so.1.0.0 /opt/home/developer/libcrypto.so") - - -def check_stub(): - print "info: Check testkit-stub." - result = SdbManager.sdbShell(DEVID, "ls /opt/home/developer/ | grep testkit-stub") - if result and len(result) > 0: - print "info: testkit-stub has been installed on device." - kill_process("testkit-stub") - install_stub() - - -def install_stub(): - print "info: Install testkit-stub." - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'testkit-stub', DEV_ARCH, 'testkit-stub'), '/opt/home/developer/testkit-stub') - SdbManager.sdbShell(DEVID, "chmod a+x /opt/home/developer/testkit-stub") - SdbManager.sdbShell(DEVID, "chsmack -e \"User\" /opt/home/developer/testkit-stub") - - -def check_testconfig(): - result = SdbManager.sdbShell(DEVID, '"cat ' + JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-testconfig/tct-testconfig.ini') + ' | grep tct"') - if result and len(result) > 0 and result.find('No such file or directory') == -1: - print "info: testconfig has already been installed on device." - else: - install_testconfig() - - -def install_testconfig(): - print "info: Install testconfig." - if TIZENV.find('tizen_5.5') > -1: - instPath = RESRC_DIR + os.sep + 'tct-testconfig' + os.sep + 'inst.py' - SdbManager.hostCommand("python %s -s %s" % (instPath, DEVID)) - else: - conf_pkg = LS(RESRC_DIR, "tct-testconfig") - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, conf_pkg), JOIN(DEVICE_SUITE_TARGET, 'tct/')) - SdbManager.sdbShell(DEVID, 'unzip -uo ' + JOIN(DEVICE_SUITE_TARGET, 'tct/') + conf_pkg + ' -d ' + JOIN(DEVICE_SUITE_TARGET, 'tct/')) - SdbManager.sdbShell(DEVID, JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-testconfig/inst.sh')) - - result = SdbManager.sdbShell(DEVID, 'cat ' + JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-testconfig/tct-testconfig.ini') + ' | grep tct') - - if result and len(result) > 0: - print "info: Install testconfig successfully." - else: - print "#ERROR#: Failed to install testconfig, please check %s" % RESRC_DIR - return False - - return True - -def install_behavior(profile_name): - print "info: Install behavior tool." - - if not profile_name in ['wearable', 'mobile', 'tv', 'ivi']: - print "#WARNING#: Invalid device profile value %s" % profile_name - return False - - if TIZENV.find('tizen_5.5') > -1: - RPMPKG = "tct-behavior-tests-5.5.zip" - opt_rpm_path = PKGS_DIR + "s" + os.sep + profile_name + os.sep + RPMPKG - local_rpm_path = PKGS_DIR + os.sep + profile_name + os.sep + RPMPKG - - install_rpm = None - install_dest = None - install_cmd = None - if os.path.exists(opt_rpm_path): - install_rpm = opt_rpm_path - install_dest = PKGS_DIR + "s" + os.sep + profile_name + os.sep - install_cmd = PKGS_DIR + "s" + os.sep + profile_name + os.sep + \ - 'opt' + os.sep + "tct-behavior-tests" + os.sep + "inst.py" - elif os.path.exists(local_rpm_path): - install_rpm = local_rpm_path - install_dest = PKGS_DIR + os.sep + profile_name + os.sep - install_cmd = PKGS_DIR + os.sep + profile_name + os.sep + \ - 'opt' + os.sep + "tct-behavior-tests" + os.sep + "inst.py" - - SdbManager.hostCommand("rm -rf %s" % install_dest + "opt/tct-behavior-tests") - SdbManager.hostCommand("unzip -uo %s -d %s" % (install_rpm, install_dest)) - SdbManager.hostCommand("python %s -s %s" % (install_cmd, DEVID)) - - print "info: Check tizen-web-ui-fw. Please wait..." - check_uifw = SdbManager.sdbShell(DEVID, "ls /usr/share/ | grep tizen-web-ui-fw") - if check_uifw and len(check_uifw) > 0: - print "info: tizen-web-ui-fw has been installed on device." - else: - SdbManager.sdbShell(DEVID, '"mkdir -p /usr/share/tizen-web-ui-fw/"') - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, "tizen-web-ui-fw"), '/usr/share/tizen-web-ui-fw/') - else: - pass - - return True - - -def install_getCap(): - print "info: Install widget getCap." - widgetCap = LS(RESRC_DIR, 'getCap', 'wgt') - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, widgetCap), JOIN(DEVICE_SUITE_TARGET, 'tct/') + widgetCap) - - if TIZENV.find('5.5') > -1: - SdbManager.sdbShell(DEVID, "su - " + DEVICE_EXECUTION_MODE_30 + \ - " -c 'pkgcmd -i -t wgt -q -p " + JOIN(DEVICE_SUITE_TARGET, 'tct/') + widgetCap + '\'') - SdbManager.sdbShell(DEVID, 'pkgcmd -i -t wgt -q -p ' + JOIN(DEVICE_SUITE_TARGET, 'tct/') + widgetCap) - - -def install_ngetCap(): - print "info: Install widget ngetCap." - getcap_pkg = LS(RESRC_DIR, 'getCap', 'tpk') - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, getcap_pkg), JOIN(DEVICE_SUITE_TARGET, 'tct/') + getcap_pkg) - - if TIZENV.find('tizen_5.5') > -1: - SdbManager.sdbShell(DEVID, "su - " + DEVICE_EXECUTION_MODE_30 + \ - " -c 'pkgcmd -ipt tpk -p " + JOIN(DEVICE_SUITE_TARGET, 'tct/') + getcap_pkg + '\'') - else: - SdbManager.sdbShell(DEVID, "pkgcmd -iqt tpk -p" + JOIN(DEVICE_SUITE_TARGET, 'tct/') + getcap_pkg) - -def uninstall_getCap(): - print "info: Uninstall widget getCap." - wgt_id = getCap_appid() - if wgt_id: - uninst_cmd = "" - if TIZENV.find('tizen_5.5') > -1: - uninst_cmd = "su - " + DEVICE_EXECUTION_MODE_30 + \ - " -c 'pkgcmd -qun " + wgt_id.split('.')[0] + '\'' - elif TIZENV.find('tizen_2.4') > -1: - uninst_cmd = "pkgcmd -u -q -t wgt -q -p " + wgt_id + '\'' - SdbManager.sdbShell(DEVID, uninst_cmd) - - else: - print "info: getCap is not installed. No need to uninstall" - - SdbManager.sdbShell(DEVID, "rm -rf " + JOIN(DEVICE_SUITE_TARGET, "Documents/tct")) - SdbManager.sdbShell(DEVID, "rm -rf " + JOIN(DEVICE_SUITE_TARGET, "tct/getCap.wgt")) - SdbManager.sdbShell(DEVID, "rm -rf " + JOIN(DEVICE_SUITE_TARGET, "tct/getCap.tpk")) - - -def uninstall_ngetCap(): - print "info: Uninstall widget ngetCap." - -def getCap_appid(): - widgetid_cmd = "" - if TIZENV.find('tizen_5.5') > -1: - widgetid_cmd = "su - " + DEVICE_EXECUTION_MODE_30 + \ - " -c \"app_launcher -l | grep getCapabilities\"" - else: - widgetid_cmd = "wrt-launcher -l | grep getCapabilities" - - widgetids = SdbManager.sdbShell(DEVID, widgetid_cmd) - if widgetids and widgetids.find('getCapabilities') > -1: - items = widgetids.split() - return items[len(items) - 1].strip("'") - else: - return None - -def check_getCap(): - print "info: Check getCap widget. Please wait..." - if getCap_appid(): - print "info: widget getCap has already been installed on device." - else: - install_getCap() - launch_getCap() - - -def check_ngetCap(): - print "info: Check ngetCap widget. Please wait..." - if getCap_appid(): - print "info: widget ngetCap has already been installed on device." - else: - install_ngetCap() - launch_ngetCap() - - -def launch_getCap(): - wgt_id = getCap_appid() - if wgt_id: - launchResult = None - if TIZENV.find('tizen_5.5') > -1: - launchResult = SdbManager.sdbShell(DEVID, 'su - ' + \ - DEVICE_EXECUTION_MODE_30 + ' -c \"app_launcher -s ' + wgt_id + '\"') - else: - launchResult = SdbManager.sdbShell(DEVID, '\"wrt-launcher -s ' + wgt_id + '\"') - - if launchResult.find('launched') > -1: - fcheck_retry = 20 - - while fcheck_retry > 0: - build = SdbManager.sdbShell(DEVID, "cat " + JOIN(DEVICE_SUITE_TARGET, "Documents/tct/buildinfo.xml") + " | grep buildinfos") - capa = SdbManager.sdbShell(DEVID, "cat " + JOIN(DEVICE_SUITE_TARGET, "Documents/tct/capability.xml") + " | grep capabilities") - if not build or not capa: - time.sleep(2) - fcheck_retry -= 1 - else: - break - if fcheck_retry == 0: - print "#ERROR#: getCap get buildinfo, capability of device failed!" - return False - else: - print "info: Launch getCap successfully" - return True - else: - print "#ERROR#: Launch getCap got failed" - return False - else: - print "#ERROR#: Widget getCap cannot be found. Please check whether the widget is installed successfully" - return False - -def launch_ngetCap(): - launch_result = None - if TIZENV.find('tizen_5.5') > -1: - launch_result = SdbManager.sdbShell(DEVID, 'su - ' + \ - DEVICE_EXECUTION_MODE_30 + ' -c \"launch_app org.example.getcap\"') - else: - launch_result = SdbManager.sdbShell(DEVID, '\"launch_app org.example.getcap\"') - - if "launched" in launch_result: - return True - else: - return False - -def getStorage_appid(): - widgetid_cmd = "su - " + DEVICE_EXECUTION_MODE_30 + \ - " -c \"app_launcher -l | grep InternalStorageSetting\"" - widgetids = SdbManager.sdbShell(DEVID, widgetid_cmd) - if widgetids and widgetids.find('InternalStorageSetting') > -1: - items = widgetids.split() - return items[len(items)-1].strip("'") - else: - return None - -def check_storage(): - print "info: Check InternalStorageSetting widget. Please wait..." - if getStorage_appid(): - print "info: widget InternalStorageSetting has already been installed on device." - else: - install_storage() - launch_storage() - -def install_storage(): - print "info: Install widget InternalStorageSetting" - widget = LS(RESRC_DIR, 'InternalStorageSetting', 'wgt') - SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, widget), JOIN(DEVICE_SUITE_TARGET, 'tct/') + widget) - - SdbManager.sdbShell(DEVID, "su - " + DEVICE_EXECUTION_MODE_30 + \ - " -c 'pkgcmd -i -t wgt -q -p " + JOIN(DEVICE_SUITE_TARGET, 'tct/') + widget + '\'') - -def launch_storage(): - wgt_id = getStorage_appid() - if wgt_id: - launch_result = SdbManager.sdbShell(DEVID, 'su - ' + \ - DEVICE_EXECUTION_MODE_30 + ' -c \"app_launcher -s ' + wgt_id + '\"') - - if launch_result.find('launched') > -1: - print "info: Launch InternalStorageSetting successfully" - return True - else: - print "#ERROR#: InternalStorageSetting launch failed" - return False - else: - print "#ERROR#: Widget InternalStorageSetting cannot be found" - return False - -def uninstall_storage(): - print "info: Uninstall widget InternalStorageSetting" - wgt_id = getStorage_appid() - if wgt_id: - uninst_cmd = "su - " + DEVICE_EXECUTION_MODE_30 + \ - " -c 'pkgcmd -qun " + wgt_id.split('.')[0] + '\'' - SdbManager.sdbShell(DEVID, uninst_cmd) - else: - print "info: InternalStorageSetting is not installed" - -def push_tctconf_file(): - local = TCT_CONFIG_FILE - remote = DEVICE_SUITE_TARGET_30 - if not SdbManager.sdbPush(DEVID, local, remote): - print "#ERROR#: TCT_CONFIG file push failed" - return False - return True - -def find_ngetCap(): - getcap_tpk = LS(RESRC_DIR, 'getCap', 'tpk') - if getcap_tpk: - return True - else: - return False - -def debug_trace(cmd, logfile): - global debug_flag, metux - - wbuffile = file(logfile, "a+") - exit_code = None - proc = subprocess.Popen(args=cmd, - shell=True, - stdout=wbuffile, - stderr=None) - while True: - exit_code = proc.poll() - if exit_code is not None: - break - time.sleep(0.6) - metux.acquire() - proc_flag = debug_flag - metux.release() - if not proc_flag: - break - wbuffile.close() - SdbManager.killall(proc.pid) - - -def start_debug(dlog_file): - global debug_flag, metux, dlog_thread - debug_flag = True - metux = threading.Lock() - clear_cmd = DLOG_CLEAR - SdbManager.sdbShell(DEVID, clear_cmd) - - dlog_cmd = DLOG_UTIL % DEVID - dlog_thread = threading.Thread(target=debug_trace, args=(dlog_cmd, dlog_file)) - dlog_thread.setDaemon(True) - dlog_thread.start() - - -def stop_debug(): - global debug_flag, metux - metux.acquire() - debug_flag = False - metux.release() - dlog_thread.join() - - -def runProcess(): - if options.purge: - print "[ Uninstall test resource on device. Please wait...]" - uninstall_testconfig() - uninstall_behavior() - uninstall_getCap() - remove_tinyweb() - kill_process("tinyweb") - kill_process("testkit-stub") - remove_stub() - if TIZENV.find('5.5') > -1: - uninstall_storage() - print "Clean the tct packages in device successfully." - - elif options.check: - check_resource_dir() - print "[ Check test resource on device. Please wait...]" - if options.process == 'tinyweb': - check_tinyweb() - elif options.process == 'testkit-stub': - check_stub() - elif options.process == 'testconfig': - check_testconfig() - elif options.process == 'getCap': - check_getCap() - elif options.process == 'ngetCap': - if find_ngetCap(): - check_ngetCap() - else: - check_getCap() - elif options.process == 'storage': - check_storage() - else: - check_tinyweb() - check_stub() - check_testconfig() - if find_ngetCap(): - check_ngetCap() - else: - check_getCap() - if TIZENV.find('5.5') > -1: - check_storage() - - print "Check finished." - - elif options.bhtest: - check_resource_dir() - if TIZENV.find('5.5') > -1: - uninstall_storage() - install_storage() - launch_storage() - - uninstall_behavior() - print "[ Install tct behavior tool on device. Please wait...]" - install_behavior(options.bhtest) - print "Installation of tct behavior on device completed." - - else: - check_resource_dir() - print "[ Clean old test resource on device. Please wait...]" - if options.process == 'tinyweb': - kill_process("tinyweb") - remove_tinyweb() - elif options.process == 'testkit-stub': - kill_process("testkit-stub") - remove_stub() - elif options.process == 'testconfig': - uninstall_testconfig() - elif options.process == 'getCap': - uninstall_getCap() - pass - elif options.process == 'ngetCap': - uninstall_ngetCap() - elif options.process == 'storage': - uninstall_storage() - else: - remove_tinyweb() - kill_process("testkit-stub") - remove_stub() - uninstall_testconfig() - uninstall_getCap() - uninstall_ngetCap() - if TIZENV.find('5.5') > -1: - uninstall_storage() - - print "Clean the tct packages in device successfully." - print "[ Install test resource on device. Please wait...]" - if options.process == 'tinyweb': - install_tinyweb() - launch_tinyweb() - elif options.process == 'testkit-stub': - install_stub() - elif options.process == 'testconfig': - install_testconfig() - elif options.process == 'getCap': - install_getCap() - launch_getCap() - elif options.process == 'ngetCap': - if find_ngetCap(): - install_ngetCap() - launch_ngetCap() - else: - install_getCap() - launch_getCap() - elif options.process == 'storage': - install_storage() - launch_storage() - else: - install_testconfig() - install_stub() - install_tinyweb() - launch_tinyweb() - if find_ngetCap(): - install_ngetCap() - launch_ngetCap() - else: - install_getCap() - launch_getCap() - - if TIZENV.find('5.5') > -1: - install_storage() - launch_storage() - - print "All of installation process on device completed." - - -if __name__ == "__main__": - - parser = OptionParser() - parser.add_option( - "--install", dest="install", action="store_true", default=False, - help="Install tct resources to TIZEN device,it can be omitted") - parser.add_option( - "--purge", dest="purge", action="store_true", default=False, - help="Clean up tct resources from TIZEN device") - parser.add_option( - "--check", dest="check", action="store_true", default=False, - help="Check test resource on device") - parser.add_option( - "--deviceid", dest="deviceid", action="store", - help="Set the device serial number") - parser.add_option( - "--procid", dest="process", action="store", - help="Set the process id for checking") - parser.add_option( - "--bhtest", dest="bhtest", action="store", - help="Install behavior test tool to device") - - (options, args) = parser.parse_args() - - devinst = DeviceManager.getInstance() - if options.deviceid: - if devinst.isDeviceAvailable(options.deviceid): - DEVID = options.deviceid - else: - sys.exit("#ERROR#: The '%s' device Id exists error" % options.deviceid) - else: - if devinst.getDeviceSize() > 1 or devinst.getDeviceSize() == 0: - sys.exit("#ERROR#: %s devices connected or device not connected" % str(devinst.getDeviceSize())) - else: - DEVID = devinst.getSdbDeviceList()[0].getDeviceId() - - print "[========== start tct-config-device : %s ==========]" % DEVID - dev_temp_dir = '/opt/tools/shell/tmp/%s/' % DEVID - if not os.path.isdir(dev_temp_dir): - os.mkdir(dev_temp_dir) - DLOG_SAVE_PATH = '/opt/tools/shell/tmp/%s/conf_dev_%s.dlog' - if options.process is None: - DLOG_SAVE_PATH = DLOG_SAVE_PATH % (DEVID, 'all') - else: - DLOG_SAVE_PATH = DLOG_SAVE_PATH % (DEVID, options.process) - - #start_debug(DLOG_SAVE_PATH) - - if not SdbManager.sdbRootOn(DEVID): - sys.exit(-1) - - SdbManager.sdbSetDate(DEVID) - - if not get_device_arch() or not push_tctconf_file(): - sys.exit(0) - - runProcess() - #stop_debug() - print "[========== end tct-config-device : %s ==========]" % DEVID +#!/usr/bin/python + +"""Usage: + tct-config-device.py [--install [--deviceid ]] + tct-config-device.py --purge [--deviceid ] + tct-config-device.py --check [--deviceid ][--procid ] + tct-config-device.py --bhtest + +Options: + -h, --help show this help message and exit + --install Install tct resources to TIZEN device,it can be omitted + --purge Clean up tct resources from TIZEN device + --check Check test resource on device + --bhtest Install tct behavior test + --deviceid Set the device serial number + --procid Set the check process name + +""" +import os +import sys +import time +import ConfigParser +import threading +import subprocess + + +from optparse import OptionParser +from devicemanager import DeviceManager +from sdbmanager import SdbManager + +JOIN = os.path.join +EXISTS = os.path.exists +DIRNAME = os.path.dirname +BASENAME = os.path.basename +ABSPATH = os.path.abspath +SPLIT = os.path.split + +CURENT_DIR = SPLIT(DIRNAME(ABSPATH(__file__)))[0] + +TOOLS_DIR = JOIN(CURENT_DIR, "tools") +RESRC_DIR = JOIN(CURENT_DIR, "resource") +PKGS_DIR = JOIN(CURENT_DIR, "package") + +DEVID = "" + +TIZENV = "tizen_5.5" + +DLOG_CLEAR = "dlogutil -c" +DLOG_UTIL = "sdb -s %s shell dlogutil -v time" + +TCT_CONFIG_FILE = "/opt/tools/TCT_CONFIG" +tct_parser = ConfigParser.ConfigParser() +tct_parser.read(TCT_CONFIG_FILE) + +DEVICE_SUITE_TARGET_24 = tct_parser.get('DEVICE', 'DEVICE_SUITE_TARGET_24') +DEVICE_SUITE_TARGET_30 = tct_parser.get('DEVICE', 'DEVICE_SUITE_TARGET_30') +DEVICE_EXECUTION_MODE_30 = tct_parser.get('DEVICE', 'DEVICE_EXECUTION_MODE_30') + +if TIZENV.find('tizen_5.5') > -1: + DEVICE_SUITE_TARGET = DEVICE_SUITE_TARGET_30 +else: + DEVICE_SUITE_TARGET = DEVICE_SUITE_TARGET_24 + +def LS(root, file_name, extension=None): + import glob + + file_path = "" + if extension: + file_path = JOIN(root, file_name) + "*." + extension + else: + file_path = JOIN(root, file_name) + "*" + files = glob.iglob(r'' + file_path + '') + for f in files: + return BASENAME(f) + +def get_device_arch(): + global DEV_ARCH + #ARCHCMD = SDB_SERNO + " shell \"cat /etc/products.d/tizen.prod |grep \armv7 + result = SdbManager.sdbShell(DEVID, arch_cmd) + if result and len(result) > 0: + arch_str = result.split('\n')[0] + if arch_str and arch_str.find('armv') > -1: + DEV_ARCH = "arm" + print "info: [* Arch Type : arm *]" + elif arch_str and arch_str.find("aarch64") > -1: + DEV_ARCH = "aarch64" + print "info: [* Arch Type : aarch64 *]" + elif arch_str and arch_str.find('x86_64') > -1: + DEV_ARCH = "ia64" + print "info: [* Arch Type : ia64 *]" + elif arch_str and (arch_str.find("i686") > -1 or arch_str.find("x86") > -1 or arch_str.find("i386") > -1): + DEV_ARCH = "ia" + print "info: [* Arch Type : ia *]" + else: + print "info: [* Arch Type : None *]" + return False + return True + else: + print "#ERROR#: Failed to get device cpu_arch type" + return False + + +def kill_process(process_name): + proc_cmd = "ps aux | grep " + process_name + " | grep -v grep | awk '{print $2}'" + result = SdbManager.sdbShell(DEVID, proc_cmd) + if result and len(result) > 0: + kill_cmd = "kill -9 " + str(result).strip() + " > /dev/null 2>&1" + SdbManager.sdbShell(DEVID, kill_cmd) + print "info: %s process has been killed" % process_name + else: + print "info: No process of %s activated" % process_name + +def remove_tinyweb(): + SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/server.pem > /dev/null 2>&1") + SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/tinyweb > /dev/null 2>&1") + SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/cgi-getcookie > /dev/null 2>&1") + SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/cgi-getfield > /dev/null 2>&1") + SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/libmongoose.so > /dev/null 2>&1") + SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/echo.so > /dev/null 2>&1") + SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/libssl.so > /dev/null 2>&1") + SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/libcrypto.so > /dev/null 2>&1") + +def remove_stub(): + SdbManager.sdbShell(DEVID, "rm -f /opt/home/developer/testkit-stub") + + +def uninstall_testconfig(): + if TIZENV.find('tizen_5.5') > -1: + inst_path = RESRC_DIR + os.sep + 'tct-testconfig' + os.sep + 'inst.py' + SdbManager.hostCommand("python %s -s %s -u" % (inst_path, DEVID)) + else: + RPMPKG = LS(RESRC_DIR, "tct-testconfig") + if not RPMPKG: + sys.exit("#ERROR#: cannot found tct-testconfig.zip file in resource dir") + uninst_cmd = JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-testconfig/inst.sh') + ' -u' + SdbManager.sdbShell(DEVID, uninst_cmd) + rm_cmd = 'rm -f ' + JOIN(DEVICE_SUITE_TARGET, 'tct/', RPMPKG) + SdbManager.sdbShell(DEVID, rm_cmd) + + +def uninstall_behavior(): + print "info: Uninstall behavior tool." + if TIZENV.find('tizen_5.5') > -1: + pass + else: + uninst_cmd = JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-behavior-tests/inst.sh') + ' -u' + SdbManager.sdbShell(DEVID, uninst_cmd) + + +def check_resource_dir(): + print "info: check resource directory." + if os.path.exists(RESRC_DIR): + SdbManager.sdbShell(DEVID, 'mkdir -p ' + JOIN(DEVICE_SUITE_TARGET, 'tct/')) + SdbManager.sdbShell(DEVID, 'mkdir -p ' + JOIN(DEVICE_SUITE_TARGET, 'Documents/')) + return True + else: + print "#WARNING#: The directory resource does not exists. Please copy test resources to %s " % RESRC_DIR + return False + +def check_tinyweb(): + print "info: Check tinyweb." + result = SdbManager.sdbShell(DEVID, "ls /opt/home/developer/ | grep tinyweb") + if result and result.find('tinyweb'): + remove_tinyweb() + install_tinyweb() + launch_tinyweb() + else: + install_tinyweb() + launch_tinyweb() + + +def port_manager(): + print "info: Check the tinyweb port" + result = SdbManager.sdbShell('fuser -n tcp 80 8080 8081 8082 8083 8443') + if result and len(result) > 0: + check_port = SdbManager.sdbShell('su "netstat -nap |grep tinyweb"') + if len(check_port) > 0: + print "info: tinyweb on" + else: + print "info: Port is available" + + +def launch_tinyweb(): + dpath_cmd = "printenv PATH" + dpath = SdbManager.sdbShell(DEVID, dpath_cmd) + + launch_cmd = 'sdb -s ' + DEVID + ' shell ' + '"env LD_LIBRARY_PATH=/opt/home/developer PATH=' + dpath.strip() + \ + ':/opt/home/developer/ tinyweb -ssl_certificate /opt/home/developer/server.pem -document_root ' + \ + JOIN(DEVICE_SUITE_TARGET, 'tct') + ' -listening_ports 80,8080,8081,8082,8083,8443s; sleep 3s" 0> /dev/null' + + SdbManager.sdbCommand(launch_cmd, 10) + + check_tinyweb_cmd = '\"ps aux | grep tinyweb | grep -v grep\"' + result = SdbManager.sdbShell(DEVID, check_tinyweb_cmd) + if result and result.find('tinyweb') > -1: + print "info: Active process tinyweb successfully." + return True + else: + print "#ERROR#: Active process tinyweb failed." + return False + +def install_tinyweb(): + print "info: Install tinyweb" + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'tinyweb'), '/opt/home/developer/') + SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/tinyweb") + + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'cgi-getcookie'), '/opt/home/developer/') + SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/cgi-getcookie") + + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'cgi-getfield'), '/opt/home/developer/') + SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/cgi-getfield") + + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'libmongoose.so'), '/opt/home/developer/') + SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/libmongoose.so") + + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'echo.so'), '/opt/home/developer/') + SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/echo.so") + + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'tinyweb', DEV_ARCH, 'server.pem'), '/opt/home/developer/') + SdbManager.sdbShell(DEVID, "chmod 777 /opt/home/developer/server.pem") + if DEV_ARCH == "arm": + SdbManager.sdbShell(DEVID, "ln -s /usr/lib/libssl.so.1.0.0 /opt/home/developer/libssl.so") + SdbManager.sdbShell(DEVID, "ln -s /usr/lib/libcrypto.so.1.0.0 /opt/home/developer/libcrypto.so") + elif DEV_ARCH == "ia": + SdbManager.sdbShell(DEVID, "ln -s /usr/lib/libssl.so.1.0.0 /opt/home/developer/libssl.so") + SdbManager.sdbShell(DEVID, "ln -s /usr/lib/libcrypto.so.1.0.0 /opt/home/developer/libcrypto.so") + elif DEV_ARCH == "aarch64": + SdbManager.sdbShell(DEVID, "ln -s /usr/lib64/libssl.so.1.0.0 /opt/home/developer/libssl.so") + SdbManager.sdbShell(DEVID, "ln -s /usr/lib64/libcrypto.so.1.0.0 /opt/home/developer/libcrypto.so") + elif DEV_ARCH == "ia64": + SdbManager.sdbShell(DEVID, "ln -s /usr/lib64/libssl.so.1.0.0 /opt/home/developer/libssl.so") + SdbManager.sdbShell(DEVID, "ln -s /usr/lib64/libcrypto.so.1.0.0 /opt/home/developer/libcrypto.so") + + +def check_stub(): + print "info: Check testkit-stub." + result = SdbManager.sdbShell(DEVID, "ls /opt/home/developer/ | grep testkit-stub") + if result and len(result) > 0: + print "info: testkit-stub has been installed on device." + kill_process("testkit-stub") + install_stub() + + +def install_stub(): + print "info: Install testkit-stub." + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, 'testkit-stub', DEV_ARCH, 'testkit-stub'), '/opt/home/developer/testkit-stub') + SdbManager.sdbShell(DEVID, "chmod a+x /opt/home/developer/testkit-stub") + SdbManager.sdbShell(DEVID, "chsmack -e \"User\" /opt/home/developer/testkit-stub") + + +def check_testconfig(): + result = SdbManager.sdbShell(DEVID, '"cat ' + JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-testconfig/tct-testconfig.ini') + ' | grep tct"') + if result and len(result) > 0 and result.find('No such file or directory') == -1: + print "info: testconfig has already been installed on device." + else: + install_testconfig() + + +def install_testconfig(): + print "info: Install testconfig." + if TIZENV.find('tizen_5.5') > -1: + instPath = RESRC_DIR + os.sep + 'tct-testconfig' + os.sep + 'inst.py' + SdbManager.hostCommand("python %s -s %s" % (instPath, DEVID)) + else: + conf_pkg = LS(RESRC_DIR, "tct-testconfig") + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, conf_pkg), JOIN(DEVICE_SUITE_TARGET, 'tct/')) + SdbManager.sdbShell(DEVID, 'unzip -uo ' + JOIN(DEVICE_SUITE_TARGET, 'tct/') + conf_pkg + ' -d ' + JOIN(DEVICE_SUITE_TARGET, 'tct/')) + SdbManager.sdbShell(DEVID, JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-testconfig/inst.sh')) + + result = SdbManager.sdbShell(DEVID, 'cat ' + JOIN(DEVICE_SUITE_TARGET, 'tct/opt/tct-testconfig/tct-testconfig.ini') + ' | grep tct') + + if result and len(result) > 0: + print "info: Install testconfig successfully." + else: + print "#ERROR#: Failed to install testconfig, please check %s" % RESRC_DIR + return False + + return True + +def install_behavior(profile_name): + print "info: Install behavior tool." + + if not profile_name in ['wearable', 'mobile', 'tv', 'ivi']: + print "#WARNING#: Invalid device profile value %s" % profile_name + return False + + if TIZENV.find('tizen_5.5') > -1: + RPMPKG = "tct-behavior-tests-5.5.zip" + opt_rpm_path = PKGS_DIR + "s" + os.sep + profile_name + os.sep + RPMPKG + local_rpm_path = PKGS_DIR + os.sep + profile_name + os.sep + RPMPKG + + install_rpm = None + install_dest = None + install_cmd = None + if os.path.exists(opt_rpm_path): + install_rpm = opt_rpm_path + install_dest = PKGS_DIR + "s" + os.sep + profile_name + os.sep + install_cmd = PKGS_DIR + "s" + os.sep + profile_name + os.sep + \ + 'opt' + os.sep + "tct-behavior-tests" + os.sep + "inst.py" + elif os.path.exists(local_rpm_path): + install_rpm = local_rpm_path + install_dest = PKGS_DIR + os.sep + profile_name + os.sep + install_cmd = PKGS_DIR + os.sep + profile_name + os.sep + \ + 'opt' + os.sep + "tct-behavior-tests" + os.sep + "inst.py" + + SdbManager.hostCommand("rm -rf %s" % install_dest + "opt/tct-behavior-tests") + SdbManager.hostCommand("unzip -uo %s -d %s" % (install_rpm, install_dest)) + SdbManager.hostCommand("python %s -s %s" % (install_cmd, DEVID)) + + print "info: Check tizen-web-ui-fw. Please wait..." + check_uifw = SdbManager.sdbShell(DEVID, "ls /usr/share/ | grep tizen-web-ui-fw") + if check_uifw and len(check_uifw) > 0: + print "info: tizen-web-ui-fw has been installed on device." + else: + SdbManager.sdbShell(DEVID, '"mkdir -p /usr/share/tizen-web-ui-fw/"') + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, "tizen-web-ui-fw"), '/usr/share/tizen-web-ui-fw/') + else: + pass + + return True + + +def install_getCap(): + print "info: Install widget getCap." + widgetCap = LS(RESRC_DIR, 'getCap', 'wgt') + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, widgetCap), JOIN(DEVICE_SUITE_TARGET, 'tct/') + widgetCap) + + if TIZENV.find('5.5') > -1: + SdbManager.sdbShell(DEVID, "su - " + DEVICE_EXECUTION_MODE_30 + \ + " -c 'pkgcmd -i -t wgt -q -p " + JOIN(DEVICE_SUITE_TARGET, 'tct/') + widgetCap + '\'') + SdbManager.sdbShell(DEVID, 'pkgcmd -i -t wgt -q -p ' + JOIN(DEVICE_SUITE_TARGET, 'tct/') + widgetCap) + + +def install_ngetCap(): + print "info: Install widget ngetCap." + getcap_pkg = LS(RESRC_DIR, 'getCap', 'tpk') + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, getcap_pkg), JOIN(DEVICE_SUITE_TARGET, 'tct/') + getcap_pkg) + + if TIZENV.find('tizen_5.5') > -1: + SdbManager.sdbShell(DEVID, "su - " + DEVICE_EXECUTION_MODE_30 + \ + " -c 'pkgcmd -ipt tpk -p " + JOIN(DEVICE_SUITE_TARGET, 'tct/') + getcap_pkg + '\'') + else: + SdbManager.sdbShell(DEVID, "pkgcmd -iqt tpk -p" + JOIN(DEVICE_SUITE_TARGET, 'tct/') + getcap_pkg) + +def uninstall_getCap(): + print "info: Uninstall widget getCap." + wgt_id = getCap_appid() + if wgt_id: + uninst_cmd = "" + if TIZENV.find('tizen_5.5') > -1: + uninst_cmd = "su - " + DEVICE_EXECUTION_MODE_30 + \ + " -c 'pkgcmd -qun " + wgt_id.split('.')[0] + '\'' + elif TIZENV.find('tizen_2.4') > -1: + uninst_cmd = "pkgcmd -u -q -t wgt -q -p " + wgt_id + '\'' + SdbManager.sdbShell(DEVID, uninst_cmd) + + else: + print "info: getCap is not installed. No need to uninstall" + + SdbManager.sdbShell(DEVID, "rm -rf " + JOIN(DEVICE_SUITE_TARGET, "Documents/tct")) + SdbManager.sdbShell(DEVID, "rm -rf " + JOIN(DEVICE_SUITE_TARGET, "tct/getCap.wgt")) + SdbManager.sdbShell(DEVID, "rm -rf " + JOIN(DEVICE_SUITE_TARGET, "tct/getCap.tpk")) + + +def uninstall_ngetCap(): + print "info: Uninstall widget ngetCap." + +def getCap_appid(): + widgetid_cmd = "" + if TIZENV.find('tizen_5.5') > -1: + widgetid_cmd = "su - " + DEVICE_EXECUTION_MODE_30 + \ + " -c \"app_launcher -l | grep getCapabilities\"" + else: + widgetid_cmd = "wrt-launcher -l | grep getCapabilities" + + widgetids = SdbManager.sdbShell(DEVID, widgetid_cmd) + if widgetids and widgetids.find('getCapabilities') > -1: + items = widgetids.split() + return items[len(items) - 1].strip("'") + else: + return None + +def check_getCap(): + print "info: Check getCap widget. Please wait..." + if getCap_appid(): + print "info: widget getCap has already been installed on device." + else: + install_getCap() + launch_getCap() + + +def check_ngetCap(): + print "info: Check ngetCap widget. Please wait..." + if getCap_appid(): + print "info: widget ngetCap has already been installed on device." + else: + install_ngetCap() + launch_ngetCap() + + +def launch_getCap(): + wgt_id = getCap_appid() + if wgt_id: + launchResult = None + if TIZENV.find('tizen_5.5') > -1: + launchResult = SdbManager.sdbShell(DEVID, 'su - ' + \ + DEVICE_EXECUTION_MODE_30 + ' -c \"app_launcher -s ' + wgt_id + '\"') + else: + launchResult = SdbManager.sdbShell(DEVID, '\"wrt-launcher -s ' + wgt_id + '\"') + + if launchResult.find('launched') > -1: + fcheck_retry = 20 + + while fcheck_retry > 0: + build = SdbManager.sdbShell(DEVID, "cat " + JOIN(DEVICE_SUITE_TARGET, "Documents/tct/buildinfo.xml") + " | grep buildinfos") + capa = SdbManager.sdbShell(DEVID, "cat " + JOIN(DEVICE_SUITE_TARGET, "Documents/tct/capability.xml") + " | grep capabilities") + if not build or not capa: + time.sleep(2) + fcheck_retry -= 1 + else: + break + if fcheck_retry == 0: + print "#ERROR#: getCap get buildinfo, capability of device failed!" + return False + else: + print "info: Launch getCap successfully" + return True + else: + print "#ERROR#: Launch getCap got failed" + return False + else: + print "#ERROR#: Widget getCap cannot be found. Please check whether the widget is installed successfully" + return False + +def launch_ngetCap(): + launch_result = None + if TIZENV.find('tizen_5.5') > -1: + launch_result = SdbManager.sdbShell(DEVID, 'su - ' + \ + DEVICE_EXECUTION_MODE_30 + ' -c \"launch_app org.example.getcap\"') + else: + launch_result = SdbManager.sdbShell(DEVID, '\"launch_app org.example.getcap\"') + + if "launched" in launch_result: + return True + else: + return False + +def getStorage_appid(): + widgetid_cmd = "su - " + DEVICE_EXECUTION_MODE_30 + \ + " -c \"app_launcher -l | grep InternalStorageSetting\"" + widgetids = SdbManager.sdbShell(DEVID, widgetid_cmd) + if widgetids and widgetids.find('InternalStorageSetting') > -1: + items = widgetids.split() + return items[len(items)-1].strip("'") + else: + return None + +def check_storage(): + print "info: Check InternalStorageSetting widget. Please wait..." + if getStorage_appid(): + print "info: widget InternalStorageSetting has already been installed on device." + else: + install_storage() + launch_storage() + +def install_storage(): + print "info: Install widget InternalStorageSetting" + widget = LS(RESRC_DIR, 'InternalStorageSetting', 'wgt') + SdbManager.sdbPush(DEVID, JOIN(RESRC_DIR, widget), JOIN(DEVICE_SUITE_TARGET, 'tct/') + widget) + + SdbManager.sdbShell(DEVID, "su - " + DEVICE_EXECUTION_MODE_30 + \ + " -c 'pkgcmd -i -t wgt -q -p " + JOIN(DEVICE_SUITE_TARGET, 'tct/') + widget + '\'') + +def launch_storage(): + wgt_id = getStorage_appid() + if wgt_id: + launch_result = SdbManager.sdbShell(DEVID, 'su - ' + \ + DEVICE_EXECUTION_MODE_30 + ' -c \"app_launcher -s ' + wgt_id + '\"') + + if launch_result.find('launched') > -1: + print "info: Launch InternalStorageSetting successfully" + return True + else: + print "#ERROR#: InternalStorageSetting launch failed" + return False + else: + print "#ERROR#: Widget InternalStorageSetting cannot be found" + return False + +def uninstall_storage(): + print "info: Uninstall widget InternalStorageSetting" + wgt_id = getStorage_appid() + if wgt_id: + uninst_cmd = "su - " + DEVICE_EXECUTION_MODE_30 + \ + " -c 'pkgcmd -qun " + wgt_id.split('.')[0] + '\'' + SdbManager.sdbShell(DEVID, uninst_cmd) + else: + print "info: InternalStorageSetting is not installed" + +def push_tctconf_file(): + local = TCT_CONFIG_FILE + remote = DEVICE_SUITE_TARGET_30 + if not SdbManager.sdbPush(DEVID, local, remote): + print "#ERROR#: TCT_CONFIG file push failed" + return False + return True + +def find_ngetCap(): + getcap_tpk = LS(RESRC_DIR, 'getCap', 'tpk') + if getcap_tpk: + return True + else: + return False + +def debug_trace(cmd, logfile): + global debug_flag, metux + + wbuffile = file(logfile, "a+") + exit_code = None + proc = subprocess.Popen(args=cmd, + shell=True, + stdout=wbuffile, + stderr=None) + while True: + exit_code = proc.poll() + if exit_code is not None: + break + time.sleep(0.6) + metux.acquire() + proc_flag = debug_flag + metux.release() + if not proc_flag: + break + wbuffile.close() + SdbManager.killall(proc.pid) + + +def start_debug(dlog_file): + global debug_flag, metux, dlog_thread + debug_flag = True + metux = threading.Lock() + clear_cmd = DLOG_CLEAR + SdbManager.sdbShell(DEVID, clear_cmd) + + dlog_cmd = DLOG_UTIL % DEVID + dlog_thread = threading.Thread(target=debug_trace, args=(dlog_cmd, dlog_file)) + dlog_thread.setDaemon(True) + dlog_thread.start() + + +def stop_debug(): + global debug_flag, metux + metux.acquire() + debug_flag = False + metux.release() + dlog_thread.join() + + +def runProcess(): + if options.purge: + print "[ Uninstall test resource on device. Please wait...]" + uninstall_testconfig() + uninstall_behavior() + uninstall_getCap() + remove_tinyweb() + kill_process("tinyweb") + kill_process("testkit-stub") + remove_stub() + if TIZENV.find('5.5') > -1: + uninstall_storage() + print "Clean the tct packages in device successfully." + + elif options.check: + check_resource_dir() + print "[ Check test resource on device. Please wait...]" + if options.process == 'tinyweb': + check_tinyweb() + elif options.process == 'testkit-stub': + check_stub() + elif options.process == 'testconfig': + check_testconfig() + elif options.process == 'getCap': + check_getCap() + elif options.process == 'ngetCap': + if find_ngetCap(): + check_ngetCap() + else: + check_getCap() + elif options.process == 'storage': + check_storage() + else: + check_tinyweb() + check_stub() + check_testconfig() + if find_ngetCap(): + check_ngetCap() + else: + check_getCap() + if TIZENV.find('5.5') > -1: + check_storage() + + print "Check finished." + + elif options.bhtest: + check_resource_dir() + if TIZENV.find('5.5') > -1: + uninstall_storage() + install_storage() + launch_storage() + + uninstall_behavior() + print "[ Install tct behavior tool on device. Please wait...]" + install_behavior(options.bhtest) + print "Installation of tct behavior on device completed." + + else: + check_resource_dir() + print "[ Clean old test resource on device. Please wait...]" + if options.process == 'tinyweb': + kill_process("tinyweb") + remove_tinyweb() + elif options.process == 'testkit-stub': + kill_process("testkit-stub") + remove_stub() + elif options.process == 'testconfig': + uninstall_testconfig() + elif options.process == 'getCap': + uninstall_getCap() + pass + elif options.process == 'ngetCap': + uninstall_ngetCap() + elif options.process == 'storage': + uninstall_storage() + else: + remove_tinyweb() + kill_process("testkit-stub") + remove_stub() + uninstall_testconfig() + uninstall_getCap() + uninstall_ngetCap() + if TIZENV.find('5.5') > -1: + uninstall_storage() + + print "Clean the tct packages in device successfully." + print "[ Install test resource on device. Please wait...]" + if options.process == 'tinyweb': + install_tinyweb() + launch_tinyweb() + elif options.process == 'testkit-stub': + install_stub() + elif options.process == 'testconfig': + install_testconfig() + elif options.process == 'getCap': + install_getCap() + launch_getCap() + elif options.process == 'ngetCap': + if find_ngetCap(): + install_ngetCap() + launch_ngetCap() + else: + install_getCap() + launch_getCap() + elif options.process == 'storage': + install_storage() + launch_storage() + else: + install_testconfig() + install_stub() + install_tinyweb() + launch_tinyweb() + if find_ngetCap(): + install_ngetCap() + launch_ngetCap() + else: + install_getCap() + launch_getCap() + + if TIZENV.find('5.5') > -1: + install_storage() + launch_storage() + + print "All of installation process on device completed." + + +if __name__ == "__main__": + + parser = OptionParser() + parser.add_option( + "--install", dest="install", action="store_true", default=False, + help="Install tct resources to TIZEN device,it can be omitted") + parser.add_option( + "--purge", dest="purge", action="store_true", default=False, + help="Clean up tct resources from TIZEN device") + parser.add_option( + "--check", dest="check", action="store_true", default=False, + help="Check test resource on device") + parser.add_option( + "--deviceid", dest="deviceid", action="store", + help="Set the device serial number") + parser.add_option( + "--procid", dest="process", action="store", + help="Set the process id for checking") + parser.add_option( + "--bhtest", dest="bhtest", action="store", + help="Install behavior test tool to device") + + (options, args) = parser.parse_args() + + devinst = DeviceManager.getInstance() + if options.deviceid: + if devinst.isDeviceAvailable(options.deviceid): + DEVID = options.deviceid + else: + sys.exit("#ERROR#: The '%s' device Id exists error" % options.deviceid) + else: + if devinst.getDeviceSize() > 1 or devinst.getDeviceSize() == 0: + sys.exit("#ERROR#: %s devices connected or device not connected" % str(devinst.getDeviceSize())) + else: + DEVID = devinst.getSdbDeviceList()[0].getDeviceId() + + print "[========== start tct-config-device : %s ==========]" % DEVID + dev_temp_dir = '/opt/tools/shell/tmp/%s/' % DEVID + if not os.path.isdir(dev_temp_dir): + os.mkdir(dev_temp_dir) + DLOG_SAVE_PATH = '/opt/tools/shell/tmp/%s/conf_dev_%s.dlog' + if options.process is None: + DLOG_SAVE_PATH = DLOG_SAVE_PATH % (DEVID, 'all') + else: + DLOG_SAVE_PATH = DLOG_SAVE_PATH % (DEVID, options.process) + + #start_debug(DLOG_SAVE_PATH) + + if not SdbManager.sdbRootOn(DEVID): + sys.exit(-1) + + SdbManager.sdbSetDate(DEVID) + + if not get_device_arch() or not push_tctconf_file(): + sys.exit(0) + + runProcess() + #stop_debug() + print "[========== end tct-config-device : %s ==========]" % DEVID