提交 14e5beb6 编写于 作者: A alex__hold

sync master xdevice code

Signed-off-by: Nalex__hold <hejian3@huawei.com>
上级 91c9a500
......@@ -17,7 +17,6 @@
#
import os
import re
import time
import json
import shutil
......@@ -55,8 +54,11 @@ from xdevice_extension._core.testkit.kit import junit_para_parse
from xdevice_extension._core.testkit.kit import junit_dex_para_parse
from xdevice_extension._core.testkit.kit import reset_junit_para
from xdevice_extension._core.utils import get_filename_extension
from xdevice_extension._core.utils import start_standing_subprocess
from xdevice_extension._core.executor.listener import CollectingTestListener
from xdevice_extension._core.testkit.kit import gtest_para_parse
from xdevice_extension._core.environment.dmlib import process_command_ret
__all__ = ["CppTestDriver", "DexTestDriver", "HapTestDriver",
"JSUnitTestDriver", "JUnitTestDriver", "RemoteTestRunner",
......@@ -339,10 +341,12 @@ class CppTestDriver(IDriver):
hilog_open = os.open(hilog, os.O_WRONLY | os.O_CREAT | os.O_APPEND,
0o755)
self.config.device.hdc_command("shell hilog -r")
self._run_cpp_test(config_file, listeners=request.listeners,
request=request)
with os.fdopen(hilog_open, "a") as hilog_file_pipe:
self.config.device.start_catch_device_log(hilog_file_pipe)
self._run_cpp_test(config_file, listeners=request.listeners,
request=request)
time.sleep(30)
hilog_file_pipe.flush()
except Exception as exception:
......@@ -506,23 +510,39 @@ class RemoteCppTestRunner:
parser_instance = parser.__class__()
parser_instances.append(parser_instance)
handler = ShellHandler(parser_instances)
command = "cd %s; chmod +x *; ./%s %s" \
% (self.config.target_test_path, self.config.module_name,
self.get_args_command())
self.config.device.execute_shell_command(
command, timeout=self.config.timeout, receiver=handler, retry=0)
# apply execute right
chmod_cmd = "shell chmod 777 {}/{}".format(
self.config.target_test_path, self.config.module_name)
LOG.info("The apply execute command is {}".format(chmod_cmd))
self.config.device.hdc_command(chmod_cmd, timeout=30*1000)
# dry run command
dry_command = ".{}/{} {}".format(self.config.target_test_path,
self.config.module_name,
self.get_args_command())
pre_cmd = "hdc_std -t %s shell " % self.config.device.device_sn
command = "%s %s" % (pre_cmd, dry_command)
LOG.info("The dry_command execute command is {}".format(command))
output = start_standing_subprocess(command.split(),
return_result=True)
LOG.debug("dryrun output ---")
output = output.replace("\r", "")
handler.__read__(output)
handler.__done__()
return parser_instances[0].tests
def run(self, listener):
handler = self._get_shell_handler(listener)
command = "cd %s; chmod +x *; ./%s %s" \
% (self.config.target_test_path, self.config.module_name,
self.get_args_command())
self.config.device.execute_shell_command(
command, timeout=self.config.timeout, receiver=handler, retry=0)
pre_cmd = "hdc_std -t %s shell " % self.config.device.device_sn
command = ".{}/{} {}".format(self.config.target_test_path,
self.config.module_name,
self.get_args_command())
command = "%s %s" % (pre_cmd, command)
LOG.debug("run command is: %s" % command)
output = start_standing_subprocess(command.split(), return_result=True)
LOG.debug("run output ---")
output = output.replace("\r", "")
handler.__read__(output)
handler.__done__()
def rerun(self, listener, test):
if self.rerun_attempt:
......@@ -531,14 +551,18 @@ class RemoteCppTestRunner:
listener_copy.append(test_tracker)
handler = self._get_shell_handler(listener_copy)
try:
command = "cd %s; chmod +x *; ./%s %s" \
% (self.config.target_test_path,
self.config.module_name,
self.get_args_command())
self.config.device.execute_shell_command(
command, timeout=self.config.timeout, receiver=handler,
retry=0)
pre_cmd = "hdc_std -t %s shell " % self.config.device.device_sn
command = ".{}/{} {}".format(self.config.target_test_path,
self.config.module_name,
self.get_args_command())
command = "%s %s" % (pre_cmd, command)
LOG.debug("rerun command is: %s" % command)
output = start_standing_subprocess(command.split(),
return_result=True)
LOG.debug("run output ---")
output = output.replace("\r", "")
handler.__read__(output)
handler.__done__()
except ShellCommandUnresponsiveException:
LOG.debug("Exception: ShellCommandUnresponsiveException")
......@@ -1743,7 +1767,7 @@ class HapTestDriver(IDriver):
filename, junit_test_para, suitefile_target_test_path)
self.result = result.get_test_results(return_message)
self._unistall_hap(self.package_name)
self._uninstall_hap(self.package_name)
else:
self.result = result.get_test_results("Error: install hap failed.")
LOG.error("Error: install hap failed.", error_no="03204")
......@@ -1906,7 +1930,7 @@ class HapTestDriver(IDriver):
LOG.info("HAP Testcase executed finished")
return return_code
def _unistall_hap(self, package_name):
def _uninstall_hap(self, package_name):
return_message = self.config.device.execute_shell_command(
"pm uninstall %s" % package_name)
_sleep_according_to_result(return_message)
......@@ -1998,10 +2022,9 @@ class JSUnitTestDriver(IDriver):
def __execute__(self, request):
try:
LOG.debug("Start execute xdevice extension JSUnit Test")
self.result = os.path.join(request.config.report_path,
"result",
'.'.join((request.get_module_name(),
"xml")))
self.result = os.path.join(
request.config.report_path, "result",
'.'.join((request.get_module_name(), "xml")))
self.config = request.config
self.config.device = request.config.environment.devices[0]
......@@ -2014,8 +2037,8 @@ class JSUnitTestDriver(IDriver):
request.root.source.source_string, error_no="00110")
LOG.debug("Test case file path: %s" % suite_file)
self.config.device.hdc_command("shell hilog -r")
self._run_jsunit(config_file, request)
self.generate_console_output(request)
except Exception as exception:
self.error_message = exception
if not getattr(exception, "error_no", ""):
......@@ -2027,7 +2050,10 @@ class JSUnitTestDriver(IDriver):
self.result = check_result_report(
request.config.report_path, self.result, self.error_message)
def generate_console_output(self, request):
def generate_console_output(self, device_log_file, request):
LOG.info("prepare to read device log, may wait some time")
result_message = self.read_device_log(device_log_file, "")
report_name = request.get_module_name()
parsers = get_plugin(
Plugin.PARSER, CommonParserType.jsunit)
......@@ -2039,37 +2065,29 @@ class JSUnitTestDriver(IDriver):
for parser in parsers:
parser_instance = parser.__class__()
parser_instance.suites_name = "{}_suites".format(report_name)
parser_instance.suites_name = report_name
parser_instance.suite_name = report_name
parser_instance.listeners = request.listeners
parser_instances.append(parser_instance)
handler = ShellHandler(parser_instances)
from xdevice_extension._core import utils
command = "hdc_std -t %s shell hilog -x " % self.config.device.\
device_sn
output = utils.start_standing_subprocess(command, return_result=True)
LOG.debug("start to parsing hilog")
handler.__read__(output)
handler.__done__()
process_command_ret(result_message, handler)
def read_device_log(self, device_log_file, result_message):
device_log_file_open = os.open(device_log_file, os.O_RDONLY,
stat.S_IWUSR | stat.S_IRUSR)
with os.fdopen(device_log_file_open, "r") as file_read_pipe:
with os.fdopen(device_log_file_open, "r", encoding='utf-8') \
as file_read_pipe:
while True:
data = file_read_pipe.readline()
result_message += data
report_name = ""
if re.match(r'.*\[create report\]*', data):
_, index = re.match(r'.*\[create report\]*', data).span()
report_name = data[index:].split(".")[0]
if result_message.find("[create report]") != -1 or \
int(time.time()) - int(self.start_time) > \
self.timeout:
if not data or not data.strip():
break
return result_message, report_name
# only filter JSApp log
if data.find("JSApp:") != -1:
result_message += data
if data.find("[end] run suites end") != -1:
break
return result_message
def _run_jsunit(self, config_file, request):
try:
......@@ -2088,22 +2106,38 @@ class JSUnitTestDriver(IDriver):
self.config.device.hdc_command("target mount")
do_module_kit_setup(request, self.kits)
# execute test case
self.config.device.hdc_command("shell hilog -r")
hilog = get_device_log_file(
request.config.report_path,
request.config.device.__get_serial__() + "_" + request.
get_module_name(),
"device_hilog")
command = "aa start -d 123 -a %s -b %s" \
% (ability_name, package)
self.start_time = time.time()
result_value = self.config.device.execute_shell_command(
command, timeout=self.timeout)
if "success" in str(result_value).lower():
LOG.info("execute %s's testcase success. result value=%s"
% (package, result_value))
time.sleep(60)
else:
LOG.info("execute %s's testcase failed. result value=%s"
% (package, result_value))
hilog_open = os.open(hilog, os.O_WRONLY | os.O_CREAT | os.O_APPEND,
0o755)
with os.fdopen(hilog_open, "a") as hilog_file_pipe:
self.config.device.start_catch_device_log(hilog_file_pipe)
# execute test case
command = "shell aa start -d 123 -a %s -b %s" \
% (ability_name, package)
result_value = self.config.device.hdc_command(command)
if "success" in str(result_value).lower():
setattr(self, "start_success", True)
LOG.info("execute %s's testcase success. result value=%s"
% (package, result_value))
else:
LOG.info("execute %s's testcase failed. result value=%s"
% (package, result_value))
self.start_time = time.time()
timeout_config = get_config_value('test-timeout',
json_config.get_driver(),
False, 60000)
timeout = int(timeout_config)/1000
LOG.info("wait {}s to keep app log".format(timeout))
time.sleep(timeout)
hilog_file_pipe.flush()
self.generate_console_output(hilog, request)
finally:
do_module_kit_teardown(request)
......
......@@ -615,6 +615,7 @@ class JSUnitParser(IParser):
self.state_machine = StateRecorder()
self.suites_name = ""
self.listeners = []
self.suite_name = ""
def get_listeners(self):
return self.listeners
......@@ -630,11 +631,12 @@ class JSUnitParser(IParser):
suite_result.is_completed = True
for listener in self.get_listeners():
suite = copy.copy(suite_result)
listener.__ended__(LifeCycle.TestSuite, suite,
listener.__ended__(LifeCycle.TestSuites, suite,
suite_report=True)
self.state_machine.current_suite = None
def parse(self, line):
line = line.strip()
if (self.state_machine.suites_is_started() or line.find(
_START_JSUNIT_RUN_MARKER) != -1) and line.find(
_ACE_LOG_MARKER) != -1:
......@@ -669,7 +671,11 @@ class JSUnitParser(IParser):
run_time = end_timestamp - start_timestamp
_, status_end_index = re.match(pattern, filter_message).span()
status = filter_message[:status_end_index]
test_name = filter_message[status_end_index:]
if " ;" in filter_message:
test_name = filter_message[status_end_index:
str(filter_message).find(" ;")]
else:
test_name = filter_message[status_end_index:]
status_dict = {"pass": ResultCode.PASSED, "fail": ResultCode.FAILED,
"ignore": ResultCode.SKIPPED}
status = status_dict.get(status[1:-1])
......
......@@ -27,6 +27,7 @@ from xdevice import Plugin
from xdevice import exec_cmd
from xdevice import ConfigConst
from xdevice_extension._core import utils
from xdevice_extension._core.environment.dmlib import HdcHelper
from xdevice_extension._core.exception import HdcError
from xdevice_extension._core.environment.dmlib import CollectingOutputReceiver
......@@ -72,7 +73,7 @@ def perform_device_action(func):
if self.usb_type == DeviceConnectorType.hdc:
cmd = "hdc reset"
self.log.info("re-execute hdc reset")
exec_cmd(cmd)
exec_cmd(cmd)
if not self.recover_device():
LOG.debug("set device %s %s false" % (
self.device_sn, ConfigConst.recover_state))
......@@ -166,16 +167,14 @@ class Device(IDevice):
return self.device_state_monitor.wait_for_device_available()
def get_device_type(self):
model = self.get_property("ro.build.characteristics",
abort_on_exception=True)
self.label = self.model_dict.get(model, None)
self.label = self.model_dict.get("default", None)
def get_property(self, prop_name, retry=RETRY_ATTEMPTS,
abort_on_exception=False):
"""
Hdc command, ddmlib function.
"""
command = "getprop %s" % prop_name
command = "getparam %s" % prop_name
stdout = self.execute_shell_command(
command, timeout=5 * 1000, output_flag=False, retry=retry,
abort_on_exception=abort_on_exception).strip()
......@@ -193,7 +192,7 @@ class Device(IDevice):
if self.usb_type == DeviceConnectorType.hdc:
LOG.debug("%s execute command hdc %s%s" % (
convert_serial(self.device_sn), command, timeout_msg))
cmd = ["hdc_std", "-t", self.device_sn]
cmd = ["hdc_std", "-t", self.device_sn]
if isinstance(command, list):
cmd.extend(command)
else:
......@@ -292,9 +291,6 @@ class Device(IDevice):
timeout = kwargs.get("timeout", TIMEOUT)
HdcHelper.push_file(self, local, remote, is_create=is_create,
timeout=timeout)
if not self.is_file_exist(remote):
LOG.error("push %s to %s failed" % (local, remote))
raise HdcError("push %s to %s failed" % (local, remote))
@perform_device_action
def pull_file(self, remote, local, **kwargs):
......@@ -337,9 +333,7 @@ class Device(IDevice):
def is_file_exist(self, file_path):
file_path = check_path_legal(file_path)
command = ["hdc_std", "shell", "ls", file_path]
output = exec_cmd(command)
output = self.execute_shell_command("ls {}".format(file_path))
if output and "No such file or directory" not in output:
return True
return False
......@@ -360,13 +354,23 @@ class Device(IDevice):
self._stop_catch_device_log()
def _start_catch_device_log(self):
pass
if self.hilog_file_pipe:
command = "hilog"
if self.usb_type == DeviceConnectorType.hdc:
cmd = ['hdc_std', "-t", self.device_sn, "shell", command]
LOG.info("execute command: %s" % " ".join(cmd).replace(
self.device_sn, convert_serial(self.device_sn)))
self.device_hilog_proc = utils.start_standing_subprocess(
cmd, self.hilog_file_pipe)
def _stop_catch_device_log(self):
pass
if self.device_hilog_proc:
utils.stop_standing_subprocess(self.device_hilog_proc)
self.device_hilog_proc = None
self.hilog_file_pipe = None
def get_recover_result(self, retry=RETRY_ATTEMPTS):
command = "getprop ro.product.device"
command = "getparam ro.product.model"
stdout = self.execute_shell_command(command, timeout=5 * 1000,
output_flag=False, retry=retry,
abort_on_exception=True).strip()
......
......@@ -86,7 +86,7 @@ class DeviceStateMonitor(object):
while int(time.time()*1000) - start_time < wait_time:
try:
result = self.device.get_recover_result(retry=0)
if result == "1":
if result == "ohos":
return True
except Exception as exception:
self.device.log.error("wait for boot complete exception: %s"
......
......@@ -217,14 +217,17 @@ class HdcMonitor:
self.main_hdc_connection)
if self.main_hdc_connection and not self.monitoring:
LOG.debug("start monitoring list targets")
self.monitoring_list_targets()
len_buf = HdcHelper.read(self.main_hdc_connection,
DATA_UNIT_LENGTH)
length = struct.unpack("!I", len_buf)[0]
LOG.debug("had received length is: %s" % length)
if length >= 0:
self.monitoring = True
self.process_incoming_target_data(length)
except (HdcError, Exception) as _:
LOG.debug("loop_monitor happened error: %s" % _)
self.handle_exception_monitor_loop()
break
......@@ -273,22 +276,21 @@ class HdcMonitor:
def process_incoming_target_data(self, length):
local_array_list = []
if length > 0:
data_buf = HdcHelper.read(self.main_hdc_connection, length)
data_str = HdcHelper.reply_to_string(data_buf)
if 'Empty' not in data_str:
lines = data_str.split('\n')
for line in lines:
items = line.strip().split('\t')
if not items[0] :
continue
items.append(DeviceState.ONLINE.value)
device_instance = self._get_device_instance(
items, DeviceOsType.default)
local_array_list.append(device_instance)
else:
LOG.debug("please check device actually.[%s]" % data_str)
data_buf = HdcHelper.read(self.main_hdc_connection, length)
data_str = HdcHelper.reply_to_string(data_buf)
if 'Empty' not in data_str:
lines = data_str.split('\n')
for line in lines:
items = line.strip().split('\t')
if not items[0] :
continue
items.append(DeviceState.ONLINE.value)
device_instance = self._get_device_instance(
items, DeviceOsType.default)
local_array_list.append(device_instance)
else:
LOG.debug("please check device actually.[%s]" % data_str)
LOG.debug("process target data, local_array_list" % local_array_list)
self.update_devices(local_array_list)
def _get_device_instance(self, items, os_type):
......@@ -751,12 +753,8 @@ class HdcHelper:
if not os.path.exists(local):
raise HdcError("Local path doesn't exist.")
sock = HdcHelper.socket(host=device.host, port=device.port,
timeout=DEFAULT_TIMEOUT)
timeout=timeout)
HdcHelper.handle_shake(sock, device.device_sn)
local_end = os.path.split(local)[-1]
remote_end = os.path.split(remote)[-1]
if not local_end == remote_end:
remote = os.path.join(remote, local_end)
request = HdcHelper.form_hdc_request("file send %s %s" %
(local, remote))
HdcHelper.write(sock, request)
......@@ -764,6 +762,7 @@ class HdcHelper:
length = struct.unpack("!I", reply)[0]
data_buf = HdcHelper.read(sock, length)
data_str = HdcHelper.reply_to_string(data_buf)
device.log.info(data_str)
@staticmethod
def pull_file(device, remote, local, is_create=False,
......@@ -772,15 +771,9 @@ class HdcHelper:
device.log.info("%s execute command: hdc file recv %s to %s" %
(convert_serial(device.device_sn), remote, local))
if not os.path.exists(local):
raise HdcError("Local path doesn't exist.")
sock = HdcHelper.socket(host=device.host, port=device.port,
timeout=DEFAULT_TIMEOUT)
timeout=timeout)
HdcHelper.handle_shake(sock, device.device_sn)
local_end = os.path.split(local)[-1]
remote_end = os.path.split(remote)[-1]
if not local_end == remote_end:
remote = os.path.join(remote, local_end)
request = HdcHelper.form_hdc_request("file recv %s %s" %
(local, remote))
HdcHelper.write(sock, request)
......@@ -788,6 +781,7 @@ class HdcHelper:
length = struct.unpack("!I", reply)[0]
data_buf = HdcHelper.read(sock, length)
data_str = HdcHelper.reply_to_string(data_buf)
device.log.info(data_str)
@staticmethod
def _install_remote_package(device, remote_file_path, command):
......@@ -854,6 +848,8 @@ class HdcHelper:
output_flag = kwargs.get("output_flag", True)
timeout_msg = '' if (timeout/1000) == 300.0 else \
" with timeout %ss" % str(timeout/1000)
end_mark = kwargs.get("end_mark", "")
read_timeout = kwargs.get("read_timeout", None)
if device.usb_type == DeviceConnectorType.hdc:
message = "%s execute command: hdc shell %s%s" % \
(convert_serial(device.device_sn), command,
......@@ -866,26 +862,31 @@ class HdcHelper:
HdcHelper.handle_shake(sock, device.device_sn)
request = HdcHelper.form_hdc_request("shell %s" % command)
HdcHelper.write(sock, request)
len_buf = HdcHelper.read(sock, DATA_UNIT_LENGTH)
if len_buf:
length = struct.unpack("!I", len_buf)[0]
resp = HdcResponse()
resp.okay = True
from xdevice import Scheduler
data = sock.recv(SOCK_DATA_MAX)
while data != b'':
start_time = int(time.time())
while True:
len_buf = HdcHelper.read(sock, DATA_UNIT_LENGTH)
if len_buf:
length = struct.unpack("!I", len_buf)[0]
else:
break
data = sock.recv(length)
ret = HdcHelper.reply_to_string(data)
if ret:
if receiver:
receiver.__read__(ret)
else:
LOG.debug(ret)
if end_mark and end_mark in ret:
break
if read_timeout and \
int(time.time()) - start_time > read_timeout:
break
if not Scheduler.is_execute:
raise ExecuteTerminate()
data = HdcHelper.read(sock, SOCK_DATA_MAX)
return resp
except socket.timeout as _:
device.log.error("%s shell %s timeout[%sS]" % (
......@@ -915,6 +916,8 @@ class HdcHelper:
Create an ASCII string preceded by four hex digits.
"""
try:
if not req.endswith('\0'):
req = "%s\0" % req
req = req.encode("utf-8")
fmt = "!I%ss" % len(req)
result = struct.pack(fmt, len(req), req)
......
......@@ -152,15 +152,7 @@ class PushKit(ITestKit):
LOG.warning(error, error_no=error.error_no)
continue
remount(device)
device.push_file(real_src_path, dst)
if os.path.isdir(real_src_path):
self.add_pushed_dir(real_src_path, dst)
else:
if device.is_directory(dst):
self.pushed_file.append(
os.path.join(dst, os.path.basename(real_src_path)))
else:
self.pushed_file.append(dst)
device.hdc_command("file send {} {}".format(real_src_path, dst))
LOG.debug("Push file finished from {} to {}".format(src, dst))
for command in self.post_push:
run_command(device, command)
......@@ -573,12 +565,13 @@ class AppInstallKit(ITestKit):
LOG.error("The app file {} does not exist".format(app))
continue
if app_file.endswith(".hap"):
self.install_hap(device, app_file)
# use app install command directly
device.hdc_command("app install {}".format(app_file))
else:
result = device.install_package(
app_file, get_install_args(
device, app_file, self.ex_args))
if not result.startswith("Success"):
if not result or not result.startswith("Success"):
raise AppInstallError(
"Failed to install %s on %s. Reason:%s" %
(app_file, device.__get_serial__(), result))
......@@ -591,10 +584,9 @@ class AppInstallKit(ITestKit):
app_name = get_app_name(app)
if app_name:
result = device.uninstall_package(app_name)
if not result.startswith("Success"):
LOG.warning("error uninstalling package %s %s" %
(device.__get_serial__(), result))
device.hdc_command("shell bm uninstall -n {}".
format(app_name))
time.sleep(20)
else:
LOG.warning("Can't find app_name for %s" % app)
if self.is_pri_app:
......@@ -682,16 +674,9 @@ class AppInstallKit(ITestKit):
def remount(device):
device.enable_hdc_root()
cmd = "target mount" \
if device.usb_type == DeviceConnectorType.hdc else "remount"
device.hdc_command(cmd)
device.execute_shell_command("remount")
device.execute_shell_command("mount -o rw,remount /cust")
device.execute_shell_command("mount -o rw,remount /product")
device.execute_shell_command("mount -o rw,remount /hw_product")
device.execute_shell_command("mount -o rw,remount /version")
device.execute_shell_command("mount -o rw,remount /%s" % "system")
def keep_screen_on(device):
......@@ -735,7 +720,7 @@ def run_command(device, command):
elif command.strip() == "reboot-delay":
pass
else:
stdout = device.execute_shell_command(command)
stdout = device.hdc_command("shell {}".format(command))
LOG.debug("Run command result: %s" % (stdout if stdout else ""))
return stdout
......
......@@ -283,3 +283,10 @@ class ConfigConst(object):
module_kits = "module_kits"
spt = "spt"
version = "version"
class FilePermission(object):
mode_777 = 0o777
mode_755 = 0o755
mode_644 = 0o644
\ No newline at end of file
......@@ -31,6 +31,7 @@ from _core.constants import ComType
from _core.constants import ParserType
from _core.constants import CKit
from _core.constants import DeviceLiteKernel
from _core.constants import FilePermission
from _core.driver.parser_lite import ShellHandler
from _core.environment.dmlib_lite import generate_report
from _core.exception import ExecuteTerminate
......@@ -178,7 +179,8 @@ class CppTestDriver(IDriver):
self.error_message = exception
finally:
device_log_file_open = os.open(device_log_file, os.O_WRONLY |
os.O_CREAT | os.O_APPEND, 0o755)
os.O_CREAT | os.O_APPEND,
FilePermission.mode_755)
with os.fdopen(device_log_file_open, "a") as file_name:
file_name.write(self.config.command_result)
file_name.flush()
......@@ -195,6 +197,7 @@ class CppTestDriver(IDriver):
self.config.device.execute_command_with_timeout(
command="cd {}".format(execute_dir), timeout=1)
self.config.execute_bin_path = execute_dir
if self.execute_bin.startswith("/"):
command = ".%s" % self.execute_bin
......@@ -274,7 +277,6 @@ class CppTestDriver(IDriver):
return tests
tests = self.read_nfs_xml(request, self.config.device_xml_path)
self.delete_device_xml(request, self.config.device_xml_path)
time.sleep(1)
return tests
else:
......@@ -384,7 +386,7 @@ class CppTestDriver(IDriver):
if self.config.xml_output:
self.run("{} --gtest_output=xml:{}".format(
command, self.config.device_report_path))
time.sleep(20)
time.sleep(5)
test_rerun = True
if self.check_xml_exist(self.execute_bin + ".xml"):
test_rerun = False
......@@ -431,7 +433,7 @@ class CppTestDriver(IDriver):
listener_copy, timeout=15)
if len(test_tracker.get_current_run_results()):
return
except LiteDeviceError:
except LiteDeviceError as _:
LOG.debug("Exception: ShellCommandUnresponsiveException")
handler.parsers[0].mark_test_as_failed(test)
......@@ -495,6 +497,8 @@ class CppTestDriver(IDriver):
if xml_file in result:
return True
time.sleep(5)
if (self.execute_bin + "_1.xml") in result:
return False
return False
def read_nfs_xml(self, request, report_path, is_true=False):
......@@ -584,9 +588,9 @@ class CppTestDriver(IDriver):
try:
sftp.remove(filepath)
time.sleep(0.5)
except IOError:
except IOError as _:
pass
except FileNotFoundError:
except FileNotFoundError as _:
pass
client.close()
else:
......@@ -595,7 +599,8 @@ class CppTestDriver(IDriver):
os.remove(report_xml)
except Exception as exception:
LOG.error(
"remove {} Failed.{}".format(report_xml, exception))
"remove {} Failed:{}".format(report_xml, exception))
pass
def __result__(self):
return self.result if os.path.exists(self.result) else ""
......@@ -701,7 +706,7 @@ class CTestDriver(IDriver):
__get_serial__())
device_log_file_open = \
os.open(device_log_file, os.O_WRONLY | os.O_CREAT |
os.O_APPEND, 0o755)
os.O_APPEND, FilePermission.mode_755)
with os.fdopen(device_log_file_open, "a") as file_name:
file_name.write("{}{}".format(
"\n".join(result.split("\n")[0:-1]), "\n"))
......@@ -858,7 +863,7 @@ class OpenSourceTestDriver(IDriver):
request.config.device.__get_serial__())
device_log_file_open = \
os.open(device_log_file, os.O_WRONLY | os.O_CREAT |
os.O_APPEND, 0o755)
os.O_APPEND, FilePermission.mode_755)
with os.fdopen(device_log_file_open, "a") as file_name:
for test_bin in copy_list:
if not test_bin.endswith(".run-test"):
......
......@@ -61,8 +61,8 @@ def check_open_source_test(result_output):
def check_read_test_end(result=None, input_command=None):
temp_result = result.replace("\n", "")
if input_command not in temp_result:
return False
# if input_command not in temp_result:
# return False
index = result.find(input_command) + len(input_command)
result_output = result[index:]
if input_command.startswith("./"):
......@@ -87,8 +87,10 @@ def check_read_test_end(result=None, input_command=None):
error_no="00402")
raise LiteDeviceExecuteCommandError("execute file not exist",
error_no="00402")
elif input_command.startswith("zcat"):
return False
else:
if "OHOS #" in result_output or "Linux" in result_output:
if "OHOS #" in result_output or "# " in result_output:
if input_command == "reboot" or input_command == "reset":
return False
if input_command.startswith("mount"):
......@@ -187,12 +189,12 @@ class LiteHelper:
status = True
from xdevice import Scheduler
while time.time() - start_time < timeout:
data = com.readline().decode('gbk', errors='ignore')
data = PATTERN.sub('', data).replace("\r", "")
result = "{}{}".format(result, data)
if command in result or linux_end_command in result:
break
# while time.time() - start_time < timeout:
# data = com.readline().decode('gbk', errors='ignore')
# data = PATTERN.sub('', data).replace("\r", "")
# result = "{}{}".format(result, data)
# if command in result or linux_end_command in result:
# break
while time.time() - start_time < timeout:
if not Scheduler.is_execute:
......
......@@ -149,7 +149,7 @@ class Scheduler(object):
error_message = "%s[%s]" % (str(exception), error_no) \
if error_no else str(exception)
error_no = error_no if error_no else "00000"
LOG.exception(exception, exc_info=False, error_no=error_no)
LOG.exception(exception, exc_info=True, error_no=error_no)
finally:
Scheduler._clear_test_dict_source()
......
......@@ -44,6 +44,7 @@ from _core.utils import get_local_ip
from _core.utils import get_test_component_version
from _core.exception import LiteDeviceConnectError
from _core.constants import DeviceLabelType
from _core.constants import FilePermission
from _core.environment.manager_env import DeviceAllocationState
......@@ -194,9 +195,8 @@ class MountKit(ITestKit):
"mount nfs_ip:nfs_directory device"
"_directory nfs"]
linux_commands = ["cd /%s" % "storage",
"fuser -k /%s/%s" % ("storage", "device_directory"),
"umount -f /%s/%s" % ("storage", "device_directory"),
"mount -t nfs -o nolock -o tcp nfs_ip:nfs_directory "
"toybox mount -t nfs -o nolock,addr=nfs_ip nfs_ip:nfs_directory "
"/%s/%s" % ("storage", "device_directory"),
"chmod 755 -R /%s/%s" % (
"storage", "device_directory")]
......@@ -244,8 +244,15 @@ class MountKit(ITestKit):
timeout=timeout)
if status:
break
LOG.info("mount failed,try "
if "already mounted" in result:
LOG.info("{} is mounted".format(target))
break
LOG.info("Mount failed,try "
"again {} time".format(mount_time))
if mount_time == 3:
raise LiteDeviceMountError("Failed to mount the "
"device[00402]",
error_no="00402")
else:
result, status, _ = device.execute_command_with_timeout(
command=command, case_type=case_type, timeout=timeout)
......@@ -365,9 +372,6 @@ class MountKit(ITestKit):
device.execute_command_with_timeout(command="cd /storage",
timeout=1)
for mounted_dir in self.mounted_dir:
device.execute_command_with_timeout(command="fuser -k {}".
format(mounted_dir),
timeout=2)
device.execute_command_with_timeout(command="umount -f "
"/storage{}".
format(mounted_dir),
......@@ -514,7 +518,8 @@ class RootFsKit(ITestKit):
hash_file_path = os.path.join(report_path, hash_file_name)
# write result to file
hash_file_path_open = os.open(hash_file_path, os.O_WRONLY |
os.O_CREAT | os.O_APPEND, 0o755)
os.O_CREAT | os.O_APPEND,
FilePermission.mode_755)
with os.fdopen(hash_file_path_open, mode="w") as hash_file:
hash_file.write(result)
......
......@@ -137,7 +137,7 @@ def _get_find_proc(find_command, list_command):
return proc
def exec_cmd(cmd, timeout=5 * 60, error_print=True, join_result=False):
def exec_cmd(cmd, timeout=1 * 60, error_print=True, join_result=False):
"""
Executes commands in a new shell. Directing stderr to PIPE.
......@@ -154,6 +154,10 @@ def exec_cmd(cmd, timeout=5 * 60, error_print=True, join_result=False):
"""
sys_type = platform.system()
if isinstance(cmd, list):
LOG.info("The running command is: {}".format(" ".join(cmd)))
if isinstance(cmd, str):
LOG.info("The running command is: {}".format(cmd))
if sys_type == "Linux" or sys_type == "Darwin":
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=False,
......@@ -173,7 +177,7 @@ def exec_cmd(cmd, timeout=5 * 60, error_print=True, join_result=False):
return err if err else out
except (TimeoutError, KeyboardInterrupt, AttributeError, ValueError,
EOFError, IOError):
EOFError, IOError, subprocess.TimeoutExpired):
sys_type = platform.system()
if sys_type == "Linux" or sys_type == "Darwin":
os.killpg(proc.pid, signal.SIGTERM)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册