feat(tlc): add --align argument
Extended the command line interface to receive an alignment
argument.
TLC tool will align the data of the TEs accordingly.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I281b0b4c1851d58377bf6b31fcee03ee2f53367b
diff --git a/tools/tlc/tests/test_cli.py b/tools/tlc/tests/test_cli.py
index a5ef30e..ebe1f6a 100644
--- a/tools/tlc/tests/test_cli.py
+++ b/tools/tlc/tests/test_cli.py
@@ -17,6 +17,7 @@
import pytest
import yaml
from click.testing import CliRunner
+from conftest import generate_random_bytes
from tlc.cli import cli
from tlc.te import TransferEntry
@@ -32,6 +33,22 @@
assert TransferList.fromfile(test_file) is not None
+@pytest.mark.parametrize("align", [4, 6, 12, 13])
+def test_create_with_align(align, tlcrunner, tmpdir):
+ tl_file = tmpdir.join("tl.bin").strpath
+ tlcrunner.invoke(cli, ["create", "-s", "10000", "-a", align, tl_file])
+
+ blob = tmpdir.join("blob.bin")
+
+ blob.write_binary(generate_random_bytes(0x200))
+ tlcrunner.invoke(cli, ["add", "--entry", 1, blob.strpath, tl_file])
+
+ tl = TransferList.fromfile(tl_file)
+ te = tl.entries[-1]
+ assert tl.alignment == align
+ assert (te.offset + te.hdr_size) % (1 << align) == 0
+
+
def test_create_with_fdt(tmpdir):
runner = CliRunner()
fdt = tmpdir.join("fdt.dtb")
@@ -69,6 +86,20 @@
assert len(tl.entries) == len(tlc_entries)
+@pytest.mark.parametrize("align", [4, 6, 12, 13])
+def test_cli_add_entry_with_align(align, tlcrunner, tmpdir, tmptlstr):
+ blob = tmpdir.join("blob.bin")
+ blob.write_binary(bytes(0x100))
+
+ tlcrunner.invoke(cli, ["add", "--align", align, "--entry", 1, blob, tmptlstr])
+ tl = TransferList.fromfile(tmptlstr)
+ te = tl.entries[-1]
+
+ print(tl, *(te for te in tl.entries), sep="\n---------------\n")
+ assert (te.offset + te.hdr_size) % (1 << align) == 0
+ assert tl.alignment == align
+
+
def test_info(tlcrunner, tmptlstr, tmpfdt):
tlcrunner.invoke(cli, ["add", "--entry", "0", "/dev/null", tmptlstr])
tlcrunner.invoke(cli, ["add", "--fdt", tmpfdt.strpath, tmptlstr])