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

49 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-09-29 22:03 +0000

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the hdl_registers project, a HDL register generator fast enough to be run 

5# in real time. 

6# https://hdl-registers.com 

7# https://gitlab.com/tsfpga/hdl_registers 

8# -------------------------------------------------------------------------------------------------- 

9 

10""" 

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

12""" 

13 

14import pytest 

15 

16import tsfpga 

17from tsfpga.examples.example_env import get_default_registers 

18from tsfpga.system_utils import read_file 

19 

20from hdl_registers import HDL_REGISTERS_DOC, HDL_REGISTERS_TEST 

21from hdl_registers.parser import from_toml 

22 

23 

24# Test with all the example TOML files that we have available 

25REGISTER_LISTS = [ 

26 from_toml( 

27 module_name="ddr_buffer", 

28 toml_file=tsfpga.TSFPGA_EXAMPLE_MODULES / "ddr_buffer" / "regs_ddr_buffer.toml", 

29 default_registers=get_default_registers(), 

30 ), 

31 from_toml(module_name="test", toml_file=HDL_REGISTERS_TEST / "regs_test.toml"), 

32 from_toml( 

33 module_name="example", 

34 toml_file=HDL_REGISTERS_DOC / "sphinx" / "files" / "regs_example.toml", 

35 ), 

36] 

37 

38 

39@pytest.mark.parametrize("register_list", REGISTER_LISTS) 

40def test_can_generate_vhdl_package_without_error(tmp_path, register_list): 

41 register_list.create_vhdl_package(tmp_path) 

42 

43 assert (tmp_path / f"{register_list.name}_regs_pkg.vhd").exists() 

44 

45 

46@pytest.mark.parametrize("register_list", REGISTER_LISTS) 

47def test_can_generate_c_header_without_error(tmp_path, register_list): 

48 register_list.create_c_header(tmp_path) 

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

50 

51 register_list.create_c_header(tmp_path, file_name="apa.h") 

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

53 

54 

55@pytest.mark.parametrize("register_list", REGISTER_LISTS) 

56def test_can_generate_cpp_without_error(tmp_path, register_list): 

57 register_list.create_cpp_interface(tmp_path) 

58 register_list.create_cpp_header(tmp_path) 

59 register_list.create_cpp_implementation(tmp_path) 

60 

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

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

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

64 

65 

66@pytest.mark.parametrize("register_list", REGISTER_LISTS) 

67def test_can_generate_html_without_error(tmp_path, register_list): 

68 register_list.create_html_constant_table(tmp_path) 

69 register_list.create_html_register_table(tmp_path) 

70 register_list.create_html_page(tmp_path) 

71 

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

73 assert (tmp_path / f"{register_list.name}_register_table.html").exists() 

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

75 assert (tmp_path / "regs_style.css").exists() 

76 

77 

78@pytest.mark.parametrize("register_list", REGISTER_LISTS) 

79def test_can_generate_python_class_file_without_error(tmp_path, register_list): 

80 register_list.create_python_class(tmp_path) 

81 

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

83 

84 

85@pytest.mark.parametrize("register_list", REGISTER_LISTS) 

86def test_copy_source_definition(tmp_path, register_list): 

87 register_list.copy_source_definition(tmp_path) 

88 

89 assert read_file(tmp_path / f"regs_{register_list.name}.toml") == read_file( 

90 register_list.source_definition_file 

91 ) 

92 

93 

94def test_copy_source_definition_with_no_file_defined(tmp_path): 

95 register_list = REGISTER_LISTS[0] 

96 register_list.source_definition_file = None 

97 

98 output_path = tmp_path / "toml" 

99 register_list.copy_source_definition(output_path) 

100 

101 assert not output_path.exists()