|
| 1 | +""" |
| 2 | +Tests related to the openxc7 package's PARTS-INDEX.json file. |
| 3 | +""" |
| 4 | + |
| 5 | +import json |
| 6 | +from tests.conftest import ApioRunner |
| 7 | +from apio.apio_context import ( |
| 8 | + ApioContext, |
| 9 | + ProjectPolicy, |
| 10 | + RemoteConfigPolicy, |
| 11 | + PackagesPolicy, |
| 12 | +) |
| 13 | +from apio.common.proto.apio_common_pb2 import ApioArch |
| 14 | + |
| 15 | + |
| 16 | +def 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 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 = apio_ctx.get_package_dir("openxc7") / "PARTS-INDEX.json" |
| 31 | + index_data = json.loads(index_path.read_text(encoding="utf-8")) |
| 32 | + assert index_data["schema"] == 5, index_data["schema"] |
| 33 | + parts = index_data["parts"] |
| 34 | + |
| 35 | + # -- Iterate FPGA definitions and verify |
| 36 | + verified = 0 |
| 37 | + for fpga_id, fpga_definition in apio_ctx.definitions.fpgas.items(): |
| 38 | + # -- Skip if not a xilinx fpga |
| 39 | + arch = fpga_definition.arch |
| 40 | + if arch != ApioArch.xilinx: |
| 41 | + continue |
| 42 | + |
| 43 | + # -- FPGA is a xilinx FPGA. Make sure it's listed in the parts |
| 44 | + # -- index. |
| 45 | + assert fpga_id in parts, fpga_id |
| 46 | + part_info = parts[fpga_id] |
| 47 | + |
| 48 | + # -- Check that the fpga is generated. |
| 49 | + assert part_info["generated"], (fpga_id, part_info) |
| 50 | + verified += 1 |
| 51 | + |
| 52 | + # -- Sanity check for the number of xilinx fpgas we verified. |
| 53 | + assert verified > 10, verified |
0 commit comments