def test_read_device_id_returns_bytearray_with_raw_id(self): # Expected SIB+ID must match mega4809 atmega4809_sib = array('B', map(ord, "megaAVR P:0D:1-3M2 (01.59B20.0)")) id_expected = bytearray([0x1E, 0x96, 0x51]) id_expected.reverse() mock_tinyxavrtarget_instance = self._mock_tinyxavrtarget() # ID is BE24 from the target mock_tinyxavrtarget_instance.memory_read.return_value = bytearray( [id_expected[2], id_expected[1], id_expected[0]]) mock_tinyxavrtarget_instance.sib_read.return_value = atmega4809_sib dinfo = deviceinfo.getdeviceinfo('atmega4809') updi = NvmAccessProviderCmsisDapUpdi(None, dinfo) id_read = updi.read_device_id() # Check normal path self.assertEqual(id_expected, id_read) # Check that an exception is raised on unexpected ID mock_tinyxavrtarget_instance.memory_read.return_value = bytearray( [0, 0, 0]) with self.assertRaises(PymcuprogSessionError): id_read = updi.read_device_id()
def test_read_device_id_returns_bytearray_with_raw_id(self): atmega4809_sib = array('B', map(ord, "megaAVR P:0D:1-3M2 (01.59B20.0)")) id_expected = bytearray([0x01, 0x02, 0x03]) mock_tinyxavrtarget_instance = self._mock_tinyxavrtarget() mock_tinyxavrtarget_instance.memory_read.return_value = bytearray( [id_expected[2], id_expected[1], id_expected[0]]) mock_tinyxavrtarget_instance.sib_read.return_value = atmega4809_sib dinfo = deviceinfo.getdeviceinfo('atmega4809') updi = NvmAccessProviderCmsisDapUpdi(None, dinfo) id_read = updi.read_device_id() self.assertEqual(id_expected, id_read)