blob: b8f88b50cd5f66dca1d982e6f03cac770d390b21 [file] [log] [blame]
Harrison Mutai19dc4f92024-05-10 16:54:29 +00001#!/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
12import pytest
Charlie Barehamd7a9efc2024-06-17 11:58:03 +010013import yaml
Harrison Mutai19dc4f92024-05-10 16:54:29 +000014from click.testing import CliRunner
15
16from tlc.cli import cli
17
18
19@pytest.fixture
20def tmptlstr(tmpdir):
21 return tmpdir.join("tl.bin").strpath
22
23
24@pytest.fixture
Charlie Barehamd7a9efc2024-06-17 11:58:03 +010025def tmpyamlconfig(tmpdir):
26 return tmpdir.join("config.yaml").strpath
27
28
29@pytest.fixture
Harrison Mutai19dc4f92024-05-10 16:54:29 +000030def tmpfdt(tmpdir):
31 fdt = tmpdir.join("fdt.dtb")
32 fdt.write_binary(b"\x00" * 100)
33 return fdt
34
35
Charlie Barehamd7a9efc2024-06-17 11:58:03 +010036@pytest.fixture(params=[1, 2, 3, 4, 5, 0x100, 0x101, 0x102, 0x104])
37def non_empty_tag_id(request):
38 return request.param
39
40
41@pytest.fixture
42def 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 Mutai19dc4f92024-05-10 16:54:29 +000062@pytest.fixture
63def tlcrunner(tmptlstr):
64 runner = CliRunner()
65 with runner.isolated_filesystem():
66 runner.invoke(cli, ["create", tmptlstr])
67 return runner
68
69
70@pytest.fixture
71def tlc_entries(tmpfdt):
72 return [(0, "/dev/null"), (1, tmpfdt.strpath), (0x102, tmpfdt.strpath)]