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

Commit 61dd595f authored by Jack He's avatar Jack He
Browse files

Cert: Cleanup gd/cert Python libraries

* Rename gd_base_test_facade_only to gd_base_test and its enclosing
  class GdBaseTestClass
* Moved OS utilities to an unified file cert/os_utils.py
* Sort imports according to PEP 8

Test: source gd/cert/run --host
Change-Id: I0d308975de72bcfc0a5aec89776137a104b76387
parent 7ce7662c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -14,18 +14,18 @@
#   See the License for the specific language governing permissions and
#   limitations under the License.

from datetime import datetime, timedelta
import logging
import time

from mobly import asserts
from datetime import datetime, timedelta

from acts.base_test import BaseTestClass
from cert.event_stream import EventStream, FilteringEventStream
from cert.truth import assertThat

# Test packet nesting
from bluetooth_packets_python3 import hci_packets
from bluetooth_packets_python3 import l2cap_packets
from cert.event_stream import EventStream, FilteringEventStream
from cert.truth import assertThat


class BogusProto:
+3 −3
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
#   See the License for the specific language governing permissions and
#   limitations under the License.

from abc import ABC, abstractmethod
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timedelta
import logging
from queue import SimpleQueue, Empty
@@ -21,10 +23,8 @@ from queue import SimpleQueue, Empty
from mobly import asserts

from google.protobuf import text_format
from concurrent.futures import ThreadPoolExecutor
from grpc import RpcError

from abc import ABC, abstractmethod
from grpc import RpcError

from cert.closable import Closable

+7 −18
Original line number Diff line number Diff line
@@ -14,30 +14,19 @@
#   See the License for the specific language governing permissions and
#   limitations under the License.

from acts import asserts
from acts.base_test import BaseTestClass
from facade import rootservice_pb2 as facade_rootservice

import importlib
import logging
import os
from pathlib import Path
import signal
import subprocess

# GD root is the parent directory of cert
GD_ROOT = str(Path(__file__).absolute().parents[1])


def is_subprocess_alive(process, timeout_seconds=1):
    try:
        process.wait(timeout=timeout_seconds)
        return False
    except subprocess.TimeoutExpired as exp:
        return True
from acts import asserts
from acts.base_test import BaseTestClass
from cert.os_utils import get_gd_root, is_subprocess_alive
from facade import rootservice_pb2 as facade_rootservice


class GdFacadeOnlyBaseTestClass(BaseTestClass):
class GdBaseTestClass(BaseTestClass):

    def setup_class(self, dut_module, cert_module):
        self.dut_module = dut_module
@@ -53,7 +42,7 @@ class GdFacadeOnlyBaseTestClass(BaseTestClass):
            self.rootcanal_logs = open(rootcanal_logpath, 'w')
            rootcanal_config = self.controller_configs['rootcanal']
            rootcanal_hci_port = str(rootcanal_config.get("hci_port", "6402"))
            rootcanal = os.path.join(GD_ROOT, "root-canal")
            rootcanal = os.path.join(get_gd_root(), "root-canal")
            self.rootcanal_process = subprocess.Popen(
                [
                    rootcanal,
@@ -61,7 +50,7 @@ class GdFacadeOnlyBaseTestClass(BaseTestClass):
                    rootcanal_hci_port,
                    str(rootcanal_config.get("link_layer_port", "6403"))
                ],
                cwd=GD_ROOT,
                cwd=get_gd_root(),
                env=os.environ.copy(),
                stdout=self.rootcanal_logs,
                stderr=self.rootcanal_logs)
+5 −5
Original line number Diff line number Diff line
@@ -16,23 +16,23 @@

import logging

from facade import rootservice_pb2_grpc as facade_rootservice_pb2_grpc
from google.protobuf import empty_pb2 as empty_proto

from cert.gd_device_base import GdDeviceBase, replace_vars
from cert.event_stream import EventStream
from facade import rootservice_pb2_grpc as facade_rootservice_pb2_grpc
from hal import facade_pb2_grpc as hal_facade_pb2_grpc
from hci.facade import facade_pb2 as hci_facade
from hci.facade import facade_pb2_grpc as hci_facade_pb2_grpc
from hci.facade import acl_manager_facade_pb2_grpc
from hci.facade import controller_facade_pb2 as controller_facade
from hci.facade import controller_facade_pb2_grpc
from hci.facade import le_acl_manager_facade_pb2_grpc
from hci.facade import le_advertising_manager_facade_pb2_grpc
from hci.facade import le_scanning_manager_facade_pb2_grpc
from neighbor.facade import facade_pb2_grpc as neighbor_facade_pb2_grpc
from l2cap.classic import facade_pb2_grpc as l2cap_facade_pb2_grpc
from l2cap.le import facade_pb2_grpc as l2cap_le_facade_pb2_grpc
from neighbor.facade import facade_pb2_grpc as neighbor_facade_pb2_grpc
from security import facade_pb2_grpc as security_facade_pb2_grpc
from google.protobuf import empty_pb2 as empty_proto
from cert.event_stream import EventStream

ACTS_CONTROLLER_CONFIG_NAME = "GdDevice"
ACTS_CONTROLLER_REFERENCE_NAME = "gd_devices"
+7 −11
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ import logging
import os
from builtins import open
import json
from pathlib import Path
import signal
import socket
import subprocess
@@ -30,14 +29,11 @@ from acts.controllers.adb import AdbProxy, AdbError

import grpc

from cert.gd_base_test_facade_only import is_subprocess_alive
from cert.os_utils import get_gd_root, is_subprocess_alive

WAIT_CHANNEL_READY_TIMEOUT = 10
WAIT_FOR_DEVICE_TIMEOUT = 180

# GD root is the parent directory of cert
GD_ROOT = str(Path(__file__).absolute().parents[1])


def replace_vars(string, config):
    serial_number = config.get("serial_number")
@@ -48,7 +44,7 @@ def replace_vars(string, config):
        rootcanal_port = ""
    if serial_number == "DUT" or serial_number == "CERT":
        raise Exception("Did you forget to configure the serial number?")
    return string.replace("$GD_ROOT", GD_ROOT) \
    return string.replace("$GD_ROOT", get_gd_root()) \
                 .replace("$(grpc_port)", config.get("grpc_port")) \
                 .replace("$(grpc_root_server_port)", config.get("grpc_root_server_port")) \
                 .replace("$(rootcanal_port)", rootcanal_port) \
@@ -90,13 +86,13 @@ class GdDeviceBase:
                int(grpc_root_server_port), int(grpc_root_server_port))
            self.adb.reverse("tcp:%s tcp:%s" % (signal_port, signal_port))
            self.push_or_die(
                os.path.join(GD_ROOT, "target", "bluetooth_stack_with_facade"),
                "system/bin")
                os.path.join(get_gd_root(), "target",
                             "bluetooth_stack_with_facade"), "system/bin")
            self.push_or_die(
                os.path.join(GD_ROOT, "target", "libbluetooth_gd.so"),
                os.path.join(get_gd_root(), "target", "libbluetooth_gd.so"),
                "system/lib64")
            self.push_or_die(
                os.path.join(GD_ROOT, "target", "libgrpc++_unsecure.so"),
                os.path.join(get_gd_root(), "target", "libgrpc++_unsecure.so"),
                "system/lib64")
            self.ensure_no_output(self.adb.shell("logcat -c"))
            self.adb.shell("rm /data/misc/bluetooth/logs/btsnoop_hci.log")
@@ -113,7 +109,7 @@ class GdDeviceBase:

        self.backing_process = subprocess.Popen(
            cmd,
            cwd=GD_ROOT,
            cwd=get_gd_root(),
            env=os.environ.copy(),
            stdout=self.backing_process_logs,
            stderr=self.backing_process_logs)
Loading