Harrison Mutai | 19dc4f9 | 2024-05-10 16:54:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # type: ignore[attr-defined] |
| 3 | |
| 4 | # |
| 5 | # Copyright (c) 2024, Arm Limited. All rights reserved. |
| 6 | # |
| 7 | # SPDX-License-Identifier: BSD-3-Clause |
| 8 | # |
| 9 | |
| 10 | """ Common configurations and fixtures for test environment.""" |
| 11 | |
| 12 | import pytest |
Charlie Bareham | d7a9efc | 2024-06-17 11:58:03 +0100 | [diff] [blame] | 13 | import yaml |
Harrison Mutai | 19dc4f9 | 2024-05-10 16:54:29 +0000 | [diff] [blame] | 14 | from click.testing import CliRunner |
| 15 | |
| 16 | from tlc.cli import cli |
| 17 | |
| 18 | |
| 19 | @pytest.fixture |
| 20 | def tmptlstr(tmpdir): |
| 21 | return tmpdir.join("tl.bin").strpath |
| 22 | |
| 23 | |
| 24 | @pytest.fixture |
Charlie Bareham | d7a9efc | 2024-06-17 11:58:03 +0100 | [diff] [blame] | 25 | def tmpyamlconfig(tmpdir): |
| 26 | return tmpdir.join("config.yaml").strpath |
| 27 | |
| 28 | |
| 29 | @pytest.fixture |
Harrison Mutai | 19dc4f9 | 2024-05-10 16:54:29 +0000 | [diff] [blame] | 30 | def tmpfdt(tmpdir): |
| 31 | fdt = tmpdir.join("fdt.dtb") |
| 32 | fdt.write_binary(b"\x00" * 100) |
| 33 | return fdt |
| 34 | |
| 35 | |
Charlie Bareham | d7a9efc | 2024-06-17 11:58:03 +0100 | [diff] [blame] | 36 | @pytest.fixture(params=[1, 2, 3, 4, 5, 0x100, 0x101, 0x102, 0x104]) |
| 37 | def non_empty_tag_id(request): |
| 38 | return request.param |
| 39 | |
| 40 | |
| 41 | @pytest.fixture |
| 42 | def tmpyamlconfig_blob_file(tmpdir, tmpfdt, non_empty_tag_id): |
| 43 | config_path = tmpdir.join("config.yaml") |
| 44 | |
| 45 | config = { |
| 46 | "has_checksum": True, |
| 47 | "max_size": 0x1000, |
| 48 | "entries": [ |
| 49 | { |
| 50 | "tag_id": non_empty_tag_id, |
| 51 | "blob_file_path": tmpfdt.strpath, |
| 52 | }, |
| 53 | ], |
| 54 | } |
| 55 | |
| 56 | with open(config_path, "w") as f: |
| 57 | yaml.safe_dump(config, f) |
| 58 | |
| 59 | return config_path |
| 60 | |
| 61 | |
Harrison Mutai | 19dc4f9 | 2024-05-10 16:54:29 +0000 | [diff] [blame] | 62 | @pytest.fixture |
| 63 | def tlcrunner(tmptlstr): |
| 64 | runner = CliRunner() |
| 65 | with runner.isolated_filesystem(): |
| 66 | runner.invoke(cli, ["create", tmptlstr]) |
| 67 | return runner |
| 68 | |
| 69 | |
| 70 | @pytest.fixture |
| 71 | def tlc_entries(tmpfdt): |
| 72 | return [(0, "/dev/null"), (1, tmpfdt.strpath), (0x102, tmpfdt.strpath)] |