Coverage for hdl_registers/generator/test/test_register_code_generation.py: 100%

60 statements  

« prev     ^ index     » next       coverage.py v7.6.8, created at 2024-12-01 20:50 +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# -------------------------------------------------------------------------------------------------- 

9 

10""" 

11Some happy path tests to show that all register code generation can run without error. 

12""" 

13 

14# Third party libraries 

15import pytest 

16import tsfpga 

17from tsfpga.examples.example_env import get_default_registers 

18 

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 

40 

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] 

54 

55 

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() 

60 

61 VhdlRecordPackageGenerator(register_list, tmp_path).create() 

62 assert (tmp_path / f"{register_list.name}_register_record_pkg.vhd").exists() 

63 

64 VhdlSimulationReadWritePackageGenerator(register_list, tmp_path).create() 

65 assert (tmp_path / f"{register_list.name}_register_read_write_pkg.vhd").exists() 

66 

67 VhdlSimulationWaitUntilPackageGenerator(register_list, tmp_path).create() 

68 assert (tmp_path / f"{register_list.name}_register_wait_until_pkg.vhd").exists() 

69 

70 VhdlAxiLiteWrapperGenerator(register_list, tmp_path).create() 

71 assert (tmp_path / f"{register_list.name}_reg_file.vhd").exists() 

72 

73 

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() 

78 

79 CHeaderGenerator(register_list, tmp_path, file_name="apa.h").create() 

80 assert (tmp_path / "apa.h").exists() 

81 

82 

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() 

87 

88 CppHeaderGenerator(register_list, tmp_path).create() 

89 assert (tmp_path / f"{register_list.name}.h").exists() 

90 

91 CppImplementationGenerator(register_list, tmp_path).create() 

92 assert (tmp_path / f"{register_list.name}.cpp").exists() 

93 

94 

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() 

99 

100 HtmlConstantTableGenerator(register_list, tmp_path).create() 

101 assert (tmp_path / f"{register_list.name}_constant_table.html").exists() 

102 

103 HtmlPageGenerator(register_list, tmp_path).create() 

104 assert (tmp_path / f"{register_list.name}_regs.html").exists() 

105 

106 

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() 

111 

112 PythonAccessorGenerator(register_list, tmp_path).create() 

113 assert (tmp_path / f"{register_list.name}_accessor.py").exists()