Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)