Ejemplo n.º 1
0
    def _get_xwalk_app(self, test_suite, test_set, fuzzy_match, auto_iu):
        test_app_id = None
        if auto_iu:
            test_wgt = test_set
            test_wgt_path = XWALK_LOCATION % (TIZEN_USER, test_suite, test_wgt)

            if not self.install_app(test_wgt_path):
                LOGGER.info("[ failed to install widget \"%s\" in target ]" %
                            test_wgt)
                return None
        else:
            test_wgt = test_suite

        # check if widget installed already
        cmd = XWALK_QUERY_STR % (self.deviceid, TIZEN_USER, self.port,
                                 test_wgt)
        exit_code, ret = shell_command(cmd)
        if exit_code == -1:
            return None
        for line in ret:
            test_app_id = line.strip('\r\n')
        if test_app_id is None:
            LOGGER.info("[ test widget \"%s\" not found in target ]" %
                        test_wgt)
            return None

        return test_app_id
Ejemplo n.º 2
0
def _adunit_test_exec(conn, test_session, test_set_path, result_obj):
    """function for running core tests"""
    global result_buffer
    result_buffer = result_obj
    result_obj.set_status(0)
    checked = False
    i = 0
    for tc in test_set_path['cases']:
        LOGGER.info('[ android unit test, entry: %s ]' % tc['entry'])
        inst_pack = conn.get_installed_package(
            tc['entry'][:tc['entry'].rindex('.')])
        if not checked and i == 0:
            if len(inst_pack) > 0:
                checked = True
                test_cmd = ANDROID_UNIT_START % (tc['entry'], '.'.join(
                    tc['entry'].split('.')[:-1]))
                _code, _out, _error = conn.shell_cmd_ext(
                    cmd=test_cmd,
                    timeout=None,
                    boutput=True,
                    callbk=_adunit_lines_handler)
            else:
                i += 1
        elif checked:
            test_cmd = ANDROID_UNIT_START % (tc['entry'], '.'.join(
                tc['entry'].split('.')[:-1]))
            _code, _out, _error = conn.shell_cmd_ext(
                cmd=test_cmd,
                timeout=None,
                boutput=True,
                callbk=_adunit_lines_handler)
            i += 1
        else:
            pass
    result_obj.set_status(1)
Ejemplo n.º 3
0
    def run_test(self, sessionid, test_set):
        """
            process the execution for a test set
        """
        if sessionid is None:
            return False

        if not "cases" in test_set:
            return False

        cases, exetype, ctype = test_set["cases"], test_set[
            "exetype"], test_set["type"]
        if len(cases) == 0:
            return False
        # start debug trace thread
        self.conn.start_debug(self.opts['debug_log_base'])
        time.sleep(1)
        self.result_obj = TestSetResut(self.opts['testsuite_name'],
                                       self.opts['testset_name'])
        if self.opts['test_type'] == "webapi":
            if ctype == 'ref':
                exetype = 'manual'
            return self.__run_web_test(sessionid, self.opts['testset_name'],
                                       exetype, ctype, cases)
        elif self.opts['test_type'] == "coreapi":
            return self.__run_core_test(sessionid, self.opts['testset_name'],
                                        exetype, cases)
        elif self.opts['test_type'] == "jqunit":
            return self.__run_jqt_test(sessionid, self.opts['testset_name'],
                                       cases)
        else:
            LOGGER.info("[ unsupported test suite type ! ]")
            return False
Ejemplo n.º 4
0
    def _get_wrt_app(self, test_suite, test_set, fuzzy_match, auto_iu):
        test_app_id = None
        if auto_iu:
            test_wgt = test_set
            test_wgt_path = WRT_LOCATION % (test_suite, test_wgt)
            if not self.install_app(test_wgt_path):
                LOGGER.info("[ failed to install widget \"%s\" in target ]"
                            % test_wgt)
                return None
        else:
            test_wgt = test_suite

        # check if widget installed already
        cmd = WRT_QUERY_STR % (self.deviceid, test_wgt)
        exit_code, ret = shell_command(cmd)
        if exit_code == -1:
            return None
        for line in ret:
            items = line.split(':')
            if len(items) < 1:
                continue
            if (fuzzy_match and items[0].find(test_wgt) != -1) or items[0] == test_wgt:
                test_app_id = items[1].strip('\r\n')
                break

        if test_app_id is None:
            LOGGER.info("[ test widget \"%s\" not found in target ]"
                        % test_wgt)
            return None

        return test_app_id
Ejemplo n.º 5
0
    def _get_xwalk_app(self, test_suite, test_set, fuzzy_match, auto_iu):
        test_app_id = ""
        if auto_iu:
            test_wgt = test_set
            test_wgt_path = XWALK_LOCATION % (DEEPIN_USER, test_suite, test_wgt)
            if not self.install_app(test_wgt_path):
                LOGGER.info("[ failed to install widget \"%s\" in target ]"
                            % test_wgt)
                return None
        else:
            test_wgt = test_suite

        arr = test_wgt.split('-')
        for item in arr:
            test_app_id += item

        test_wgt = test_app_id 
        # check if widget installed already
        cmd = XWALK_QUERY_STR % (test_wgt)
        exit_code, ret = shell_command(cmd)
       
        if exit_code == -1:
            return None
     #   for line in ret:
     #       test_app_id = line.strip('\r\n')

        if test_app_id is None:
            LOGGER.info("[ test widget \"%s\" not found in target ]"
                        % test_wgt)
            return None

        return test_app_id
Ejemplo n.º 6
0
    def _get_wrt_app(self, test_suite, test_set, fuzzy_match, auto_iu):
        test_app_id = None
        if auto_iu:
            test_wgt = test_set
            test_wgt_path = WRT_LOCATION % (test_suite, test_wgt)
            if not self.install_app(test_wgt_path):
                LOGGER.info("[ failed to install widget \"%s\" in target ]" %
                            test_wgt)
                return None
        else:
            test_wgt = test_suite

        # check if widget installed already
        cmd = WRT_QUERY_STR % (self.deviceid, test_wgt)
        exit_code, ret = shell_command(cmd)
        if exit_code == -1:
            return None
        for line in ret:
            items = line.split(':')
            if len(items) < 1:
                continue
            if (fuzzy_match
                    and items[0].find(test_wgt) != -1) or items[0] == test_wgt:
                test_app_id = items[1].strip('\r\n')
                break

        if test_app_id is None:
            LOGGER.info("[ test widget \"%s\" not found in target ]" %
                        test_wgt)
            return None

        return test_app_id
Ejemplo n.º 7
0
    def _get_xwalk_app(self, test_suite, test_set, fuzzy_match, auto_iu):
        test_app_id = None
        if auto_iu:
            test_wgt = test_set
            test_wgt_path = XWALK_LOCATION % (test_suite, test_wgt)
            if not self.install_app(test_wgt_path):
                LOGGER.info("[ failed to install widget \"%s\" in target ]"
                            % test_wgt)
                return None
        else:
            test_wgt = test_suite

        # check if widget installed already
        cmd = XWALK_QUERY_STR % (self.deviceid, test_wgt)
        exit_code, ret = shell_command(cmd)
        if exit_code == -1:
            return None
        for line in ret:
            test_app_id = line.strip('\r\n')

        if test_app_id is None:
            LOGGER.info("[ test widget \"%s\" not found in target ]"
                        % test_wgt)
            return None

        return test_app_id
Ejemplo n.º 8
0
    def run_test(self, sessionid, test_set):
        """
            process the execution for a test set
        """
        if sessionid is None:
            return False

        if not "cases" in test_set:
            return False
        disabledlog = os.environ.get('disabledlog','')
        cases, exetype, ctype = test_set[
            "cases"], test_set["exetype"], test_set["type"]
        #print 'exetype', exetype
        if len(cases) == 0:
            return False
        # start debug trace thread
        if disabledlog == 'True':
            pass
        else:
            self.conn.start_debug(self.opts['debug_log_base'])
        time.sleep(1)
        self.result_obj = TestSetResut(
            self.opts['testsuite_name'], self.opts['testset_name'])
        if self.opts['test_type'] == "webapi":
            if ctype == 'ref':
                exetype = 'manual'
            return self.__run_web_test(sessionid, self.opts['testset_name'], exetype, ctype, cases)
        elif self.opts['test_type'] == "coreapi":
            return self.__run_core_test(sessionid, self.opts['testset_name'], exetype, cases)
        #elif self.opts['test_type'] == "jqunit":
        elif self.opts['test_type'] in ["jqunit",'pyunit']:
            return self.__run_jqt_test(sessionid, self.opts['testset_name'], cases)
        else:
            LOGGER.info("[ unsupported test suite type ! ]")
            return False
Ejemplo n.º 9
0
def _adunit_test_exec(conn, test_session, test_set_path, result_obj):
    """function for running core tests"""
    global result_buffer
    result_buffer = result_obj
    result_obj.set_status(0)
    LOGGER.info('[ android unit test, entry: %s ]' % test_set_path)
    test_cmd = ANDROID_UNIT_START % (test_set_path, '.'.join(test_set_path.split('.')[:-1]))
    _code, _out, _error = conn.shell_cmd_ext(cmd=test_cmd, timeout=None, boutput=True, callbk=_adunit_lines_handler)
    result_obj.set_status(1)
Ejemplo n.º 10
0
    def get_launcher_opt(self, test_launcher, test_ext, test_widget, test_suite, test_set):
        """
        get test option dict
        """
        test_opt = {}
        test_opt["launcher"] = WIN_MAIN
        LOGGER.info("[ test_ext: %s; test_widget: %s; test_suite: %s]" % (test_ext, test_widget, test_suite))
        test_opt["test_app_id"] = test_suite

        return test_opt
Ejemplo n.º 11
0
 def _get_user_id(self):
     if TIZEN_USER.lower() == 'app':
         self.port = '5000'
     else:
         cmdline = XWALK_QUERY_ID % (self.deviceid, TIZEN_USER)
         exit_code, ret = shell_command(cmdline)
         if exit_code == -1:
             LOGGER.info("[ can not get user id ]")
         if len(ret) > 0 :
             self.port = ret[0].strip('\r\n')
Ejemplo n.º 12
0
 def get_user_id(self):
     if TIZEN_USER == 'app':
         self.port = '5000'
     else:
         cmdline = XWALK_QUERY_ID % (self.deviceid, TIZEN_USER)
         exit_code, ret = shell_command(cmdline)
         if exit_code == -1:
             LOGGER.info("[ can not get user id ]")
         if len(ret) > 0:
             self.port = ret[0].strip('\r\n')
Ejemplo n.º 13
0
 def download_file(self, remote_path, local_path):
     """download file from device"""
     cmd = "adb -s %s pull %s %s" % (self.deviceid, remote_path, local_path)
     exit_code, ret = shell_command(cmd)
     if exit_code != 0:
         error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout"
         LOGGER.info("[ Download file \"%s\" failed, error: %s ]"
                     % (remote_path, error))
         return False
     else:
         return True
Ejemplo n.º 14
0
 def download_file(self, remote_path, local_path):
     """download file from device"""
     cmd = "adb -s %s pull %s %s" % (self.deviceid, remote_path, local_path)
     exit_code, ret = shell_command(cmd)
     if exit_code != 0:
         error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout"
         LOGGER.info("[ Download file \"%s\" failed, error: %s ]" %
                     (remote_path, error))
         return False
     else:
         return True
Ejemplo n.º 15
0
 def upload_file(self, remote_path, local_path):
     """upload file to device"""
     cmd = "sdb -s %s push %s %s" % (self.deviceid, local_path, remote_path)
     exit_code, ret = shell_command(cmd)
     if exit_code != 0:
         error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout"
         LOGGER.info("[ Upload file \"%s\" failed,"
                     " get error: %s ]" % (local_path, error))
         return False
     else:
         return True
Ejemplo n.º 16
0
 def upload_file(self, remote_path, local_path):
     """upload file to device"""
     cmd = "sdb -s %s push %s %s" % (self.deviceid, local_path, remote_path)
     exit_code, ret = shell_command(cmd)
     if exit_code != 0:
         error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout"
         LOGGER.info("[ Upload file \"%s\" failed,"
                     " get error: %s ]" % (local_path, error))
         return False
     else:
         return True
Ejemplo n.º 17
0
    def extend_result(self, cases_result=None, print_out=True):
        """update cases result to the result buffer"""
        self._mutex.acquire()
        if cases_result is not None:
            self._result["cases"].extend(cases_result)

        if print_out:
            for case_it in cases_result:
                LOGGER.info(self._progress % (self._suite_name, case_it["case_id"], case_it["result"]))
                if case_it["result"].lower() in ["fail", "block"] and "stdout" in case_it:
                    LOGGER.info(str2str(case_it["stdout"]))
        self._mutex.release()
Ejemplo n.º 18
0
def _pyunit_test_exec(test_session, test_set_path, result_obj):
    """function for running core tests"""
    global result_buffer
    result_buffer = result_obj
    result_obj.set_status(0)
    LOGGER.info('[ pyunit test: %s ]' % test_set_path)
    try:
        tests = unittest.TestLoader().discover(test_set_path, pattern='*test*.py')
        unittest.TextTestRunner(resultclass=LiteTestResult, buffer=True).run(tests)
    except ImportError as error:
        pass
    result_obj.set_status(1)
Ejemplo n.º 19
0
    def get_launcher_opt(self, test_launcher, test_ext, test_widget,
                         test_suite, test_set):
        """
        get test option dict
        """
        test_opt = {}
        test_opt["launcher"] = WIN_MAIN
        LOGGER.info("[ test_ext: %s; test_widget: %s; test_suite: %s]" %
                    (test_ext, test_widget, test_suite))
        test_opt["test_app_id"] = test_suite

        return test_opt
Ejemplo n.º 20
0
    def extend_result(self, cases_result=None, print_out=True):
        """update cases result to the result buffer"""
        self._mutex.acquire()
        if cases_result is not None:
            self._result["cases"].extend(cases_result)

        if print_out:
            for case_it in cases_result:
                LOGGER.info(self._progress %
                            (self._suite_name, case_it['case_id'], case_it['result']))
                if case_it['result'].lower() in ['fail', 'block'] and 'stdout' in case_it:
                    LOGGER.info(str2str(case_it['stdout']))
        self._mutex.release()
Ejemplo n.º 21
0
def kill_testkit_lite(pid_file):
    """ kill testkit lite"""
    try:
        with open(pid_file, "r") as pidfile:
            pid = pidfile.readline().rstrip("\n")
            if pid:
                killall(pid)
    except IOError as error:
        pattern = re.compile("No such file or directory|No such process")
        match = pattern.search(str(error))
        if not match:
            LOGGER.info("[ Error: fail to kill existing testkit-lite, " "error: %s ]\n" % error)
    return None
Ejemplo n.º 22
0
def kill_testkit_lite(pid_file):
    """ kill testkit lite"""
    try:
        with open(pid_file, "r") as pidfile:
            pid = pidfile.readline().rstrip("\n")
            if pid:
                killall(pid)
    except IOError as error:
        pattern = re.compile('No such file or directory|No such process')
        match = pattern.search(str(error))
        if not match:
            LOGGER.info("[ Error: fail to kill existing testkit-lite, "\
                "error: %s ]\n" % error)
    return None
Ejemplo n.º 23
0
    def extend_result(self, cases_result=None, print_out=True):
        """update cases result to the result buffer"""
        self._mutex.acquire()
        if cases_result is not None:
            self._result["cases"].extend(cases_result)

        if print_out:
            for case_it in cases_result:
                LOGGER.info(
                    self._progress %
                    (self._suite_name, case_it['case_id'], case_it['result']))
                if case_it['result'].lower() in ['fail', 'block'
                                                 ] and 'stdout' in case_it:
                    LOGGER.info(str2str(case_it['stdout']))
        self._mutex.release()
Ejemplo n.º 24
0
    def launch_app(self, wgt_name, extension=None):
        blauched = False
        if wgt_name.find('xwalk') != -1:
            timecnt = 0
            blauched = False
            pkg_name, actv_name = wgt_name.split('/')
            actv_name = actv_name.strip('.')
            origin_active_name = actv_name
            cmdline = APP_STOP % (self.deviceid, pkg_name)
            exit_code, ret = shell_command(cmdline)
            # cmdline = APP_START % (self.deviceid, wgt_name)
            # exit_code, ret = shell_command(cmdline)

            if self.launcher == "CordovaLauncher":
                # remove Activity to retry
                actv_name = actv_name.replace('Activity', '')
                LOGGER.info("[ Try to launch app: %s ]" %
                            (pkg_name + '/.' + actv_name))
                cmdline = APP_START % (self.deviceid,
                                       pkg_name + '/.' + actv_name)
                exit_code, ret = shell_command(cmdline)
            else:
                # use capitalize to retry
                actv_name = actv_name.replace('Activity', '')
                tmps = actv_name.split('_')
                actv_name = ''.join([it.capitalize() for it in tmps if it])
                LOGGER.info("[ Try to launch app: %s ]" %
                            (pkg_name + '/.' + actv_name + 'Activity'))
                cmdline = APP_START % (self.deviceid, pkg_name + '/.' +
                                       actv_name + 'Activity')
                exit_code, ret = shell_command(cmdline)
                if len(ret) > 1:
                    # remove Activity
                    LOGGER.info("[ Retry to launch app: %s ]" %
                                (pkg_name + '/.' + actv_name))
                    cmdline = APP_START % (self.deviceid,
                                           pkg_name + '/.' + actv_name)
                    exit_code, ret = shell_command(cmdline)
                    if len(ret) > 1:
                        actv_name = origin_active_name.capitalize().replace(
                            "activity", "Activity")
                        LOGGER.info("[ Try to launch app: %s ]" %
                                    (pkg_name + '/.' + actv_name))
                        cmdline = APP_START % (self.deviceid,
                                               pkg_name + '/.' + actv_name)
                        exit_code, ret = shell_command(cmdline)

            blauched = True
            time.sleep(3)
        else:
            cmdline = APP_NONBLOCK_STR % (self.deviceid, wgt_name)
            exit_code, ret = shell_command(cmdline)
            time.sleep(3)
            cmd = APP_QUERY_STR % (self.deviceid, wgt_name)
            exit_code, ret = shell_command(cmd)
            if ret and len(ret):
                blauched = True
        return blauched
Ejemplo n.º 25
0
def _webuifw_test_exec(conn, test_web_app, test_session, test_set_name,
                       exetype, cases_queue, result_obj):
    """function for running webuifw tests"""
    global UIFW_SET_NUM
    UIFW_SET_NUM = UIFW_SET_NUM + 1
    set_UIFW_RESULT = UIFW_RESULT + "_" + str(UIFW_SET_NUM) + ".xml"
    result_obj.set_status(0)
    result_obj.set_result({"resultfile": ""})
    ls_cmd = "ls -l %s" % set_UIFW_RESULT
    sz_cmd = "du -hk %s " % set_UIFW_RESULT
    time_out = UIFW_MAX_TIME
    rm_cmd = "rm /opt/usr/media/Documents/tcresult*.xml"

    if exetype == "auto":
        conn.shell_cmd(rm_cmd)
        UIFW_SET_NUM = 1
        LOGGER.info('[webuifw] start test executing')
        if not conn.launch_app(test_web_app):
            LOGGER.info("[ launch test app \"%s\" failed! ]" % test_web_app)
            result_obj.set_result({"resultfile": ""})
            result_obj.set_status(1)

    result_file = FILES_ROOT + test_session + "_uifw.xml"

    while time_out > 0:
        LOGGER.info('[webuifw] waiting for test completed...')
        exit_code, ret = conn.shell_cmd(ls_cmd)
        if not 'No such file or directory' in ret[0]:
            exit_code, ret = conn.shell_cmd(sz_cmd)
            f_size = int(ret[0].split("\t")[0])
            if f_size > 0:
                break
            if time_out > UIFW_MAX_WRITE_TIME:
                time_out = UIFW_MAX_WRITE_TIME
        time.sleep(2)
        time_out -= 2

    LOGGER.info('[webuifw] end test executing')
    if conn.download_file(set_UIFW_RESULT, result_file):
        result_obj.set_result({"resultfile": result_file})
    for test_case in cases_queue:
        LOGGER.info("[webuifw] execute case: %s # %s" %
                    (test_set_name, test_case['case_id']))
    result_obj.set_status(1)
Ejemplo n.º 26
0
 def download_file(self, remote_path, local_path):
     """download file from device"""
     local_path_dir = os.path.dirname(local_path)
     if not os.path.exists(local_path_dir):
         os.makedirs(local_path_dir)
     filename = os.path.basename(remote_path)
     cmd = "sdb -s %s pull %s %s" % (
         self.deviceid, remote_path, local_path_dir)
     exit_code, ret = shell_command(cmd)
     if exit_code != 0:
         error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout"
         LOGGER.info("[ Download file \"%s\" failed, error: %s ]"
                     % (remote_path, error))
         return False
     else:
         src_path = os.path.join(local_path_dir, filename)
         if src_path != local_path:
             shutil.move(src_path, local_path)
         return True
Ejemplo n.º 27
0
 def download_file(self, remote_path, local_path):
     """download file from device"""
     local_path_dir = os.path.dirname(local_path)
     if not os.path.exists(local_path_dir):
         os.makedirs(local_path_dir)
     filename = os.path.basename(remote_path)
     cmd = "sdb -s %s pull %s %s" % (self.deviceid, remote_path,
                                     local_path_dir)
     exit_code, ret = shell_command(cmd)
     if exit_code != 0:
         error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout"
         LOGGER.info("[ Download file \"%s\" failed, error: %s ]" %
                     (remote_path, error))
         return False
     else:
         src_path = os.path.join(local_path_dir, filename)
         if src_path != local_path:
             shutil.move(src_path, local_path)
         return True
Ejemplo n.º 28
0
def _webuifw_test_exec(conn, test_web_app, test_session, test_set_name, exetype, cases_queue, result_obj):
    """function for running webuifw tests"""
    global UIFW_SET_NUM
    UIFW_SET_NUM = UIFW_SET_NUM + 1
    set_UIFW_RESULT = UIFW_RESULT + "_" + str(UIFW_SET_NUM) +".xml"
    result_obj.set_status(0)
    result_obj.set_result({"resultfile": ""})
    ls_cmd = "ls -l %s" % set_UIFW_RESULT
    sz_cmd = "du -hk %s " % set_UIFW_RESULT
    time_out = UIFW_MAX_TIME
    rm_cmd = "rm /opt/usr/media/Documents/tcresult*.xml"

    if exetype == "auto":
        conn.shell_cmd(rm_cmd)
        UIFW_SET_NUM = 1
        LOGGER.info('[webuifw] start test executing')
        if not conn.launch_app(test_web_app):
            LOGGER.info("[ launch test app \"%s\" failed! ]" % test_web_app)
            result_obj.set_result({"resultfile": ""})
            result_obj.set_status(1)

    result_file = FILES_ROOT + test_session + "_uifw.xml"

    while time_out > 0:
        LOGGER.info('[webuifw] waiting for test completed...')
        exit_code, ret = conn.shell_cmd(ls_cmd)
        if not 'No such file or directory' in ret[0]:
            exit_code, ret = conn.shell_cmd(sz_cmd)
            f_size = int(ret[0].split("\t")[0])
            if f_size > 0:
                break
            if time_out > UIFW_MAX_WRITE_TIME:
                time_out = UIFW_MAX_WRITE_TIME
        time.sleep(2)
        time_out -= 2

    LOGGER.info('[webuifw] end test executing')
    if conn.download_file(set_UIFW_RESULT, result_file):
        result_obj.set_result({"resultfile": result_file})
    for test_case in cases_queue:
        LOGGER.info("[webuifw] execute case: %s # %s" %
                    (test_set_name, test_case['case_id']))
    result_obj.set_status(1)
Ejemplo n.º 29
0
    def launch_app(self, wgt_name, extension=None):
        blauched = False
        cmdline = LAUNCH_XWALK % (wgt_name, wgt_name, wgt_name)
        if extension is not None:
            cmdline = LAUNCH_XWALK_EXTENSIONS % (wgt_name, wgt_name, wgt_name, wgt_name, extension)
        cmd_json = {}
        cmd_json['cmd'] = cmdline
        server_url = "http://%s:8000" % self.deviceip
        ret = http_request(
            get_url(server_url, "/execute_async_cmd"), "POST", cmd_json, 30)
        time.sleep(3)

        cmdline = QUERY_XWALK
        cmd_json['cmd'] = cmdline
        ret = http_request(
            get_url(server_url, "/execute_cmd"), "POST", cmd_json, 30)
        if ret and len(ret):
            blauched = True
        LOGGER.info("[ Launch test cases launcher: %s" % blauched);
        return blauched
Ejemplo n.º 30
0
    def launch_app(self, wgt_name, extension=None):
        blauched = False
        cmdline = LAUNCH_XWALK % (wgt_name, wgt_name, wgt_name)
        if extension is not None:
            cmdline = LAUNCH_XWALK_EXTENSIONS % (wgt_name, wgt_name, wgt_name,
                                                 wgt_name, extension)
        cmd_json = {}
        cmd_json['cmd'] = cmdline
        server_url = "http://%s:8000" % self.deviceip
        ret = http_request(get_url(server_url, "/execute_async_cmd"), "POST",
                           cmd_json, 30)
        time.sleep(3)

        cmdline = QUERY_XWALK
        cmd_json['cmd'] = cmdline
        ret = http_request(get_url(server_url, "/execute_cmd"), "POST",
                           cmd_json, 30)
        if ret and len(ret):
            blauched = True
        LOGGER.info("[ Launch test cases launcher: %s" % blauched)
        return blauched
Ejemplo n.º 31
0
    def __init_test_stub(self, stub_app, stub_port, debug_opt):
        # init testkit-stub deamon process
        timecnt = 0
        blaunched = False
        while timecnt < CNT_RETRY:
            if not self.conn.check_process(stub_app):
                LOGGER.info(
                    "[ no stub process activated, now try to launch %s ]" %
                    stub_app)
                self.conn.launch_stub(stub_app, stub_port, debug_opt)
                timecnt += 1
            else:
                blaunched = True
                break

        if not blaunched:
            LOGGER.info("[ launch stub process failed! ]")
            return False

        if self.server_url is None:
            self.server_url = self.conn.get_server_url(stub_port)

        timecnt = 0
        blaunched = False
        while timecnt < CNT_RETRY:
            ret = http_request(
                get_url(self.server_url, "/check_server_status"), "GET", {})
            if ret is None:
                LOGGER.info("[ check server status, not ready yet! ]")
                timecnt += 1
                time.sleep(1)
            else:
                blaunched = True
                break
        return blaunched
Ejemplo n.º 32
0
    def __init_test_stub(self, stub_app, stub_port, debug_opt):
        # init testkit-stub deamon process
        timecnt = 0
        blaunched = False
        while timecnt < CNT_RETRY:
            #print 'stub_app' ,stub_app
            if not self.conn.check_process(stub_app):
                LOGGER.info("[ no stub process activated, now try to launch %s ]" % stub_app)
                self.conn.launch_stub(stub_app, stub_port, debug_opt)
                timecnt += 1
            else:
                blaunched = True
                break

        if not blaunched:
            LOGGER.info("[ launch stub process failed! ]")
            return False

        if self.server_url is None:
            self.server_url = self.conn.get_server_url(stub_port)

        timecnt = 0
        blaunched = False
        while timecnt < CNT_RETRY:
            ret = http_request(get_url(
                self.server_url, "/check_server_status"), "GET", {})
            if ret is None:
                LOGGER.info("[ check server status, not ready yet! ]")
                timecnt += 1
                time.sleep(1)
            else:
                blaunched = True
                break
        return blaunched
Ejemplo n.º 33
0
    def launch_app(self, wgt_name, extension=None):
        blauched = False
        if wgt_name.find('xwalk') != -1:
            timecnt = 0
            blauched = False
            pkg_name, actv_name = wgt_name.split('/')
            actv_name = actv_name.strip('.')
            origin_active_name = actv_name
            cmdline = APP_STOP % (self.deviceid, pkg_name)
            exit_code, ret = shell_command(cmdline)
           # cmdline = APP_START % (self.deviceid, wgt_name)
           # exit_code, ret = shell_command(cmdline)

            if  self.launcher == "CordovaLauncher" :
                # remove Activity to retry
                actv_name = actv_name.replace('Activity', '')
                LOGGER.info("[ Try to launch app: %s ]" % (pkg_name + '/.' + actv_name))
                cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name)
                exit_code, ret = shell_command(cmdline)
            else:
                # use capitalize to retry
                actv_name = actv_name.replace('Activity', '')
                tmps = actv_name.split('_')
                actv_name = ''.join([it.capitalize() for it in tmps if it])
                LOGGER.info("[ Try to launch app: %s ]" % (pkg_name + '/.' + actv_name + 'Activity'))
                cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name + 'Activity')
                exit_code, ret = shell_command(cmdline)
                if len(ret) > 1:
                    # remove Activity
                    LOGGER.info("[ Retry to launch app: %s ]" % (pkg_name + '/.' + actv_name))
                    cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name)
                    exit_code, ret = shell_command(cmdline)
                    if len(ret) > 1:
                        actv_name = origin_active_name.capitalize().replace("activity", "Activity")
                        LOGGER.info("[ Try to launch app: %s ]" % (pkg_name + '/.' + actv_name))
                        cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name)
                        exit_code, ret = shell_command(cmdline)

            blauched = True
            time.sleep(3)
        else:
            cmdline = APP_NONBLOCK_STR % (self.deviceid, wgt_name)
            exit_code, ret = shell_command(cmdline)
            time.sleep(3)
            cmd = APP_QUERY_STR % (self.deviceid, wgt_name)
            exit_code, ret = shell_command(cmd)
            if ret and len(ret):
                blauched = True
        return blauched
Ejemplo n.º 34
0
    def run_test(self, sessionid, test_set):
        """
            process the execution for a test set
        """
        extension = test_set["extension"]

        if sessionid is None:
            return False

        if not "cases" in test_set:
            return False
        disabledlog = os.environ.get('disabledlog','')
        cases, exetype, ctype = test_set[
            "cases"], test_set["exetype"], test_set["type"]
        

        if len(cases) == 0:
            return False
        # start debug trace thread
        if disabledlog == 'True':
            pass
        else:
            self.conn.start_debug(self.opts['debug_log_base'])
        time.sleep(1)
        self.result_obj = TestSetResut(
            self.opts['testsuite_name'], self.opts['testset_name'])
        if self.opts['test_type'] == "webapi":
            if ctype == 'ref':
                exetype = 'manual'
            return self.__run_web_test(sessionid, self.opts['testset_name'], exetype, ctype, cases, extension)
        elif self.opts['test_type'] == "coreapi":
            return self.__run_core_test(sessionid, self.opts['testset_name'], exetype, cases)
        #elif self.opts['test_type'] == "jqunit":
        elif self.opts['test_type'] in ["jqunit",'pyunit']:
            return self.__run_jqt_test(sessionid, self.opts['testset_name'], cases)
        else:
            LOGGER.info("[ unsupported test suite type ! ]")
            return False
Ejemplo n.º 35
0
def _adunit_test_exec(conn, test_session, test_set_path, result_obj):
    """function for running core tests"""
    global result_buffer
    result_buffer = result_obj
    result_obj.set_status(0)
    checked = False
    i = 0
    for tc in test_set_path['cases']:
        LOGGER.info('[ android unit test, entry: %s ]' % tc['entry'])
        inst_pack = conn.get_installed_package(tc['entry'][:tc['entry'].rindex('.')])
        if not checked and i == 0:
            if  len(inst_pack) > 0:
                checked = True
                test_cmd = ANDROID_UNIT_START % (tc['entry'], '.'.join(tc['entry'].split('.')[:-1]))
                _code, _out, _error = conn.shell_cmd_ext(cmd=test_cmd, timeout=None, boutput=True, callbk=_adunit_lines_handler)
            else:
                i += 1
        elif checked:
            test_cmd = ANDROID_UNIT_START % (tc['entry'], '.'.join(tc['entry'].split('.')[:-1]))
            _code, _out, _error = conn.shell_cmd_ext(cmd=test_cmd, timeout=None, boutput=True, callbk=_adunit_lines_handler)
            i += 1
        else:
            pass
    result_obj.set_status(1)
Ejemplo n.º 36
0
    def launch_app(self, wgt_name):
        blauched = False
        print 'debug wgt name', wgt_name
        if wgt_name.find('xwalk') != -1:
            timecnt = 0
            blauched = False
            pkg_name, actv_name = wgt_name.split('/')
            actv_name = actv_name.strip('.')
            cmdline = APP_STOP % (self.deviceid, pkg_name)
            exit_code, ret = shell_command(cmdline)
            cmdline = APP_START % (self.deviceid, wgt_name)
            print 'debug', cmdline
            exit_code, ret = shell_command(cmdline)
            if len(ret) > 1:
                # remove Activity to retry
                actv_name = actv_name.replace('Activity', '')
                LOGGER.info("[ Retry to launch app: %s ]" % (pkg_name + '/.' + actv_name))
                cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name)
                exit_code, ret = shell_command(cmdline)
            if len(ret) > 1:
                # use capitalize to retry
                tmps = actv_name.split('_')
                actv_name = ''.join([it.capitalize() for it in tmps if it])
                LOGGER.info("[ Retry to launch app: %s ]" % (pkg_name + '/.' + actv_name + 'Activity'))
                cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name + 'Activity')
                exit_code, ret = shell_command(cmdline)
                if len(ret) > 1:
                    # remove Activity
                    LOGGER.info("[ Retry to launch app: %s ]" % (pkg_name + '/.' + actv_name))
                    cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name)
                    exit_code, ret = shell_command(cmdline)

            blauched = True
            time.sleep(3)
        else:
            cmdline = APP_NONBLOCK_STR % (self.deviceid, wgt_name)
            exit_code, ret = shell_command(cmdline)
            time.sleep(3)
            cmd = APP_QUERY_STR % (self.deviceid, wgt_name)
            exit_code, ret = shell_command(cmd)
            if ret and len(ret):
                blauched = True
        return blauched
Ejemplo n.º 37
0
 def shell_cmd_ext(self,
                   cmd="",
                   timeout=None,
                   boutput=False,
                   stdout_file=None,
                   stderr_file=None):
     check_stub_num = 0
     while (not self.check_process("")) and check_stub_num < 3:
         self.launch_stub("")
         check_stub_num += 1
         time.sleep(3)
     cmd_json = {}
     cmd_json['cmd'] = cmd
     server_url = "http://%s:8000" % self.deviceip
     result = http_request(get_url(server_url, "/general_cmd_response"),
                           "POST", cmd_json, 30)
     if result is not None:
         LOGGER.info("Response exit_code: %s" % result["exit_code"])
         LOGGER.info("Response output: %s" % result["output"])
         time.sleep(1)
         return [int(result["exit_code"]), result["output"], []]
     else:
         LOGGER.info("Fail to connect stub!")
         return [-1, ["Fail to connect stub"], []]
Ejemplo n.º 38
0
 def shell_cmd_ext(self,
                   cmd="",
                   timeout=None,
                   boutput=False,
                   stdout_file=None,
                   stderr_file=None):
     check_stub_num = 0
     while (not self.check_process("")) and check_stub_num < 3:
         self.launch_stub("")
         check_stub_num += 1
         time.sleep(3)
     cmd_json = {}
     cmd_json['cmd'] = cmd
     server_url = "http://%s:8000" % self.deviceip
     result = http_request(
         get_url(server_url, "/general_cmd_response"), "POST", cmd_json, 30)
     if result is not None:
         LOGGER.info("Response exit_code: %s" % result["exit_code"])
         LOGGER.info("Response output: %s" % result["output"])
         time.sleep(1)
         return [int(result["exit_code"]), result["output"], []]
     else:
         LOGGER.info("Fail to connect stub!")
         return [-1, ["Fail to connect stub"], []]
Ejemplo n.º 39
0
import os
import time
import socket
import threading
import re
import sys
from shutil import copyfile
from testkitlite.util.log import LOGGER
from testkitlite.util.autoexec import shell_command, shell_command_ext
from testkitlite.util.killall import killall
from testkitlite.util.errors import InvalidDeviceException

try:
    import paramiko
except ImportError, err:
    LOGGER.info("Failed to import 'paramiko' module, please check your installation:")
    LOGGER.info("  You can use 'sudo pip install paramiko' to install the module!")
    sys.exit(1)


HOST_NS = "127.0.0.1"
os.environ['no_proxy'] = HOST_NS
os.environ['TEST_PLATFORM'] = 'tizen'
os.environ['CONNECT_TYPE'] = 'ssh'
TIZEN_USER = os.environ.get('TIZEN_USER', 'app')
#print 'debug', os.environ.get('TIZEN_USER','')

# common constants
RPM_INSTALL = "ssh %s rpm -ivh %s"
RPM_UNINSTALL = "ssh %s rpm -e %s"
RPM_LIST = "ssh %s rpm -qa | grep tct"
Ejemplo n.º 40
0
def _core_test_exec(conn, test_session, test_set_name, exetype, cases_queue,
                    result_obj):
    """function for running core tests"""
    exetype = exetype.lower()
    total_count = len(cases_queue)
    current_idx = 0
    manual_skip_all = False
    result_list = []
    stdout_file = FILES_ROOT + test_session + "_stdout.log"
    stderr_file = FILES_ROOT + test_session + "_stderr.log"
    for test_case in cases_queue:
        if result_obj.get_status() == 1:
            break

        current_idx += 1
        core_cmd = ""
        if "entry" in test_case:
            core_cmd = test_case["entry"]
        else:
            LOGGER.info("[ Warnning: test script is empty,"
                        " please check your test xml file ]")
            continue
        expected_result = test_case.get('expected_result', '0')
        time_out = int(test_case.get('timeout', '90'))
        location = test_case.get('location', 'device')
        measures = test_case.get('measures', [])
        retmeasures = []
        LOGGER.info("\n[core test] execute case:\nTestCase: %s\n"
                    "TestEntry: %s\nExpected: %s\nTotal: %s, Current: %s" %
                    (test_case['case_id'], test_case['entry'], expected_result,
                     total_count, current_idx))
        LOGGER.info("[ execute core test script, please wait ! ]")
        strtime = datetime.now().strftime(DATE_FORMAT_STR)
        LOGGER.info("start time: %s" % strtime)
        test_case["start_at"] = strtime
        if exetype == 'auto':
            return_code, stdout, stderr = -1, [], []
            if location == 'host':
                return_code, stdout, stderr = conn.shell_cmd_host(
                    core_cmd, time_out, False, stdout_file, stderr_file)
            else:
                return_code, stdout, stderr = conn.shell_cmd_ext(
                    core_cmd, time_out, False, stdout_file, stderr_file)
            if return_code is not None and return_code != "timeout":
                test_case["result"] = "pass" if str(
                    return_code) == expected_result else "fail"
                test_case["stdout"] = stdout
                test_case["stderr"] = stderr
                for item in measures:
                    ind = item['name']
                    fname = item['file']
                    if fname is None:
                        continue
                    tmpname = FILES_ROOT + test_session + "_mea_tmp"
                    if conn.download_file(fname, tmpname):
                        try:
                            config = ConfigParser.ConfigParser()
                            config.read(tmpname)
                            item['value'] = config.get(ind, 'value')
                            retmeasures.append(item)
                            os.remove(tmpname)
                        except IOError as error:
                            LOGGER.error("[ Error: fail to parse value,"
                                         " error:%s ]\n" % error)
                test_case["measures"] = retmeasures
            else:
                test_case["result"] = "BLOCK"
                test_case["stdout"] = stdout
                test_case["stderr"] = stderr
        elif exetype == 'manual':
            # handle manual core cases
            try:
                # LOGGER.infopre-condition info
                if "pre_condition" in test_case:
                    LOGGER.info("\n****\nPre-condition: %s\n ****\n" %
                                test_case['pre_condition'])
                # LOGGER.infostep info
                if "steps" in test_case:
                    for step in test_case['steps']:
                        LOGGER.info("********************\n"
                                    "Step Order: %s" % step['order'])
                        LOGGER.info("Step Desc: %s" % step['step_desc'])
                        LOGGER.info("Expected: %s\n********************\n" %
                                    step['expected'])
                if manual_skip_all:
                    test_case["result"] = "N/A"
                else:
                    while True:
                        test_result = raw_input(
                            '[ please input case result ]'
                            ' (p^PASS, f^FAIL, b^BLOCK, n^Next, d^Done):')
                        if test_result.lower() == 'p':
                            test_case["result"] = "PASS"
                            break
                        elif test_result.lower() == 'f':
                            test_case["result"] = "FAIL"
                            break
                        elif test_result.lower() == 'b':
                            test_case["result"] = "BLOCK"
                            break
                        elif test_result.lower() == 'n':
                            test_case["result"] = "N/A"
                            break
                        elif test_result.lower() == 'd':
                            manual_skip_all = True
                            test_case["result"] = "N/A"
                            break
                        else:
                            LOGGER.info(
                                "[ Warnning: you input: '%s' is invalid,"
                                " please try again ]" % test_result)
            except IOError as error:
                LOGGER.info("[ Error: fail to get core manual test step,"
                            " error: %s ]\n" % error)
        strtime = datetime.now().strftime(DATE_FORMAT_STR)
        LOGGER.info("end time: %s" % strtime)
        test_case["end_at"] = strtime
        LOGGER.info("Case Result: %s" % test_case["result"])
        result_list.append(test_case)

    result_obj.extend_result(result_list, False)
    result_obj.set_status(1)
Ejemplo n.º 41
0
    def __init_webtest_opt(self, params):
        """init the test runtime, mainly process the star up of test stub"""
        if params is None:
            return None

        session_id = str(uuid.uuid1())
        stub_app = params.get('stub-name', 'testkit-stub')
        stub_port = params.get('stub-port', '8000')
        testsuite_name = params.get('testsuite-name', '')
        testset_name = params.get('testset-name', '')
        capability_opt = params.get("capability", None)
        test_launcher = params.get('test-launcher', '')
        test_extension = params.get('test-extension', None)
        test_widget = params.get('test-widget', None)

        test_opt = self.conn.get_launcher_opt(test_launcher, test_extension,
                                              test_widget, testsuite_name,
                                              testset_name)
        if test_opt is None:
            LOGGER.info("[ init the test launcher, get failed ]")
            return None
        LOGGER.info("[ web test launcher: %s ]" % test_opt["launcher"])
        LOGGER.info("[ web test app: %s ]" % test_opt["test_app_id"])
        self.opts.update(test_opt)
        self.opts['debug_mode'] = params.get("debug", False)

        # uifw, this suite don't need stub
        if self.opts['self_exec'] or self.opts['self_repeat']:
            self.opts['test_type'] = "jqunit"
            return session_id

        # enable debug information
        stub_debug_opt = "--debug" if self.opts['debug_mode'] else ""

        # suite_id to be removed in later version
        test_opt["suite_id"] = test_opt["test_app_id"]
        if self.__init_test_stub(stub_app, stub_port, stub_debug_opt):
            ret = http_request(get_url(self.server_url, "/init_test"), "POST",
                               test_opt)
            if ret is None:
                LOGGER.info("[ init test suite failed! ]")
                return None
            elif "error_code" in ret:
                LOGGER.info("[ init test suite, "
                            "get error code %d ! ]" % ret["error_code"])
                return None

            if capability_opt is not None:
                ret = http_request(get_url(self.server_url, "/set_capability"),
                                   "POST", capability_opt)
            return session_id
        else:
            LOGGER.info("[ Init test failed ! ]")
            return None
Ejemplo n.º 42
0
import logging
import subprocess
import ConfigParser
from testkitlite.util import tr_utils
from testkitlite.util.log import LOGGER as g_logger
from urlparse import urlparse
import md5


try:
    from selenium.webdriver.common.by import By
    from selenium.webdriver.remote.webdriver import WebDriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
except ImportError, err:
    g_logger.info("Failed to import 'selenium' module, please check your installation:")
    g_logger.info("  You can use 'sudo pip install selenium' to install the module!")
    raise ImportError

TE = None
EXE_LOCK = threading.Lock()
DEFAULT_TIMEOUT = 90
REF_SET_TYPE = 'ref'
JS_SET_TYPE = 'js'
QUNIT_SET_TYPE = 'qunit'
STR_PASS = '******'
STR_FAIL = 'FAIL'
STR_BLOCK = 'BLOCK'
STR_NOTRUN = 'n/a'
DEFAULT_WD_URL = 'http://127.0.0.1:9515'
MH_FILE = "/opt/testkit/lite/mh.html"
Ejemplo n.º 43
0
def _core_test_exec(conn, test_session, test_set_name, exetype, cases_queue, result_obj):
    """function for running core tests"""
    exetype = exetype.lower()
    total_count = len(cases_queue)
    current_idx = 0
    manual_skip_all = False
    result_list = []
    stdout_file = FILES_ROOT + test_session + "_stdout.log"
    stderr_file = FILES_ROOT + test_session + "_stderr.log"
    initscript = os.environ.get('initscript','')
    postscript = os.environ.get('postscript','')
    for test_case in cases_queue:
        if result_obj.get_status() == 1:
            break

        current_idx += 1
        core_cmd = ""
        if "entry" in test_case:
            core_cmd = test_case["entry"]
        else:
            LOGGER.info(
                "[ Warnning: test script is empty,"
                " please check your test xml file ]")
            continue
        expected_result = test_case.get('expected_result', '0')
        time_out = int(test_case.get('timeout', '90'))
        location = test_case.get('location', 'device')
        measures = test_case.get('measures', [])
        retmeasures = []
        #LOGGER.info("CASE_ID %s"  %test_case['case_id'])
        os.environ['CASE_ID'] = test_case['case_id']
        LOGGER.info("\n[core test] execute case:\nTestCase: %s\n"
                    "TestEntry: %s\nExpected: %s\nTotal: %s, Current: %s"
                    % (test_case['case_id'], test_case['entry'],
                       expected_result, total_count, current_idx))
        LOGGER.info("[ execute core test script, please wait ! ]")
        strtime = datetime.now().strftime(DATE_FORMAT_STR)
        LOGGER.info("start time: %s" % strtime)
        test_case["start_at"] = strtime
        if exetype == 'auto':
            return_code, stdout, stderr = -1, [], []
            if location == 'host':
                if len(initscript) > 1:
                    return_code, stdout, stderr = conn.shell_cmd_host(initscript, time_out, False, stdout_file, stderr_file)
                   
                    if return_code is not None and return_code != "timeout":
                        LOGGER.info('init script ok')
                    else:
                        LOGGER.info('init script fail')
                return_code, stdout, stderr = -1, [], []
                return_code, stdout, stderr = conn.shell_cmd_host(core_cmd, time_out, False, stdout_file, stderr_file)
            else:
                if len(initscript) >1 :
                    return_code, stdout, stderr = conn.shell_cmd_ext(initscript, time_out, False, stdout_file, stderr_file)
                    if return_code is not None and return_code != "timeout":
                        LOGGER.info('init script ok')
                    else:
                        LOGGER.info('init script fail')
                return_code, stdout, stderr = -1, [], []
                return_code, stdout, stderr = conn.shell_cmd_ext(core_cmd, time_out, False, stdout_file, stderr_file)
            print 'return ', return_code, stdout, stderr
            if return_code is not None and return_code != "timeout":
                test_case["result"] = "pass" if str(
                    return_code) == expected_result else "fail"
                test_case["stdout"] = stdout
                test_case["stderr"] = stderr
                for item in measures:
                    ind = item['name']
                    fname = item['file']
                    if fname is None:
                        continue
                    tmpname = FILES_ROOT + test_session + "_mea_tmp"
                    if conn.download_file(fname, tmpname):
                        try:
                            config = ConfigParser.ConfigParser()
                            config.read(tmpname)
                            item['value'] = config.get(ind, 'value')
                            retmeasures.append(item)
                            os.remove(tmpname)
                        except IOError as error:
                            LOGGER.error(
                                "[ Error: fail to parse value,"
                                " error:%s ]\n" % error)
                test_case["measures"] = retmeasures
            else:
                test_case["result"] = "BLOCK"
                test_case["stdout"] = stdout
                test_case["stderr"] = stderr
        elif exetype == 'manual':
            # handle manual core cases
            try:
                # LOGGER.infopre-condition info
                if "pre_condition" in test_case:
                    LOGGER.info("\n****\nPre-condition: %s\n ****\n"
                                % test_case['pre_condition'])
                # LOGGER.infostep info
                if "steps" in test_case:
                    for step in test_case['steps']:
                        LOGGER.info(
                            "********************\n"
                            "Step Order: %s" % step['order'])
                        LOGGER.info("Step Desc: %s" % step['step_desc'])
                        LOGGER.info(
                            "Expected: %s\n********************\n"
                            % step['expected'])
                if manual_skip_all:
                    test_case["result"] = "N/A"
                else:
                    while True:
                        test_result = raw_input(
                            '[ please input case result ]'
                            ' (p^PASS, f^FAIL, b^BLOCK, n^Next, d^Done):')
                        if test_result.lower() == 'p':
                            test_case["result"] = "PASS"
                            break
                        elif test_result.lower() == 'f':
                            test_case["result"] = "FAIL"
                            break
                        elif test_result.lower() == 'b':
                            test_case["result"] = "BLOCK"
                            break
                        elif test_result.lower() == 'n':
                            test_case["result"] = "N/A"
                            break
                        elif test_result.lower() == 'd':
                            manual_skip_all = True
                            test_case["result"] = "N/A"
                            break
                        else:
                            LOGGER.info(
                                "[ Warnning: you input: '%s' is invalid,"
                                " please try again ]" % test_result)
            except IOError as error:
                LOGGER.info(
                    "[ Error: fail to get core manual test step,"
                    " error: %s ]\n" % error)
        strtime = datetime.now().strftime(DATE_FORMAT_STR)
        LOGGER.info("end time: %s" % strtime)
        test_case["end_at"] = strtime
        LOGGER.info("Case Result: %s" % test_case["result"])
        result_list.append(test_case)
        if len(postscript) > 1 :
            if location == 'host':
                return_code, stdout, stderr = conn.shell_cmd_host(postscript, time_out, False, stdout_file, stderr_file)
                if return_code is not None and return_code != "timeout":
                    LOGGER.info('post script ok')
                else:
                    LOGGER.info('post script fail')
               
            else:
                if postscript is not None or postscript is not '':
                    return_code, stdout, stderr = conn.shell_cmd_ext(postscript, time_out, False, stdout_file, stderr_file)
                    if return_code is not None and return_code != "timeout":
                        LOGGER.info('post script ok')
                    else:
                        LOGGER.info('post script fail')

    result_obj.extend_result(result_list, False)
    result_obj.set_status(1)
Ejemplo n.º 44
0
def _web_test_exec(conn, server_url, test_web_app, exetype, cases_queue,
                   result_obj):
    """function for running web tests"""
    exetype = exetype.lower()
    test_set_finished = False
    err_cnt = 0
    for test_group in cases_queue:
        if test_set_finished:
            break

        ret = http_request(get_url(server_url, "/set_testcase"), "POST",
                           test_group, 30)
        if ret is None:
            LOGGER.error("[ set testcases timeout, please check device! ]")
            result_obj.set_status(1)
            break

        if not conn.launch_app(test_web_app):
            LOGGER.error("[ ERROR: launch test app %s failed! ]" %
                         test_web_app)
            result_obj.set_status(1)
            break

        while True:
            if result_obj.get_status() == 1:
                test_set_finished = True
                break
            ret = http_request(get_url(server_url, "/check_server_status"),
                               "GET", {})
            if ret is None:
                LOGGER.error(
                    "[ ERROR: get server status timeout, please check deivce! ]"
                )
                err_cnt += 1
            else:
                result_cases = ret.get("cases")
                error_code = ret.get("error_code")
                if error_code is not None:
                    if not conn.launch_app(test_web_app):
                        test_set_finished = True
                        result_obj.set_status(1)
                        break
                    if error_code == LAUNCH_ERROR:
                        LOGGER.error(
                            "[ ERROR: test app no response, hang or not launched! ]"
                        )
                        test_set_finished = True
                        result_obj.set_status(1)
                        break
                    elif error_code == BLOCK_ERROR:
                        LOGGER.error("[ ERROR: test case block issue! ]")
                        err_cnt += 1
                else:
                    err_cnt = 0

                if result_cases is not None and len(result_cases):
                    result_obj.extend_result(result_cases)
                elif exetype == 'manual':
                    LOGGER.info("[ please execute manual cases ]\r\n")

                if ret["finished"] == 1:
                    test_set_finished = True
                    result_obj.set_status(1)
                    break
                elif ret["block_finished"] == 1:
                    break

            if err_cnt >= CNT_RETRY:
                LOGGER.error(
                    "[ ERROR: get too many errors, stop current set! ]")
                test_set_finished = True
                result_obj.set_status(1)
                break
            time.sleep(2)
Ejemplo n.º 45
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# Authors:
#           Liu,chengtao <*****@*****.**>
""" The http request process module"""

import json
from testkitlite.util.log import LOGGER

try:
    import requests
except ImportError, err:
    LOGGER.info("Failed to import 'requests' module, please check your installation:")
    LOGGER.info("  You can use 'sudo pip install requests' to install the module!")
    raise ImportError

def get_url(baseurl, api):
    """get full url string"""
    return "%s%s" % (baseurl, api)


def http_request(url, rtype="POST", data=None, time_out=10):
    """
    http request to the device http server
    """
    result = None
    if rtype == "POST":
        headers = {'content-type': 'application/json'}
Ejemplo n.º 46
0
import os
import time
import socket
import threading
import re
import sys
from shutil import copyfile
from testkitlite.util.log import LOGGER
from testkitlite.util.autoexec import shell_command, shell_command_ext
from testkitlite.util.killall import killall
from testkitlite.util.errors import InvalidDeviceException

try:
    import paramiko
except ImportError, err:
    LOGGER.info("Failed to import 'paramiko' module, please check your installation:")
    LOGGER.info("  You can use 'sudo pip install paramiko' to install the module!")
    sys.exit(1)


HOST_NS = "127.0.0.1"
os.environ['no_proxy'] = HOST_NS
os.environ['TEST_PLATFORM'] = 'tizen'
os.environ['CONNECT_TYPE'] = 'ssh'
TIZEN_USER = os.environ.get('TIZEN_USER', 'app')
#print 'debug', os.environ.get('TIZEN_USER','')

# common constants
RPM_INSTALL = "ssh %s rpm -ivh %s"
RPM_UNINSTALL = "ssh %s rpm -e %s"
RPM_LIST = "ssh %s rpm -qa | grep tct"
Ejemplo n.º 47
0
import signal
import logging
import subprocess
import ConfigParser
from testkitlite.util import tr_utils
from testkitlite.util.log import LOGGER as g_logger
from urlparse import urlparse
import md5

try:
    from selenium.webdriver.common.by import By
    from selenium.webdriver.remote.webdriver import WebDriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
except ImportError, err:
    g_logger.info(
        "Failed to import 'selenium' module, please check your installation:")
    g_logger.info(
        "  You can use 'sudo pip install selenium' to install the module!")
    raise ImportError

TE = None
EXE_LOCK = threading.Lock()
DEFAULT_TIMEOUT = 90
REF_SET_TYPE = 'ref'
JS_SET_TYPE = 'js'
QUNIT_SET_TYPE = 'qunit'
STR_PASS = '******'
STR_FAIL = 'FAIL'
STR_BLOCK = 'BLOCK'
STR_NOTRUN = 'n/a'
DEFAULT_WD_URL = 'http://127.0.0.1:9515'
Ejemplo n.º 48
0
def _web_test_exec(conn, server_url, test_web_app, exetype, cases_queue, result_obj):
    """function for running web tests"""
    print 'test_web_app', test_web_app
    exetype = exetype.lower()
    test_set_finished = False
    err_cnt = 0
    for test_group in cases_queue:
        if test_set_finished:
            break

        ret = http_request(
            get_url(server_url, "/set_testcase"), "POST", test_group, 30)
        if ret is None:
            LOGGER.error(
                "[ set testcases timeout, please check device! ]")
            result_obj.set_status(1)
            break

        if not conn.launch_app(test_web_app):
            LOGGER.error("[ ERROR: launch test app %s failed! ]" % test_web_app)
            result_obj.set_status(1)
            break

        while True:
            if result_obj.get_status() == 1:
                test_set_finished = True
                break
            ret = http_request(
                get_url(server_url, "/check_server_status"), "GET", {})
            if ret is None:
                LOGGER.error(
                    "[ ERROR: get server status timeout, please check deivce! ]")
                err_cnt += 1
            else:
                result_cases = ret.get("cases")
                error_code = ret.get("error_code")
                if error_code is not None:
                    if not conn.launch_app(test_web_app):
                        test_set_finished = True
                        result_obj.set_status(1)
                        break
                    if error_code == LAUNCH_ERROR:
                        LOGGER.error("[ ERROR: test app no response, hang or not launched! ]")
                        test_set_finished = True
                        result_obj.set_status(1)
                        break
                    elif error_code == BLOCK_ERROR:
                        LOGGER.error("[ ERROR: test case block issue! ]")
                        err_cnt += 1
                else:
                    err_cnt = 0

                if result_cases is not None and len(result_cases):
                    result_obj.extend_result(result_cases)
                elif exetype == 'manual':
                    LOGGER.info(
                        "[ please execute manual cases ]\r\n")

                if ret["finished"] == 1:
                    test_set_finished = True
                    result_obj.set_status(1)
                    break
                elif ret["block_finished"] == 1:
                    break

            if err_cnt >= CNT_RETRY:
                LOGGER.error(
                    "[ ERROR: get too many errors, stop current set! ]")
                test_set_finished = True
                result_obj.set_status(1)
                break
            time.sleep(2)
Ejemplo n.º 49
0
    def __init_webtest_opt(self, params):
        """init the test runtime, mainly process the star up of test stub"""
        if params is None:
            return None

        session_id = str(uuid.uuid1())
        stub_app = params.get('stub-name', 'testkit-stub')
        stub_port = params.get('stub-port', '8000')
        testsuite_name = params.get('testsuite-name', '')
        testset_name = params.get('testset-name', '')
        capability_opt = params.get("capability", None)
        test_launcher = params.get('test-launcher', '')
        test_extension = params.get('test-extension', None)
        test_widget = params.get('test-widget', None)

        test_opt = self.conn.get_launcher_opt(
            test_launcher, test_extension, test_widget, testsuite_name, testset_name)
        if test_opt is None:
            LOGGER.info("[ init the test launcher, get failed ]")
            return None
        LOGGER.info("[ web test launcher: %s ]" % test_opt["launcher"])
        LOGGER.info("[ web test app: %s ]" % test_opt["test_app_id"])
        self.opts.update(test_opt)
        self.opts['debug_mode'] = params.get("debug", False)

        # uifw, this suite don't need stub
        if self.opts['self_exec'] or self.opts['self_repeat']:
            self.opts['test_type'] = "jqunit"
            return session_id

        # enable debug information
        stub_debug_opt = "--debug" if self.opts['debug_mode'] else ""

        # suite_id to be removed in later version
        test_opt["suite_id"] = test_opt["test_app_id"]
        if self.__init_test_stub(stub_app, stub_port, stub_debug_opt):
            ret = http_request(get_url(
                self.server_url, "/init_test"), "POST", test_opt)
            if ret is None:
                LOGGER.info("[ init test suite failed! ]")
                return None
            elif "error_code" in ret:
                LOGGER.info("[ init test suite, "
                            "get error code %d ! ]" % ret["error_code"])
                return None

            if capability_opt is not None:
                ret = http_request(get_url(self.server_url,
                                           "/set_capability"),
                                   "POST", capability_opt)
            return session_id
        else:
            LOGGER.info("[ Init test failed ! ]")
            return None
Ejemplo n.º 50
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# Authors:
#           Liu,chengtao <*****@*****.**>
""" The http request process module"""

import json
from testkitlite.util.log import LOGGER

try:
    import requests
except ImportError, err:
    LOGGER.info(
        "Failed to import 'requests' module, please check your installation:")
    LOGGER.info(
        "  You can use 'sudo pip install requests' to install the module!")
    raise ImportError


def get_url(baseurl, api):
    """get full url string"""
    return "%s%s" % (baseurl, api)


def http_request(url, rtype="POST", data=None, time_out=10):
    """
    http request to the device http server
    """
    result = None