Coverage for hdl_registers/generator/test/test_register_code_generation.py: 100%
60 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-07 20:51 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-07 20:51 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the hdl-registers project, an HDL register generator fast enough to run
5# in real time.
6# https://hdl-registers.com
7# https://github.com/hdl-registers/hdl-registers
8# --------------------------------------------------------------------------------------------------
10"""
11Some happy path tests to show that all register code generation can run without error.
12"""
14# Third party libraries
15import pytest
16import tsfpga
17from tsfpga.examples.example_env import get_default_registers
19# First party libraries
20from hdl_registers import HDL_REGISTERS_DOC, HDL_REGISTERS_TESTS
21from hdl_registers.generator.c.header import CHeaderGenerator
22from hdl_registers.generator.cpp.header import CppHeaderGenerator
23from hdl_registers.generator.cpp.implementation import CppImplementationGenerator
24from hdl_registers.generator.cpp.interface import CppInterfaceGenerator
25from hdl_registers.generator.html.constant_table import HtmlConstantTableGenerator
26from hdl_registers.generator.html.page import HtmlPageGenerator
27from hdl_registers.generator.html.register_table import HtmlRegisterTableGenerator
28from hdl_registers.generator.python.accessor import PythonAccessorGenerator
29from hdl_registers.generator.python.pickle import PythonPickleGenerator
30from hdl_registers.generator.vhdl.axi_lite.wrapper import VhdlAxiLiteWrapperGenerator
31from hdl_registers.generator.vhdl.record_package import VhdlRecordPackageGenerator
32from hdl_registers.generator.vhdl.register_package import VhdlRegisterPackageGenerator
33from hdl_registers.generator.vhdl.simulation.read_write_package import (
34 VhdlSimulationReadWritePackageGenerator,
35)
36from hdl_registers.generator.vhdl.simulation.wait_until_package import (
37 VhdlSimulationWaitUntilPackageGenerator,
38)
39from hdl_registers.parser.toml import from_toml
41# Test with all the example TOML files that we have available
42REGISTER_LISTS = [
43 from_toml(
44 name="ddr_buffer",
45 toml_file=tsfpga.TSFPGA_EXAMPLE_MODULES / "ddr_buffer" / "regs_ddr_buffer.toml",
46 default_registers=get_default_registers(),
47 ),
48 from_toml(name="caesar", toml_file=HDL_REGISTERS_TESTS / "regs_test.toml"),
49 from_toml(
50 name="example",
51 toml_file=HDL_REGISTERS_DOC / "sphinx" / "rst" / "user_guide" / "toml" / "toml_format.toml",
52 ),
53]
56@pytest.mark.parametrize("register_list", REGISTER_LISTS)
57def test_can_generate_vhdl_without_error(tmp_path, register_list):
58 VhdlRegisterPackageGenerator(register_list, tmp_path).create()
59 assert (tmp_path / f"{register_list.name}_regs_pkg.vhd").exists()
61 VhdlRecordPackageGenerator(register_list, tmp_path).create()
62 assert (tmp_path / f"{register_list.name}_register_record_pkg.vhd").exists()
64 VhdlSimulationReadWritePackageGenerator(register_list, tmp_path).create()
65 assert (tmp_path / f"{register_list.name}_register_read_write_pkg.vhd").exists()
67 VhdlSimulationWaitUntilPackageGenerator(register_list, tmp_path).create()
68 assert (tmp_path / f"{register_list.name}_register_wait_until_pkg.vhd").exists()
70 VhdlAxiLiteWrapperGenerator(register_list, tmp_path).create()
71 assert (tmp_path / f"{register_list.name}_reg_file.vhd").exists()
74@pytest.mark.parametrize("register_list", REGISTER_LISTS)
75def test_can_generate_c_without_error(tmp_path, register_list):
76 CHeaderGenerator(register_list, tmp_path).create()
77 assert (tmp_path / f"{register_list.name}_regs.h").exists()
79 CHeaderGenerator(register_list, tmp_path, file_name="apa.h").create()
80 assert (tmp_path / "apa.h").exists()
83@pytest.mark.parametrize("register_list", REGISTER_LISTS)
84def test_can_generate_cpp_without_error(tmp_path, register_list):
85 CppInterfaceGenerator(register_list, tmp_path).create()
86 assert (tmp_path / f"i_{register_list.name}.h").exists()
88 CppHeaderGenerator(register_list, tmp_path).create()
89 assert (tmp_path / f"{register_list.name}.h").exists()
91 CppImplementationGenerator(register_list, tmp_path).create()
92 assert (tmp_path / f"{register_list.name}.cpp").exists()
95@pytest.mark.parametrize("register_list", REGISTER_LISTS)
96def test_can_generate_html_without_error(tmp_path, register_list):
97 HtmlRegisterTableGenerator(register_list, tmp_path).create()
98 assert (tmp_path / f"{register_list.name}_register_table.html").exists()
100 HtmlConstantTableGenerator(register_list, tmp_path).create()
101 assert (tmp_path / f"{register_list.name}_constant_table.html").exists()
103 HtmlPageGenerator(register_list, tmp_path).create()
104 assert (tmp_path / f"{register_list.name}_regs.html").exists()
107@pytest.mark.parametrize("register_list", REGISTER_LISTS)
108def test_can_generate_python_without_error(tmp_path, register_list):
109 PythonPickleGenerator(register_list, tmp_path).create()
110 assert (tmp_path / f"{register_list.name}.py").exists()
112 PythonAccessorGenerator(register_list, tmp_path).create()
113 assert (tmp_path / f"{register_list.name}_accessor.py").exists()