示例#1
0
def test_firmware_validation() -> None:
    downloader = FirmwareDownloader()
    installer = FirmwareInstaller()

    # Pixhawk1 and Pixhawk4 APJ firmwares should always work
    temporary_file = downloader.download(Vehicle.Sub, Platform.Pixhawk1)
    installer.validate_firmware(temporary_file, Platform.Pixhawk1)

    temporary_file = downloader.download(Vehicle.Sub, Platform.Pixhawk4)
    installer.validate_firmware(temporary_file, Platform.Pixhawk4)

    # New SITL firmwares should always work
    temporary_file = downloader.download(Vehicle.Sub,
                                         Platform.SITL,
                                         version="DEV")
    installer.validate_firmware(temporary_file, Platform.SITL)

    # Raise when validating Navigator firmwares (as test platform is x86)
    temporary_file = downloader.download(Vehicle.Sub, Platform.Navigator)
    with pytest.raises(InvalidFirmwareFile):
        installer.validate_firmware(temporary_file, Platform.Navigator)

    # Install SITL firmware
    temporary_file = downloader.download(Vehicle.Sub,
                                         Platform.SITL,
                                         version="DEV")
    board = FlightController(name="SITL",
                             manufacturer="ArduPilot Team",
                             platform=Platform.SITL)
    installer.install_firmware(temporary_file, board,
                               pathlib.Path(f"{temporary_file}_dest"))
def test_firmware_validation() -> None:
    downloader = FirmwareDownloader()
    installer = FirmwareInstaller()

    # Pixhawk1 APJ firmwares should always work
    temporary_file = downloader.download(Vehicle.Sub, Platform.Pixhawk1)
    installer.validate_firmware(temporary_file, Platform.Pixhawk1)

    # New SITL firmwares should always work
    temporary_file = downloader.download(Vehicle.Sub,
                                         Platform.SITL,
                                         version="DEV")
    installer.validate_firmware(temporary_file, Platform.SITL)

    # Raise when validating for Undefined platform
    with pytest.raises(UndefinedPlatform):
        installer.validate_firmware(pathlib.Path(""), Platform.Undefined)

    # Raise when validating Navigator firmwares (as test platform is x86)
    temporary_file = downloader.download(Vehicle.Sub, Platform.NavigatorR5)
    with pytest.raises(InvalidFirmwareFile):
        installer.validate_firmware(temporary_file, Platform.NavigatorR5)

    # Install SITL firmware
    temporary_file = downloader.download(Vehicle.Sub,
                                         Platform.SITL,
                                         version="DEV")
    installer.install_firmware(temporary_file, Platform.SITL,
                               pathlib.Path(f"{temporary_file}_dest"))
def test_firmware_download() -> None:
    firmware_download = FirmwareDownloader()
    assert firmware_download.download_manifest(
    ), "Failed to download/validate manifest file."

    versions = firmware_download._find_version_item(
        vehicletype="Sub",
        format="apj",
        mav_firmware_version_type="STABLE-4.0.1",
        platform=Platform.Pixhawk1)
    assert len(versions) == 1, "Failed to find a single firmware."

    versions = firmware_download._find_version_item(
        vehicletype="Sub",
        mav_firmware_version_type="STABLE-4.0.1",
        platform=Platform.Pixhawk1)
    assert len(versions) == 3, "Failed to find multiple versions."

    available_versions = firmware_download.get_available_versions(
        Vehicle.Sub, Platform.Pixhawk1)
    assert len(available_versions) == len(
        set(available_versions)), "Available versions are not unique."

    test_available_versions = [
        "STABLE-4.0.1", "STABLE-4.0.0", "OFFICIAL", "DEV", "BETA"
    ]
    assert len(set(available_versions)) >= len(
        set(test_available_versions
            )), "Available versions are missing know versions."

    assert firmware_download.download(
        Vehicle.Sub, Platform.Pixhawk1,
        "STABLE-4.0.1"), "Failed to download a valid firmware file."

    assert firmware_download.download(
        Vehicle.Sub,
        Platform.Pixhawk1), "Failed to download latest valid firmware file."

    assert firmware_download.download(
        Vehicle.Sub,
        Platform.Pixhawk4), "Failed to download latest valid firmware file."

    assert firmware_download.download(
        Vehicle.Sub, Platform.SITL), "Failed to download SITL."

    # It'll fail if running in an arch different of ARM
    if "x86" in os.uname().machine:
        assert firmware_download.download(
            Vehicle.Sub,
            Platform.Navigator), "Failed to download navigator binary."
    else:
        with pytest.raises(Exception):
            firmware_download.download(Vehicle.Sub, Platform.Navigator)