Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6af317a authored by Jack He's avatar Jack He
Browse files

Cert: Check time delta after sync and improve logging

Bug: 156383450
Tag: #gd-refactor
Test: gd/cert/run --host
Change-Id: I776081c768a0167aee488f77adab35cfe426a623
parent e12f6c13
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -75,13 +75,15 @@ class GdBaseTestClass(BaseTestClass):
                "Failed to make root canal ports available")

            # Start root canal process
            self.rootcanal_process = subprocess.Popen(
                [
            rootcanal_cmd = [
                rootcanal,
                str(rootcanal_test_port),
                str(rootcanal_hci_port),
                str(rootcanal_link_layer_port)
                ],
            ]
            self.log.debug("Running %s" % " ".join(rootcanal_cmd))
            self.rootcanal_process = subprocess.Popen(
                rootcanal_cmd,
                cwd=get_gd_root(),
                env=os.environ.copy(),
                stdout=subprocess.PIPE,
+24 −4
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#   limitations under the License.

from abc import ABC
from datetime import datetime
import inspect
import logging
import os
@@ -204,6 +205,7 @@ class GdDeviceBase(ABC):
            signal_socket.listen(1)

            # Start backing process
            logging.debug("Running %s" % " ".join(self.cmd))
            self.backing_process = subprocess.Popen(
                self.cmd,
                cwd=get_gd_root(),
@@ -487,6 +489,7 @@ class GdAndroidDevice(GdDeviceBase):
            "adb", "-s", self.serial_number, "logcat", "-T", "1", "-v", "year",
            "-v", "uid"
        ]
        logging.debug("Running %s", " ".join(self.logcat_cmd))
        self.logcat_process = subprocess.Popen(
            self.logcat_cmd,
            stdout=subprocess.PIPE,
@@ -506,6 +509,8 @@ class GdAndroidDevice(GdDeviceBase):
            color=self.terminal_color)

        # Done run parent setup
        logging.info("Done preparation for %s, starting backing process" %
                     self.serial_number)
        super().setup()

    def teardown(self):
@@ -561,7 +566,7 @@ class GdAndroidDevice(GdDeviceBase):
        host_tz = time.strftime("%z")
        if device_tz != host_tz:
            target_timezone = utils.get_timezone_olson_id()
            logging.info("Device timezone %s does not match host timezone %s, "
            logging.debug("Device timezone %s does not match host timezone %s, "
                          "syncing them by setting timezone to %s" %
                          (device_tz, host_tz, target_timezone))
            self.adb.shell("setprop persist.sys.timezone %s" % target_timezone)
@@ -572,6 +577,22 @@ class GdAndroidDevice(GdDeviceBase):
                "Device timezone %s still does not match host "
                "timezone %s after reset" % (device_tz, host_tz))
        self.adb.shell("date %s" % time.strftime("%m%d%H%M%Y.%S"))
        datetime_format = "%Y-%m-%dZ%H:%M:%S%z"
        host_time = datetime.today()
        try:
            device_time = datetime.strptime(
                self.adb.shell("date +'%s'" % datetime_format), datetime_format)
        except ValueError:
            asserts.fail("Failed to get time after sync")
            return
        max_delta_seconds = 0.5
        asserts.assert_almost_equal(
            (device_time - host_time).total_seconds(),
            0,
            msg="Device time %s and host time %s off by >%dms after sync" %
            (device_time.isoformat, host_time.isoformat(),
             int(max_delta_seconds * 1000)),
            delta=max_delta_seconds)

    def push_or_die(self, src_file_path, dst_file_path, push_timeout=300):
        """Pushes a file to the Android device
@@ -582,7 +603,6 @@ class GdAndroidDevice(GdDeviceBase):
            push_timeout: How long to wait for the push to finish in seconds
        """
        try:
            self.ensure_verity_disabled()
            out = self.adb.push(
                '%s %s' % (src_file_path, dst_file_path), timeout=push_timeout)
            if 'error' in out: