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 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 size 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 ( 

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

37 ) 

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 size 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 size check failed for maximum logic level. Got 11, expected < 7.\n" 

70 )