Coverage for tests/integration_tests/test_xilinx_parts.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-23 03:53 +0000

1""" 

2Tests related to the openxc7 package's XILINX-PARTS-INDEX.json file. 

3""" 

4 

5import json 

6from tests.conftest import ApioRunner 

7from apio.apio_context import ( 

8 ApioContext, 

9 ProjectPolicy, 

10 RemoteConfigPolicy, 

11 PackagesPolicy, 

12) 

13from apio.common.proto.apio_common_pb2 import ApioArch 

14 

15 

16def test_fpgas_yosys_part_num(apio_runner: ApioRunner): 

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

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

19 

20 with apio_runner.in_sandbox(): 

21 

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

23 apio_ctx = ApioContext( 

24 project_policy=ProjectPolicy.NO_PROJECT, 

25 remote_config_policy=RemoteConfigPolicy.CACHED_OK, 

26 packages_policy=PackagesPolicy.ENSURE_PACKAGES, 

27 ) 

28 

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

30 index_path = ( 

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

32 ) 

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

34 assert index_data["schema"] == 6, index_data["schema"] 

35 parts = index_data["parts"] 

36 

37 # -- Iterate FPGA definitions and verify 

38 verified = 0 

39 assert apio_ctx.definitions is not None 

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

41 # -- Skip if not a xilinx fpga 

42 arch = fpga_definition.arch 

43 if arch != ApioArch.xilinx: 

44 continue 

45 

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

47 # -- index. 

48 assert fpga_id in parts, fpga_id 

49 part_info = parts[fpga_id] 

50 

51 # -- Check that the fpga is generated. 

52 assert part_info["generated"], (fpga_id, part_info) 

53 verified += 1 

54 

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

56 assert verified > 10, verified