Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

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

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9""" 

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

11""" 

12 

13import pytest 

14 

15import tsfpga 

16from tsfpga.system_utils import read_file 

17from tsfpga.registers.parser import from_toml 

18 

19from examples.tsfpga_example_env import get_default_registers 

20 

21 

22# Test with the two example TOML files that we have available 

23REGISTER_LISTS = [ 

24 from_toml( 

25 module_name="ddr_buffer", 

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

27 default_registers=get_default_registers(), 

28 ), 

29 from_toml( 

30 module_name="artyz7", 

31 toml_file=tsfpga.TSFPGA_EXAMPLE_MODULES / "artyz7" / "regs_artyz7.toml", 

32 default_registers=get_default_registers(), 

33 ), 

34] 

35 

36 

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

38def test_can_generate_vhdl_package_without_error(tmp_path, register_list): 

39 register_list.create_vhdl_package(tmp_path) 

40 

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

42 

43 

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

45def test_can_generate_c_header_without_error(tmp_path, register_list): 

46 register_list.create_c_header(tmp_path) 

47 

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

49 

50 

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

52def test_can_generate_cpp_without_error(tmp_path, register_list): 

53 register_list.create_cpp_interface(tmp_path) 

54 register_list.create_cpp_header(tmp_path) 

55 register_list.create_cpp_implementation(tmp_path) 

56 

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

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

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

60 

61 

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

63def test_can_generate_html_without_error(tmp_path, register_list): 

64 register_list.create_html_constant_table(tmp_path) 

65 register_list.create_html_register_table(tmp_path) 

66 register_list.create_html_page(tmp_path) 

67 

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

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

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

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

72 

73 

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

75def test_can_generate_python_class_file_without_error(tmp_path, register_list): 

76 register_list.create_python_class(tmp_path) 

77 

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

79 

80 

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

82def test_copy_source_definition(tmp_path, register_list): 

83 register_list.copy_source_definition(tmp_path) 

84 

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

86 register_list.source_definition_file 

87 ) 

88 

89 

90def test_copy_source_definition_with_no_file_defined(tmp_path): 

91 register_list = REGISTER_LISTS[0] 

92 register_list.source_definition_file = None 

93 

94 output_path = tmp_path / "toml" 

95 register_list.copy_source_definition(output_path) 

96 

97 assert not output_path.exists()