Coverage for tsfpga/vivado/test/test_build_result_checker.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v6.4, created at 2022-05-28 04:01 +0000

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 unittest.mock import MagicMock, patch 

10import io 

11 

12from tsfpga.vivado.build_result_checker import ( 

13 DspBlocks, 

14 EqualTo, 

15 LessThan, 

16 MaximumLogicLevel, 

17 TotalLuts, 

18) 

19from tsfpga.vivado.build_result import BuildResult as build_result_spec 

20 

21 

22@patch("sys.stdout", new_callable=io.StringIO) 

23def test_size_checker_less_than_pass(mock_stdout): 

24 build_result = MagicMock(spec=build_result_spec) 

25 build_result.synthesis_size = {"Total LUTs": 5} 

26 assert TotalLuts(LessThan(10)).check(build_result) 

27 assert mock_stdout.getvalue() == "Result check passed for Total LUTs: 5 (< 10)\n" 

28 

29 

30@patch("sys.stdout", new_callable=io.StringIO) 

31def test_size_checker_equal_to_fail(mock_stdout): 

32 build_result = MagicMock(spec=build_result_spec) 

33 build_result.synthesis_size = {"Total LUTs": 5} 

34 assert not TotalLuts(EqualTo(50)).check(build_result) 

35 assert mock_stdout.getvalue() == "Result check failed for Total LUTs. Got 5, expected 50.\n" 

36 

37 

38def test_size_checker_dsp_blocks_has_two_names(): 

39 build_result = MagicMock(spec=build_result_spec) 

40 

41 build_result.synthesis_size = {"DSP Blocks": 5} 

42 

43 assert DspBlocks(EqualTo(5)).check(build_result) 

44 assert not DspBlocks(EqualTo(2)).check(build_result) 

45 

46 build_result.synthesis_size = {"DSP48 Blocks": 7} 

47 

48 assert DspBlocks(EqualTo(7)).check(build_result) 

49 assert not DspBlocks(EqualTo(2)).check(build_result) 

50 

51 

52@patch("sys.stdout", new_callable=io.StringIO) 

53def test_logic_level_checker_equal_to_pass(mock_stdout): 

54 build_result = MagicMock(spec=build_result_spec) 

55 build_result.maximum_logic_level = 5 

56 assert MaximumLogicLevel(EqualTo(5)).check(build_result) 

57 assert mock_stdout.getvalue() == "Result check passed for maximum logic level: 5 (5)\n" 

58 

59 

60@patch("sys.stdout", new_callable=io.StringIO) 

61def test_logic_level_checker_less_than_fail(mock_stdout): 

62 build_result = MagicMock(spec=build_result_spec) 

63 build_result.maximum_logic_level = 11 

64 assert not MaximumLogicLevel(LessThan(7)).check(build_result) 

65 assert ( 

66 mock_stdout.getvalue() 

67 == "Result check failed for maximum logic level. Got 11, expected < 7.\n" 

68 )