def test_ota_image_header(): hdr = firmware.OTAImageHeader() assert hdr.security_credential_version_present is None assert hdr.device_specific_file is None assert hdr.hardware_versions_present is None extra = b"abcdefghklmnpqr" hdr, rest = _test_ota_img_header(b"\x00\x00", extra=extra) assert rest == extra assert hdr.security_credential_version_present is False assert hdr.device_specific_file is False assert hdr.hardware_versions_present is False
def test_ota_img_should_upgrade(): manufacturer_id = 0x2345 image_type = 0x4567 version = 0xABBA hdr = firmware.OTAImageHeader() hdr.manufacturer_id = manufacturer_id hdr.image_type = image_type hdr.file_version = version img = CachedImage(firmware.OTAImage(hdr)) assert img.should_update(manufacturer_id, image_type, version) is False assert img.should_update(manufacturer_id, image_type, version - 1) is True assert img.should_update(manufacturer_id, image_type - 1, version - 1) is False assert img.should_update(manufacturer_id, image_type + 1, version - 1) is False assert img.should_update(manufacturer_id - 1, image_type, version - 1) is False assert img.should_update(manufacturer_id + 1, image_type, version - 1) is False
def image(): img = firmware.OTAImage() img.header = firmware.OTAImageHeader( upgrade_file_id=firmware.OTAImageHeader.MAGIC_VALUE, header_version=256, header_length=56, field_control=0, manufacturer_id=9876, image_type=123, file_version=12345, stack_version=2, header_string="This is a test header!", image_size=56 + 2 + 4 + 4, ) img.subelements = [firmware.SubElement(tag_id=0x0000, data=b"data")] return img
def test_ota_img_should_upgrade_hw_ver(): manufacturer_id = 0x2345 image_type = 0x4567 version = 0xABBA hdr = firmware.OTAImageHeader() hdr.field_control = 0x0004 hdr.manufacturer_id = manufacturer_id hdr.image_type = image_type hdr.file_version = version hdr.minimum_hardware_version = 2 hdr.maximum_hardware_version = 4 img = CachedImage(firmware.OTAImage(hdr)) assert img.should_update(manufacturer_id, image_type, version - 1) is True for hw_ver in range(2, 4): assert ( img.should_update(manufacturer_id, image_type, version - 1, hw_ver) is True ) assert img.should_update(manufacturer_id, image_type, version - 1, 1) is False assert img.should_update(manufacturer_id, image_type, version - 1, 5) is False