Coverage for tests/unit_tests/scons/test_plugin_xilinx.py: 100%
41 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 05:08 +0000
« 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
9"""
10Tests of the scons plugin_xilinx.py place and route builder.
11"""
13from pathlib import Path
14from google.protobuf import text_format
15from tests.unit_tests.scons.testing import make_test_apio_env
16from tests.conftest import ApioRunner
17from apio.scons.plugin_xilinx import PluginXilinx
18from apio.common.proto.stubs.apio_definitions_pb2 import FpgaDefinition
20# -- An xc7a35t (Artix-7, Arty A7-35T) FPGA info.
21XILINX_FPGA_DEFINITION = """
22arch: xilinx
23vendor_part: "XC7A35T-1CSG324C"
24size: "35k"
25xilinx_params {
26 yosys_arch: "xc7"
27 yosys_family: "artix7"
28 nextpnr_device: "xc7a35tcsg324-1"
29}
30"""
33def _pnr_action(
34 apio_runner: ApioRunner,
35 *,
36 pnr_verbose: bool = False,
37 extra_options: list[str] | None = None,
38) -> str:
39 """Returns the pnr command of a xilinx env."""
40 with apio_runner.in_sandbox() as sb:
41 sb.write_file("arty.xdc", "")
42 apio_env = make_test_apio_env()
43 # apio_env.params.arch = ApioArch.xilinx
44 apio_env.params.fpga_definition.CopyFrom(
45 text_format.Parse(XILINX_FPGA_DEFINITION, FpgaDefinition())
46 )
47 apio_env.params.verbosity.pnr = pnr_verbose
48 if extra_options:
49 apio_env.params.apio_env_params.nextpnr_extra_options.extend(
50 extra_options
51 )
52 builder = PluginXilinx(apio_env).make_pnr_builder()
53 return str(builder.action)
56def test_pnr_builder(apio_runner: ApioRunner):
57 """nextpnr-xilinx takes the full part as --device, and the xilinx
58 outputs as uarch options."""
59 action = _pnr_action(apio_runner)
60 assert action.startswith("nextpnr-xilinx --device xc7a35tcsg324-1 ")
61 assert "-o xdc=arty.xdc" in action
62 assert "-o fasm=$TARGET" in action
63 assert "--json $SOURCE" in action
64 assert f"--report {Path('_build', 'default', 'hardware.pnr')}" in action
65 assert action.split()[-1] == "-q"
66 assert "--xdc" not in action
67 assert "--fasm" not in action
70def test_pnr_builder_verbose(apio_runner: ApioRunner):
71 """With pnr verbosity the command line has no -q."""
72 action = _pnr_action(apio_runner, pnr_verbose=True)
73 assert "-q" not in action.split()
76def test_pnr_builder_extra_options(apio_runner: ApioRunner):
77 """nextpnr-extra-options from apio.ini go at the end of the command."""
78 action = _pnr_action(
79 apio_runner, extra_options=["--seed", "7", "--router", "router2"]
80 )
81 assert action.endswith("-q --seed 7 --router router2")
84def test_synth_builder(apio_runner: ApioRunner):
85 """The synth command writes the JSON after synth_xilinx."""
86 with apio_runner.in_sandbox():
87 apio_env = make_test_apio_env()
88 apio_env.params.fpga_definition.CopyFrom(
89 text_format.Parse(XILINX_FPGA_DEFINITION, FpgaDefinition())
90 )
91 action = str(PluginXilinx(apio_env).make_synth_builder().action)
92 assert "synth_xilinx -arch xc7 -top main ; " in action
93 assert "write_json $TARGET" in action
94 assert "simplemap" not in action