def testVerifyOverlay(self):
     """Verifies application of DT overlays."""
     overlay_idx_string = self.adb.shell(
         "cat /proc/cmdline | "
         "grep -o \"androidboot.dtbo_idx=[^ ]*\" |"
         "cut -d \"=\" -f 2")
     asserts.assertNotEqual(
         len(overlay_idx_string), 0,
         "Kernel command line missing androidboot.dtbo_idx")
     overlay_idx_list = overlay_idx_string.split(",")
     overlay_arg = []
     for idx in overlay_idx_list:
         overlay_file = "dumped_dtbo." + idx.rstrip()
         overlay_path = os.path.join(self.temp_dir, overlay_file)
         self.adb.push(overlay_path, self.device_path)
         overlay_arg.append(overlay_file)
     final_dt_path = path_utils.JoinTargetPath(self.device_path, "final_dt")
     self.shell.Execute("cp %s %s" % (FDT_PATH, final_dt_path))
     verification_test_path = path_utils.JoinTargetPath(
         self.device_path, "ufdt_verify_overlay")
     chmod_cmd = "chmod 755 %s" % verification_test_path
     results = self.shell.Execute(chmod_cmd)
     asserts.assertEqual(results[const.EXIT_CODE][0], 0, "Unable to chmod")
     cd_cmd = "cd %s" % (self.device_path)
     verify_cmd = "./ufdt_verify_overlay final_dt %s" % (
         " ".join(overlay_arg))
     cmd = str("%s && %s" % (cd_cmd, verify_cmd))
     logging.info(cmd)
     results = self.shell.Execute(cmd)
     asserts.assertEqual(results[const.EXIT_CODE][0], 0,
                         "Incorrect Overlay Application")
    def extractValue(self, propValue):
        """Extracts value depending on data type of the property"""
        if propValue == None:
            return None

        # Extract data type
        dataType = propValue['prop'] & self.vtypes.VehiclePropertyType.MASK
        val = propValue['value']
        if self.vtypes.VehiclePropertyType.STRING == dataType:
            asserts.assertNotEqual(None, val['stringValue'])
            return val['stringValue']
        elif self.vtypes.VehiclePropertyType.INT32 == dataType or \
                self.vtypes.VehiclePropertyType.BOOLEAN == dataType:
            asserts.assertEqual(1, len(val["int32Values"]))
            return val["int32Values"][0]
        elif self.vtypes.VehiclePropertyType.INT64 == dataType:
            asserts.assertEqual(1, len(val["int64Values"]))
            return val["int64Values"][0]
        elif self.vtypes.VehiclePropertyType.FLOAT == dataType:
            asserts.assertEqual(1, len(val["floatValues"]))
            return val["floatValues"][0]
        elif self.vtypes.VehiclePropertyType.INT32_VEC == dataType:
            asserts.assertLess(0, len(val["int32Values"]))
            return val["int32Values"]
        elif self.vtypes.VehiclePropertyType.FLOAT_VEC == dataType:
            asserts.assertLess(0, len(val["floatValues"]))
            return val["floatValues"]
        elif self.vtypes.VehiclePropertyType.BYTES == dataType:
            asserts.assertLess(0, len(val["bytes"]))
            return val["bytes"]
        else:
            return val
    def CheckImageHeader(self, boot_image, is_recovery=False):
        """Verifies the boot image header version, header size and recovery dtbo size.

        Args:
            boot_image: Path to the boot image.
            is_recovery: Indicates that the image is recovery if true.
        """
        try:
            with open(boot_image, "rb") as image_file:
                image_file.read(8)  # read boot magic
                host_image_header_version = unpack("10I",
                                                   image_file.read(10 * 4))[8]
                asserts.assertEqual(
                    host_image_header_version, 1,
                    "Device does not have boot image of version 1")
                image_file.seek(BOOT_HEADER_DTBO_SIZE_OFFSET)
                recovery_dtbo_size = unpack("I", image_file.read(4))[0]
                image_file.read(8)  # ignore recovery dtbo load address
                if is_recovery:
                    asserts.assertNotEqual(
                        recovery_dtbo_size, 0,
                        "recovery partition for non-A/B devices must contain the recovery DTBO"
                    )
                boot_header_size = unpack("I", image_file.read(4))[0]
                expected_header_size = image_file.tell()
                asserts.assertEqual(
                    boot_header_size, expected_header_size,
                    "Test failure due to boot header size mismatch. Expected %s Actual %s"
                    % (expected_header_size, boot_header_size))
        except IOError as e:
            logging.exception(e)
            asserts.fail("Unable to open boot image file")
 def testVehicleStaticProps(self):
     """Verifies that static properties are configured correctly"""
     staticProperties = set([
         self.vtypes.VehicleProperty.INFO_VIN,
         self.vtypes.VehicleProperty.INFO_MAKE,
         self.vtypes.VehicleProperty.INFO_MODEL,
         self.vtypes.VehicleProperty.INFO_MODEL_YEAR,
         self.vtypes.VehicleProperty.INFO_FUEL_CAPACITY,
         self.vtypes.VehicleProperty.INFO_FUEL_TYPE,
         self.vtypes.VehicleProperty.INFO_EV_BATTERY_CAPACITY,
         self.vtypes.VehicleProperty.INFO_EV_CONNECTOR_TYPE,
         self.vtypes.VehicleProperty.HVAC_FAN_DIRECTION_AVAILABLE,
         self.vtypes.VehicleProperty.AP_POWER_BOOTUP_REASON,
     ])
     for c in self.configList:
         prop = c['prop']
         msg = "Prop 0x%x" % prop
         if (c["prop"] in staticProperties):
             asserts.assertEqual(
                 self.vtypes.VehiclePropertyChangeMode.STATIC,
                 c["changeMode"], msg)
             asserts.assertEqual(self.vtypes.VehiclePropertyAccess.READ,
                                 c["access"], msg)
             propValue = self.readVhalProperty(prop)
             asserts.assertEqual(prop, propValue["prop"])
             self.setVhalProperty(
                 prop,
                 propValue["value"],
                 expectedStatus=self.vtypes.StatusCode.ACCESS_DENIED)
         else:  # Non-static property
             asserts.assertNotEqual(
                 self.vtypes.VehiclePropertyChangeMode.STATIC,
                 c["changeMode"], msg)
    def testSerialNotEqual(self):
        '''Checks serial number from two device not being equal.'''
        command = 'getprop | grep ro.serial'

        res1 = self.shell1.Execute(command)
        res2 = self.shell2.Execute(command)

        asserts.assertFalse(
            any(res1[const.EXIT_CODE]),
            'command for device 1 failed: %s' % res1)  # checks the exit code
        asserts.assertFalse(
            any(res2[const.EXIT_CODE]),
            'command for device 2 failed: %s' % res2)  # checks the exit code

        def getSerial(output):
            '''Get serial from getprop query'''
            return output.strip().split(' ')[-1][1:-1]

        serial1 = getSerial(res1[const.STDOUT][0])
        serial2 = getSerial(res2[const.STDOUT][0])

        logging.info('Serial number of device 1: %s', serial1)
        logging.info('Serial number of device 2: %s', serial2)

        asserts.assertNotEqual(
            serial1, serial2,
            'serials from two devices should not be the same')
 def getValueIfPropSupported(self, propertyId):
     """Returns tuple of boolean (indicating value supported or not) and the value itself"""
     if (propertyId in self.propToConfig):
         propValue = self.readVhalProperty(propertyId)
         asserts.assertNotEqual(None, propValue,
                                "expected value, prop: 0x%x" % propertyId)
         asserts.assertEqual(propertyId, propValue['prop'])
         return True, self.extractValue(propValue)
     else:
         return False, None
 def __call__(self):
     """Reads the specified property and validates the result."""
     propValue = self.testobject.readVhalProperty(self.propertyId)
     asserts.assertNotEqual(
         propValue,
         None,
         msg="reading %s should not return None" % self.name)
     logging.info("%s = %s", self.name, propValue)
     self.onReadSuccess(propValue)
     logging.info("%s pass" % self.name)
        def validateGet(self, status, value):
            """Validate the result of IVehicle.get.

            Args:
                status: the StatusCode returned from Vehicle HAL.
                value: the VehiclePropValue returned from Vehicle HAL.

            Returns: a VehiclePropValue instance, or None on failure."""
            asserts.assertEqual(self.test.vtypes.StatusCode.OK, status)
            asserts.assertNotEqual(value, None)
            asserts.assertEqual(self.propertyId, value['prop'])
            return value
    def testOpenCloseINETSocketStream(self):
        """Tests open and close socket operations for INET communication.

        Uses IP addresses and a streaming socket.
        """
        result = self.dut.lib.libc.socket(self.dut.lib.libc.PF_INET,
                                          self.dut.lib.libc.SOCK_STREAM, 0)
        asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1,
                               "libc.socket: could not create socket.")

        result = self.dut.lib.libc.close(
            result.return_type.scalar_value.int32_t)
        asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1,
                               "libc.close: unable to close socket.")
    def testOpenCloseLocalSocketSequential(self):
        """Tests open and close socket operations for local communication.

        Uses local addresses and a sequential socket.
        """
        result = self.dut.lib.libc.socket(self.dut.lib.libc.PF_UNIX,
                                          self.dut.lib.libc.SOCK_SEQPACKET, 0)
        asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1,
                               "libc.socket: could not create socket.")

        result = self.dut.lib.libc.close(
            result.return_type.scalar_value.int32_t)
        asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1,
                               "libc.close: unable to close socket.")
Пример #11
0
    def CheckImageHeader(self, boot_image, is_recovery=False):
        """Verifies the boot image format.

        Args:
            boot_image: Path to the boot image.
            is_recovery: Indicates that the image is recovery if true.
        """
        try:
            with open(boot_image, "rb") as image_file:
                image_file.read(8)  # read boot magic
                (kernel_size, _, ramdisk_size, _, _, _, _, page_size,
                 host_image_header_version) = unpack("9I",
                                                     image_file.read(9 * 4))

                asserts.assertNotEqual(
                    kernel_size, 0,
                    "boot.img/recovery.img must contain kernel")

                if self.launch_api_level > api.PLATFORM_API_LEVEL_P:
                    asserts.assertTrue(
                        host_image_header_version >= 2,
                        "Device must atleast have a boot image of version 2")

                    asserts.assertNotEqual(ramdisk_size, 0,
                                           "boot.img must contain ramdisk")

                    # ramdisk comes after the header and kernel pages
                    num_kernel_pages = self.get_number_of_pages(
                        kernel_size, page_size)
                    ramdisk_offset = page_size * (1 + num_kernel_pages)
                    image_file.seek(ramdisk_offset)
                    ramdisk_buf = image_file.read(ramdisk_size)
                    self.checkValidRamdisk(ramdisk_buf)
                else:
                    asserts.assertTrue(
                        host_image_header_version >= 1,
                        "Device must atleast have a boot image of version 1")
                image_file.seek(BOOT_HEADER_DTBO_SIZE_OFFSET)
                recovery_dtbo_size = unpack("I", image_file.read(4))[0]
                image_file.read(8)  # ignore recovery dtbo load address
                if is_recovery:
                    asserts.assertNotEqual(
                        recovery_dtbo_size, 0,
                        "recovery partition for non-A/B devices must contain the recovery DTBO"
                    )
                boot_header_size = unpack("I", image_file.read(4))[0]
                if host_image_header_version > 1:
                    dtb_size = unpack("I", image_file.read(4))[0]
                    asserts.assertNotEqual(
                        dtb_size, 0, "Boot/recovery image must contain DTB")
                    image_file.read(8)  # ignore DTB physical load address
                expected_header_size = image_file.tell()
                asserts.assertEqual(
                    boot_header_size, expected_header_size,
                    "Test failure due to boot header size mismatch. Expected %s Actual %s"
                    % (expected_header_size, boot_header_size))
        except IOError as e:
            logging.exception(e)
            asserts.fail("Unable to open boot image file")
Пример #12
0
    def testHidlHandleArgument(self):
        """Test calling APIs in dumpstate HAL server.

        Host side specifies a handle object in resource_manager, ans pass
        it to dumpstate HAL server to write debug message into it.
        Host side then reads part of the debug message.
        """
        # Prepare a VariableSpecificationMessage to specify the handle object
        # that will be passed into the HAL service.
        var_msg = CompSpecMsg.VariableSpecificationMessage()
        var_msg.type = CompSpecMsg.TYPE_HANDLE
        var_msg.handle_value.handle_id = self._writer.handleId

        self._dumpstate.dumpstateBoard(var_msg)
        # Read 1000 bytes to retrieve part of debug message.
        debug_msg = self._reader.readFile(1000)
        logging.info("Below are part of result from dumpstate: ")
        logging.info(debug_msg)
        asserts.assertNotEqual(debug_msg, "")
Пример #13
0
    def setUp(self):
        """Initialize a writer and a reader for each test case.

        We open the file with w+ in every test case, which will create the file
        if it doesn't exist, or truncate the file if it exists, because some
        test case won't fully read the content of the file, causing dependency
        between test cases.
        """
        self._writer = self.dut.resource.InitHidlHandleForSingleFile(
            self.TEST_FILE_PATH,
            "w+",
            client=self.dut.hal.GetTcpClient("dumpstate"))
        self._reader = self.dut.resource.InitHidlHandleForSingleFile(
            self.TEST_FILE_PATH,
            "r",
            client=self.dut.hal.GetTcpClient("dumpstate"))
        asserts.assertTrue(self._writer is not None,
                           "Writer should be initialized successfully.")
        asserts.assertTrue(self._reader is not None,
                           "Reader should be initialized successfully.")
        asserts.assertNotEqual(self._writer.handleId, -1)
        asserts.assertNotEqual(self._reader.handleId, -1)
Пример #14
0
    def setUp(self):
        # Initialize a FMQ on the target-side driver.
        self._sync_client = self.dut.resource.InitFmq(
            data_type="uint16_t",
            sync=True,
            queue_size=self.MAX_NUM_MSG,
            blocking=True,
            client=self.dut.hal.GetTcpClient("tests_msgq"))
        asserts.assertNotEqual(self._sync_client.queueId, -1)

        # Prepare a VariableSpecificationMessage to specify the FMQ that will be
        # passed into the HAL service.
        var_msg = CompSpecMsg.VariableSpecificationMessage()
        var_msg.type = CompSpecMsg.TYPE_FMQ_SYNC
        fmq_val = var_msg.fmq_value.add()
        fmq_val.fmq_id = self._sync_client.queueId
        fmq_val.scalar_type = "uint16_t"
        fmq_val.type = CompSpecMsg.TYPE_SCALAR

        # Call API in the HAL server.
        sync_init_result = self._tests_msgq.configureFmqSyncReadWrite(var_msg)
        asserts.assertTrue(
            sync_init_result,
            "Hal should configure a synchronized queue without error.")

        # Initialize an unsynchronized queue on the server.
        [success,
         self._unsync_client1] = self._tests_msgq.getFmqUnsyncWrite(True)
        asserts.assertTrue(
            success,
            "Hal should configure an unsynchronized queue without error.")
        # An unsynchronized queue is registered successfully on the target driver.
        asserts.assertNotEqual(self._unsync_client1, None)
        asserts.assertNotEqual(self._unsync_client1.queueId, -1)
        # Register another reader.
        self._unsync_client2 = self.dut.resource.InitFmq(
            existing_queue=self._unsync_client1,
            client=self.dut.hal.GetTcpClient("tests_msgq"))
        asserts.assertNotEqual(self._unsync_client2.queueId, -1)
 def testDebugDump(self):
     """Verifies that call to IVehicle#debugDump is not failing"""
     dumpStr = self.vehicle.debugDump()
     asserts.assertNotEqual(None, dumpStr)
Пример #16
0
    def setUpClass(self):
        """This class loads audio HAL in our target-side driver.

        It also initializes four queues for testing:
        Queue 1: synchronized queue (without blocking) between
                 one writer and one reader, sending uint16_t type in the queue.
        Queue 2: synchronized queue (with blocking feature) between
                 one writer and one reader, sending uint32_t type in
                 the queue.
        Queue 3: unsynchronized queue (without blocking) between
                 one writer and two readers, sending double_t type in
                 the queue.
        Queue 4: synchronized queue (without blocking) between
                 one writer and one reader, sending predefined
                 ReadParameters type in IStreamIn.hal interface.
        """
        self.dut = self.android_devices[0]
        # Initialize an audio hal driver to start all managers
        # on the target side.
        # We use it to check sending FMQ with primitive types and
        # other predefined types (e.g. ReadParameters) in audio HAL.
        self.dut.hal.InitHidlHal(
            target_type="audio",
            target_basepaths=self.dut.libPaths,
            target_version_major=4,
            target_version_minor=0,
            target_package="android.hardware.audio",
            target_component_name="IDevicesFactory",
            bits=int(self.abi_bitness))
        # Create a shortcut for audio HAL server.
        self._audio = self.dut.hal.audio

        # Initialize a non-blocking, synchronized writer.
        self._queue1_writer = self.dut.resource.InitFmq(
            data_type="uint16_t",
            sync=True,
            queue_size=2048,
            blocking=False,
            client=self.dut.hal.GetTcpClient("audio"))
        queue1_writer_id = self._queue1_writer.queueId
        asserts.assertNotEqual(queue1_writer_id, -1)

        # Initialize a non-blocking, synchronized reader.
        # This reader shares the same queue as self._queue1_writer.
        self._queue1_reader = self.dut.resource.InitFmq(
            existing_queue=self._queue1_writer,
            client=self.dut.hal.GetTcpClient("audio"))
        queue1_reader_id = self._queue1_reader.queueId
        asserts.assertNotEqual(queue1_reader_id, -1)

        # Initialize a blocking, synchronized writer.
        self._queue2_writer = self.dut.resource.InitFmq(
            data_type="uint32_t",
            sync=True,
            queue_size=2048,
            blocking=True,
            client=self.dut.hal.GetTcpClient("audio"))
        queue2_writer_id = self._queue2_writer.queueId
        asserts.assertNotEqual(queue2_writer_id, -1)

        # Initialize a blocking, synchronized reader.
        # This reader shares the same queue as self._queue2_writer.
        self._queue2_reader = self.dut.resource.InitFmq(
            existing_queue=self._queue2_writer,
            client=self.dut.hal.GetTcpClient("audio"))
        queue2_reader_id = self._queue2_reader.queueId
        asserts.assertNotEqual(queue2_reader_id, -1)

        # Initialize a non-blocking, unsynchronized writer.
        self._queue3_writer = self.dut.resource.InitFmq(
            data_type="double_t",
            sync=False,
            queue_size=2048,
            blocking=False,
            client=self.dut.hal.GetTcpClient("audio"))
        queue3_writer_id = self._queue3_writer.queueId
        asserts.assertNotEqual(queue3_writer_id, -1)

        # Initialize a non-blocking, unsynchronized reader 1.
        # This reader shares the same queue as self._queue3_writer.
        self._queue3_reader1 = self.dut.resource.InitFmq(
            existing_queue=self._queue3_writer,
            client=self.dut.hal.GetTcpClient("audio"))
        queue3_reader1_id = self._queue3_reader1.queueId
        asserts.assertNotEqual(queue3_reader1_id, -1)

        # Initialize a non-blocking, unsynchronized reader 2.
        # This reader shares the same queue as self._queue3_writer and self._queue3_reader1.
        self._queue3_reader2 = self.dut.resource.InitFmq(
            existing_queue=self._queue3_writer,
            client=self.dut.hal.GetTcpClient("audio"))
        queue3_reader2_id = self._queue3_reader2.queueId
        asserts.assertNotEqual(queue3_reader2_id, -1)

        # Find the user-defined type in IStreamIn.hal service.
        self._stream_in_types = self._audio.GetHidlTypeInterface("IStreamIn")
        read_param_type = self._stream_in_types.GetAttribute("ReadParameters")
        # Initialize a non-blocking, synchronized writer.
        self._queue4_writer = self.dut.resource.InitFmq(
            # ::android::hardware::audio::V4_0::IStreamIn::ReadParameters
            data_type=read_param_type.name,
            sync=True,
            queue_size=2048,
            blocking=False,
            client=self.dut.hal.GetTcpClient("audio"))
        queue4_writer_id = self._queue4_writer.queueId
        asserts.assertNotEqual(queue4_writer_id, -1)

        # Initialize a non-blocking, synchronized reader.
        # This reader shares the same queue as self._queue4_writer.
        self._queue4_reader = self.dut.resource.InitFmq(
            existing_queue=self._queue4_writer,
            client=self.dut.hal.GetTcpClient("audio"))
        queue4_reader_id = self._queue4_reader.queueId
        asserts.assertNotEqual(queue4_reader_id, -1)