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

36 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-29 20:01 +0000

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

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

3# 

4# This file is part of the tsfpga project, a project platform for modern FPGA development. 

5# https://tsfpga.com 

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

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

8 

9# Standard libraries 

10import io 

11from unittest.mock import MagicMock, patch 

12 

13# First party libraries 

14from tsfpga.vivado.build_result import BuildResult as build_result_spec 

15from tsfpga.vivado.build_result_checker import ( 

16 DspBlocks, 

17 EqualTo, 

18 LessThan, 

19 MaximumLogicLevel, 

20 TotalLuts, 

21) 

22 

23 

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

25def test_size_checker_less_than_pass(mock_stdout): 

26 build_result = MagicMock(spec=build_result_spec) 

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

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

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

30 

31 

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

33def test_size_checker_equal_to_fail(mock_stdout): 

34 build_result = MagicMock(spec=build_result_spec) 

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

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

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

38 

39 

40def test_size_checker_dsp_blocks_has_two_names(): 

41 build_result = MagicMock(spec=build_result_spec) 

42 

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

44 

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

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

47 

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

49 

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

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

52 

53 

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

55def test_logic_level_checker_equal_to_pass(mock_stdout): 

56 build_result = MagicMock(spec=build_result_spec) 

57 build_result.maximum_logic_level = 5 

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

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

60 

61 

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

63def test_logic_level_checker_less_than_fail(mock_stdout): 

64 build_result = MagicMock(spec=build_result_spec) 

65 build_result.maximum_logic_level = 11 

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

67 assert ( 

68 mock_stdout.getvalue() 

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

70 )