!30 解决linux镜像运行ssts用例问题

Merge pull request !30 from alex_hold/master
This commit is contained in:
openharmony_ci 2021-09-13 11:38:14 +00:00 committed by Gitee
commit bb55bc8612
4 changed files with 44 additions and 25 deletions

View File

@ -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

View 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"):

View File

@ -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:

View File

@ -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)