Beispiel #1
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)
Beispiel #2
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
    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
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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
    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
Beispiel #8
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
Beispiel #9
0
def _iosuiauto_test_exec(test_session, cases, result_obj, session_dir):
    """function for running iosuiauto tests"""
    result_obj.set_status(0)
    result_list = []
    for i_case in cases['cases']:
        i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT)
        try:
            case_entry = i_case['entry']
            expected_result = int(i_case['expected_result'])
            if not EXISTS(case_entry):
                i_case['result'] = STR_BLOCK
                i_case[
                    'stdout'] = "[Message]No such file or dirctory: %s" % case_entry
                result_list.append(i_case)
                continue
            case_id = i_case['case_id']
            destination = "platform=%s,name=%s" % (os.environ["IOS_PLATFORM"],
                                                   os.environ["IOS_NAME"])
            if os.environ.get("IOS_VERSION", None):
                destination = "%s,OS=%s" % (destination,
                                            os.environ["IOS_VERSION"])
            device_id = os.environ["DEVICE_ID"]
            popen_args = 'python %s -d "%s" -u "%s"' % (case_entry,
                                                        destination, device_id)
            i_case_proc = subprocess.Popen(args=popen_args,
                                           shell=True,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
            i_case_pre_time = time.time()
            while True:
                output_infos = i_case_proc.communicate()
                i_case_exit_code = i_case_proc.returncode
                i_case_elapsed_time = time.time() - i_case_pre_time
                if i_case_exit_code == None:
                    if i_case_elapsed_time >= i_case_timeout:
                        tr_utils.KillAllProcesses(ppid=i_case_proc.pid)
                        i_case['result'] = STR_BLOCK
                        i_case['stdout'] = "[Message]Timeout"
                        LOGGER.debug("Run %s timeout" % case_id)
                        result_list.append(i_case)
                        break
                else:
                    if i_case_exit_code == expected_result:
                        i_case['result'] = STR_PASS
                        i_case[
                            'stdout'] = "[Message]" + output_infos[0].replace(
                                "\n", "\r")
                    else:
                        i_case['result'] = STR_FAIL
                        i_case['stderr'] = output_infos[1].replace("\n", "\r")
                    result_list.append(i_case)
                    break

                time.sleep(1)
        except Exception, e:
            i_case['result'] = STR_BLOCK
            i_case['stdout'] = "[Message]%s" % e
            LOGGER.error("Run %s: failed: %s, exit from executer" %
                         (case_id, e))
            result_list.append(i_case)
Beispiel #10
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)
Beispiel #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')
Beispiel #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')
Beispiel #13
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
Beispiel #14
0
 def launch_stub(self, stub_app, stub_port="8000", debug_opt=""):
     stub_status = False
     server_url = "http://%s:9000" % self.deviceip
     ret = http_request(
         get_url(server_url, "/launch_stub"), "GET", {})
     if ret is None:
         LOGGER.error("[ ERROR: get server status timeout, please check deivce! ]")
     else: 
         if ret.get("OK") is not None:
             stub_status = True
     return stub_status
Beispiel #15
0
 def launch_stub(self, stub_app, stub_port="8000", debug_opt=""):
     stub_status = False
     server_url = "http://%s:9000" % self.deviceip
     ret = http_request(get_url(server_url, "/launch_stub"), "GET", {})
     if ret is None:
         LOGGER.error(
             "[ ERROR: get server status timeout, please check deivce! ]")
     else:
         if ret.get("OK") is not None:
             stub_status = True
     return stub_status
Beispiel #16
0
 def kill_stub(self):
     stub_status = False
     server_url = "http://%s:9000" % self.deviceip
     ret = http_request(get_url(server_url, "/kill_stub"), "GET", {})
     if ret is None:
         LOGGER.error(
             "[ ERROR: get server status timeout, please check deivce! ]")
     else:
         if ret.get("OK") is not None:
             stub_status = True
     return stub_status
Beispiel #17
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
Beispiel #18
0
 def kill_stub(self):
     stub_status = False
     server_url = "http://%s:9000" % self.deviceip
     ret = http_request(
         get_url(server_url, "/kill_stub"), "GET", {})
     if ret is None:
         LOGGER.error("[ ERROR: get server status timeout, please check deivce! ]")
     else: 
         if ret.get("OK") is not None:
             stub_status = True
     return stub_status
 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
Beispiel #20
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
Beispiel #21
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
Beispiel #22
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
Beispiel #23
0
 def check_process(self, process_name):
     stub_status = 0
     server_url = "http://%s:9000" % self.deviceip
     LOGGER.error("[ Server URL: %s]" % server_url)
     ret = http_request(get_url(server_url, "/check_stub"), "GET", {})
     if ret is None:
         LOGGER.error(
             "[ ERROR: get server status timeout, please check deivce! ]")
     else:
         if ret.get("OK") is not None:
             stub_status = 1
     return stub_status
Beispiel #24
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)
Beispiel #25
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()
Beispiel #26
0
 def check_process(self, process_name):
     stub_status = 0       
     server_url = "http://%s:9000" % self.deviceip
     LOGGER.error("[ Server URL: %s]" % server_url)
     ret = http_request(
         get_url(server_url, "/check_stub"), "GET", {})
     if ret is None:
         LOGGER.error("[ ERROR: get server status timeout, please check deivce! ]")
     else: 
         if ret.get("OK") is not None:
             stub_status = 1
     return stub_status
Beispiel #27
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
Beispiel #28
0
 def __init__(self, config):
     self.conn = None
     if "commodule" in config:
         try:
             exec "from testkitlite.commodule.%s import get_target_conn" % config[
                 "commodule"]
             device_no = config.get('deviceid', None)
             if device_no is not None:
                 self.conn = get_target_conn(device_no)
             else:
                 self.conn = get_target_conn()
         except Exception as error:
             LOGGER.error("[ Error: Initialize commodule failed: '%s']\n" % error)
Beispiel #29
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()
Beispiel #30
0
def _iosuiauto_test_exec(test_session, cases, result_obj, session_dir):
    """function for running iosuiauto tests"""
    result_obj.set_status(0)
    result_list = []
    for i_case in cases['cases']:
        i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT)
        try:
            case_entry = i_case['entry']
	    expected_result = int(i_case['expected_result'])
            if not EXISTS(case_entry):
                i_case['result'] = STR_BLOCK
                i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry
                result_list.append(i_case)
                continue
            case_id = i_case['case_id']
	    destination = "platform=%s,name=%s" % (os.environ["IOS_PLATFORM"], os.environ["IOS_NAME"])
            if os.environ.get("IOS_VERSION", None):
	        destination = "%s,OS=%s" % (destination, os.environ["IOS_VERSION"])
	    device_id = os.environ["DEVICE_ID"]
            popen_args = 'python %s -d "%s" -u "%s"' % (case_entry, destination, device_id)
            i_case_proc = subprocess.Popen(args=popen_args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            i_case_pre_time = time.time()
            while True:
	        output_infos = i_case_proc.communicate()
                i_case_exit_code = i_case_proc.returncode
                i_case_elapsed_time = time.time() - i_case_pre_time
                if i_case_exit_code == None:
                    if i_case_elapsed_time >= i_case_timeout:
                        tr_utils.KillAllProcesses(ppid=i_case_proc.pid)
                        i_case['result'] = STR_BLOCK
                        i_case['stdout'] = "[Message]Timeout"
                        LOGGER.debug("Run %s timeout" % case_id)
			result_list.append(i_case)
                        break
                else:
                    if i_case_exit_code == expected_result:
		        i_case['result'] = STR_PASS
                        i_case['stdout'] = "[Message]" + output_infos[0].replace("\n", "\r")
		    else:
		        i_case['result'] = STR_FAIL
			i_case['stderr'] = output_infos[1].replace("\n", "\r")
                    result_list.append(i_case)
		    break

                time.sleep(1)
        except Exception, e:
           i_case['result'] = STR_BLOCK
           i_case['stdout'] = "[Message]%s" % e
           LOGGER.error(
               "Run %s: failed: %s, exit from executer" % (case_id, e))
           result_list.append(i_case)
Beispiel #31
0
def _nodeunit_test_exec(test_session, cases, result_obj, session_dir):
    """function for running nodeunit tests"""
    result_obj.set_status(0)
    result_list = []
    for i_case in cases['cases']:
        i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT)

        try:
            case_entry = i_case['entry']
            if not EXISTS(case_entry):
                i_case['result'] = STR_BLOCK
                i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry
                result_list.append(i_case)
                continue

            case_id = i_case['case_id']
            tmp_result_dir = "%s/%s" % (session_dir, case_id)
            os.makedirs(tmp_result_dir)
            popen_args = "nodeunit %s --reporter junit --output %s" % (case_entry, tmp_result_dir)
            i_case_proc = subprocess.Popen(args=popen_args, shell=True, stderr=subprocess.PIPE)
            i_case_pre_time = time.time()

            while True:
                i_case_exit_code = i_case_proc.poll()
                i_case_elapsed_time = time.time() - i_case_pre_time

                if i_case_exit_code == None:
                    if i_case_elapsed_time >= i_case_timeout:
                        tr_utils.KillAllProcesses(ppid=i_case_proc.pid)
                        i_case['result'] = STR_BLOCK
                        i_case['stdout'] = "[Message]Timeout"
                        LOGGER.debug("Run %s timeout" % case_id)
                        break
                else:
                    if int(i_case_exit_code) == 0:
                        i_case['result'] = STR_PASS
                        i_case['stdout'] = tmp_result_dir
                    elif int(i_case_exit_code) == 1:
                        i_case['result'] = STR_FAIL
                        i_case['stdout'] = tmp_result_dir
                    else:
                        i_case['result'] = STR_BLOCK
                        i_case['stdout'] = "[Message]%s" % ''.join(i_case_proc.stderr.readlines()).strip('\n')
                    break
                time.sleep(1)
        except Exception, e:
           i_case['result'] = STR_BLOCK
           i_case['stdout'] = "[Message]%s" % e
           LOGGER.error(
               "Run %s: failed: %s, exit from executer" % (case_id, e))
        result_list.append(i_case)
Beispiel #32
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
Beispiel #33
0
 def __init__(self, config):
     self.conn = None
     if "commodule" in config:
         try:
             exec "from testkitlite.commodule.%s import get_target_conn" % config[
                 "commodule"]
             device_no = config.get('deviceid', None)
             if device_no is not None:
                 self.conn = get_target_conn(device_no)
             else:
                 self.conn = get_target_conn()
         except Exception as error:
             LOGGER.error("[ Error: Initialize commodule failed: '%s']\n" %
                          error)
Beispiel #34
0
def _xcunit_test_exec(test_session, cases, result_obj, session_dir):
    """function for running xcunit tests"""
    result_obj.set_status(0)
    result_list = []
    for i_case in cases['cases']:
        i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT)
        try:
            case_entry = i_case['entry']
            if not EXISTS(case_entry):
                i_case['result'] = STR_BLOCK
                i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry
                result_list.append(i_case)
                continue
            case_id = i_case['case_id']
	    destination = "platform=%s,name=%s" % (os.environ["IOS_PLATFORM"], os.environ["IOS_NAME"])
            if os.environ.get("IOS_VERSION", None):
	        destination = "%s,OS=%s" % (destination, os.environ["IOS_VERSION"])
            popen_args = 'python %s -d "%s"' % (case_entry, destination)
            i_case_proc = subprocess.Popen(args=popen_args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            i_case_pre_time = time.time()
            while True:
		output_infos = i_case_proc.communicate()
                i_case_exit_code = i_case_proc.returncode
                i_case_elapsed_time = time.time() - i_case_pre_time
                if i_case_exit_code == None:
                    if i_case_elapsed_time >= i_case_timeout:
                        tr_utils.KillAllProcesses(ppid=i_case_proc.pid)
                        i_case['result'] = STR_BLOCK
                        i_case['stdout'] = "[Message]Timeout"
                        LOGGER.debug("Run %s timeout" % case_id)
			result_list.append(i_case)
                        break
                else:
                    for line in output_infos[0].split('\n'):
		        result_dic = {}
			if line.startswith("Test Case '-["):
			    if line.find("seconds") != -1:
			        info_list = line.split(' ')
                                result_dic['case_id'] = "%s/%s" % (info_list[2][3:], info_list[3][:-2])
                                result_dic['result'] = {"passed": STR_PASS, "failed": STR_FAIL}[info_list[4]] 
				result_list.append(result_dic)
                    break
                time.sleep(1)
        except Exception, e:
           i_case['result'] = STR_BLOCK
           i_case['stdout'] = "[Message]%s" % e
           LOGGER.error(
               "Run %s: failed: %s, exit from executer" % (case_id, e))
           result_list.append(i_case)
Beispiel #35
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()
Beispiel #36
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
Beispiel #37
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)
Beispiel #38
0
def _mocha_test_exec(test_session, cases, result_obj, session_dir):
    """function for running mocha tests"""
    result_obj.set_status(0)
    result_list = []
    for i_case in cases['cases']:
        i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT)

        try:
            case_entry = i_case['entry']
            status, output =  commands.getstatusoutput("ssh %s 'ls %s'" %  (os.environ["DEVICE_ID"], case_entry))
            if status != 0:
                i_case['result'] = STR_BLOCK
                i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry
                result_list.append(i_case)
                continue

            case_id = i_case['case_id']
            tmp_result_dir = "%s/json_results" % session_dir
            os.makedirs(tmp_result_dir)
            popen_args = "ssh %s 'mocha %s --reporter json' > %s/%s.json" % (os.environ["DEVICE_ID"], case_entry, tmp_result_dir, case_id)
            i_case_proc = subprocess.Popen(args=popen_args, shell=True)
            i_case_pre_time = time.time()
            while True:
                i_case_exit_code = i_case_proc.poll()
                i_case_elapsed_time = time.time() - i_case_pre_time
                if i_case_exit_code == None:
                    if i_case_elapsed_time >= i_case_timeout:
                        tr_utils.KillAllProcesses(ppid=i_case_proc.pid)
                        i_case['result'] = STR_BLOCK
                        i_case['stdout'] = "[Message]Timeout"
                        LOGGER.debug("Run %s timeout" % case_id)
                        break
                else:
                    i_case['result'] = STR_FAIL
                    i_case['stdout'] = tmp_result_dir
                    break
                time.sleep(1)
        except Exception, e:
           i_case['result'] = STR_BLOCK
           i_case['stdout'] = "[Message]%s" % e
           LOGGER.error(
               "Run %s: failed: %s, exit from executer" % (case_id, e))
        result_list.append(i_case)
Beispiel #39
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
Beispiel #40
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)
Beispiel #41
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
Beispiel #42
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
Beispiel #43
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
Beispiel #44
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
Beispiel #45
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
Beispiel #46
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
Beispiel #47
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
Beispiel #48
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)
Beispiel #49
0
def _bdd_test_exec(test_session, cases, result_obj, session_dir):
    """function for running bdd tests"""
    result_obj.set_status(0)
    result_list = []
    for i_case in cases['cases']:
        i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT)

        try:
            case_entry = i_case['entry']
            if not EXISTS(case_entry):
                i_case['result'] = STR_BLOCK
                i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry
                result_list.append(i_case)
                continue

            case_id = i_case['case_id']
            tmp_result_dir = "%s/%s" % (session_dir, case_id)
            os.makedirs(tmp_result_dir)
            popen_args = "behave %s --junit --junit-directory %s" % (case_entry, tmp_result_dir)
            i_case_proc = subprocess.Popen(args=popen_args, shell=True)
            i_case_pre_time = time.time()
            while True:
                i_case_exit_code = i_case_proc.poll()
                i_case_elapsed_time = time.time() - i_case_pre_time
                if i_case_exit_code == None:
                    if i_case_elapsed_time >= i_case_timeout:
                        tr_utils.KillAllProcesses(ppid=i_case_proc.pid)
                        i_case['result'] = STR_BLOCK
                        i_case['stdout'] = "[Message]Timeout"
                        LOGGER.debug("Run %s timeout" % case_id)
                        break
                elif str(i_case_exit_code) == str(i_case['expected_result']):
                    i_case['result'] = STR_PASS
                    i_case['stdout'] = tmp_result_dir
                    break
                else:
                    i_case['result'] = STR_FAIL
                    i_case['stdout'] = tmp_result_dir
                    break
                time.sleep(1)
        except KeyError:
           i_case['result'] = STR_BLOCK
           i_case['stdout'] = "[Message]No 'bdd_test_script_entry' node."
           LOGGER.error(
               "Run %s: failed: No 'bdd_test_script_entry' node, exit from executer" % case_id)
        except Exception, e:
           i_case['result'] = STR_BLOCK
           i_case['stdout'] = "[Message]%s" % e
           LOGGER.error(
               "Run %s: failed: %s, exit from executer" % (case_id, e))
        result_list.append(i_case)
Beispiel #50
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
Beispiel #51
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"], []]
Beispiel #52
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"], []]
Beispiel #53
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)
Beispiel #54
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