M test/pytest/conftest.py => test/pytest/conftest.py +24 -0
@@ 15,6 15,7 @@ from harness.harness import Harness
from harness import utils
from harness.interface.error import TestError, Error
from harness.interface.CDCSerial import Keytype, CDCSerial as serial
+from harness.api.security import SetPhoneLockOff, GetPhoneLockStatus
from harness.interface.defs import key_codes
@@ 27,6 28,8 @@ def pytest_addoption(parser):
parser.addoption("--call_duration", type=int, action="store", default=30)
parser.addoption("--sms_text", type=str, action="store", default='')
parser.addoption("--bt_device", type=str, action="store", default='')
+ parser.addoption("--passcode", type=str, action="store", default='')
+ parser.addoption("--update_file_path", type=str, action="store", default='')
@pytest.fixture(scope='session')
@@ 35,6 38,17 @@ def phone_number(request):
assert phone_number
return phone_number
+@pytest.fixture(scope='session')
+def passcode(request):
+ passcode = request.config.option.passcode
+ assert passcode
+ return passcode
+@pytest.fixture(scope='session')
+def update_file_path(request):
+ update_file_path = request.config.option.update_file_path
+ assert update_file_path
+ return update_file_path
+
@pytest.fixture(scope='session')
def call_duration(request):
@@ 187,6 201,16 @@ def phone_ends_test_in_desktop(harness):
assert harness.get_application_name() == target_application
time.sleep(1)
+@pytest.fixture(scope='session')
+def phone_security_unlocked(harness,passcode):
+ for _ in range(2):
+ try:
+ GetPhoneLockStatus().run(harness)
+ except TransactionError as e:
+ log.info(f"transaction code: {e}")
+ log.info("Phone security locked, unlocking")
+ SetPhoneLockOff(passcode=passcode).run(harness)
+
def pytest_configure(config):
config.addinivalue_line("markers",
"service_desktop_test: mark test if it's related to service-desktop API")
M test/pytest/test_updater.py => test/pytest/test_updater.py +47 -28
@@ 3,54 3,73 @@
import os
import pytest
-import logging
-from harness import log
+import shutil
+from harness import log, utils
from harness.interface.defs import Method, Endpoint
-from harness.request import Transaction, Request, TransactionError
from harness.rt_harness_discovery import get_harness_automatic
from harness.harness import Harness
from harness.api.filesystem import put_file, get_file
-from harness.api.developermode import PhoneModeLock
from harness.api.update import PhoneReboot, Reboot
+from harness.api.device_info import GetDeviceInfo
+
+old_version = None
+old_sha = None
def get_version(harness: Harness):
r = harness.request(Endpoint.DEVICEINFO, Method.GET, {}).response
version = r.body["version"]
sha = r.body["gitRevision"]
- return f"version: {version} sha: {sha}"
+ return version, sha
-def disable_some_logs(harness: Harness):
- from harness.interface.defs import PureLogLevel
- for val in ["SysMgrService", "ServiceDesktop_w2", "CellularMux"]:
- ret = harness.request(Endpoint.DEVELOPERMODE, Method.POST, {
- "log": True, "service": val, "level": PureLogLevel.LOGERROR.value})
- log.info(f"{ret.response}")
+@pytest.mark.usefixtures("phone_security_unlocked")
+@pytest.mark.rt1051
+@pytest.mark.order("first")
+def test_perform_update(harness: Harness, update_file_path):
+ filename = os.path.basename(update_file_path)
+ path = os.path.dirname(update_file_path)
+ if filename != "update.tar":
+ filename = "update.tar"
+ try:
+ os.remove(os.path.join(path, filename))
+ except OSError:
+ pass
+ shutil.copyfile(update_file_path, os.path.join(path, filename))
+ update_file_path = os.path.join(path, filename)
-@pytest.mark.usefixtures("phone_unlocked")
-@pytest.mark.rt1051
-def test_update(harness: Harness):
- filename = "update.tar"
+ global old_version
+ global old_sha
+ (old_version, old_sha) = get_version(harness)
- log.info(get_version(harness))
- PhoneModeLock(False).run(harness)
- put_file(harness, filename, "/sys/user/temp")
+ put_file(harness, update_file_path, "/sys/user/temp")
PhoneReboot(Reboot.UPDATE).run(harness)
assert harness.connection.watch_port_reboot(300)
+
+@pytest.mark.usefixtures("phone_security_unlocked")
+@pytest.mark.rt1051
+@pytest.mark.order("second")
+def test_verify_update():
+ global old_version
+ global old_sha
+
harness = get_harness_automatic(300)
- import time
- time.sleep(15)
- harness.unlock_phone()
- PhoneModeLock(False).run(harness)
-
- log.info(get_version(harness))
- get_file(harness, "updater.log", "./")
- with open("updater.log") as f:
+
+ ret = GetDeviceInfo().run(harness)
+ recovery_status_path = ret.response.body["recoveryStatusFilePath"]
+ path = os.path.dirname(recovery_status_path)
+ filename = os.path.basename(recovery_status_path)
+
+ (new_version, new_sha) = get_version(harness)
+ assert new_version != old_version
+ assert new_sha != old_sha
+
+ get_file(harness, file_pure=filename, path_local="./", path_pure=path)
+ with open(filename) as f:
line = f.readline()
- assert "OK" in line
- PhoneModeLock(True).run(harness)
+ print(line)
+ assert "successful" in line
log.info("update done!")