Coverage for tests/unit_tests/test_definitions.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-07 05:08 +0000

1# This file is part of the Apio project 

2# (C) 2016-present FPGAwars 

3# Project authors: 

4# * Jesús Arroyo (Jesus89) (2016-2019) 

5# * Juan Gonzalez (obijuan) (2019-2024) 

6# * The Apio Team (2024-present) 

7# License: GPLv2 

8 

9""" 

10Tests board/fpga/programmer definitions. 

11""" 

12 

13from tests.conftest import ApioRunner 

14from apio.apio_context import ( 

15 ApioContext, 

16 PackagesPolicy, 

17 ProjectPolicy, 

18 RemoteConfigPolicy, 

19) 

20 

21 

22def test_definitions_references(apio_runner: ApioRunner): 

23 """Tests the consistency of the board references to fpgas and 

24 programmers.""" 

25 

26 with apio_runner.in_sandbox(): 

27 

28 # -- Create an apio context so we can access the resources. 

29 apio_ctx = ApioContext( 

30 project_policy=ProjectPolicy.NO_PROJECT, 

31 remote_config_policy=RemoteConfigPolicy.CACHED_OK, 

32 packages_policy=PackagesPolicy.ENSURE_PACKAGES, 

33 ) 

34 assert apio_ctx.definitions is not None 

35 

36 unused_programmers = set(apio_ctx.definitions.programmers.keys()) 

37 

38 for board_id, board_definition in apio_ctx.definitions.boards.items(): 

39 # -- Prepare a context message for failing assertions. 

40 board_msg = f"While testing board {board_id}" 

41 

42 # -- Check that the fpga exists. 

43 board_fpga_id = board_definition.fpga_id 

44 assert apio_ctx.definitions.fpgas[board_fpga_id], board_msg 

45 

46 # -- Check that the programmer exists. 

47 board_programmer_id = board_definition.programmer.id 

48 assert apio_ctx.definitions.programmers[ 

49 board_programmer_id 

50 ], board_msg 

51 

52 # -- Track unused programmers. Since a programmer may be used 

53 # -- by more than one board, it may already be removed. 

54 if board_programmer_id in unused_programmers: 

55 unused_programmers.remove(board_programmer_id) 

56 

57 # -- We should end up with an empty set of unused programmers. 

58 assert not unused_programmers, unused_programmers 

59 

60 

61# def test_fpgas_yosys_part_num(apio_runner: ApioRunner): 

62# """Tests that all xilinx fpgas has a valid yosys-part value, that is, 

63# it's listed on XILINX-PARTS-INDEX.json as a generated part.""" 

64 

65# with apio_runner.in_sandbox(): 

66 

67# # -- Create an ApioContext with access to Apio packages. 

68# apio_ctx = ApioContext( 

69# project_policy=ProjectPolicy.NO_PROJECT, 

70# remote_config_policy=RemoteConfigPolicy.CACHED_OK, 

71# packages_policy=PackagesPolicy.ENSURE_PACKAGES, 

72# ) 

73 

74# # -- Read the parts index of the Apio's openxc7 package 

75# index_path = ( 

76# apio_ctx.get_package_dir("openxc7") / "XILINX-PARTS-INDEX.json" 

77# ) 

78# index_data = json.loads(index_path.read_text(encoding="utf-8")) 

79# # assert index_data["schema"] == 8, index_data["schema"] 

80# parts = index_data["parts"] 

81 

82# # -- Iterate FPGA definitions and verify 

83# verified = 0 

84# assert apio_ctx.definitions is not None 

85# for fpga_id, fpga_definition in apio_ctx.definitions.fpgas.items(): 

86# # -- Skip if not a xilinx fpga 

87# arch = fpga_definition.arch 

88# if arch != ApioArch.xilinx: 

89# continue 

90 

91# # -- FPGA is a xilinx FPGA. Make sure it's listed in the parts 

92# # -- index. 

93# assert fpga_id in parts, fpga_id 

94# part_info = parts[fpga_id] 

95 

96# # -- Check that the fpga is generated. 

97# assert part_info["generated"], (fpga_id, part_info) 

98# verified += 1 

99 

100# # -- Sanity check for the number of xilinx fpgas we verified. 

101# assert verified > 10, verified