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 

9from pathlib import Path 

10from unittest.mock import patch 

11 

12import pytest 

13 

14from tsfpga.formal_project import FormalConfig, FormalProject, FormalTestCase 

15 

16 

17def test_generics_dict_should_be_copied(): 

18 """ 

19 It should be possible to update the original dict object without affecting the already-created 

20 formal test case 

21 """ 

22 formal_project = FormalProject(project_path=Path(), modules=[]) 

23 

24 generics = dict(a=1) 

25 formal_project.add_config(top="apa", generics=generics) 

26 

27 generics.update(a=2) 

28 formal_project.add_config(top="hest", generics=generics) 

29 

30 formal_project.add_config(top="zebra") 

31 

32 # pylint: disable=protected-access 

33 assert formal_project._formal_config_list[0].top == "apa" 

34 assert formal_project._formal_config_list[0].generics == dict(a=1) 

35 assert formal_project._formal_config_list[1].top == "hest" 

36 assert formal_project._formal_config_list[1].generics == dict(a=2) 

37 assert formal_project._formal_config_list[2].top == "zebra" 

38 assert formal_project._formal_config_list[2].generics is None 

39 

40 

41def test_formal_project_run(tmp_path): 

42 project_path = tmp_path / "projects" 

43 formal_project = FormalProject(modules=[], project_path=project_path) 

44 formal_project.add_config(top="top", engine_command="engine") 

45 

46 src_files = ["src_file1", "src_file2"] 

47 compiled_libraries = ["compiled_library1", "compiled_library2"] 

48 with patch( 

49 "tsfpga.formal_project.FormalProject._compile_source_code", autospec=True 

50 ) as mocked_compile_source_code, patch( 

51 "tsfpga.formal_project.FormalTestCase", autospec=True 

52 ) as mocked_formal_test_case, patch( 

53 "tsfpga.formal_project.TestList.keep_matches", autospec=True 

54 ): 

55 mocked_compile_source_code.return_value = (src_files, compiled_libraries) 

56 mocked_formal_test_case.return_value.name = "apa" 

57 

58 formal_project.run() 

59 

60 mocked_formal_test_case.return_value.set_src_files.assert_called_once_with(src_files=src_files) 

61 mocked_formal_test_case.return_value.run.assert_called_once() 

62 

63 

64def test_formal_test_case_fails_when_missing_settings(tmp_path): 

65 formal_config = FormalConfig(top="top") 

66 formal_test_case = FormalTestCase(formal_config) 

67 formal_test_case.set_compiled_libraries([]) 

68 

69 with pytest.raises(ValueError) as exception_info: 

70 formal_test_case.run(output_path=tmp_path, read_output=None) 

71 assert ( 

72 exception_info.value is not None 

73 ), "Run should fail with ValueError when not ok src_files is missing" 

74 

75 formal_test_case = FormalTestCase(formal_config) 

76 formal_test_case.set_src_files([]) 

77 

78 with pytest.raises(ValueError) as exception_info: 

79 formal_test_case.run(output_path=tmp_path, read_output=None) 

80 assert ( 

81 exception_info.value is not None 

82 ), "Run should fail with ValueError when not ok compiled_libraries is missing" 

83 

84 

85def test_formal_test_case_run(tmp_path): 

86 formal_config = FormalConfig(top="top") 

87 formal_test_case = FormalTestCase(formal_config) 

88 

89 formal_test_case.set_src_files([]) 

90 formal_test_case.set_compiled_libraries([]) 

91 

92 with patch("tsfpga.yosys_project.Process", autospec=True): 

93 formal_test_case.run(output_path=tmp_path, read_output=None) 

94 

95 

96def test_create_formal_config_with_default_arguments(): 

97 formal_config = FormalConfig(top="top") 

98 assert formal_config.test_name == "top"