Пример #1
0
def chmod(filePath, mode = 777,recursive = True):
    osInfo = get_platform_info()
    if(osInfo == 'Linux-Phone'):
        if recursive:
            os.system('chmod -R '+str(mode)+" "+filePath)
        else:
            os.system('chmod '+str(mode)+" "+filePath)
Пример #2
0
def chmod(filePath, mode = 777,recursive = True):
    osInfo = get_platform_info()
    if(osInfo == 'Linux-Phone'):
        if recursive:
            os.system('chmod -R '+str(mode)+" "+filePath)
        else:
            os.system('chmod '+str(mode)+" "+filePath)
Пример #3
0
    def __init__(self, local_socket_name, port):
        """
        Initialize the SocketUtil Instance  by passing local socket name.
        For Windows and Linux-PC , it will connect localhost:6100 since this
        port will forward to remote socket myuiautomator on device. For running
        on Linux-Phone , it will connect to socket myuiautomator directly.

        @type local_socket_name:string
        @param local_socket_name: name of socket.
        @port port:port of socket.
        """
        osInfo = get_platform_info()
        try:
            if osInfo == "Windows" or osInfo == "Linux-PC":
                self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                self.sock.connect(("127.0.0.1", port))
                self.fd = self.sock.makefile("rw", 0)
            elif osInfo == "Linux-Phone":
                self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
                self.sock.connect(local_socket_name)
                self.fd = self.sock.makefile("rw", 0)
        except socket.error, msg:
            log_test_framework("io_wrapper", "socket error: " + msg.strerror)
            self.sock = None
            self.fd = None
            raise IOError, "msg"
Пример #4
0
def kpi_path():
    '''
    This function used to save the log on the path. Weight and Data also on the path.
    @return: kpi_path
    '''
    osInfo = get_platform_info()
    kpi_path = sys.path[0] + os.sep + 'kpi'+os.sep
    return kpi_path
Пример #5
0
def kpi_path():
    '''
    This function used to save the log on the path. Weight and Data also on the path.
    @return: kpi_path
    '''
    osInfo = get_platform_info()
    kpi_path = sys.path[0] + os.sep + 'kpi' + os.sep
    return kpi_path
Пример #6
0
def init_acessibility_socket():
    '''
    Initialize server side socket, it will start up uiautomator socket.
    If used on PC , it will use also used adb forward  tcp:6100 to remote uiautomator
    socket running on device.
    '''
    kill_by_name('uiautomator')
    osInfo = get_platform_info()
    if (osInfo == "Windows" or osInfo == "Linux-PC"):
        if (SC.PUBLIC_ENABLE_USER_RELEASE_ONLINE_DEBUG == False):
            os.system(
                'adb shell am startservice -n com.android.qrdtest/.QsstService'
            )
            qsst_forward_cmd = 'adb forward tcp:' + str(
                port_qsst) + ' tcp:' + str(port_qsst)
            os.system(qsst_forward_cmd)
            os.system(
                'adb shell am startservice -n com.android/.MyTrackService')
            mytrackservice_forward_cmd = 'adb forward tcp:' + str(
                localport_mytrackservice) + ' tcp:' + str(
                    localport_mytrackservice)
            os.system(mytrackservice_forward_cmd)
        if (SC.PUBLIC_ENABLE_USER_RELEASE_ONLINE_DEBUG == True):
            os.system(
                'adb shell su -c am startservice -n com.android.qrdtest/.QsstService'
            )
            qsst_forward_cmd = 'adb forward tcp:' + str(
                port_qsst) + ' tcp:' + str(port_qsst)
            os.system(qsst_forward_cmd)
            os.system(
                'adb shell su -c am startservice -n com.android/.MyTrackService'
            )
            mytrackservice_forward_cmd = 'adb forward tcp:' + str(
                localport_mytrackservice) + ' tcp:' + str(
                    localport_mytrackservice)
            os.system(mytrackservice_forward_cmd)

        #subprocess.Popen(["adb", "shell", "uiautomator translatecases &"],stdout=subprocess.PIPE)
        thread.start_new_thread(Host_Start_Uiautomator, ())
        uiautomator_forward_cmd = 'adb forward tcp:' + str(
            port_uiautomator) + ' tcp:' + str(port_uiautomator)
        os.system(uiautomator_forward_cmd)
        forwardCmd = 'adb forward tcp:' + str(
            localport_grouptest_meserver) + ' tcp:' + str(
                port_grouptest_meserver)
        print forwardCmd
        os.system(forwardCmd)
        #subprocess.Popen(cmd)
        pass
    elif (osInfo == "Linux-Phone"):
        os.system('am startservice -n com.android.qrdtest/.QsstService')
        os.system('uiautomator translatecases &')
        os.system('am startservice -n com.android/.MyTrackService')
    time.sleep(10)
    if not init_thrift_client():
        return False
    return True
Пример #7
0
def init_filepath():
    global FILE_PATH_COMMON
    global FILE_PATH_CONFIG
    osInfo = get_platform_info()
    currLocation = os.getcwd()
    if(osInfo == 'Linux-Phone' or osInfo == 'Linux-PC'):
        FILE_PATH_COMMON = currLocation + '/settings/common.py'
        FILE_PATH_CONFIG = currLocation + '/settings/config.xml'
    elif(osInfo == 'Windows'):
        FILE_PATH_COMMON = currLocation + '\\settings\\common.py'
        FILE_PATH_CONFIG = currLocation + '\\settings\\config.xml'
Пример #8
0
def init_filepath():
    global FILE_PATH_COMMON
    global FILE_PATH_CONFIG
    osInfo = get_platform_info()
    currLocation = os.getcwd()
    if (osInfo == 'Linux-Phone' or osInfo == 'Linux-PC'):
        FILE_PATH_COMMON = currLocation + '/settings/common.py'
        FILE_PATH_CONFIG = currLocation + '/settings/config.xml'
    elif (osInfo == 'Windows'):
        FILE_PATH_COMMON = currLocation + '\\settings\\common.py'
        FILE_PATH_CONFIG = currLocation + '\\settings\\config.xml'
Пример #9
0
def getprop_suspend():
    os_info = get_platform_info()
    ps_cmd = None
    if os_info == "Linux-Phone":
        ps_cmd = ['getprop','python.process.suspend']
    else:
        ps_cmd = ['adb', 'shell', 'getprop','python.process.suspend']
    p = subprocess.Popen(ps_cmd,stdout=subprocess.PIPE)
    out = p.communicate()[0]
    for line in out.splitlines():
        if 'true' in line:
            log_test_framework(LOG_TAG, "suspend_flag = true, ---2 getprop");
            return True
    log_test_framework(LOG_TAG, "suspend_flag = false, ---2  getprop");
    return False
Пример #10
0
def getprop_suspend():
    os_info = get_platform_info()
    ps_cmd = None
    if os_info == "Linux-Phone":
        ps_cmd = ['getprop', 'python.process.suspend']
    else:
        ps_cmd = ['adb', 'shell', 'getprop', 'python.process.suspend']
    p = subprocess.Popen(ps_cmd, stdout=subprocess.PIPE)
    out = p.communicate()[0]
    for line in out.splitlines():
        if 'true' in line:
            log_test_framework(LOG_TAG, "suspend_flag = true, ---2 getprop")
            return True
    log_test_framework(LOG_TAG, "suspend_flag = false, ---2  getprop")
    return False
Пример #11
0
def init_logging_file(currentTime=1,repeatTime=1,test_env_xxx='/data/test_env'):
    '''
    ini the logging file which is saved the all python logs
    '''
    global python_log_path
    global osInfo
    global log_root
    global logging_filepath
    global status_path
    global python_log_name

    if log_root==None or log_root=="":
        osInfo = get_platform_info()
        if(osInfo == 'Linux-Phone'):
            import settings.common as SC
            log_root = SC.PUBLIC_LOG_PATH + '/'
            s = test_env_xxx.strip('/')[5:]
            __write_status(PREFIX_TEST_ENV_XXX + DIVIDE + s)
        elif(osInfo == 'Linux-PC' or osInfo == 'Windows'):
            os.system('adb root')
            global TEST_ENV_DIR
            log_root = TEST_ENV_DIR + os.sep + 'com.android.qrdtest'+os.sep
        if is_in_reboot_status():
            log_root = get_last_log_root()
            root_list = log_root.split('/')
            python_log_name = root_list[len(root_list)-2]
        else:
            python_log_name = get_file_timestring()
            log_root = log_root + python_log_name + os.sep
    log_status = log_root + os.sep + "log_status.qsst"
    if int(currentTime) == 1:
        __write_log(PREFIX_REPEAT_TIME + DIVIDE + str(repeatTime), log_status)
        __write_log(SERVICE_START_TIME + DIVIDE + get_file_timestring(), log_status)
    #if the repeat time is not 1. will create the child dir include the current time to save the log
    if int(repeatTime) > 1:
        logging_filepath = log_root + os.sep + str(currentTime)+ os.sep
        __write_log(PREFIX_LOGGING_PATH + DIVIDE + str(currentTime), log_status)
        __write_log("SUITS_START_TIME" + DIVIDE +get_file_timestring(), logging_filepath+ "log_status_"+str(currentTime)+".qsst")
    else:
        logging_filepath = log_root
        __write_log(PREFIX_LOGGING_PATH + DIVIDE + ".", log_status)
    python_log_path = logging_filepath + 'python.log'
    if not is_in_reboot_status():
        try:
            if not os.path.exists(logging_filepath):
                os.makedirs(logging_filepath)
        except OSError, why:
            print "Faild: %s " % str(why)
Пример #12
0
def notify_monitor_service_change():
    '''
    Notify Qsst Server to auto monitor service change, only run in Phone and items are not null.
    '''
    from case_utility import send_value_to_qsst, SEND_ITEMS_AUTO_MONITOR_SERVICE_CHANGE, BOOL_TRUE, BOOL_FALSE, SEND_FLAG_AUTO_MONITOR_SERVICE_CHANGE, SEND_TEST_ENV_DIR, SEND_LOG_ROOT
    import settings.common as SC
    osInfo = get_platform_info()
    if (osInfo == 'Linux-Phone'):
        send_value_to_qsst(SEND_ITEMS_AUTO_MONITOR_SERVICE_CHANGE,
                           SC.PUBLIC_SERVICE_CHANGE_ITEMS_FOR_AUTO_MONITOR)
        if (SC.PUBLIC_SERVICE_CHANGE_ITEMS_FOR_AUTO_MONITOR != ''):
            test_env = TEST_ENV_DIR[TEST_ENV_DIR.rfind('/') + 1:]
            send_value_to_qsst(SEND_TEST_ENV_DIR, test_env)
            send_value_to_qsst(SEND_LOG_ROOT, get_log_root())
            send_value_to_qsst(SEND_FLAG_AUTO_MONITOR_SERVICE_CHANGE,
                               BOOL_TRUE)
        else:
            send_value_to_qsst(SEND_FLAG_AUTO_MONITOR_SERVICE_CHANGE,
                               BOOL_FALSE)
Пример #13
0
def isAliveforProcess(pro_name):
    '''
    check a process's living state by given it's process name.
    
    @type pro_name: string
    @param pro_name: process name.
    @return: boolean
    '''
    os_info = get_platform_info()
    ps_cmd = None
    if os_info == "Linux-Phone":
        ps_cmd = ['ps']
    else:
        ps_cmd = ['adb', 'shell', 'ps']
        p = subprocess.Popen(ps_cmd,stdout=subprocess.PIPE)
        out = p.communicate()[0]
    for line in out.splitlines():
        if pro_name in line:
            return True
    return False
Пример #14
0
def init_logging_file(currentTime=0,repeatTime=1,test_env_xxx='/data/test_env'):
    '''
    ini the logging file which is saved the all python logs
    '''
    global python_log_path
    global osInfo
    global log_root
    global logging_filepath
    global status_path
    if log_root==None or log_root=="":
        osInfo = get_platform_info()
        if(osInfo == 'Linux-Phone'):
            import settings.common as SC
            log_root = SC.PUBLIC_LOG_PATH + '/'
            s = test_env_xxx.strip('/')[5:]
            __write_status(PREFIX_TEST_ENV_XXX + DIVIDE + s)
        elif(osInfo == 'Linux-PC' or osInfo == 'Windows'):
            os.system('adb root')
            global TEST_ENV_DIR
            log_root = TEST_ENV_DIR + os.sep + 'com.android.qrdtest'+os.sep
        if is_in_reboot_status():
            log_root = get_last_log_root()
        else:
            log_root = log_root + get_file_timestring() + os.sep
    log_status = log_root + os.sep + "log_status.qsst"
    if int(currentTime) == 0:
        __write_log(PREFIX_REPEAT_TIME + DIVIDE + str(repeatTime), log_status)
    #if the repeat time is not 1. will create the child dir include the current time to save the log
    if int(repeatTime) > 1:
        logging_filepath = log_root + os.sep + str(currentTime+1)+ os.sep
        __write_log(PREFIX_LOGGING_PATH + DIVIDE + str(currentTime+1), log_status)
    else:
        logging_filepath = log_root
        __write_log(PREFIX_LOGGING_PATH + DIVIDE + ".", log_status)
    python_log_path = logging_filepath + 'python.log'
    if not is_in_reboot_status():
        try:
            if not os.path.exists(logging_filepath):
                os.makedirs(logging_filepath)
        except OSError, why:
            print "Faild: %s " % str(why)
Пример #15
0
def __update_status_file_line(type, value):
    osInfo = get_platform_info()
    if not (osInfo == 'Linux-Phone'):
        return
    print type + str(value)
    global status_path
    f = open(status_path, 'r')
    lines = f.readlines()
    newLines = ''
    boo = False
    for line in lines:
         if line.find(type) >= 0:
              line = type + DIVIDE + str(value) + '\n'
              boo = True
         newLines += line
    f.close()

    f = open(status_path, 'w')
    if not boo:
        f.write(type + DIVIDE + str(value) + '\n')
    f.write(newLines)
    f.close()
Пример #16
0
def __update_status_file_line(type, value):
    osInfo = get_platform_info()
    if not (osInfo == 'Linux-Phone'):
        return
    print type + str(value)
    global status_path
    f = open(status_path, 'r')
    lines = f.readlines()
    newLines = ''
    boo = False
    for line in lines:
         if line.find(type) >= 0:
              line = type + DIVIDE + str(value) + '\n'
              boo = True
         newLines += line
    f.close()

    f = open(status_path, 'w')
    if not boo:
        f.write(type + DIVIDE + str(value) + '\n')
    f.write(newLines)
    f.close()
Пример #17
0
def kill_by_name(pro_name):
    '''
    kill a process by given it's process name.

    @type pro_name: string
    @param pro_name: process name.
    @return: none
    '''
    os_info = get_platform_info()
    ps_cmd = None
    if os_info == "Linux-Phone":
        ps_cmd = ['ps']
    else:
        ps_cmd = ['adb', 'shell', 'ps']
    p = subprocess.Popen(ps_cmd,stdout=subprocess.PIPE)
    out = p.communicate()[0]
    for line in out.splitlines():
        if pro_name in line:
            pid = int(line.split()[1])
            if os_info == "Linux-Phone":
                os.kill(pid,signal.SIGKILL)
            else:
                subprocess.call(['adb', 'shell', 'kill', str(pid)])
Пример #18
0
def kill_by_name(pro_name):
    '''
    kill a process by given it's process name.

    @type pro_name: string
    @param pro_name: process name.
    @return: none
    '''
    os_info = get_platform_info()
    ps_cmd = None
    if os_info == "Linux-Phone":
        ps_cmd = ['ps']
    else:
        ps_cmd = ['adb', 'shell', 'ps']
    p = subprocess.Popen(ps_cmd, stdout=subprocess.PIPE)
    out = p.communicate()[0]
    for line in out.splitlines():
        if pro_name in line:
            pid = int(line.split()[1])
            if os_info == "Linux-Phone":
                os.kill(pid, signal.SIGKILL)
            else:
                subprocess.call(['adb', 'shell', 'kill', str(pid)])
Пример #19
0
def init_acessibility_socket():
    '''
    Initialize server side socket, it will start up uiautomator socket.
    If used on PC , it will use also used adb forward  tcp:6100 to remote uiautomator
    socket running on device.
    '''
    kill_by_name('uiautomator')
    osInfo = get_platform_info()
    if(osInfo == "Windows" or osInfo == "Linux-PC"):
        os.system('adb shell am startservice -n com.android.qrdtest/.QsstService')
        os.system('adb forward tcp:6200 localabstract:myqsstservice')
        #subprocess.Popen(["adb", "shell", "uiautomator translatecases &"],stdout=subprocess.PIPE)
        thread.start_new_thread(Host_Start_Uiautomator, ())
        os.system('adb forward tcp:6100 localabstract:myuiautomator')
        #subprocess.Popen(cmd)
        pass
    elif(osInfo == "Linux-Phone"):
        os.system('am startservice -n com.android.qrdtest/.QsstService')
        os.system('uiautomator translatecases &')
    time.sleep(4)
    if not init_socket('\0' + fs_wrapper.ACCESSIBILITY_SOCKET_NAME, '\0' + fs_wrapper.QSSTSERVICE_SOCKET_NAME):
        print_report_line('init accessibility socket fail')
        return False
    return True
Пример #20
0
from qrd_shared.language.language import Language
import time
import qrd_shared.ime.methods.google_pinyin.key_map_800_480 as GOOGLE_PINYIN_KEY_800_480
import qrd_shared.ime.methods.google_pinyin.key_map_960_540 as GOOGLE_PINYIN_KEY_960_540
import qrd_shared.ime.methods.google_pinyin.key_map_1280_720 as GOOGLE_PINYIN_KEY_1280_720
import qrd_shared.ime.methods.predefine_input_seq as INPUT_SEQ
from qrd_shared.case import *
from platform_check import get_platform_info
############################################
#author:
#    [email protected]
#function:
#    the IME mode of qrd share lib.
#doc:
############################################
osInfo = get_platform_info()
if osInfo == 'Linux-Phone':
    wait_time = 0
elif osInfo == 'Linux-PC' or osInfo == 'Windows':
    wait_time = 0.5

class IME(Base):

    def __init__(self):
        self.mode_name = "ime"
        Base.__init__(self,self.mode_name)
        self.debug_print( 'Base init:%f' %(time.time()))

    def set_default_input_method(self, input_method_name):
        sleep(1)
Пример #21
0
def init_thrift_client():
    try:
        transport_qsst = TSocket.TSocket('localhost', port_qsst)
        # Buffering is critical. Raw sockets are very slow
        transport_qsst = TTransport.TBufferedTransport(transport_qsst)
        # Wrap in a protocol
        protocol_qsst = TBinaryProtocol.TBinaryProtocol(transport_qsst)
        # Create a client to use the protocol encoder
        transport_qsst.open()

        #set thrift qsst client
        thriftClient = ThriftClient()
        thriftClient.transport_qsst = transport_qsst
        thriftClient.protocol_qsst = protocol_qsst
        thriftClient.client_qsst = QSST_Thrift_Interface.Client(protocol_qsst)

        transport_uiautomator = TSocket.TSocket('localhost', port_uiautomator)
        # Buffering is critical. Raw sockets are very slow
        transport_uiautomator = TTransport.TBufferedTransport(
            transport_uiautomator)
        # Wrap in a protocol
        protocol_uiautomator = TBinaryProtocol.TBinaryProtocol(
            transport_uiautomator)
        # Create a client to use the protocol encoder
        transport_uiautomator.open()

        global transport_grouptest
        global protocol_grouptest
        global client_grouptest
        osInfo = get_platform_info()
        if (osInfo == "Windows" or osInfo == "Linux-PC"):
            transport_grouptest = TSocket.TSocket(
                'localhost', localport_grouptest_meserver)
        elif (osInfo == "Linux-Phone"):
            transport_grouptest = TSocket.TSocket('localhost',
                                                  port_grouptest_meserver)
        transport_grouptest = TTransport.TBufferedTransport(
            transport_grouptest)
        protocol_grouptest = TBinaryProtocol.TBinaryProtocol(
            transport_grouptest)
        client_grouptest = GroupTestMEService.Client(protocol_grouptest)
        print str(client_grouptest)
        transport_grouptest.open()

        #set thrift uiautomator client
        thriftClient.transport_uiautomator = transport_uiautomator
        thriftClient.protocol_uiautomator = protocol_uiautomator
        thriftClient.client_uiautomator = Uiautomator_Thrift_Interface.Client(
            protocol_uiautomator)

        #set thrift mytrackservice client
        transport_mytrackservice = TSocket.TSocket('localhost',
                                                   localport_mytrackservice)
        transport_mytrackservice = TTransport.TBufferedTransport(
            transport_mytrackservice)
        protocol_mytrackservice = TBinaryProtocol.TBinaryProtocol(
            transport_mytrackservice)
        transport_mytrackservice.open()

        thriftClient.transport_mytrackservice = transport_mytrackservice
        thriftClient.protocol_mytrackservice = protocol_mytrackservice
        thriftClient.client_mytrackservice = LocalMyTrackInterface.Client(
            protocol_mytrackservice)

        set_tls_thrift_client(thriftClient)

        return True
    except Thrift.TException, tx:
        log_test_framework(LOG_TAG, 'exception' + str(tx._get_message))
        return False
Пример #22
0
def enableTouchPanel():
    print('enable Touch Panel')
    if get_platform_info() == "Linux-Phone":
        os.system('sh /data/EnableTouchPanel.sh &')
Пример #23
0
def DisableTouchPanel(test_env_xxx):
    print('path is ' + test_env_xxx)
    if get_platform_info() == "Linux-Phone":
        os.system('sh /data/disableTouchPanel.sh ' + test_env_xxx + ' &')
    print('disable Touch Panel')
Пример #24
0
   @bug:
   @warning:



'''
from case_utility import *
from qrd_shared.Base import Base
from qrd_shared.language.language import Language
import time
import qrd_shared.ime.methods.predefine_input_seq as INPUT_SEQ
from qrd_shared.case import *
from platform_check import get_platform_info
from utility_wrapper import *

osInfo = get_platform_info()
if osInfo == 'Linux-Phone':
    wait_time = 0
elif osInfo == 'Linux-PC' or osInfo == 'Windows':
    wait_time = 0


class IME(Base):
    def __init__(self):
        '''
        init function.

        @see: L{Base <Base>}
        '''
        self.mode_name = "ime"
        Base.__init__(self, self.mode_name)
Пример #25
0
settings = Settings()
playstore = PlayStore()
launcher = Launcher()
phone = Phone()
browser = Browser()
email = Email()
doubanfm = Doubanfm()
mms = Mms()
gmail = Gmail()
ime = IME()
contact = Contact()
gallery = Gallery()
cmcc = Cmcc()
stability = Stability()

if(get_platform_info() == 'Windows'):
    shieldbox = ShieldBox()

LOG_TAG = 'qrd_share_case'

#create a instance
def createInstance(class_name, *args, **kwargs):
    (module_name, class_name) = class_name.rsplit('.', 1)
    module_meta = __import__(module_name, globals(), locals(), [class_name])
    class_meta = getattr(module_meta, class_name)
    o = class_meta(*args, **kwargs)
    return o


#call a case, will return the suit result
def call(suit_name,case_name,config_file_name='all_suit_config'):