import re
import time
import pytest
from utils import GP, check_hdc_cmd, check_hdc_targets, check_rom, check_hdc_version, get_shell_result, \
run_command_with_timeout, check_shell, get_remote_path, get_local_path, load_gp
def clear_and_restart():
check_hdc_cmd("kill")
check_hdc_cmd("start")
check_hdc_cmd("wait")
check_hdc_cmd("shell rm -rf data/local/tmp/it_*")
check_hdc_cmd("shell rm data/log/faultlog/faultlogger/cppcrash*hdcd*")
check_hdc_cmd("shell mkdir data/local/tmp/it_send_dir")
class TestListTarget:
@classmethod
def setup_class(self):
clear_and_restart()
@pytest.mark.L0
def test_list_targets(self):
assert check_hdc_targets()
time.sleep(3)
class TestROM:
@pytest.mark.L0
def test_hdcd_rom(self):
baseline = 2200
assert check_rom(baseline)
class TestVersion:
@pytest.mark.L0
def test_version_cmd(self):
version = "Ver: 3.1.0a"
assert check_hdc_version("-v", version)
assert check_hdc_version("version", version)
@pytest.mark.L0
def test_version_match(self):
"""
Check that the version numbers of each program are the same
1. client
2. server
3. daemon program
4. device param
"""
daemon_param_version = get_shell_result("shell param get const.hdc.version").strip()
print(f"param version:{daemon_param_version}")
daemon_version = get_shell_result("shell hdcd -v").strip()
print(f"daemon version:{daemon_version}")
client_version = get_shell_result("-v").strip()
print(f"client version:{client_version}")
server_version = get_shell_result("version").strip()
print(f"server version:{server_version}")
client_server_version = get_shell_result("checkserver").strip()
print(f"checkserver version:{client_server_version}")
assert(daemon_param_version == daemon_version)
assert(daemon_param_version == client_version)
assert(daemon_param_version == server_version)
assert(client_server_version.count(daemon_param_version) == 2)
class TestTargetKey:
@pytest.mark.L0
def test_target_key(self):
device_key = re.split("\r|\n", get_shell_result(f"list targets"))[0]
hdcd_pid = re.split("\r|\n", get_shell_result(f"-t {device_key} shell pgrep -x hdcd"))[0]
assert hdcd_pid.isdigit()
class TestTargetCommand:
@pytest.mark.L0
def test_target_cmd(self):
assert check_hdc_targets()
check_hdc_cmd("target boot")
start_time = time.time()
run_command_with_timeout(f"{GP.hdc_head} wait", 30)
time.sleep(3)
run_command_with_timeout(f"{GP.hdc_head} wait", 30)
end_time = time.time()
print(f"command exec time {end_time - start_time}")
time.sleep(3)
assert (end_time - start_time) > 8
@pytest.mark.L0
def test_target_mount(self):
assert (check_hdc_cmd("target mount", "Mount finish" or "[Fail]Operate need running as root"))
is_linux = check_hdc_cmd("shell uname", "Linux")
sep = "/"
remount_vendor = get_shell_result(f'shell "mount |grep {sep}vendor |head -1"')
print(remount_vendor)
if is_linux:
assert "rw" in remount_vendor
else:
assert "ro" in remount_vendor
remount_system = get_shell_result(f'shell "cat proc/mounts | grep {sep}system |head -1"')
print(remount_system)
assert "rw" in remount_system
class TestSwitch:
@pytest.mark.L0
@pytest.mark.repeat(1)
def test_file_switch_off(self):
assert check_hdc_cmd("shell param set persist.hdc.control.file false")
assert check_shell(f"shell param get persist.hdc.control.file", "false")
assert check_shell(f"file send {get_local_path('small')} {get_remote_path('it_small')}",
"debugging is not allowed")
assert check_shell(f"file recv {get_remote_path('it_small')} {get_local_path('small_recv')}",
"debugging is not allowed")
@pytest.mark.L0
@pytest.mark.repeat(1)
def test_file_switch_on(self):
assert check_hdc_cmd("shell param set persist.hdc.control.file true")
assert check_shell(f"shell param get persist.hdc.control.file", "true")
assert check_hdc_cmd(f"file send {get_local_path('small')} {get_remote_path('it_small')}")
assert check_hdc_cmd(f"file recv {get_remote_path('it_small')} {get_local_path('small_recv')}")