Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP3 IO constraints test #592

Merged
merged 3 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion quicklogic/common/cmake/quicklogic_toolchain_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

function(ADD_BINARY_TOOLCHAIN_TEST)

set(options)
set(options CHECK_CONSTRAINTS)
set(oneValueArgs TEST_NAME DIRECTIVE DEVICE PINMAP PCF SDC EXTRA_ARGS ASSERT_USAGE ASSERT_TIMING)
set(multiValueArgs SOURCES ASSERT_EXISTS)

Expand Down Expand Up @@ -57,8 +57,12 @@ function(ADD_BINARY_TOOLCHAIN_TEST)
-P ${PINMAP} "
)

set(REF_PCF "")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PCF}")
set(TOOLCHAIN_COMMAND "${TOOLCHAIN_COMMAND} -p \"${PCF}\"")
if(${ADD_BINARY_TOOLCHAIN_TEST_CHECK_CONSTRAINTS})
file(REAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${PCF}" REF_PCF)
endif()
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SDC}")
set(TOOLCHAIN_COMMAND "${TOOLCHAIN_COMMAND} -s \"${SDC}\"")
Expand Down Expand Up @@ -107,6 +111,7 @@ function(ADD_BINARY_TOOLCHAIN_TEST)
-DASSERT_USAGE=${ADD_BINARY_TOOLCHAIN_TEST_ASSERT_USAGE}
-DASSERT_TIMING=${ADD_BINARY_TOOLCHAIN_TEST_ASSERT_TIMING}
-DASSERT_EXISTS=${ASSERT_EXISTS}
-DREF_PCF=${REF_PCF}
-P ${symbiflow-arch-defs_SOURCE_DIR}/quicklogic/common/cmake/run_toolchain_test.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
Expand Down
10 changes: 10 additions & 0 deletions quicklogic/common/cmake/run_toolchain_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ if (NOT "${ASSERT_TIMING}" STREQUAL "")
run("PYTHONPATH=${PYTHONPATH} python3 ${TIMING_UTIL} ${ROUTE_LOG} --assert ${ASSERT_TIMING}")
endif ()

# Check if IO constraints has been correctly applied. This is done by verifying
# the original PCF file agains the one produced by fasm2bels. For this to work
# "post_verilog" dump option must be enabled for a test (i.e. provided within
# EXTRA_ARGS).
set(PCF_UTIL ${PYTHONPATH}/pcf_compare.py)
set(OUT_PCF ${BUILD_DIR}/top.bit.v.pcf)

if (NOT "${REF_PCF}" STREQUAL "")
run("PYTHONPATH=${PYTHONPATH} python3 ${PCF_UTIL} ${REF_PCF} ${OUT_PCF}")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_binary_toolchain_test(

ASSERT_USAGE PB-CLOCK=0,PB-GMUX=0,PB-BIDIR=5
ASSERT_TIMING fmax>=30.0
CHECK_CONSTRAINTS

ASSERT_EXISTS
"top_post_synthesis.v"
Expand All @@ -25,6 +26,7 @@ add_binary_toolchain_test(

ASSERT_USAGE PB-CLOCK=0,PB-GMUX=0,PB-BIDIR=5
ASSERT_TIMING fmax>=30.0
CHECK_CONSTRAINTS

ASSERT_EXISTS
"top_post_synthesis.v"
Expand All @@ -43,5 +45,11 @@ add_binary_toolchain_test(

ASSERT_USAGE PB-CLOCK=0,PB-GMUX=0,PB-BIDIR=5
ASSERT_TIMING fmax>=30.0
)
CHECK_CONSTRAINTS

ASSERT_EXISTS
"top_post_synthesis.v"
"top_post_synthesis.sdf"
"top.bit.v"
"top.bit.v.pcf"
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_binary_toolchain_test(
EXTRA_ARGS "-dump post_verilog"

ASSERT_USAGE PB-ASSP=1,PB-GMUX=1
CHECK_CONSTRAINTS

ASSERT_EXISTS
"top_post_synthesis.v"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set_io led[0] IO_21
set_io led[0] H7
set_io led[1] G7
set_io led[2] F6
set_io led[3] E8
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_binary_toolchain_test(
PCF chandalar.pcf
EXTRA_ARGS "-dump post_verilog"

CHECK_CONSTRAINTS
ASSERT_USAGE PB-CLOCK=1,PB-GMUX=1,PB-BIDIR=4
ASSERT_TIMING fmax>56.0

Expand All @@ -23,6 +24,7 @@ add_binary_toolchain_test(
PCF jimbob4.pcf
EXTRA_ARGS "-dump post_verilog"

CHECK_CONSTRAINTS
ASSERT_USAGE PB-CLOCK=1,PB-GMUX=1,PB-BIDIR=4
ASSERT_TIMING fmax>56.0

Expand All @@ -41,6 +43,7 @@ add_binary_toolchain_test(
PCF pd64.pcf
EXTRA_ARGS "-dump post_verilog"

CHECK_CONSTRAINTS
ASSERT_USAGE PB-CLOCK=1,PB-GMUX=1,PB-BIDIR=4
ASSERT_TIMING fmax>40.0

Expand Down
49 changes: 49 additions & 0 deletions utils/pcf_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
"""
This script parses and then compares contents of two PCF files. If the
constraints are identical exits with code 0. Otherwise prints parsed content
of both files and exits with -1
"""
import argparse

from lib.parse_pcf import parse_simple_pcf


def main():
parser = argparse.ArgumentParser(
description="Compares IO constraints across two PCF files"
)
parser.add_argument("pcf", nargs=2, type=str, help="PCF files")
args = parser.parse_args()

# Read constraints, convert them to tuples for easy comparison
pcf = []
for i in [0, 1]:
with open(args.pcf[i], "r") as fp:
constrs = set()
for constr in parse_simple_pcf(fp):
key = tuple(
[
type(constr).__name__, constr.net,
None if not hasattr(constr, "pad") else constr.pad
]
)
constrs.add(key)
pcf.append(constrs)

# We have a match
if pcf[0] == pcf[1]:
exit(0)

# Print difference
print("PCF constraints mismatch!")
for i in [0, 1]:
print("'{}'".format(args.pcf[i]))
for key in sorted(pcf[i]):
print("", key)

exit(-1)


if __name__ == "__main__":
main()