mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-08 05:43:53 +00:00
feat(tlc): formalise random generation of TEs
To facillitate our testing, add some fixtures to make it easier to generate transfer entry data. Change-Id: Ieb76e54e69f410f4f7e1b55fc2cff282e592d1a4 Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
This commit is contained in:
parent
ae952c1e51
commit
157c619786
2 changed files with 30 additions and 6 deletions
|
@ -9,6 +9,8 @@
|
|||
|
||||
""" Common configurations and fixtures for test environment."""
|
||||
|
||||
from random import randint
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
from click.testing import CliRunner
|
||||
|
@ -16,6 +18,10 @@ from click.testing import CliRunner
|
|||
from tlc.cli import cli
|
||||
|
||||
|
||||
def generate_random_bytes(n):
|
||||
return bytes([randint(0, 255) for _ in range(n)])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tmptlstr(tmpdir):
|
||||
return tmpdir.join("tl.bin").strpath
|
||||
|
@ -70,3 +76,20 @@ def tlcrunner(tmptlstr):
|
|||
@pytest.fixture
|
||||
def tlc_entries(tmpfdt):
|
||||
return [(0, "/dev/null"), (1, tmpfdt.strpath), (0x102, tmpfdt.strpath)]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def random_entry():
|
||||
def _random_entry(max_size):
|
||||
return randint(0, 0xFFFFFF), generate_random_bytes(randint(0, max_size))
|
||||
|
||||
return _random_entry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def random_entries(random_entry):
|
||||
def _random_entries(n=5, max_size=0x100):
|
||||
for _ in range(n):
|
||||
yield random_entry(max_size)
|
||||
|
||||
return _random_entries
|
||||
|
|
|
@ -125,12 +125,13 @@ def test_single_te_transfer_list(tag_id, data, tmpdir):
|
|||
assert f.read(te.data_size) == te.data
|
||||
|
||||
|
||||
def test_multiple_te_transfer_list(tmpdir):
|
||||
def test_write_multiple_tes_to_file(tmpdir, random_entries):
|
||||
"""Check that we can create a TL with multiple TE's."""
|
||||
test_file = tmpdir.join("test_tl_blob.bin")
|
||||
tl = TransferList(0x1000)
|
||||
tl = TransferList(0x4000)
|
||||
_test_entries = random_entries()
|
||||
|
||||
for tag_id, data in test_entries:
|
||||
for tag_id, data in _test_entries:
|
||||
tl.add_transfer_entry(tag_id, data)
|
||||
|
||||
tl.write_to_file(test_file)
|
||||
|
@ -138,9 +139,9 @@ def test_multiple_te_transfer_list(tmpdir):
|
|||
with open(test_file, "rb") as f:
|
||||
assert f.read(tl.hdr_size) == tl.header_to_bytes()
|
||||
# Ensure that TE's have the correct alignment
|
||||
for tag_id, data in test_entries:
|
||||
f.seek(int(math.ceil(f.tell() / 2**tl.alignment) * 2**tl.alignment))
|
||||
print(f.tell())
|
||||
for tag_id, data in _test_entries:
|
||||
f.seek(int(math.ceil(f.tell() / 8) * 8))
|
||||
|
||||
assert int.from_bytes(f.read(3), "little") == tag_id
|
||||
assert int.from_bytes(f.read(1), "little") == TransferEntry.hdr_size
|
||||
# Make sure the data in the TE matches the data in the original case
|
||||
|
|
Loading…
Add table
Reference in a new issue