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

Commit 2d7ead85 authored by Jack He's avatar Jack He
Browse files

Test: Zip dynamic libraries and push to device if not present

* Bluetooth mainline modules keeps its own copies of dynamic libraries
* Hence now GD cert binaries have to keep another copy when running

Test: gd/cert/run --sl4a
Bug: 232048916
Tag: #gd-refactor
Merged-In: I716b47f6b808cd42b0713f55ba08544011652730
Change-Id: I716b47f6b808cd42b0713f55ba08544011652730
(cherry picked from commit d500fed0)
parent 78374f5f
Loading
Loading
Loading
Loading
+33 −4
Original line number Diff line number Diff line
@@ -46,13 +46,42 @@ LOCAL_target_executables := \
	$(TARGET_OUT_EXECUTABLES)/bluetooth_stack_with_facade

LOCAL_target_libraries := \
	$(TARGET_OUT_SHARED_LIBRARIES)/android.hardware.bluetooth@1.0.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/android.hardware.bluetooth@1.1.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libandroid_runtime_lazy.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libbacktrace.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libbase.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libbinder_ndk.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libbinder.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libc++.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libcrypto.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libbluetooth_gd.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libcutils.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libgrpc_wrap.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libgrpc++_unsecure.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libgrpc++.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libgrpc_wrap.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libstatslog_bt.so
#LINT.ThenChange(gd/cert/run)
	$(TARGET_OUT_SHARED_LIBRARIES)/libhidlbase.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/liblog.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/liblzma.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libprotobuf-cpp-full.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libssl.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libstatslog_bt.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libunwindstack.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libutils.so \
	$(TARGET_OUT_SHARED_LIBRARIES)/libz.so
	# libclang_rt.asan-aarch64-android.so is only generated for ASAN build and included automatically
	# on devices
	# $(TARGET_OUT_SHARED_LIBRARIES)/libclang_rt.asan-aarch64-android.so \
	# libc.so, libdl_android.so, libdl.so, and libm.so are provided by com.android.runtime APEX
	# Hence we cannot manually add them here
	# $(TARGET_OUT_SHARED_LIBRARIES)/libc.so \
	# $(TARGET_OUT_SHARED_LIBRARIES)/libdl_android.so \
	# $(TARGET_OUT_SHARED_LIBRARIES)/libdl.so \
	# $(TARGET_OUT_SHARED_LIBRARIES)/libm.so \
	# libstatssocket.so is provided by co.android.os.statsd APEX
	# $(TARGET_OUT_SHARED_LIBRARIES)/libstatssocket.so
	# linux-vdso.so.1 is always provided by OS
	# $(TARGET_OUT_SHARED_LIBRARIES)/linux-vdso.so.1
#LINT.ThenChange(blueberry/tests/gd/cert/gd_device.py)

bluetooth_cert_src_and_bin_zip := \
	$(call intermediates-dir-for,PACKAGING,bluetooth_cert_src_and_bin,HOST)/bluetooth_cert_src_and_bin.zip
+16 −0
Original line number Diff line number Diff line
@@ -156,3 +156,19 @@ class BlueberryAdbProxy(AdbProxy):
            # The actual port we need to disable via adb is on the remote host.
            host_port = remote_port
        self.forward(["--remove", "tcp:%d" % host_port])

    def path_exists(self, path):
        """Check if a file path exists on an Android device

        :param path: file path, could be a directory
        :return: True if file path exists
        """
        try:
            ret = self.shell("ls {}".format(path))
            if ret is not None and len(ret) > 0:
                return True
            else:
                return False
        except AdbError as e:
            logging.debug("path {} does not exist, error={}".format(path, e))
            return False
+51 −7
Original line number Diff line number Diff line
@@ -463,6 +463,8 @@ class GdAndroidDevice(GdDeviceBase):
    WAIT_FOR_DEVICE_TIMEOUT_SECONDS = 180
    WAIT_FOR_DEVICE_SIGINT_TIMEOUT_SECONDS = 1
    ADB_ABORT_EXIT_CODE = 134
    DEVICE_LIB_DIR = "/system/lib64"
    DEVICE_BIN_DIR = "/system/bin"

    def __init__(self, grpc_port: str, grpc_root_server_port: str, signal_port: str, cmd: List[str], label: str,
                 type_identifier: str, name: str, serial_number: str, verbose_mode: bool):
@@ -490,12 +492,51 @@ class GdAndroidDevice(GdDeviceBase):
        logging.info("Port forwarding done on device %s %s" % (self.label, self.serial_number))

        # Push test binaries
        self.push_or_die(os.path.join(get_gd_root(), "target", "bluetooth_stack_with_facade"), "system/bin")
        self.push_or_die(os.path.join(get_gd_root(), "target", "libbluetooth_gd.so"), "system/lib64")
        self.push_or_die(os.path.join(get_gd_root(), "target", "libgrpc++_unsecure.so"), "system/lib64")
        self.push_or_die(os.path.join(get_gd_root(), "target", "libgrpc++.so"), "system/lib64")
        self.push_or_die(os.path.join(get_gd_root(), "target", "libgrpc_wrap.so"), "system/lib64")
        self.push_or_die(os.path.join(get_gd_root(), "target", "libstatslog_bt.so"), "system/lib64")
        local_dir = os.path.join(get_gd_root(), "target")

        def generate_dir_pair(local_dir, device_dir, filename):
            return os.path.join(local_dir, filename), os.path.join(device_dir, filename)

        # Do not override exist libraries shared by other binaries on the Android device to avoid corrupting the Android device
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_BIN_DIR, "bluetooth_stack_with_facade"))
        self.push_or_die(
            *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.0.so"),
            overwrite_existing=False)
        self.push_or_die(
            *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.1.so"),
            overwrite_existing=False)
        self.push_or_die(
            *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libandroid_runtime_lazy.so"), overwrite_existing=False)
        self.push_or_die(
            *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbacktrace.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbase.so"), overwrite_existing=False)
        self.push_or_die(
            *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbinder_ndk.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbinder.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libc++.so"), overwrite_existing=False)
        # libclang_rt.asan-aarch64-android.so is only needed for ASAN build and is automatically included on device
        #self.push_or_die(
        #    *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libclang_rt.asan-aarch64-android.so"),
        #    overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libcrypto.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libcutils.so"), overwrite_existing=False)
        self.push_or_die(
            *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc_wrap.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++_unsecure.so"))
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++.so"))
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libhidlbase.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "liblog.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "liblzma.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libprotobuf-cpp-full.so"))
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libssl.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++.so"))
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libstatslog_bt.so"))
        self.push_or_die(
            *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libunwindstack.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libutils.so"), overwrite_existing=False)
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++.so"))
        self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libz.so"), overwrite_existing=False)

        logging.info("Binaries pushed to device %s %s" % (self.label, self.serial_number))

        try:
@@ -674,7 +715,7 @@ class GdAndroidDevice(GdDeviceBase):
            (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):
    def push_or_die(self, src_file_path, dst_file_path, push_timeout=300, overwrite_existing=True):
        """Pushes a file to the Android device

        Args:
@@ -682,6 +723,9 @@ class GdAndroidDevice(GdDeviceBase):
            dst_file_path: The destination of the file.
            push_timeout: How long to wait for the push to finish in seconds
        """
        if not overwrite_existing and self.adb.path_exists(dst_file_path):
            logging.info("Skip pushing {} to {} as it already exists on device".format(src_file_path, dst_file_path))
            return
        out = self.adb.push([src_file_path, dst_file_path], timeout=push_timeout).decode(UTF_8).rstrip()
        if 'error' in out:
            asserts.fail('Unable to push file %s to %s due to %s' % (src_file_path, dst_file_path, out))