actually call the test case defined callback functions
Change-Id: I973d0e1b1367cb47cb1c03f9a4f26b857656195e
diff --git a/utils/python/controllers/adb.py b/utils/python/controllers/adb.py
index 40b64c2..00f952a 100644
--- a/utils/python/controllers/adb.py
+++ b/utils/python/controllers/adb.py
@@ -142,7 +142,7 @@
return self._exec_cmd(' '.join((self.adb_str, name, arg_str)))
def tcp_forward(self, host_port, device_port):
- """Starts tcp forwarding.
+ """Starts TCP forwarding.
Args:
host_port: Port number to use on the computer.
@@ -150,7 +150,17 @@
"""
self.forward("tcp:{} tcp:{}".format(host_port, device_port))
+ def reverse_tcp_forward(self, device_port, host_port):
+ """Starts reverse TCP forwarding.
+
+ Args:
+ device_port: Port number to use on the android device.
+ host_port: Port number to use on the computer.
+ """
+ self.reverse("tcp:{} tcp:{}".format(device_port, host_port))
+
def __getattr__(self, name):
+
def adb_call(*args):
clean_name = name.replace('_', '-')
arg_str = ' '.join(str(elem) for elem in args)
diff --git a/utils/python/controllers/android_device.py b/utils/python/controllers/android_device.py
index e7c33ca..a24b34e 100644
--- a/utils/python/controllers/android_device.py
+++ b/utils/python/controllers/android_device.py
@@ -99,8 +99,7 @@
def list_adb_devices():
- """List all android devices connected to the computer that are detected by
- adb.
+ """List all target devices connected to the host and detected by adb.
Returns:
A list of android device serials. Empty if there's none.
@@ -266,8 +265,10 @@
Attributes:
serial: A string that's the serial number of the Androi device.
- d_port: An integer that's the port number used on the Android device
- for adb port forwarding.
+ device_command_port: int, the port number used on the Android device
+ for adb port forwarding (for command-response sessions).
+ device_callback_port: int, the port number used on the Android device
+ for adb port reverse forwarding (for callback sessions).
log_path: A string that is the path where all logs collected on this
android device should be stored.
adb_logcat_process: A process that collects the adb logcat.
@@ -276,11 +277,16 @@
adb: An AdbProxy object used for interacting with the device via adb.
fastboot: A FastbootProxy object used for interacting with the device
via fastboot.
+ host_command_port: the host-side port for runner to agent sessions
+ (to send commands and receive responses).
+ host_callback_port: the host-side port for agent to runner sessions
+ (to get callbacks from agent).
"""
- def __init__(self, serial="", device_port=5001):
+ def __init__(self, serial="", device_port=5001, device_callback_port=5010):
self.serial = serial
- self.device_port = device_port
+ self.device_command_port = device_port
+ self.device_callback_port = device_callback_port
self.log = logging.getLogger()
base_log_path = getattr(self.log, "log_path", "/tmp/logs/")
self.log_path = os.path.join(base_log_path, "AndroidDevice%s" % serial)
@@ -290,13 +296,17 @@
self.fastboot = fastboot.FastbootProxy(serial)
if not self.isBootloaderMode:
self.rootAdb()
- self.host_port = adb.get_available_host_port()
- self.adb.tcp_forward(self.host_port, self.device_port)
- self.hal = hal_mirror.HalMirror(self.host_port)
+ self.host_command_port = adb.get_available_host_port()
+ self.host_callback_port = adb.get_available_host_port()
+ self.adb.tcp_forward(self.host_command_port, self.device_command_port)
+ self.adb.reverse_tcp_forward(
+ self.device_callback_port, self.host_callback_port)
+ self.hal = hal_mirror.HalMirror(
+ self.host_command_port, self.host_callback_port)
def __del__(self):
- if self.host_port:
- self.adb.forward("--remove tcp:%s" % self.host_port)
+ if self.host_command_port:
+ self.adb.forward("--remove tcp:%s" % self.host_command_port)
if self.adb_logcat_process:
self.stopAdbLogcat()
@@ -459,4 +469,3 @@
self.rootAdb()
if has_adb_log:
self.startAdbLogcat()
-
diff --git a/utils/python/mirror/hal_mirror.py b/utils/python/mirror/hal_mirror.py
index d60cc66..3f6ace4 100644
--- a/utils/python/mirror/hal_mirror.py
+++ b/utils/python/mirror/hal_mirror.py
@@ -37,6 +37,8 @@
"light": 4,
"wifi": 5}
+VTS_CALLBACK_SERVER_TARGET_SIDE_PORT = 5010
+
_DEFAULT_TARGET_BASE_PATHS = ["/system/lib64/hw"]
@@ -49,15 +51,19 @@
One can use this class to create and destroy a HAL mirror object.
Attributes:
+ _host_command_port: int, the host-side port for command-response
+ sessions.
+ _host_callback_port: int, the host-side port for callback sessions.
_hal_level_mirrors: dict, key is HAL handler name, value is HAL
mirror object.
_host_port: int, the port number on the host side to use.
_callback_server: the instance of a callback server.
_callback_port: int, the port number of a host-side callback server.
"""
- def __init__(self, host_port):
+ def __init__(self, host_command_port, host_callback_port):
self._hal_level_mirrors = {}
- self._host_port = host_port
+ self._host_command_port = host_command_port
+ self._host_callback_port = host_callback_port
self._callback_server = None
self._callback_port = 0
@@ -99,8 +105,7 @@
target_basepaths=_DEFAULT_TARGET_BASE_PATHS,
handler_name=None,
bits=64):
- """Initiates a handler for a particular legacy HAL that does not use
- HIDL.
+ """Initiates a handler for a particular legacy HAL.
This will initiate a stub service for a HAL on the target side, create
the top level mirror object for a HAL, and register it in the manager.
@@ -153,9 +158,13 @@
raise error.ComponentLoadingError("Invalid value for bits: %s" % bits)
client = vts_tcp_client.VtsTcpClient()
callback_server = vts_tcp_server.VtsTcpServer()
- _, self._callback_port = callback_server.Start()
- client.Connect(port=self._host_port,
- callback_port=self._callback_port)
+ _, port = callback_server.Start(self._host_callback_port)
+ if port != self._host_callback_port:
+ raise errors.ComponentLoadingError(
+ "Couldn't start a callback TcpServer at port %s" %
+ self._host_callback_port)
+ client.Connect(command_port=self._host_command_port,
+ callback_port=self._host_callback_port)
if not handler_name:
handler_name = target_type
service_name = "vts_binder_%s" % handler_name
diff --git a/utils/python/mirror/mirror_object.py b/utils/python/mirror/mirror_object.py
index df8b7d2..f883522 100644
--- a/utils/python/mirror/mirror_object.py
+++ b/utils/python/mirror/mirror_object.py
@@ -312,7 +312,8 @@
logging.debug("Found match for API name %s.", name)
ret_v = getattr(value, p_type, None)
if ret_v is None:
- raise MirrorObjectError("No value found for type %s in %s." % (p_type, value))
+ raise MirrorObjectError(
+ "No value found for type %s in %s." % (p_type, value))
return ret_v
raise MirrorObjectError("const %s not found" % api_name)