Example #1
0
def test_remove_with_opts(mock_subprocess):
    img_spec = fiptool.ImageSpec({"soc-fw-cert": {"path": "fw_cert.pem"}})
    output = fiptool.remove(
        img_spec,
        "fip.bin",
        align=1,
        blob_uuid="2222",
        force=True,
        out=pathlib.Path("output", "path"),
    )

    assert isinstance(output, subprocess.CompletedProcess)
    mock_subprocess.run.assert_called_once_with(
        [
            fiptool.ToolPaths.FIPTOOL_BIN,
            "remove",
            *str(img_spec).split(" "),
            "--align=1",
            "--blob-uuid=2222",
            "--force",
            "--out=output/path",
            "fip.bin",
        ],
        check=True,
        stdout=mock_subprocess.PIPE,
        stderr=mock_subprocess.PIPE,
        universal_newlines=True,
    )
Example #2
0
def test_unpack(mock_subprocess):
    mock_ret = namedtuple("CompletedProcess", "stdout, stderr, returncode")
    mock_ret.stdout = (
        "Trusted Boot Firmware BL2: offset=0xB0, size=0x145E0, "
        'cmdline="--tb-fw"\n'
        "Trusted Boot Firmware BL2 certificate: offset=0x14C9E, size=0x46F,"
        ' cmdline="--tb-fw-cert"\n')
    mock_subprocess.run.return_value = mock_ret

    img_spec = fiptool.ImageSpec({"nt-fw": True, "trusted-key-cert": True})
    fiptool.unpack(pathlib.Path("fip.bin"), img_spec=img_spec)

    mock_subprocess.run.assert_any_call(
        [
            fiptool.ToolPaths.FIPTOOL_BIN,
            "unpack",
            "--nt-fw",
            "--trusted-key-cert",
            "fip.bin",
        ],
        check=True,
        stdout=mock_subprocess.PIPE,
        stderr=mock_subprocess.PIPE,
        universal_newlines=True,
    )
Example #3
0
def test_update(mock_subprocess):
    img_spec = fiptool.ImageSpec({"soc-fw-cert": dict()})
    output = fiptool.update(img_spec, pathlib.Path("fip.bin"))

    assert isinstance(output, subprocess.CompletedProcess)
    mock_subprocess.run.assert_called_once_with(
        [fiptool.ToolPaths.FIPTOOL_BIN, "update",
         str(img_spec), "fip.bin"],
        check=True,
        capture_output=True,
        text=True,
    )
Example #4
0
def test_update(mock_subprocess):
    img_spec = fiptool.ImageSpec({"soc-fw-cert": dict()})
    output = fiptool.update(img_spec, pathlib.Path("fip.bin"))

    assert isinstance(output, subprocess.CompletedProcess)
    mock_subprocess.run.assert_called_once_with(
        [
            fiptool.ToolPaths.FIPTOOL_BIN,
            "update",
            *str(img_spec).split(" "),
            "fip.bin",
        ],
        check=True,
        stdout=mock_subprocess.PIPE,
        stderr=mock_subprocess.PIPE,
        universal_newlines=True,
    )
Example #5
0
def test_create(mock_subprocess):
    img_spec = fiptool.ImageSpec({
        "tb-fw": {
            "path": "bl1.bin"
        },
        "trusted-key-cert": {
            "path": "rotkey.pem"
        },
    })
    output = fiptool.create(img_spec, pathlib.Path("fip.bin"))

    assert isinstance(output, subprocess.CompletedProcess)
    mock_subprocess.run.assert_called_once_with(
        [fiptool.ToolPaths.FIPTOOL_BIN, "create",
         str(img_spec), "fip.bin"],
        check=True,
        capture_output=True,
        text=True,
    )
Example #6
0
def test_create(mock_subprocess):
    img_spec = fiptool.ImageSpec({
        "tb-fw": {
            "path": "bl1.bin"
        },
        "trusted-key-cert": {
            "path": "rotkey.pem"
        },
    })
    output = fiptool.create(img_spec, pathlib.Path("fip.bin"))

    assert isinstance(output, subprocess.CompletedProcess)
    mock_subprocess.run.assert_called_once_with(
        [
            fiptool.ToolPaths.FIPTOOL_BIN,
            "create",
            *str(img_spec).split(" "),
            "fip.bin",
        ],
        check=True,
        stdout=mock_subprocess.PIPE,
        stderr=mock_subprocess.PIPE,
        universal_newlines=True,
    )
Example #7
0
def test_remove_with_opts(mock_subprocess):
    img_spec = fiptool.ImageSpec({"soc-fw-cert": {"path": "fw_cert.pem"}})
    output = fiptool.remove(
        img_spec,
        "fip.bin",
        align=1,
        blob_uuid="2222",
        force=True,
        out=pathlib.Path("output", "path"),
    )

    assert isinstance(output, subprocess.CompletedProcess)
    mock_subprocess.run.assert_called_once_with(
        [
            fiptool.ToolPaths.FIPTOOL_BIN,
            "remove",
            str(img_spec),
            "--align=1 --blob-uuid=2222 --force --out=output/path",
            "fip.bin",
        ],
        check=True,
        capture_output=True,
        text=True,
    )
Example #8
0
def test_raises_correct_exception_on_invalid_command(tmp_path):
    with pytest.raises(fiputils.FiptoolCommandError) as err:
        fiptool.create(fiptool.ImageSpec(), tmp_path)
        assert err.return_code is not 0
        assert err.stderr is not None
        assert str(err) != ""
Example #9
0
def test_image_spec_invalid_options():
    with pytest.raises(fiptool.UnknownOptionError):
        fiptool.ImageSpec({"invalid": "aaaaa"})