From 134bb59baa5844fad3bdb420ee84eb5474f89070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 18 Mar 2026 22:35:13 +0100 Subject: [PATCH 1/9] flow: move PYTHON_EXE definition before platform config.mk include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit config.mk files may use $(shell $(PYTHON_EXE) ...) to generate variables. PYTHON_EXE must be defined before the include directive at variables.mk:40, not after it at the former line 73. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- flow/scripts/variables.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flow/scripts/variables.mk b/flow/scripts/variables.mk index d6f0712079..0381710005 100644 --- a/flow/scripts/variables.mk +++ b/flow/scripts/variables.mk @@ -37,6 +37,10 @@ else $(error [ERROR][FLOW] Platform '$(PLATFORM)' not found.) endif +# PYTHON_EXE must be defined before including config.mk, as +# config.mk may use $(shell $(PYTHON_EXE) ...) to generate variables. +export PYTHON_EXE ?= $(shell command -v python3) + include $(PLATFORM_DIR)/config.mk # __SPACE__ is a workaround for whitespace hell in "foreach"; there @@ -70,7 +74,6 @@ export NUM_CORES #------------------------------------------------------------------------------- # setup all commands used within this flow -export PYTHON_EXE ?= $(shell command -v python3) export TIME_BIN ?= env time TIME_CMD = $(TIME_BIN) -f 'Elapsed time: %E[h:]min:sec. CPU time: user %U sys %S (%P). Peak memory: %MKB.' From c00db00fc2b84a6d81cf3315d702a8545ded4f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 18 Mar 2026 22:35:26 +0100 Subject: [PATCH 2/9] flow: replace platform config.mk with Python config.py + shim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrate all 6 platform configurations from Make syntax to Python: nangate45, sky130hs, sky130hd, gf180, ihp-sg13g2, asap7. Each config.py generates identical variable assignments to the original config.mk. The config.mk becomes a one-liner shim that calls config.py via $(foreach)/$(eval), the same pattern as defaults.py in variables.mk. This enables: - Unit testing of platform configurations with pytest - JSON output for bazel-orfs (--format=json) to bypass Make - Piecemeal migration per Plan E of the bazel-orfs Make dependency reduction effort Make users see zero change in behavior. variables.mk does not need porting to Python. Its logic (tool discovery, derived paths, WRAPPED_LEFS, STREAM_SYSTEM, NUM_CORES) is Make-flow plumbing that bazel-orfs replaces with Bazel-native equivalents. The only shared concern is platform config, which config.py now provides. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- flow/platforms/asap7/config.mk | 219 +----------------- flow/platforms/asap7/config.py | 315 ++++++++++++++++++++++++++ flow/platforms/gf180/config.mk | 151 +----------- flow/platforms/gf180/config.py | 182 +++++++++++++++ flow/platforms/ihp-sg13g2/config.mk | 184 +-------------- flow/platforms/ihp-sg13g2/config.py | 187 +++++++++++++++ flow/platforms/nangate45/config.mk | 111 +-------- flow/platforms/nangate45/config.py | 106 +++++++++ flow/platforms/sky130hd/config.mk | 156 +------------ flow/platforms/sky130hd/config.py | 142 ++++++++++++ flow/platforms/sky130hs/config.mk | 111 +-------- flow/platforms/sky130hs/config.py | 104 +++++++++ flow/scripts/platform_config_utils.py | 119 ++++++++++ 13 files changed, 1173 insertions(+), 914 deletions(-) create mode 100755 flow/platforms/asap7/config.py create mode 100755 flow/platforms/gf180/config.py create mode 100755 flow/platforms/ihp-sg13g2/config.py create mode 100755 flow/platforms/nangate45/config.py create mode 100755 flow/platforms/sky130hd/config.py create mode 100755 flow/platforms/sky130hs/config.py create mode 100644 flow/scripts/platform_config_utils.py diff --git a/flow/platforms/asap7/config.mk b/flow/platforms/asap7/config.mk index 873d5dedf1..d61901351a 100644 --- a/flow/platforms/asap7/config.mk +++ b/flow/platforms/asap7/config.mk @@ -1,216 +1,3 @@ -export PLATFORM = asap7 -export PROCESS = 7 - -ifeq ($(LIB_MODEL),) - export LIB_MODEL = NLDM -endif -export LIB_DIR ?= $(PLATFORM_DIR)/lib/$(LIB_MODEL) - -export PLATFORM_TCL = $(PLATFORM_DIR)/liberty_suppressions.tcl - -#Library Setup variable -export TECH_LEF = $(PLATFORM_DIR)/lef/asap7_tech_1x_201209.lef - -export BC_TEMPERATURE = 25C -export TC_TEMPERATURE = 0C -export WC_TEMPERATURE = 100C - -export BC_VOLTAGE = 0.77 -export TC_VOLTAGE = 0.70 -export WC_VOLTAGE = 0.63 - -# Dont use cells to ease congestion -# Specify at least one filler cell if none -export DONT_USE_CELLS = *x1p*_ASAP7* *xp*_ASAP7* -export DONT_USE_CELLS += SDF* ICG* - -export SYNTH_MINIMUM_KEEP_SIZE ?= 1000 - -# BUF_X1, pin (A) = 0.974659. Arbitrarily multiply by 4 -export ABC_LOAD_IN_FF = 3.898 - - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE ?= asap7sc7p5t - -export MAKE_TRACKS = $(PLATFORM_DIR)/openRoad/make_tracks.tcl - -# Define default PDN config -ifeq ($(BLOCKS),) - export PDN_TCL ?= $(PLATFORM_DIR)/openRoad/pdn/grid_strategy-M1-M2-M5-M6.tcl -else - export PDN_TCL ?= $(PLATFORM_DIR)/openRoad/pdn/BLOCKS_grid_strategy.tcl -endif - - -# IO Placer pin layers -export IO_PLACER_H ?= M4 -export IO_PLACER_V ?= M5 - -export MACRO_PLACE_HALO ?= 10 10 - -# the followings create a keep out / halo between -# macro and core rows -export MACRO_ROWS_HALO_X ?= 2 -export MACRO_ROWS_HALO_Y ?= 2 - -export PLACE_DENSITY ?= 0.60 - -# Endcap and Welltie cells -export TAPCELL_TCL ?= $(PLATFORM_DIR)/openRoad/tapcell.tcl - -export SET_RC_TCL = $(PLATFORM_DIR)/setRC.tcl - -# Route options -export MIN_ROUTING_LAYER ?= M2 -export MIN_CLK_ROUTING_LAYER ?= M4 -export MAX_ROUTING_LAYER ?= M7 - -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/KLayout/asap7.lyt - -# KLayout DRC ruledeck -export KLAYOUT_DRC_FILE = $(PLATFORM_DIR)/drc/asap7.lydrc - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules - -# PLACEHOLDER gets replaced with the appropriate VT tag in the following templates -export BC_NLDM_DFF_LIB_FILE_T = $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_nldm_220123.lib -export BC_CCS_DFF_LIB_FILE_T = $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_ccs_220123.lib -export WC_NLDM_DFF_LIB_FILE_T = $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_SS_nldm_220123.lib -export TC_NLDM_DFF_LIB_FILE_T = $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_TT_nldm_220123.lib -export BC_NLDM_LIB_FILES_T = $(LIB_DIR)/asap7sc7p5t_AO_PLACEHOLDERVT_FF_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_INVBUF_PLACEHOLDERVT_FF_nldm_220122.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_OA_PLACEHOLDERVT_FF_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_FF_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_nldm_220123.lib -export BC_CCS_LIB_FILES_T = $(LIB_DIR)/asap7sc7p5t_AO_PLACEHOLDERVT_FF_ccs_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_INVBUF_PLACEHOLDERVT_FF_ccs_220122.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_OA_PLACEHOLDERVT_FF_ccs_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_FF_ccs_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_ccs_220123.lib -export WC_NLDM_LIB_FILES_T = $(LIB_DIR)/asap7sc7p5t_AO_PLACEHOLDERVT_SS_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_INVBUF_PLACEHOLDERVT_SS_nldm_220122.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_OA_PLACEHOLDERVT_SS_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_SS_nldm_220123.lib \ - $(LIB_DIR)/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_SS_nldm_211120.lib.gz -export TC_NLDM_LIB_FILES_T = $(LIB_DIR)/asap7sc7p5t_AO_PLACEHOLDERVT_TT_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_INVBUF_PLACEHOLDERVT_TT_nldm_220122.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_OA_PLACEHOLDERVT_TT_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_TT_nldm_220123.lib \ - $(LIB_DIR)/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_TT_nldm_211120.lib.gz -export FILL_CELLS_T = FILLERxp5_ASAP7_75t_ \ - FILLER_ASAP7_75t_ \ - DECAPx1_ASAP7_75t_ \ - DECAPx2_ASAP7_75t_ \ - DECAPx4_ASAP7_75t_ \ - DECAPx6_ASAP7_75t_ \ - DECAPx10_ASAP7_75t_ - -# Default to RVT if unset -export VT_LIST = $(if $(strip $(ASAP7_USE_VT)), $(ASAP7_USE_VT), RVT) - -# # The first VT in the ASAP7_USE_VT list is the primary VT. The others get added to OTHER_VT -export PRIMARY_VT = $(word 1, $(VT_LIST)) -export PRIMARY_VT_TAG = $(strip $(patsubst %VT, %, $(PRIMARY_VT))) -export OTHER_VT = $(wordlist 2, $(words $(VT_LIST)), $(VT_LIST)) - -## Set cells based on the primary VT first -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT ?= TIEHIx1_ASAP7_75t_$(PRIMARY_VT_TAG) H -export TIELO_CELL_AND_PORT ?= TIELOx1_ASAP7_75t_$(PRIMARY_VT_TAG) L - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS ?= BUFx2_ASAP7_75t_$(PRIMARY_VT_TAG) A Y - -export HOLD_BUF_CELL ?= BUFx2_ASAP7_75t_$(PRIMARY_VT_TAG) - -export ABC_DRIVER_CELL ?= BUFx2_ASAP7_75t_$(PRIMARY_VT_TAG) - -# Fill cells used in fill cell insertion -export FILL_CELLS ?= $(addsuffix $(PRIMARY_VT_TAG), $(FILL_CELLS_T)) - -export TAP_CELL_NAME ?= TAPCELL_ASAP7_75t_$(PRIMARY_VT_TAG) - -# GDS_FILES has to be = vs. ?= because GDS_FILES gets set in the ORFS Makefile -export GDS_FILES = $(PLATFORM_DIR)/gds/asap7sc7p5t_28_$(PRIMARY_VT_TAG)_220121a.gds - -export SC_LEF ?= $(PLATFORM_DIR)/lef/asap7sc7p5t_28_$(PRIMARY_VT_TAG)_1x_220121a.lef - -# Yosys mapping files -export LATCH_MAP_FILE ?= $(PLATFORM_DIR)/yoSys/cells_latch_$(PRIMARY_VT_TAG).v -export CLKGATE_MAP_FILE ?= $(PLATFORM_DIR)/yoSys/cells_clkgate_$(PRIMARY_VT_TAG).v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/yoSys/cells_adders_$(PRIMARY_VT_TAG).v - -export BC_NLDM_DFF_LIB_FILE ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(BC_NLDM_DFF_LIB_FILE_T)) -export BC_NLDM_LIB_FILES ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(BC_NLDM_LIB_FILES_T)) -export BC_CCS_LIB_FILES ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(BC_CCS_LIB_FILES_T)) \ - $(BC_ADDITIONAL_LIBS) -export BC_CCS_DFF_LIB_FILE ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(BC_CCS_DFF_LIB_FILE_T)) - -export WC_NLDM_DFF_LIB_FILE ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(WC_NLDM_DFF_LIB_FILE_T)) -export WC_NLDM_LIB_FILES ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(WC_NLDM_LIB_FILES_T)) - -export TC_NLDM_DFF_LIB_FILE ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(TC_NLDM_DFF_LIB_FILE_T)) -export TC_NLDM_LIB_FILES ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(TC_NLDM_LIB_FILES_T)) - -ifeq ($(CLUSTER_FLOPS),1) - # Add the multi-bit FF for clustering. These are single corner libraries. - export ADDITIONAL_LIBS += $(LIB_DIR)/asap7sc7p5t_DFFHQNH2V2X_$(PRIMARY_VT_TAG)VT_TT_nldm_FAKE.lib \ - $(LIB_DIR)/asap7sc7p5t_DFFHQNV2X_$(PRIMARY_VT_TAG)VT_TT_nldm_FAKE.lib - - export ADDITIONAL_LEFS += $(PLATFORM_DIR)/lef/asap7sc7p5t_DFFHQNH2V2X.lef \ - $(PLATFORM_DIR)/lef/asap7sc7p5t_DFFHQNV2X.lef - export ADDITIONAL_SITES += asap7sc7p5t_pg - export GDS_ALLOW_EMPTY ?= DFFHQN[VH][24].* -endif - -### Add additional files to the variables based on the OTHER_VT list -$(foreach vt_type,$(OTHER_VT),\ - $(eval OTHER_VT_TAG = $(strip $(patsubst %VT, %, $(vt_type)))) \ - $(eval ADDITIONAL_LEFS += $(PLATFORM_DIR)/lef/asap7sc7p5t_28_$(OTHER_VT_TAG)_1x_220121a.lef) \ - $(eval BC_NLDM_DFF_LIB_FILE += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(BC_NLDM_DFF_LIB_FILE_T))) \ - $(eval BC_CCS_DFF_LIB_FILE += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(BC_CCS_DFF_LIB_FILE_T))) \ - $(eval WC_NLDM_DFF_LIB_FILE += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(WC_NLDM_DFF_LIB_FILE_T))) \ - $(eval TC_NLDM_DFF_LIB_FILE += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(TC_NLDM_DFF_LIB_FILE_T))) \ - $(eval BC_NLDM_LIB_FILES += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(BC_NLDM_LIB_FILES_T))) \ - $(eval BC_CCS_LIB_FILES += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(BC_CCS_LIB_FILES_T))) \ - $(eval WC_NLDM_LIB_FILES += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(WC_NLDM_LIB_FILES_T))) \ - $(eval TC_NLDM_LIB_FILES += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(TC_NLDM_LIB_FILES_T))) \ - $(eval GDS_FILES += $(PLATFORM_DIR)/gds/asap7sc7p5t_28_$(OTHER_VT_TAG)_220121a.gds) \ - $(eval FILL_CELLS += $(addsuffix $(OTHER_VT_TAG), $(FILL_CELLS_T))) \ -) - -# Dont use SC library based on CORNER selection -# -# BC - Best case, fastest -# WC - Worst case, slowest -# TC - Typical case -export CORNER ?= BC -export LIB_FILES += $($(CORNER)_$(LIB_MODEL)_LIB_FILES) -export LIB_FILES += $(ADDITIONAL_LIBS) -export GDS_FILES += $(ADDITIONAL_GDS) -export DB_FILES += $(realpath $($(CORNER)_DB_FILES)) -export TEMPERATURE = $($(CORNER)_TEMPERATURE) -export VOLTAGE = $($(CORNER)_VOLTAGE) - -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD $(VOLTAGE) -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= M1 - -# Allow empty GDS cell -export GDS_ALLOW_EMPTY ?= fakeram.* - -export REMOVE_CELLS_FOR_LEC = TAPCELL* +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/asap7/config.py b/flow/platforms/asap7/config.py new file mode 100755 index 0000000000..f4f6207546 --- /dev/null +++ b/flow/platforms/asap7/config.py @@ -0,0 +1,315 @@ +#!/usr/bin/env python3 +"""Platform configuration for asap7. + +Generates the same variable assignments as config.mk. +Handles VT variant selection, PLACEHOLDER template expansion, +foreach/eval loop for OTHER_VT, and corner-based indirection. +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + + cfg.set("PLATFORM", "asap7") + cfg.set("PROCESS", "7") + + # LIB_MODEL defaults to NLDM if not set + lib_model = cfg.env("LIB_MODEL", "NLDM") + if not lib_model: + lib_model = "NLDM" + cfg.set("LIB_MODEL", lib_model) + lib_dir = f"{pd}/lib/{lib_model}" + cfg.set("LIB_DIR", lib_dir, conditional=True) + + cfg.set("PLATFORM_TCL", f"{pd}/liberty_suppressions.tcl") + + # Library Setup + cfg.set("TECH_LEF", f"{pd}/lef/asap7_tech_1x_201209.lef") + + cfg.set("BC_TEMPERATURE", "25C") + cfg.set("TC_TEMPERATURE", "0C") + cfg.set("WC_TEMPERATURE", "100C") + + cfg.set("BC_VOLTAGE", "0.77") + cfg.set("TC_VOLTAGE", "0.70") + cfg.set("WC_VOLTAGE", "0.63") + + # Dont use cells + cfg.set("DONT_USE_CELLS", "*x1p*_ASAP7* *xp*_ASAP7*") + cfg.append("DONT_USE_CELLS", "SDF* ICG*") + + cfg.set("SYNTH_MINIMUM_KEEP_SIZE", "1000", conditional=True) + cfg.set("ABC_LOAD_IN_FF", "3.898") + + # Placement site + cfg.set("PLACE_SITE", "asap7sc7p5t", conditional=True) + cfg.set("MAKE_TRACKS", f"{pd}/openRoad/make_tracks.tcl") + + # PDN - conditional on BLOCKS + blocks = cfg.env("BLOCKS") + if not blocks: + cfg.set( + "PDN_TCL", + f"{pd}/openRoad/pdn/grid_strategy-M1-M2-M5-M6.tcl", + conditional=True, + ) + else: + cfg.set( + "PDN_TCL", f"{pd}/openRoad/pdn/BLOCKS_grid_strategy.tcl", conditional=True + ) + + # IO Placer + cfg.set("IO_PLACER_H", "M4", conditional=True) + cfg.set("IO_PLACER_V", "M5", conditional=True) + cfg.set("MACRO_PLACE_HALO", "10 10", conditional=True) + cfg.set("MACRO_ROWS_HALO_X", "2", conditional=True) + cfg.set("MACRO_ROWS_HALO_Y", "2", conditional=True) + cfg.set("PLACE_DENSITY", "0.60", conditional=True) + + # Endcap and Welltie + cfg.set("TAPCELL_TCL", f"{pd}/openRoad/tapcell.tcl", conditional=True) + cfg.set("SET_RC_TCL", f"{pd}/setRC.tcl") + + # Route options + cfg.set("MIN_ROUTING_LAYER", "M2", conditional=True) + cfg.set("MIN_CLK_ROUTING_LAYER", "M4", conditional=True) + cfg.set("MAX_ROUTING_LAYER", "M7", conditional=True) + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/KLayout/asap7.lyt") + cfg.set("KLAYOUT_DRC_FILE", f"{pd}/drc/asap7.lydrc") + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # PLACEHOLDER templates + bc_nldm_dff_t = f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_nldm_220123.lib" + bc_ccs_dff_t = f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_ccs_220123.lib" + wc_nldm_dff_t = f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_SS_nldm_220123.lib" + tc_nldm_dff_t = f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_TT_nldm_220123.lib" + + bc_nldm_libs_t = ( + f"{lib_dir}/asap7sc7p5t_AO_PLACEHOLDERVT_FF_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_INVBUF_PLACEHOLDERVT_FF_nldm_220122.lib.gz " + f"{lib_dir}/asap7sc7p5t_OA_PLACEHOLDERVT_FF_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_FF_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_nldm_220123.lib" + ) + bc_ccs_libs_t = ( + f"{lib_dir}/asap7sc7p5t_AO_PLACEHOLDERVT_FF_ccs_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_INVBUF_PLACEHOLDERVT_FF_ccs_220122.lib.gz " + f"{lib_dir}/asap7sc7p5t_OA_PLACEHOLDERVT_FF_ccs_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_FF_ccs_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_ccs_220123.lib" + ) + wc_nldm_libs_t = ( + f"{lib_dir}/asap7sc7p5t_AO_PLACEHOLDERVT_SS_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_INVBUF_PLACEHOLDERVT_SS_nldm_220122.lib.gz " + f"{lib_dir}/asap7sc7p5t_OA_PLACEHOLDERVT_SS_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_SS_nldm_220123.lib " + f"{lib_dir}/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_SS_nldm_211120.lib.gz" + ) + tc_nldm_libs_t = ( + f"{lib_dir}/asap7sc7p5t_AO_PLACEHOLDERVT_TT_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_INVBUF_PLACEHOLDERVT_TT_nldm_220122.lib.gz " + f"{lib_dir}/asap7sc7p5t_OA_PLACEHOLDERVT_TT_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_TT_nldm_220123.lib " + f"{lib_dir}/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_TT_nldm_211120.lib.gz" + ) + + fill_cells_t = [ + "FILLERxp5_ASAP7_75t_", + "FILLER_ASAP7_75t_", + "DECAPx1_ASAP7_75t_", + "DECAPx2_ASAP7_75t_", + "DECAPx4_ASAP7_75t_", + "DECAPx6_ASAP7_75t_", + "DECAPx10_ASAP7_75t_", + ] + + # VT list: default to RVT if ASAP7_USE_VT is unset + asap7_use_vt = cfg.env("ASAP7_USE_VT", "").strip() + vt_list = asap7_use_vt.split() if asap7_use_vt else ["RVT"] + primary_vt = vt_list[0] + primary_vt_tag = primary_vt.replace("VT", "") # RVT -> R, LVT -> L, SLVT -> SL + other_vt = vt_list[1:] + + # Set cells based on primary VT + cfg.set( + "TIEHI_CELL_AND_PORT", f"TIEHIx1_ASAP7_75t_{primary_vt_tag} H", conditional=True + ) + cfg.set( + "TIELO_CELL_AND_PORT", f"TIELOx1_ASAP7_75t_{primary_vt_tag} L", conditional=True + ) + cfg.set( + "MIN_BUF_CELL_AND_PORTS", + f"BUFx2_ASAP7_75t_{primary_vt_tag} A Y", + conditional=True, + ) + cfg.set("HOLD_BUF_CELL", f"BUFx2_ASAP7_75t_{primary_vt_tag}", conditional=True) + cfg.set("ABC_DRIVER_CELL", f"BUFx2_ASAP7_75t_{primary_vt_tag}", conditional=True) + + # Fill cells: $(addsuffix $(PRIMARY_VT_TAG), $(FILL_CELLS_T)) + cfg.set( + "FILL_CELLS", + " ".join(f"{cell}{primary_vt_tag}" for cell in fill_cells_t), + conditional=True, + ) + + cfg.set("TAP_CELL_NAME", f"TAPCELL_ASAP7_75t_{primary_vt_tag}", conditional=True) + + # GDS_FILES uses = (not ?=) because it gets set in the ORFS Makefile + cfg.set("GDS_FILES", f"{pd}/gds/asap7sc7p5t_28_{primary_vt_tag}_220121a.gds") + + cfg.set( + "SC_LEF", + f"{pd}/lef/asap7sc7p5t_28_{primary_vt_tag}_1x_220121a.lef", + conditional=True, + ) + + # Yosys mapping files + cfg.set( + "LATCH_MAP_FILE", f"{pd}/yoSys/cells_latch_{primary_vt_tag}.v", conditional=True + ) + cfg.set( + "CLKGATE_MAP_FILE", + f"{pd}/yoSys/cells_clkgate_{primary_vt_tag}.v", + conditional=True, + ) + cfg.set( + "ADDER_MAP_FILE", + f"{pd}/yoSys/cells_adders_{primary_vt_tag}.v", + conditional=True, + ) + + # Expand primary VT templates + def expand(template, tag): + return template.replace("PLACEHOLDER", tag) + + cfg.set( + "BC_NLDM_DFF_LIB_FILE", expand(bc_nldm_dff_t, primary_vt_tag), conditional=True + ) + cfg.set( + "BC_NLDM_LIB_FILES", expand(bc_nldm_libs_t, primary_vt_tag), conditional=True + ) + bc_ccs_libs = expand(bc_ccs_libs_t, primary_vt_tag) + bc_additional = cfg.env("BC_ADDITIONAL_LIBS") + if bc_additional: + bc_ccs_libs += f" {bc_additional}" + cfg.set("BC_CCS_LIB_FILES", bc_ccs_libs, conditional=True) + cfg.set( + "BC_CCS_DFF_LIB_FILE", expand(bc_ccs_dff_t, primary_vt_tag), conditional=True + ) + + cfg.set( + "WC_NLDM_DFF_LIB_FILE", expand(wc_nldm_dff_t, primary_vt_tag), conditional=True + ) + cfg.set( + "WC_NLDM_LIB_FILES", expand(wc_nldm_libs_t, primary_vt_tag), conditional=True + ) + + cfg.set( + "TC_NLDM_DFF_LIB_FILE", expand(tc_nldm_dff_t, primary_vt_tag), conditional=True + ) + cfg.set( + "TC_NLDM_LIB_FILES", expand(tc_nldm_libs_t, primary_vt_tag), conditional=True + ) + + # CLUSTER_FLOPS conditional + cluster_flops = cfg.env("CLUSTER_FLOPS") + if cluster_flops == "1": + cfg.append( + "ADDITIONAL_LIBS", + f"{lib_dir}/asap7sc7p5t_DFFHQNH2V2X_{primary_vt_tag}VT_TT_nldm_FAKE.lib " + f"{lib_dir}/asap7sc7p5t_DFFHQNV2X_{primary_vt_tag}VT_TT_nldm_FAKE.lib", + ) + cfg.append( + "ADDITIONAL_LEFS", + f"{pd}/lef/asap7sc7p5t_DFFHQNH2V2X.lef " + f"{pd}/lef/asap7sc7p5t_DFFHQNV2X.lef", + ) + cfg.append("ADDITIONAL_SITES", "asap7sc7p5t_pg") + cfg.set("GDS_ALLOW_EMPTY", "DFFHQN[VH][24].*", conditional=True) + + # foreach/eval loop: expand OTHER_VT templates and append + for vt_type in other_vt: + vt_tag = vt_type.replace("VT", "") # LVT -> L, SLVT -> SL + + cfg.append( + "ADDITIONAL_LEFS", f"{pd}/lef/asap7sc7p5t_28_{vt_tag}_1x_220121a.lef" + ) + cfg.append("BC_NLDM_DFF_LIB_FILE", expand(bc_nldm_dff_t, vt_tag)) + cfg.append("BC_CCS_DFF_LIB_FILE", expand(bc_ccs_dff_t, vt_tag)) + cfg.append("WC_NLDM_DFF_LIB_FILE", expand(wc_nldm_dff_t, vt_tag)) + cfg.append("TC_NLDM_DFF_LIB_FILE", expand(tc_nldm_dff_t, vt_tag)) + cfg.append("BC_NLDM_LIB_FILES", expand(bc_nldm_libs_t, vt_tag)) + cfg.append("BC_CCS_LIB_FILES", expand(bc_ccs_libs_t, vt_tag)) + cfg.append("WC_NLDM_LIB_FILES", expand(wc_nldm_libs_t, vt_tag)) + cfg.append("TC_NLDM_LIB_FILES", expand(tc_nldm_libs_t, vt_tag)) + cfg.append("GDS_FILES", f"{pd}/gds/asap7sc7p5t_28_{vt_tag}_220121a.gds") + cfg.append( + "FILL_CELLS", + " ".join(f"{cell}{vt_tag}" for cell in fill_cells_t), + ) + + # Corner selection via variable indirection + corner = cfg.env("CORNER", "BC") + cfg.set("CORNER", corner, conditional=True) + + # $($(CORNER)_$(LIB_MODEL)_LIB_FILES) + corner_model_key = f"{corner}_{lib_model}_LIB_FILES" + # Map to the right variable we computed above + lib_model_map = { + "BC_NLDM": "BC_NLDM_LIB_FILES", + "BC_CCS": "BC_CCS_LIB_FILES", + "WC_NLDM": "WC_NLDM_LIB_FILES", + "TC_NLDM": "TC_NLDM_LIB_FILES", + } + corner_lib_key = lib_model_map.get( + f"{corner}_{lib_model}", f"{corner}_{lib_model}_LIB_FILES" + ) + corner_lib_files = cfg.get(corner_lib_key, "") + + cfg.append("LIB_FILES", corner_lib_files) + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + cfg.append("LIB_FILES", additional_libs) + + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + cfg.append("GDS_FILES", additional_gds) + + # DB_FILES uses $(realpath $($(CORNER)_DB_FILES)) + corner_db_key = f"{corner}_DB_FILES" + db_files = cfg.get(corner_db_key, cfg.env(corner_db_key, "")) + if db_files: + resolved = " ".join(os.path.realpath(p) for p in db_files.split() if p) + cfg.append("DB_FILES", resolved) + + cfg.set("TEMPERATURE", cfg.get(f"{corner}_TEMPERATURE", "25C")) + cfg.set("VOLTAGE", cfg.get(f"{corner}_VOLTAGE", "0.77")) + + # IR Drop + voltage = cfg.get("VOLTAGE", "0.77") + cfg.set("PWR_NETS_VOLTAGES", f"VDD {voltage}", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "M1", conditional=True) + + # Allow empty GDS + cfg.set("GDS_ALLOW_EMPTY", "fakeram.*", conditional=True) + + cfg.set("REMOVE_CELLS_FOR_LEC", "TAPCELL*") + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/gf180/config.mk b/flow/platforms/gf180/config.mk index 46bbb7b54d..d61901351a 100644 --- a/flow/platforms/gf180/config.mk +++ b/flow/platforms/gf180/config.mk @@ -1,148 +1,3 @@ -#----------------------------------------------------- -# Tech/Libs -# TRACK_OPTION - 9t 7t -# METAL_OPTION - 5LM_1TM -#---------------------------------------------------- -export TRACK_OPTION ?= 9t -export METAL_OPTION ?= 5LM_1TM -export KVALUE ?= 9 -export POWER_OPTION ?= 5v0 -export CORNER ?= BC -export PROCESS = 180 - -#---------------------------------------------------- -# OpenROAD -#---------------------------------------------------- -export TECH_LEF = $(PLATFORM_DIR)/lef/gf180mcu_$(METAL_OPTION)_$(KVALUE)K_$(TRACK_OPTION)_tech.lef - -export SC_LEF ?= $(PLATFORM_DIR)/lef/gf180mcu_$(METAL_OPTION)_$(KVALUE)K_$(TRACK_OPTION)_sc.lef - -export GDS_FILES = $(wildcard $(PLATFORM_DIR)/gds/$(TRACK_OPTION)/*.gds) \ - $(ADDITIONAL_GDS) - -# Dont use cells -export DONT_USE_CELLS = *_1 - -# Fill cells used in fill cell insertion -export FILL_CELLS ?= gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_64 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_32 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_16 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_8 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_4 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_2 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_1 - -export TIE_CELL = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__filltie -export ENDCAP_CELL = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__endcap -export RC_FILE = $(PLATFORM_DIR)/setRC.tcl - -#----------------------------------------------------- -# Yosys -#----------------------------------------------------- - -# set the TIEHI/TIELO cells -export TIEHI_CELL_AND_PORT = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__tieh Z -export TIELO_CELL_AND_PORT = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__tiel ZN - -export ABC_DRIVER_CELL = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__buf_4 -export ABC_LOAD_IN_FF = 0.01343 - -# hold buffer cell -export MIN_BUF_CELL_AND_PORTS = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__dlya_4 I Z - -# Used in synthesis -export MAX_FANOUT = 20 - -# Yosys mapping files -export LATCH_MAP_FILE ?= $(PLATFORM_DIR)/cells_latch.v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/cells_adders.v - -#-------------------------------------------------------- -# Floorplan -#------------------------------------------------------- -# Placement site for core cells -ifeq ($(TRACK_OPTION),9t) -export PLACE_SITE ?= GF018hv5v_green_sc9 -else -export PLACE_SITE ?= GF018hv5v_mcu_sc7 -endif - -# IO Placer pin layers -export IO_PLACER_H ?= Metal3 -export IO_PLACER_V ?= Metal4 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/openROAD/pdn/pdn_grid_strategy_$(TRACK_OPTION)_6M.cfg - -# Endcap and Welltie cells -export TAPCELL_TCL ?= $(PLATFORM_DIR)/openROAD/tapcell.tcl - -# macro planning -export MACRO_PLACE_HALO ?= 10 10 - -#--------------------------------------------------------- -# Place -#-------------------------------------------------------- -export PLACE_DENSITY ?= 0.40 - -#--------------------------------------------------------- -# Route -#--------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER ?= Metal2 -export MAX_ROUTING_LAYER ?= Metal5 -export DISABLE_VIA_GEN ?= 1 - -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout layer properties -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/KLayout/gf180mcu_$(METAL_OPTION)_$(KVALUE)K_$(TRACK_OPTION).lyt -export KLAYOUT_LEF_FILE = $(PLATFORM_DIR)/KLayout/tech_$(TRACK_OPTION)_$(METAL_OPTION).lef -export GDS_LAYER_MAP = $(abspath $(PLATFORM_DIR)/gds/$(TRACK_OPTION)/gf180mcu_$(METAL_OPTION)_$(KVALUE)K_$(TRACK_OPTION)_edi2gds.layermap) - -# For RCX -export BC_RCX_RULES = $(PLATFORM_DIR)/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_bst.rules -export WC_RCX_RULES = $(PLATFORM_DIR)/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_wst.rules -export TC_RCX_RULES = $(PLATFORM_DIR)/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_typ.rules - -export BC_RCX_RC_CORNER = FuncRCmin -export WC_RCX_RC_CORNER = FuncRCmax -export TC_RCX_RC_CORNER = FuncRCtyp - -export RCX_RULES = $($(CORNER)_RCX_RULES) -export RCX_RC_CORNER = $($(CORNER)_RCX_RC_CORNER) - -#---------------------------------------------------------------------------------------------------- -# define libraries - corner dependant setting -#---------------------------------------------------------------------------------------------------- -# standard cell section -#---------------------------------------------------------------------------------------------------- -export BC_LIB_FILES = $(abspath $(PLATFORM_DIR)/lib/gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__ff_n40C_5v50.lib.gz) -export BC_TEMPERATURE = -40c -export BC_VOLTAGE = 5.5 - -export WC_LIB_FILES = $(abspath $(PLATFORM_DIR)/lib/gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__ss_125C_4v50.lib.gz) -export WC_TEMPERATURE = 125c -export WC_VOLTAGE = 4.5 - -export TC_LIB_FILES = $(abspath $(PLATFORM_DIR)/lib/gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__tt_025C_5v00.lib.gz) -export TC_TEMPERATURE = 25c -export TC_VOLTAGE = 5.0 - -# ---------------------------------------------------------------------------------------------------- -# now, set files from user setting CORNER -# ---------------------------------------------------------------------------------------------------- -export TEMPERATURE = $($(CORNER)_TEMPERATURE) -export VOLTAGE = $($(CORNER)_VOLTAGE) -export LIB_FILES = $($(CORNER)_LIB_FILES) \ - $(ADDITIONAL_LIBS) - -# IR drop estimation supply net name to be analyzed and supply voltage variable -export PWR_NETS_VOLTAGES ?= VDD $(VOLTAGE) -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= Metal1 - -# For proprietary tool enablements that are not public -export GF180_PRIVATE_DIR ?= ../../gf180-private --include $(GF180_PRIVATE_DIR)/private.mk +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/gf180/config.py b/flow/platforms/gf180/config.py new file mode 100755 index 0000000000..68b37dcb21 --- /dev/null +++ b/flow/platforms/gf180/config.py @@ -0,0 +1,182 @@ +#!/usr/bin/env python3 +"""Platform configuration for gf180. + +Generates the same variable assignments as config.mk. +Parameterized by TRACK_OPTION, METAL_OPTION, KVALUE, POWER_OPTION, CORNER. +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + + # Parameterized options + track = cfg.env("TRACK_OPTION", "9t") + metal = cfg.env("METAL_OPTION", "5LM_1TM") + kvalue = cfg.env("KVALUE", "9") + power = cfg.env("POWER_OPTION", "5v0") + corner = cfg.env("CORNER", "BC") + + cfg.set("TRACK_OPTION", track, conditional=True) + cfg.set("METAL_OPTION", metal, conditional=True) + cfg.set("KVALUE", kvalue, conditional=True) + cfg.set("POWER_OPTION", power, conditional=True) + cfg.set("CORNER", corner, conditional=True) + cfg.set("PROCESS", "180") + + # Tech/Libs + cfg.set("TECH_LEF", f"{pd}/lef/gf180mcu_{metal}_{kvalue}K_{track}_tech.lef") + cfg.set( + "SC_LEF", + f"{pd}/lef/gf180mcu_{metal}_{kvalue}K_{track}_sc.lef", + conditional=True, + ) + + gds = cfg.wildcard_glob(f"{pd}/gds/{track}/*.gds") + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + gds += f" {additional_gds}" + cfg.set("GDS_FILES", gds) + + cfg.set("DONT_USE_CELLS", "*_1") + + # Fill cells + sc = f"gf180mcu_fd_sc_mcu{track}{power}" + cfg.set( + "FILL_CELLS", + f"{sc}__fill_64 {sc}__fill_32 {sc}__fill_16 {sc}__fill_8 {sc}__fill_4 {sc}__fill_2 {sc}__fill_1", + conditional=True, + ) + + cfg.set("TIE_CELL", f"{sc}__filltie") + cfg.set("ENDCAP_CELL", f"{sc}__endcap") + cfg.set("RC_FILE", f"{pd}/setRC.tcl") + + # Yosys + cfg.set("TIEHI_CELL_AND_PORT", f"{sc}__tieh Z") + cfg.set("TIELO_CELL_AND_PORT", f"{sc}__tiel ZN") + cfg.set("ABC_DRIVER_CELL", f"{sc}__buf_4") + cfg.set("ABC_LOAD_IN_FF", "0.01343") + cfg.set("MIN_BUF_CELL_AND_PORTS", f"{sc}__dlya_4 I Z") + cfg.set("MAX_FANOUT", "20") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch.v", conditional=True) + cfg.set("ADDER_MAP_FILE", f"{pd}/cells_adders.v", conditional=True) + + # Floorplan + if track == "9t": + cfg.set("PLACE_SITE", "GF018hv5v_green_sc9", conditional=True) + else: + cfg.set("PLACE_SITE", "GF018hv5v_mcu_sc7", conditional=True) + + cfg.set("IO_PLACER_H", "Metal3", conditional=True) + cfg.set("IO_PLACER_V", "Metal4", conditional=True) + cfg.set( + "PDN_TCL", + f"{pd}/openROAD/pdn/pdn_grid_strategy_{track}_6M.cfg", + conditional=True, + ) + cfg.set("TAPCELL_TCL", f"{pd}/openROAD/tapcell.tcl", conditional=True) + cfg.set("MACRO_PLACE_HALO", "10 10", conditional=True) + + # Place + cfg.set("PLACE_DENSITY", "0.40", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "Metal2", conditional=True) + cfg.set("MAX_ROUTING_LAYER", "Metal5", conditional=True) + cfg.set("DISABLE_VIA_GEN", "1", conditional=True) + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/KLayout/gf180mcu_{metal}_{kvalue}K_{track}.lyt") + cfg.set("KLAYOUT_LEF_FILE", f"{pd}/KLayout/tech_{track}_{metal}.lef") + cfg.set( + "GDS_LAYER_MAP", + os.path.abspath( + f"{pd}/gds/{track}/gf180mcu_{metal}_{kvalue}K_{track}_edi2gds.layermap" + ), + ) + + # RCX - corner-dependent + cfg.set( + "BC_RCX_RULES", f"{pd}/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_bst.rules" + ) + cfg.set( + "WC_RCX_RULES", f"{pd}/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_wst.rules" + ) + cfg.set( + "TC_RCX_RULES", f"{pd}/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_typ.rules" + ) + + cfg.set("BC_RCX_RC_CORNER", "FuncRCmin") + cfg.set("WC_RCX_RC_CORNER", "FuncRCmax") + cfg.set("TC_RCX_RC_CORNER", "FuncRCtyp") + + # Variable indirection for RCX + rcx_rules = { + "BC": cfg.get("BC_RCX_RULES"), + "WC": cfg.get("WC_RCX_RULES"), + "TC": cfg.get("TC_RCX_RULES"), + } + rcx_corners = {"BC": "FuncRCmin", "WC": "FuncRCmax", "TC": "FuncRCtyp"} + cfg.set("RCX_RULES", rcx_rules.get(corner, rcx_rules["BC"])) + cfg.set("RCX_RC_CORNER", rcx_corners.get(corner, rcx_corners["BC"])) + + # Corner-dependent libraries + bc_lib = os.path.abspath( + f"{pd}/lib/gf180mcu_fd_sc_mcu{track}{power}__ff_n40C_5v50.lib.gz" + ) + wc_lib = os.path.abspath( + f"{pd}/lib/gf180mcu_fd_sc_mcu{track}{power}__ss_125C_4v50.lib.gz" + ) + tc_lib = os.path.abspath( + f"{pd}/lib/gf180mcu_fd_sc_mcu{track}{power}__tt_025C_5v00.lib.gz" + ) + + cfg.set("BC_LIB_FILES", bc_lib) + cfg.set("BC_TEMPERATURE", "-40c") + cfg.set("BC_VOLTAGE", "5.5") + + cfg.set("WC_LIB_FILES", wc_lib) + cfg.set("WC_TEMPERATURE", "125c") + cfg.set("WC_VOLTAGE", "4.5") + + cfg.set("TC_LIB_FILES", tc_lib) + cfg.set("TC_TEMPERATURE", "25c") + cfg.set("TC_VOLTAGE", "5.0") + + # Variable indirection for corner selection + corner_libs = {"BC": bc_lib, "WC": wc_lib, "TC": tc_lib} + corner_temps = {"BC": "-40c", "WC": "125c", "TC": "25c"} + corner_volts = {"BC": "5.5", "WC": "4.5", "TC": "5.0"} + + lib_files = corner_libs.get(corner, corner_libs["BC"]) + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + lib_files += f" {additional_libs}" + cfg.set("TEMPERATURE", corner_temps.get(corner, corner_temps["BC"])) + cfg.set("VOLTAGE", corner_volts.get(corner, corner_volts["BC"])) + cfg.set("LIB_FILES", lib_files) + + # IR Drop + voltage = corner_volts.get(corner, corner_volts["BC"]) + cfg.set("PWR_NETS_VOLTAGES", f"VDD {voltage}", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "Metal1", conditional=True) + + # Private dir (skipped: -include private.mk is for vendor-specific additions) + cfg.set("GF180_PRIVATE_DIR", "../../gf180-private", conditional=True) + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/ihp-sg13g2/config.mk b/flow/platforms/ihp-sg13g2/config.mk index 3bd9248abb..d61901351a 100644 --- a/flow/platforms/ihp-sg13g2/config.mk +++ b/flow/platforms/ihp-sg13g2/config.mk @@ -1,181 +1,3 @@ -# Process node -export PROCESS = ihp-sg13g2 - -#----------------------------------------------------- -# Tech/Libs -# ---------------------------------------------------- -# Add IO related files when a TCL script is assigned to 'FOOTPRINT_TCL'. -# This variable is used to pass IO information. -export LOAD_ADDITIONAL_FILES ?= 1 -ifneq ($(FOOTPRINT_TCL),) - ifeq ($(LOAD_ADDITIONAL_FILES),1) - export ADDITIONAL_LEFS += $(PLATFORM_DIR)/lef/sg13g2_io.lef \ - $(PLATFORM_DIR)/lef/bondpad_70x70.lef - export ADDITIONAL_SLOW_LIBS += $(PLATFORM_DIR)/lib/sg13g2_io_slow_1p08V_3p0V_125C.lib - export ADDITIONAL_FAST_LIBS += $(PLATFORM_DIR)/lib/sg13g2_io_fast_1p32V_3p6V_m40C.lib - export ADDITIONAL_TYP_LIBS += $(PLATFORM_DIR)/lib/sg13g2_io_typ_1p2V_3p3V_25C.lib - export ADDITIONAL_GDS += $(PLATFORM_DIR)/gds/sg13g2_io.gds \ - $(PLATFORM_DIR)/gds/bondpad_70x70.gds - endif -endif -export TECH_LEF ?= $(PLATFORM_DIR)/lef/sg13g2_tech.lef -export SC_LEF ?= $(PLATFORM_DIR)/lef/sg13g2_stdcell.lef - -export SLOW_LIB_FILES ?= $(PLATFORM_DIR)/lib/sg13g2_stdcell_slow_1p08V_125C.lib \ - $(ADDITIONAL_SLOW_LIBS) -export FAST_LIB_FILES ?= $(PLATFORM_DIR)/lib/sg13g2_stdcell_fast_1p32V_m40C.lib \ - $(ADDITIONAL_FAST_LIBS) -export TYP_LIB_FILES ?= $(PLATFORM_DIR)/lib/sg13g2_stdcell_typ_1p20V_25C.lib \ - $(ADDITIONAL_TYP_LIBS) -export LIB_FILES ?= $(TYP_LIB_FILES) -export GDS_FILES ?= $(PLATFORM_DIR)/gds/sg13g2_stdcell.gds \ - $(ADDITIONAL_GDS) - -# Dont use cells to ease congestion -# Specify at least one filler cell if none - -# The *probe* are for inserting probe points and have metal shapes -# on all layers. -# *lpflow* cells are for multi-power domains -export DONT_USE_CELLS += \ -sg13g2_lgcp_1 \ -sg13g2_sighold \ -sg13g2_slgcp_1 \ -sg13g2_dfrbp_2 - - -# Define fill cells -export FILL_CELLS ?= sg13g2_fill_1 sg13g2_fill_2 sg13g2_decap_4 sg13g2_decap_8 -# ----------------------------------------------------- -# Yosys -# ---------------------------------------------------- -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT = sg13g2_tiehi L_HI -export TIELO_CELL_AND_PORT = sg13g2_tielo L_LO - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS = sg13g2_buf_1 A X - -# Yosys mapping files -export LATCH_MAP_FILE = $(PLATFORM_DIR)/cells_latch.v -export CLKGATE_MAP_FILE = $(PLATFORM_DIR)/cells_clkgate.v - -# Define ABC driver and load -export ABC_DRIVER_CELL = sg13g2_buf_4 -export ABC_LOAD_IN_FF = 6.0 -ifeq ($(origin ABC_CLOCK_PERIOD_IN_PS), undefined) - ifneq ($(wildcard $(SDC_FILE)),) - # Set yosys-abc clock period to first "clk_period" value or "-period" value found in sdc file - export ABC_CLOCK_PERIOD_IN_PS ?= $(shell sed -nE "s/^set clk_period (.+)|.* -period (.+) .*/\1\2/p" $(SDC_FILE) | head -1 | awk '{print $$1*1000}') - endif -endif - -# ----------------------------------------------------- -# Sizing -# ----------------------------------------------------- - -export MATCH_CELL_FOOTPRINT = 1 - -#-------------------------------------------------------- -# Floorplan -# ------------------------------------------------------- - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE = CoreSite - -# IO Placer pin layers -export IO_PLACER_V ?= Metal2 -export IO_PLACER_H ?= Metal3 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/pdn.tcl - -# To allow the core rings to fit inside the core area -export CORE_MARGIN ?= 17.5 - -# There are no Endcap and Welltie cells in this PDK, so -# `cut_rows` has to be called from the tapcell script. -export TAPCELL_TCL ?= $(PLATFORM_DIR)/tapcell.tcl - -export MACRO_PLACE_HALO ?= 40 40 - -# Will be placed left to right -export IO_NORTH_PINS ??= -export IO_SOUTH_PINS ??= -# Will be placed bottom to top -export IO_EAST_PINS ??= -export IO_WEST_PINS ??= - -# Variables for bondpad -export IO_BONDPAD_SIZE ?= 70 -export IO_BONDPAD_NAME ?= bondpad_70x70 -# Variables for padframe -export IO_LENGTH ?= 180 -export IO_WIDTH ?= 80 -export IO_SEALRING_OFFSET ?= 70 -export IO_FILLER_CELLS ?= \ -sg13g2_Filler10000 \ -sg13g2_Filler4000 \ -sg13g2_Filler2000 \ -sg13g2_Filler1000 \ -sg13g2_Filler400 \ -sg13g2_Filler200 - -#--------------------------------------------------------- -# Place -# -------------------------------------------------------- -export PLACE_DENSITY ?= 0.65 - -# --------------------------------------------------------- -# Route -# --------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER ?= Metal2 -export MAX_ROUTING_LAYER ?= Metal5 -#export VIA_IN_PIN_MIN_LAYER ?= Metal1 -#export VIA_IN_PIN_MAX_LAYER ?= Metal1 -#export DISABLE_VIA_GEN ?= 1 - -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/sg13g2.lyt -# -# Rules for metal fill -export FILL_CONFIG = $(PLATFORM_DIR)/fill.json -# -# Template definition for power grid analysis -#export TEMPLATE_PGA_CFG ?= $(PLATFORM_DIR)/template_pga.cfg - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules - -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD 1.2 -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= Metal1 - -# DRC Check -export KLAYOUT_DRC_FILE ?= $(PLATFORM_DIR)/drc/sg13g2_minimal.lydrc - -#LVS Check -export CDL_FILE ?= $(PLATFORM_DIR)/cdl/sg13g2_stdcell.cdl -#export KLAYOUT_LVS_FILE = $(PLATFORM_DIR)/lvs/$(PLATFORM).lylvs - -export REMOVE_CELLS_FOR_LEC ?= "bondpad_70* sg13g2*" - -# --------------------------------------------------------- -# Final -# --------------------------------------------------------- - -# SRAM macros have empty placeholder cells included. Just ignore them to not -# thrown an error. -export GDS_ALLOW_EMPTY = RM_IHPSG13_\dP_BITKIT_16x2_(CORNER|EDGE_TB|LE_con_corner|LE_con_edge_lr|LE_con_tap_lr|POWER_ramtap|TAP|TAP_LR) +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/ihp-sg13g2/config.py b/flow/platforms/ihp-sg13g2/config.py new file mode 100755 index 0000000000..30ce36e189 --- /dev/null +++ b/flow/platforms/ihp-sg13g2/config.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python3 +"""Platform configuration for ihp-sg13g2. + +Generates the same variable assignments as config.mk. +""" + +import os +import re +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + + # Process node + cfg.set("PROCESS", "ihp-sg13g2") + + # Tech/Libs - conditional IO files when FOOTPRINT_TCL is set + cfg.set("LOAD_ADDITIONAL_FILES", "1", conditional=True) + footprint_tcl = cfg.env("FOOTPRINT_TCL") + load_additional = cfg.env("LOAD_ADDITIONAL_FILES", "1") + if footprint_tcl and load_additional == "1": + cfg.append( + "ADDITIONAL_LEFS", f"{pd}/lef/sg13g2_io.lef {pd}/lef/bondpad_70x70.lef" + ) + cfg.append( + "ADDITIONAL_SLOW_LIBS", f"{pd}/lib/sg13g2_io_slow_1p08V_3p0V_125C.lib" + ) + cfg.append( + "ADDITIONAL_FAST_LIBS", f"{pd}/lib/sg13g2_io_fast_1p32V_3p6V_m40C.lib" + ) + cfg.append("ADDITIONAL_TYP_LIBS", f"{pd}/lib/sg13g2_io_typ_1p2V_3p3V_25C.lib") + cfg.append( + "ADDITIONAL_GDS", f"{pd}/gds/sg13g2_io.gds {pd}/gds/bondpad_70x70.gds" + ) + + cfg.set("TECH_LEF", f"{pd}/lef/sg13g2_tech.lef", conditional=True) + cfg.set("SC_LEF", f"{pd}/lef/sg13g2_stdcell.lef", conditional=True) + + additional_slow_libs = cfg.get( + "ADDITIONAL_SLOW_LIBS", cfg.env("ADDITIONAL_SLOW_LIBS") + ) + additional_fast_libs = cfg.get( + "ADDITIONAL_FAST_LIBS", cfg.env("ADDITIONAL_FAST_LIBS") + ) + additional_typ_libs = cfg.get("ADDITIONAL_TYP_LIBS", cfg.env("ADDITIONAL_TYP_LIBS")) + additional_gds = cfg.get("ADDITIONAL_GDS", cfg.env("ADDITIONAL_GDS")) + + slow_lib = f"{pd}/lib/sg13g2_stdcell_slow_1p08V_125C.lib" + if additional_slow_libs: + slow_lib += f" {additional_slow_libs}" + cfg.set("SLOW_LIB_FILES", slow_lib, conditional=True) + + fast_lib = f"{pd}/lib/sg13g2_stdcell_fast_1p32V_m40C.lib" + if additional_fast_libs: + fast_lib += f" {additional_fast_libs}" + cfg.set("FAST_LIB_FILES", fast_lib, conditional=True) + + typ_lib = f"{pd}/lib/sg13g2_stdcell_typ_1p20V_25C.lib" + if additional_typ_libs: + typ_lib += f" {additional_typ_libs}" + cfg.set("TYP_LIB_FILES", typ_lib, conditional=True) + + cfg.set("LIB_FILES", cfg.get("TYP_LIB_FILES", typ_lib), conditional=True) + + gds_files = f"{pd}/gds/sg13g2_stdcell.gds" + if additional_gds: + gds_files += f" {additional_gds}" + cfg.set("GDS_FILES", gds_files, conditional=True) + + # Dont use cells + cfg.append( + "DONT_USE_CELLS", + "sg13g2_lgcp_1 sg13g2_sighold sg13g2_slgcp_1 sg13g2_dfrbp_2", + ) + + # Fill cells + cfg.set( + "FILL_CELLS", + "sg13g2_fill_1 sg13g2_fill_2 sg13g2_decap_4 sg13g2_decap_8", + conditional=True, + ) + + # Yosys + cfg.set("TIEHI_CELL_AND_PORT", "sg13g2_tiehi L_HI") + cfg.set("TIELO_CELL_AND_PORT", "sg13g2_tielo L_LO") + cfg.set("MIN_BUF_CELL_AND_PORTS", "sg13g2_buf_1 A X") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch.v") + cfg.set("CLKGATE_MAP_FILE", f"{pd}/cells_clkgate.v") + + cfg.set("ABC_DRIVER_CELL", "sg13g2_buf_4") + cfg.set("ABC_LOAD_IN_FF", "6.0") + + # SDC clock period extraction: $(shell sed ...) + # Replaces: $(origin ABC_CLOCK_PERIOD_IN_PS) check + $(shell sed ...) + awk + if "ABC_CLOCK_PERIOD_IN_PS" not in os.environ: + sdc_file = cfg.env("SDC_FILE") + if sdc_file and os.path.isfile(sdc_file): + with open(sdc_file) as f: + for line in f: + m = re.search( + r"^set\s+clk_period\s+(\S+)|.*-period\s+(\S+)", + line, + ) + if m: + val = m.group(1) or m.group(2) + try: + period_ps = str(float(val) * 1000) + cfg.set( + "ABC_CLOCK_PERIOD_IN_PS", period_ps, conditional=True + ) + except ValueError: + pass + break + + # Sizing + cfg.set("MATCH_CELL_FOOTPRINT", "1") + + # Floorplan + cfg.set("PLACE_SITE", "CoreSite") + cfg.set("IO_PLACER_V", "Metal2", conditional=True) + cfg.set("IO_PLACER_H", "Metal3", conditional=True) + cfg.set("PDN_TCL", f"{pd}/pdn.tcl", conditional=True) + cfg.set("CORE_MARGIN", "17.5", conditional=True) + cfg.set("TAPCELL_TCL", f"{pd}/tapcell.tcl", conditional=True) + cfg.set("MACRO_PLACE_HALO", "40 40", conditional=True) + + # IO pin variables (??= treated as ?=) + cfg.set("IO_NORTH_PINS", "", conditional=True) + cfg.set("IO_SOUTH_PINS", "", conditional=True) + cfg.set("IO_EAST_PINS", "", conditional=True) + cfg.set("IO_WEST_PINS", "", conditional=True) + + # Bondpad/padframe variables + cfg.set("IO_BONDPAD_SIZE", "70", conditional=True) + cfg.set("IO_BONDPAD_NAME", "bondpad_70x70", conditional=True) + cfg.set("IO_LENGTH", "180", conditional=True) + cfg.set("IO_WIDTH", "80", conditional=True) + cfg.set("IO_SEALRING_OFFSET", "70", conditional=True) + cfg.set( + "IO_FILLER_CELLS", + "sg13g2_Filler10000 sg13g2_Filler4000 sg13g2_Filler2000 sg13g2_Filler1000 sg13g2_Filler400 sg13g2_Filler200", + conditional=True, + ) + + # Place + cfg.set("PLACE_DENSITY", "0.65", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "Metal2", conditional=True) + cfg.set("MAX_ROUTING_LAYER", "Metal5", conditional=True) + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/sg13g2.lyt") + cfg.set("FILL_CONFIG", f"{pd}/fill.json") + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # IR Drop + cfg.set("PWR_NETS_VOLTAGES", "VDD 1.2", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "Metal1", conditional=True) + + # DRC/LVS + cfg.set("KLAYOUT_DRC_FILE", f"{pd}/drc/sg13g2_minimal.lydrc", conditional=True) + cfg.set("CDL_FILE", f"{pd}/cdl/sg13g2_stdcell.cdl", conditional=True) + cfg.set("REMOVE_CELLS_FOR_LEC", "bondpad_70* sg13g2*", conditional=True) + + # Final + cfg.set( + "GDS_ALLOW_EMPTY", + r"RM_IHPSG13_\dP_BITKIT_16x2_(CORNER|EDGE_TB|LE_con_corner|LE_con_edge_lr|LE_con_tap_lr|POWER_ramtap|TAP|TAP_LR)", + ) + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/nangate45/config.mk b/flow/platforms/nangate45/config.mk index d8b60131f4..d61901351a 100644 --- a/flow/platforms/nangate45/config.mk +++ b/flow/platforms/nangate45/config.mk @@ -1,108 +1,3 @@ -# Process node -export PROCESS = 45 - -#----------------------------------------------------- -# Tech/Libs -# ---------------------------------------------------- -export TECH_LEF = $(PLATFORM_DIR)/lef/NangateOpenCellLibrary.tech.lef -export SC_LEF = $(PLATFORM_DIR)/lef/NangateOpenCellLibrary.macro.mod.lef - -export LIB_FILES = $(PLATFORM_DIR)/lib/NangateOpenCellLibrary_typical.lib \ - $(ADDITIONAL_LIBS) -export GDS_FILES = $(sort $(wildcard $(PLATFORM_DIR)/gds/*.gds)) \ - $(ADDITIONAL_GDS) -# Dont use cells to ease congestion -# Specify at least one filler cell if none -export DONT_USE_CELLS = TAPCELL_X1 FILLCELL_X1 AOI211_X1 OAI211_X1 - -# Fill cells used in fill cell insertion -export FILL_CELLS ?= FILLCELL_X1 FILLCELL_X2 FILLCELL_X4 FILLCELL_X8 FILLCELL_X16 FILLCELL_X32 - -# ----------------------------------------------------- -# Yosys -# ---------------------------------------------------- -# Ungroup size for hierarchical synthesis -export SYNTH_MINIMUM_KEEP_SIZE ?= 10000 -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT = LOGIC1_X1 Z -export TIELO_CELL_AND_PORT = LOGIC0_X1 Z - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS = BUF_X1 A Z - - -# Yosys mapping files -export LATCH_MAP_FILE = $(PLATFORM_DIR)/cells_latch.v -export CLKGATE_MAP_FILE = $(PLATFORM_DIR)/cells_clkgate.v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/cells_adders.v -# -export ABC_DRIVER_CELL = BUF_X1 -# BUF_X1, pin (A) = 0.974659. Arbitrarily multiply by 4 -export ABC_LOAD_IN_FF = 3.898 - -#-------------------------------------------------------- -# Floorplan -# ------------------------------------------------------- - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE = FreePDK45_38x28_10R_NP_162NW_34O - -# IO Placer pin layers -export IO_PLACER_H ?= metal5 -export IO_PLACER_V ?= metal6 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/grid_strategy-M1-M4-M7.tcl - -# Endcap and Welltie cells -export TAPCELL_TCL ?= $(PLATFORM_DIR)/tapcell.tcl -export TAP_CELL_NAME = TAPCELL_X1 - -export MACRO_PLACE_HALO ?= 22.4 15.12 - -#--------------------------------------------------------- -# Place -# -------------------------------------------------------- -export PLACE_DENSITY ?= 0.30 - -# --------------------------------------------------------- -# Route -# --------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER = metal2 -export MIN_CLK_ROUTING_LAYER = metal4 -export MAX_ROUTING_LAYER = metal10 - -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/FreePDK45.lyt - -# KLayout DRC ruledeck -export KLAYOUT_DRC_FILE = $(PLATFORM_DIR)/drc/FreePDK45.lydrc - -# KLayout LVS ruledeck -export KLAYOUT_LVS_FILE = $(PLATFORM_DIR)/lvs/FreePDK45.lylvs - -# Allow empty GDS cell -export GDS_ALLOW_EMPTY ?= fakeram.* - -export CDL_FILE = $(PLATFORM_DIR)/cdl/NangateOpenCellLibrary.cdl - -# Template definition for power grid analysis -export TEMPLATE_PGA_CFG ?= $(PLATFORM_DIR)/template_pga.cfg - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD 1.1 -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= metal1 +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/nangate45/config.py b/flow/platforms/nangate45/config.py new file mode 100755 index 0000000000..55d4f18774 --- /dev/null +++ b/flow/platforms/nangate45/config.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Platform configuration for nangate45. + +Generates the same variable assignments as config.mk. +Called by Make via $(shell) or by bazel-orfs for JSON output. + +Usage: + python config.py # Make-compatible output + python config.py --format=json # JSON dict for bazel-orfs +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + + # Process node + cfg.set("PROCESS", "45") + + # Tech/Libs + cfg.set("TECH_LEF", f"{pd}/lef/NangateOpenCellLibrary.tech.lef") + cfg.set("SC_LEF", f"{pd}/lef/NangateOpenCellLibrary.macro.mod.lef") + + lib_files = f"{pd}/lib/NangateOpenCellLibrary_typical.lib" + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + lib_files += f" {additional_libs}" + cfg.set("LIB_FILES", lib_files) + + gds = cfg.sorted_glob(f"{pd}/gds/*.gds") + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + gds += f" {additional_gds}" + cfg.set("GDS_FILES", gds) + + cfg.set("DONT_USE_CELLS", "TAPCELL_X1 FILLCELL_X1 AOI211_X1 OAI211_X1") + + # Fill cells + cfg.set( + "FILL_CELLS", + "FILLCELL_X1 FILLCELL_X2 FILLCELL_X4 FILLCELL_X8 FILLCELL_X16 FILLCELL_X32", + conditional=True, + ) + + # Yosys + cfg.set("SYNTH_MINIMUM_KEEP_SIZE", "10000", conditional=True) + cfg.set("TIEHI_CELL_AND_PORT", "LOGIC1_X1 Z") + cfg.set("TIELO_CELL_AND_PORT", "LOGIC0_X1 Z") + cfg.set("MIN_BUF_CELL_AND_PORTS", "BUF_X1 A Z") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch.v") + cfg.set("CLKGATE_MAP_FILE", f"{pd}/cells_clkgate.v") + cfg.set("ADDER_MAP_FILE", f"{pd}/cells_adders.v", conditional=True) + + cfg.set("ABC_DRIVER_CELL", "BUF_X1") + cfg.set("ABC_LOAD_IN_FF", "3.898") + + # Floorplan + cfg.set("PLACE_SITE", "FreePDK45_38x28_10R_NP_162NW_34O") + cfg.set("IO_PLACER_H", "metal5", conditional=True) + cfg.set("IO_PLACER_V", "metal6", conditional=True) + cfg.set("PDN_TCL", f"{pd}/grid_strategy-M1-M4-M7.tcl", conditional=True) + cfg.set("TAPCELL_TCL", f"{pd}/tapcell.tcl", conditional=True) + cfg.set("TAP_CELL_NAME", "TAPCELL_X1") + cfg.set("MACRO_PLACE_HALO", "22.4 15.12", conditional=True) + + # Place + cfg.set("PLACE_DENSITY", "0.30", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "metal2") + cfg.set("MIN_CLK_ROUTING_LAYER", "metal4") + cfg.set("MAX_ROUTING_LAYER", "metal10") + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/FreePDK45.lyt") + cfg.set("KLAYOUT_DRC_FILE", f"{pd}/drc/FreePDK45.lydrc") + cfg.set("KLAYOUT_LVS_FILE", f"{pd}/lvs/FreePDK45.lylvs") + + # Allow empty GDS cell + cfg.set("GDS_ALLOW_EMPTY", "fakeram.*", conditional=True) + + cfg.set("CDL_FILE", f"{pd}/cdl/NangateOpenCellLibrary.cdl") + cfg.set("TEMPLATE_PGA_CFG", f"{pd}/template_pga.cfg", conditional=True) + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # IR Drop + cfg.set("PWR_NETS_VOLTAGES", "VDD 1.1", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "metal1", conditional=True) + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/sky130hd/config.mk b/flow/platforms/sky130hd/config.mk index d8a7f998fd..d61901351a 100644 --- a/flow/platforms/sky130hd/config.mk +++ b/flow/platforms/sky130hd/config.mk @@ -1,153 +1,3 @@ -# Process node -export PROCESS = 130 - -#----------------------------------------------------- -# Tech/Libs -# ---------------------------------------------------- -export TECH_LEF = $(PLATFORM_DIR)/lef/sky130_fd_sc_hd.tlef -export SC_LEF = $(PLATFORM_DIR)/lef/sky130_fd_sc_hd_merged.lef - -export LIB_FILES = $(PLATFORM_DIR)/lib/sky130_fd_sc_hd__tt_025C_1v80.lib \ - $(ADDITIONAL_LIBS) -export GDS_FILES = $(wildcard $(PLATFORM_DIR)/gds/*.gds) \ - $(ADDITIONAL_GDS) - -# Dont use cells to ease congestion -# Specify at least one filler cell if none - -# The *probe* are for inserting probe points and have metal shapes -# on all layers. -# *lpflow* cells are for multi-power domains -export DONT_USE_CELLS += \ - sky130_fd_sc_hd__probe_p_8 sky130_fd_sc_hd__probec_p_8 \ - sky130_fd_sc_hd__lpflow_bleeder_1 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_1 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_16 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_2 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_4 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_8 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_1 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_16 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_2 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_4 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_8 \ - sky130_fd_sc_hd__lpflow_decapkapwr_12 \ - sky130_fd_sc_hd__lpflow_decapkapwr_3 \ - sky130_fd_sc_hd__lpflow_decapkapwr_4 \ - sky130_fd_sc_hd__lpflow_decapkapwr_6 \ - sky130_fd_sc_hd__lpflow_decapkapwr_8 \ - sky130_fd_sc_hd__lpflow_inputiso0n_1 \ - sky130_fd_sc_hd__lpflow_inputiso0p_1 \ - sky130_fd_sc_hd__lpflow_inputiso1n_1 \ - sky130_fd_sc_hd__lpflow_inputiso1p_1 \ - sky130_fd_sc_hd__lpflow_inputisolatch_1 \ - sky130_fd_sc_hd__lpflow_isobufsrc_1 \ - sky130_fd_sc_hd__lpflow_isobufsrc_16 \ - sky130_fd_sc_hd__lpflow_isobufsrc_2 \ - sky130_fd_sc_hd__lpflow_isobufsrc_4 \ - sky130_fd_sc_hd__lpflow_isobufsrc_8 \ - sky130_fd_sc_hd__lpflow_isobufsrckapwr_16 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_1 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_2 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_4 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_4 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_1 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_2 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_4 -# -# Define fill cells -export FILL_CELLS ?= sky130_fd_sc_hd__fill_1 sky130_fd_sc_hd__fill_2 sky130_fd_sc_hd__fill_4 sky130_fd_sc_hd__fill_8 - -# ----------------------------------------------------- -# Yosys -# ---------------------------------------------------- -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT = sky130_fd_sc_hd__conb_1 HI -export TIELO_CELL_AND_PORT = sky130_fd_sc_hd__conb_1 LO - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS = sky130_fd_sc_hd__buf_4 A X - -# Yosys mapping files -export LATCH_MAP_FILE = $(PLATFORM_DIR)/cells_latch_hd.v -export CLKGATE_MAP_FILE = $(PLATFORM_DIR)/cells_clkgate_hd.v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/cells_adders_hd.v - -# Define ABC driver and load -export ABC_DRIVER_CELL = sky130_fd_sc_hd__buf_1 -export ABC_LOAD_IN_FF = 5 - -# ----------------------------------------------------- -# Sizing -# ----------------------------------------------------- - -export MATCH_CELL_FOOTPRINT = 1 - -#-------------------------------------------------------- -# Floorplan -# ------------------------------------------------------- - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE = unithd - -# IO Placer pin layers -export IO_PLACER_H ?= met3 -export IO_PLACER_V ?= met2 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/pdn.tcl - -# Endcap and Welltie cells -export TAP_CELL_NAME = sky130_fd_sc_hd__tapvpwrvgnd_1 -export TAPCELL_TCL ?= $(PLATFORM_DIR)/tapcell.tcl - -export MACRO_PLACE_HALO ?= 40 40 - -#--------------------------------------------------------- -# Place -# -------------------------------------------------------- -export PLACE_DENSITY ?= 0.60 - -# --------------------------------------------------------- -# Route -# --------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER ?= met1 -export MIN_CLK_ROUTING_LAYER ?= met3 -export MAX_ROUTING_LAYER ?= met5 - -# -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/$(PLATFORM).lyt -# -# Rules for metal fill -export FILL_CONFIG = $(PLATFORM_DIR)/fill.json -# -# Template definition for power grid analysis -export TEMPLATE_PGA_CFG ?= $(PLATFORM_DIR)/template_pga.cfg - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules - -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD 1.8 -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= met1 - -# DRC Check -export KLAYOUT_DRC_FILE = $(PLATFORM_DIR)/drc/$(PLATFORM).lydrc - -#LVS Check -export CDL_FILE = $(PLATFORM_DIR)/cdl/$(PLATFORM).cdl -export KLAYOUT_LVS_FILE = $(PLATFORM_DIR)/lvs/$(PLATFORM).lylvs -export REMOVE_CELLS_FOR_LEC = sky130_fd_sc_hd__tapvpwrvgnd* +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/sky130hd/config.py b/flow/platforms/sky130hd/config.py new file mode 100755 index 0000000000..ee8738be6f --- /dev/null +++ b/flow/platforms/sky130hd/config.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 +"""Platform configuration for sky130hd. + +Generates the same variable assignments as config.mk. +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + platform = cfg.env("PLATFORM", "sky130hd") + + # Process node + cfg.set("PROCESS", "130") + + # Tech/Libs + cfg.set("TECH_LEF", f"{pd}/lef/sky130_fd_sc_hd.tlef") + cfg.set("SC_LEF", f"{pd}/lef/sky130_fd_sc_hd_merged.lef") + + lib_files = f"{pd}/lib/sky130_fd_sc_hd__tt_025C_1v80.lib" + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + lib_files += f" {additional_libs}" + cfg.set("LIB_FILES", lib_files) + + gds = cfg.wildcard_glob(f"{pd}/gds/*.gds") + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + gds += f" {additional_gds}" + cfg.set("GDS_FILES", gds) + + # Dont use cells + cfg.append( + "DONT_USE_CELLS", + "sky130_fd_sc_hd__probe_p_8 sky130_fd_sc_hd__probec_p_8 " + "sky130_fd_sc_hd__lpflow_bleeder_1 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_1 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_16 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_2 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_4 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_8 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_1 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_16 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_2 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_4 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_8 " + "sky130_fd_sc_hd__lpflow_decapkapwr_12 " + "sky130_fd_sc_hd__lpflow_decapkapwr_3 " + "sky130_fd_sc_hd__lpflow_decapkapwr_4 " + "sky130_fd_sc_hd__lpflow_decapkapwr_6 " + "sky130_fd_sc_hd__lpflow_decapkapwr_8 " + "sky130_fd_sc_hd__lpflow_inputiso0n_1 " + "sky130_fd_sc_hd__lpflow_inputiso0p_1 " + "sky130_fd_sc_hd__lpflow_inputiso1n_1 " + "sky130_fd_sc_hd__lpflow_inputiso1p_1 " + "sky130_fd_sc_hd__lpflow_inputisolatch_1 " + "sky130_fd_sc_hd__lpflow_isobufsrc_1 " + "sky130_fd_sc_hd__lpflow_isobufsrc_16 " + "sky130_fd_sc_hd__lpflow_isobufsrc_2 " + "sky130_fd_sc_hd__lpflow_isobufsrc_4 " + "sky130_fd_sc_hd__lpflow_isobufsrc_8 " + "sky130_fd_sc_hd__lpflow_isobufsrckapwr_16 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_1 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_2 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_4 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_4 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_1 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_2 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_4", + ) + + # Fill cells + cfg.set( + "FILL_CELLS", + "sky130_fd_sc_hd__fill_1 sky130_fd_sc_hd__fill_2 sky130_fd_sc_hd__fill_4 sky130_fd_sc_hd__fill_8", + conditional=True, + ) + + # Yosys + cfg.set("TIEHI_CELL_AND_PORT", "sky130_fd_sc_hd__conb_1 HI") + cfg.set("TIELO_CELL_AND_PORT", "sky130_fd_sc_hd__conb_1 LO") + cfg.set("MIN_BUF_CELL_AND_PORTS", "sky130_fd_sc_hd__buf_4 A X") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch_hd.v") + cfg.set("CLKGATE_MAP_FILE", f"{pd}/cells_clkgate_hd.v") + cfg.set("ADDER_MAP_FILE", f"{pd}/cells_adders_hd.v", conditional=True) + + cfg.set("ABC_DRIVER_CELL", "sky130_fd_sc_hd__buf_1") + cfg.set("ABC_LOAD_IN_FF", "5") + + # Sizing + cfg.set("MATCH_CELL_FOOTPRINT", "1") + + # Floorplan + cfg.set("PLACE_SITE", "unithd") + cfg.set("IO_PLACER_H", "met3", conditional=True) + cfg.set("IO_PLACER_V", "met2", conditional=True) + cfg.set("PDN_TCL", f"{pd}/pdn.tcl", conditional=True) + cfg.set("TAP_CELL_NAME", "sky130_fd_sc_hd__tapvpwrvgnd_1") + cfg.set("TAPCELL_TCL", f"{pd}/tapcell.tcl", conditional=True) + cfg.set("MACRO_PLACE_HALO", "40 40", conditional=True) + + # Place + cfg.set("PLACE_DENSITY", "0.60", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "met1", conditional=True) + cfg.set("MIN_CLK_ROUTING_LAYER", "met3", conditional=True) + cfg.set("MAX_ROUTING_LAYER", "met5", conditional=True) + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/{platform}.lyt") + cfg.set("FILL_CONFIG", f"{pd}/fill.json") + cfg.set("TEMPLATE_PGA_CFG", f"{pd}/template_pga.cfg", conditional=True) + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # IR Drop + cfg.set("PWR_NETS_VOLTAGES", "VDD 1.8", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "met1", conditional=True) + + # DRC/LVS + cfg.set("KLAYOUT_DRC_FILE", f"{pd}/drc/{platform}.lydrc") + cfg.set("CDL_FILE", f"{pd}/cdl/{platform}.cdl") + cfg.set("KLAYOUT_LVS_FILE", f"{pd}/lvs/{platform}.lylvs") + cfg.set("REMOVE_CELLS_FOR_LEC", "sky130_fd_sc_hd__tapvpwrvgnd*") + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/sky130hs/config.mk b/flow/platforms/sky130hs/config.mk index 1cf050536c..d61901351a 100644 --- a/flow/platforms/sky130hs/config.mk +++ b/flow/platforms/sky130hs/config.mk @@ -1,108 +1,3 @@ -# Process node -export PROCESS = 130 - -#----------------------------------------------------- -# Tech/Libs -# ---------------------------------------------------- -export TECH_LEF = $(PLATFORM_DIR)/lef/sky130_fd_sc_hs.tlef -export SC_LEF = $(PLATFORM_DIR)/lef/sky130_fd_sc_hs_merged.lef - -export LIB_FILES = $(PLATFORM_DIR)/lib/sky130_fd_sc_hs__tt_025C_1v80.lib \ - $(ADDITIONAL_LIBS) -export GDS_FILES = $(wildcard $(PLATFORM_DIR)/gds/*.gds) \ - $(ADDITIONAL_GDS) - -# Dont use cells to ease congestion -# Specify at least one filler cell if none -export DONT_USE_CELLS += - -# Define fill cells -export FILL_CELLS ?= sky130_fd_sc_hs__fill_1 sky130_fd_sc_hs__fill_2 sky130_fd_sc_hs__fill_4 sky130_fd_sc_hs__fill_8 - -# ----------------------------------------------------- -# Yosys -# ---------------------------------------------------- -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT = sky130_fd_sc_hs__conb_1 HI -export TIELO_CELL_AND_PORT = sky130_fd_sc_hs__conb_1 LO - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS = sky130_fd_sc_hs__buf_4 A X - - -# Yosys mapping files -export LATCH_MAP_FILE = $(PLATFORM_DIR)/cells_latch_hs.v -export CLKGATE_MAP_FILE = $(PLATFORM_DIR)/cells_clkgate_hs.v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/cells_adders_hs.v -# -# Define ABC driver and load -export ABC_DRIVER_CELL = sky130_fd_sc_hs__buf_1 -export ABC_LOAD_IN_FF = 5 - -# ----------------------------------------------------- -# Sizing -# ----------------------------------------------------- - -export MATCH_CELL_FOOTPRINT = 1 - -#-------------------------------------------------------- -# Floorplan -# ------------------------------------------------------- - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE = unit - -# IO Placer pin layers -export IO_PLACER_H ?= met3 -export IO_PLACER_V ?= met2 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/pdn.tcl - -# Endcap and Welltie cells -export TAP_CELL_NAME = sky130_fd_sc_hs__tapvpwrvgnd_1 -export TAPCELL_TCL ?= $(PLATFORM_DIR)/tapcell.tcl - -export MACRO_PLACE_HALO ?= 40 40 - -#--------------------------------------------------------- -# Place -# -------------------------------------------------------- -export PLACE_DENSITY ?= 0.50 - -# --------------------------------------------------------- -# Route -# --------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER = met1 -export MIN_CLK_ROUTING_LAYER = met3 -export MAX_ROUTING_LAYER = met5 - -# -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/$(PLATFORM).lyt -# -# Rules for metal fill -export FILL_CONFIG = $(PLATFORM_DIR)/fill.json -# -# Template definition for power grid analysis -export TEMPLATE_PGA_CFG ?= $(PLATFORM_DIR)/template_pga.cfg - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD 1.8 -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= met1 -export REMOVE_CELLS_FOR_LEC = sky130_fd_sc_hs__tapvpwrvgnd* \ No newline at end of file +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/sky130hs/config.py b/flow/platforms/sky130hs/config.py new file mode 100755 index 0000000000..2848807ebf --- /dev/null +++ b/flow/platforms/sky130hs/config.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +"""Platform configuration for sky130hs. + +Generates the same variable assignments as config.mk. +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + platform = cfg.env("PLATFORM", "sky130hs") + + # Process node + cfg.set("PROCESS", "130") + + # Tech/Libs + cfg.set("TECH_LEF", f"{pd}/lef/sky130_fd_sc_hs.tlef") + cfg.set("SC_LEF", f"{pd}/lef/sky130_fd_sc_hs_merged.lef") + + lib_files = f"{pd}/lib/sky130_fd_sc_hs__tt_025C_1v80.lib" + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + lib_files += f" {additional_libs}" + cfg.set("LIB_FILES", lib_files) + + gds = cfg.wildcard_glob(f"{pd}/gds/*.gds") + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + gds += f" {additional_gds}" + cfg.set("GDS_FILES", gds) + + # DONT_USE_CELLS += (empty in sky130hs) + # Only append if there's something to append from env + dont_use = cfg.env("DONT_USE_CELLS") + if dont_use: + cfg.set("DONT_USE_CELLS", dont_use) + + # Fill cells + cfg.set( + "FILL_CELLS", + "sky130_fd_sc_hs__fill_1 sky130_fd_sc_hs__fill_2 sky130_fd_sc_hs__fill_4 sky130_fd_sc_hs__fill_8", + conditional=True, + ) + + # Yosys + cfg.set("TIEHI_CELL_AND_PORT", "sky130_fd_sc_hs__conb_1 HI") + cfg.set("TIELO_CELL_AND_PORT", "sky130_fd_sc_hs__conb_1 LO") + cfg.set("MIN_BUF_CELL_AND_PORTS", "sky130_fd_sc_hs__buf_4 A X") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch_hs.v") + cfg.set("CLKGATE_MAP_FILE", f"{pd}/cells_clkgate_hs.v") + cfg.set("ADDER_MAP_FILE", f"{pd}/cells_adders_hs.v", conditional=True) + + cfg.set("ABC_DRIVER_CELL", "sky130_fd_sc_hs__buf_1") + cfg.set("ABC_LOAD_IN_FF", "5") + + # Sizing + cfg.set("MATCH_CELL_FOOTPRINT", "1") + + # Floorplan + cfg.set("PLACE_SITE", "unit") + cfg.set("IO_PLACER_H", "met3", conditional=True) + cfg.set("IO_PLACER_V", "met2", conditional=True) + cfg.set("PDN_TCL", f"{pd}/pdn.tcl", conditional=True) + cfg.set("TAP_CELL_NAME", "sky130_fd_sc_hs__tapvpwrvgnd_1") + cfg.set("TAPCELL_TCL", f"{pd}/tapcell.tcl", conditional=True) + cfg.set("MACRO_PLACE_HALO", "40 40", conditional=True) + + # Place + cfg.set("PLACE_DENSITY", "0.50", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "met1") + cfg.set("MIN_CLK_ROUTING_LAYER", "met3") + cfg.set("MAX_ROUTING_LAYER", "met5") + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/{platform}.lyt") + cfg.set("FILL_CONFIG", f"{pd}/fill.json") + cfg.set("TEMPLATE_PGA_CFG", f"{pd}/template_pga.cfg", conditional=True) + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # IR Drop + cfg.set("PWR_NETS_VOLTAGES", "VDD 1.8", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "met1", conditional=True) + + cfg.set("REMOVE_CELLS_FOR_LEC", "sky130_fd_sc_hs__tapvpwrvgnd*") + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/scripts/platform_config_utils.py b/flow/scripts/platform_config_utils.py new file mode 100644 index 0000000000..da485e3d57 --- /dev/null +++ b/flow/scripts/platform_config_utils.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python3 +"""Shared utilities for platform config.py files. + +Each platform's config.py uses PlatformConfig to accumulate variables +and output them in Make-compatible or JSON format. This follows the +same pattern as defaults.py: Python generates Make code that Make +$(eval)s back into itself. +""" + +import glob +import json +import os +import sys + + +class PlatformConfig: + """Accumulates platform configuration variables and outputs them. + + Maintains ordered list of (key, value, conditional) tuples. + conditional=True means ?= (only set if not already defined). + conditional=False means = (unconditional assignment). + """ + + def __init__(self, platform_dir=None): + if platform_dir is not None: + self.platform_dir = platform_dir + else: + self.platform_dir = os.environ.get( + "PLATFORM_DIR", + os.path.dirname( + os.path.abspath(sys._getframe(1).f_globals["__file__"]) + ), + ) + self._vars = [] # ordered list of (key, value, conditional) + self._index = {} # key -> index in _vars for fast lookup + + def env(self, key, default=""): + """Read a variable from the environment.""" + return os.environ.get(key, default) + + def set(self, key, value, conditional=False): + """Set a variable. conditional=True means ?= semantics.""" + value = str(value) + if conditional and key in self._index: + # Already set internally, skip conditional + return + if conditional and key in os.environ: + # Already set in environment, use env value + value = os.environ[key] + conditional = False + if key in self._index: + self._vars[self._index[key]] = (key, value, conditional) + else: + self._index[key] = len(self._vars) + self._vars.append((key, value, conditional)) + + def append(self, key, value): + """Append to a variable (like Make +=). + + If the key exists internally, appends to that value. + Otherwise reads current value from environment first. + """ + value = str(value) + if key in self._index: + existing = self._vars[self._index[key]][1] + combined = (existing + " " + value).strip() + self._vars[self._index[key]] = (key, combined, False) + else: + existing = os.environ.get(key, "") + combined = (existing + " " + value).strip() + self._index[key] = len(self._vars) + self._vars.append((key, combined, False)) + + def get(self, key, default=""): + """Get a variable's current value (from internal state).""" + if key in self._index: + return self._vars[self._index[key]][1] + return default + + def sorted_glob(self, pattern): + """sorted(glob.glob(pattern)) -- replaces $(sort $(wildcard ...))""" + return " ".join(sorted(glob.glob(pattern))) + + def wildcard_glob(self, pattern): + """glob.glob(pattern) -- replaces $(wildcard ...)""" + return " ".join(glob.glob(pattern)) + + def output_make(self): + """Print Make-compatible output lines. + + Format matches defaults.py: export KEY=VALUE or export KEY?=VALUE + with spaces replaced by __SPACE__. + """ + for key, value, conditional in self._vars: + op = "?=" if conditional else "=" + encoded = value.replace(" ", "__SPACE__") + print(f"export {key}{op}{encoded}") + + def output_json(self): + """Print flat JSON dict for bazel-orfs or other consumers.""" + result = {} + for key, value, _conditional in self._vars: + result[key] = value + json.dump(result, sys.stdout, indent=2) + print() # trailing newline + + def output(self): + """Select output mode based on --format=json argument.""" + if "--format=json" in sys.argv: + self.output_json() + else: + self.output_make() + + def to_dict(self): + """Return flat dict of all variables (for testing).""" + result = {} + for key, value, _conditional in self._vars: + result[key] = value + return result From ff3661cdf6225b23377ef2b735b312aad3e4efcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 18 Mar 2026 22:35:34 +0100 Subject: [PATCH 3/9] flow: add 137 unit tests for platform config.py files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests cover all Make constructs used across the 6 platform config.mk files: unconditional/conditional assignment, +=, glob, ifeq/ifneq, variable indirection, PLACEHOLDER template expansion, foreach/eval VT loop, SDC clock extraction, corner selection, CLUSTER_FLOPS, design-config overrides, and Make shim round-trip format validation. Includes __main__ guard so Jenkins CI can run it with plain python. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- flow/test/conftest.py | 7 + flow/test/test_platform_config.py | 1198 +++++++++++++++++++++++++++++ 2 files changed, 1205 insertions(+) create mode 100644 flow/test/conftest.py create mode 100644 flow/test/test_platform_config.py diff --git a/flow/test/conftest.py b/flow/test/conftest.py new file mode 100644 index 0000000000..8d8f9a6425 --- /dev/null +++ b/flow/test/conftest.py @@ -0,0 +1,7 @@ +import pytest + + +def pytest_configure(config): + config.addinivalue_line( + "markers", "integration: mark test as integration test (requires Make)" + ) diff --git a/flow/test/test_platform_config.py b/flow/test/test_platform_config.py new file mode 100644 index 0000000000..43869ca2f3 --- /dev/null +++ b/flow/test/test_platform_config.py @@ -0,0 +1,1198 @@ +#!/usr/bin/env python3 +"""Tests for platform config.py files. + +Covers every Make construct used across all 6 platform config.mk files. +Tests are organized by use-case (Make construct) and by platform. + +Run: pytest flow/test/test_platform_config.py -v +Integration: pytest flow/test/test_platform_config.py -v -m integration +""" + +import json +import os +import subprocess +import sys +import textwrap + +import pytest + +# Add scripts dir to path for imports +FLOW_DIR = os.path.join(os.path.dirname(__file__), "..") +sys.path.insert(0, os.path.join(FLOW_DIR, "scripts")) + +from platform_config_utils import PlatformConfig + +# Import platform config modules +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "nangate45")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "sky130hs")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "sky130hd")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "gf180")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "ihp-sg13g2")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "asap7")) + +# We import via importlib to handle the hyphenated directory name +import importlib.util + + +def _load_config_module(platform_name): + """Load a platform's config.py module by path.""" + if platform_name == "ihp-sg13g2": + dirname = "ihp-sg13g2" + else: + dirname = platform_name + spec = importlib.util.spec_from_file_location( + f"config_{platform_name.replace('-', '_')}", + os.path.join(FLOW_DIR, "platforms", dirname, "config.py"), + ) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod + + +nangate45_config = _load_config_module("nangate45") +sky130hs_config = _load_config_module("sky130hs") +sky130hd_config = _load_config_module("sky130hd") +gf180_config = _load_config_module("gf180") +ihp_config = _load_config_module("ihp-sg13g2") +asap7_config = _load_config_module("asap7") + +PLATFORMS = ["nangate45", "sky130hs", "sky130hd", "gf180", "ihp-sg13g2", "asap7"] +PLATFORM_MODULES = { + "nangate45": nangate45_config, + "sky130hs": sky130hs_config, + "sky130hd": sky130hd_config, + "gf180": gf180_config, + "ihp-sg13g2": ihp_config, + "asap7": asap7_config, +} + + +# --------------------------------------------------------------------------- +# Helpers +# --------------------------------------------------------------------------- +def get_platform_dir(platform): + return os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) + + +def clean_env(monkeypatch, platform, extras=None): + """Set up a clean environment for testing a platform config.""" + pd = get_platform_dir(platform) + monkeypatch.setenv("PLATFORM_DIR", pd) + monkeypatch.setenv("PLATFORM", platform) + # Remove variables that might leak from the real environment + for var in [ + "ADDITIONAL_LIBS", + "ADDITIONAL_GDS", + "ADDITIONAL_LEFS", + "BLOCKS", + "CORNER", + "ASAP7_USE_VT", + "LIB_MODEL", + "CLUSTER_FLOPS", + "FOOTPRINT_TCL", + "LOAD_ADDITIONAL_FILES", + "TRACK_OPTION", + "METAL_OPTION", + "KVALUE", + "POWER_OPTION", + "SDC_FILE", + "ABC_CLOCK_PERIOD_IN_PS", + "DONT_USE_CELLS", + "BC_ADDITIONAL_LIBS", + "ADDITIONAL_SLOW_LIBS", + "ADDITIONAL_FAST_LIBS", + "ADDITIONAL_TYP_LIBS", + ]: + monkeypatch.delenv(var, raising=False) + if extras: + for k, v in extras.items(): + monkeypatch.setenv(k, v) + + +# =================================================================== +# 1. PlatformConfig utility tests +# =================================================================== +class TestPlatformConfigUtility: + """Test the shared PlatformConfig class in isolation.""" + + def test_set_unconditional(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "bar") + d = cfg.to_dict() + assert d["FOO"] == "bar" + + def test_set_conditional_default(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "default_val", conditional=True) + d = cfg.to_dict() + assert d["FOO"] == "default_val" + + def test_set_conditional_override_from_env(self, monkeypatch): + monkeypatch.setenv("FOO", "from_env") + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "default_val", conditional=True) + d = cfg.to_dict() + assert d["FOO"] == "from_env" + + def test_set_conditional_does_not_overwrite_internal(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "first") + cfg.set("FOO", "second", conditional=True) + d = cfg.to_dict() + assert d["FOO"] == "first" + + def test_append_internal(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "a b") + cfg.append("FOO", "c d") + d = cfg.to_dict() + assert d["FOO"] == "a b c d" + + def test_append_from_env(self, monkeypatch): + monkeypatch.setenv("FOO", "from_env") + cfg = PlatformConfig(platform_dir="/fake") + cfg.append("FOO", "extra") + d = cfg.to_dict() + assert d["FOO"] == "from_env extra" + + def test_append_new_var(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.append("FOO", "value") + d = cfg.to_dict() + assert d["FOO"] == "value" + + def test_get(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "bar") + assert cfg.get("FOO") == "bar" + assert cfg.get("MISSING", "default") == "default" + + def test_output_make(self, capsys): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("SIMPLE", "value") + cfg.set("SPACES", "a b c") + cfg.set("COND", "default", conditional=True) + cfg.output_make() + out = capsys.readouterr().out + lines = out.strip().split("\n") + assert "export SIMPLE=value" in lines + assert "export SPACES=a__SPACE__b__SPACE__c" in lines + assert "export COND?=default" in lines + + def test_output_json(self, capsys): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("KEY1", "val1") + cfg.set("KEY2", "val2") + cfg.output_json() + out = capsys.readouterr().out + data = json.loads(out) + assert data["KEY1"] == "val1" + assert data["KEY2"] == "val2" + + def test_sorted_glob(self, tmp_path): + # Create some files + (tmp_path / "c.gds").touch() + (tmp_path / "a.gds").touch() + (tmp_path / "b.gds").touch() + cfg = PlatformConfig(platform_dir="/fake") + result = cfg.sorted_glob(str(tmp_path / "*.gds")) + files = result.split() + assert len(files) == 3 + assert files[0].endswith("a.gds") + assert files[1].endswith("b.gds") + assert files[2].endswith("c.gds") + + def test_wildcard_glob(self, tmp_path): + (tmp_path / "x.gds").touch() + (tmp_path / "y.gds").touch() + cfg = PlatformConfig(platform_dir="/fake") + result = cfg.wildcard_glob(str(tmp_path / "*.gds")) + files = result.split() + assert len(files) == 2 + + +# =================================================================== +# 2. Per-platform unit tests -- use-case coverage +# =================================================================== + + +# --- Test 1: Unconditional assignment (export VAR = value) --- +class TestUnconditionalAssignment: + @pytest.mark.parametrize( + "platform,key,expected_substr", + [ + ("nangate45", "PROCESS", "45"), + ("sky130hs", "PROCESS", "130"), + ("sky130hd", "PROCESS", "130"), + ("gf180", "PROCESS", "180"), + ("ihp-sg13g2", "PROCESS", "ihp-sg13g2"), + ("asap7", "PROCESS", "7"), + ], + ) + def test_unconditional_assignment( + self, monkeypatch, platform, key, expected_substr + ): + clean_env(monkeypatch, platform) + cfg = PLATFORM_MODULES[platform].get_config() + d = cfg.to_dict() + assert d[key] == expected_substr + + +# --- Test 2: Conditional assignment (export VAR ?= value) --- +class TestConditionalAssignment: + @pytest.mark.parametrize( + "platform,key,default_val", + [ + ("nangate45", "PLACE_DENSITY", "0.30"), + ("sky130hs", "PLACE_DENSITY", "0.50"), + ("sky130hd", "PLACE_DENSITY", "0.60"), + ("gf180", "PLACE_DENSITY", "0.40"), + ("ihp-sg13g2", "PLACE_DENSITY", "0.65"), + ("asap7", "PLACE_DENSITY", "0.60"), + ], + ) + def test_conditional_assignment_default( + self, monkeypatch, platform, key, default_val + ): + clean_env(monkeypatch, platform) + cfg = PLATFORM_MODULES[platform].get_config() + d = cfg.to_dict() + assert d[key] == default_val + + @pytest.mark.parametrize("platform", PLATFORMS) + def test_conditional_assignment_override(self, monkeypatch, platform): + clean_env(monkeypatch, platform, {"PLACE_DENSITY": "0.99"}) + cfg = PLATFORM_MODULES[platform].get_config() + d = cfg.to_dict() + assert d["PLACE_DENSITY"] == "0.99" + + +# --- Test 3: Internal append (VAR += value within same config) --- +class TestInternalAppend: + def test_asap7_dont_use_cells_internal_append(self, monkeypatch): + """asap7: DONT_USE_CELLS = X then DONT_USE_CELLS += SDF* ICG*""" + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "*x1p*_ASAP7*" in d["DONT_USE_CELLS"] + assert "SDF*" in d["DONT_USE_CELLS"] + assert "ICG*" in d["DONT_USE_CELLS"] + + +# --- Test 4: External append (VAR += from env) --- +class TestExternalAppend: + def test_sky130hd_dont_use_cells_from_env(self, monkeypatch): + """sky130hd: DONT_USE_CELLS += list (appends to env value)""" + clean_env(monkeypatch, "sky130hd", {"DONT_USE_CELLS": "EXISTING_CELL"}) + cfg = sky130hd_config.get_config() + d = cfg.to_dict() + assert "EXISTING_CELL" in d["DONT_USE_CELLS"] + assert "sky130_fd_sc_hd__probe_p_8" in d["DONT_USE_CELLS"] + + def test_ihp_dont_use_cells_from_env(self, monkeypatch): + """ihp-sg13g2: DONT_USE_CELLS += list (appends to env value)""" + clean_env(monkeypatch, "ihp-sg13g2", {"DONT_USE_CELLS": "EXISTING"}) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "EXISTING" in d["DONT_USE_CELLS"] + assert "sg13g2_lgcp_1" in d["DONT_USE_CELLS"] + + +# --- Test 5: $(PLATFORM_DIR)/path expansion --- +class TestPlatformDirExpansion: + @pytest.mark.parametrize( + "platform,key,suffix", + [ + ("nangate45", "TECH_LEF", "/lef/NangateOpenCellLibrary.tech.lef"), + ("sky130hd", "TECH_LEF", "/lef/sky130_fd_sc_hd.tlef"), + ("asap7", "TECH_LEF", "/lef/asap7_tech_1x_201209.lef"), + ], + ) + def test_platform_dir_expansion(self, monkeypatch, platform, key, suffix): + clean_env(monkeypatch, platform) + cfg = PLATFORM_MODULES[platform].get_config() + d = cfg.to_dict() + assert d[key].endswith(suffix) + assert get_platform_dir(platform) in d[key] + + +# --- Test 6: $(sort $(wildcard ...)) --- +class TestSortedGlob: + def test_nangate45_gds_files_sorted(self, monkeypatch): + clean_env(monkeypatch, "nangate45") + cfg = nangate45_config.get_config() + d = cfg.to_dict() + gds = d["GDS_FILES"].split() + # Verify files are sorted + assert gds == sorted(gds) + + +# --- Test 7: $(wildcard ...) --- +class TestWildcardGlob: + def test_sky130hd_gds_files(self, monkeypatch): + clean_env(monkeypatch, "sky130hd") + cfg = sky130hd_config.get_config() + d = cfg.to_dict() + # GDS_FILES should contain at least one .gds file + if d["GDS_FILES"].strip(): + assert ".gds" in d["GDS_FILES"] + + +# --- Test 8: ifeq/ifneq conditionals --- +class TestConditionalIfeq: + def test_gf180_place_site_9t(self, monkeypatch): + """gf180: ifeq ($(TRACK_OPTION),9t) -> GF018hv5v_green_sc9""" + clean_env(monkeypatch, "gf180") + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["PLACE_SITE"] == "GF018hv5v_green_sc9" + + def test_gf180_place_site_7t(self, monkeypatch): + """gf180: else -> GF018hv5v_mcu_sc7""" + clean_env(monkeypatch, "gf180", {"TRACK_OPTION": "7t"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["PLACE_SITE"] == "GF018hv5v_mcu_sc7" + + def test_asap7_pdn_no_blocks(self, monkeypatch): + """asap7: ifeq ($(BLOCKS),) -> grid_strategy-M1-M2-M5-M6.tcl""" + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "grid_strategy-M1-M2-M5-M6.tcl" in d["PDN_TCL"] + + def test_asap7_pdn_with_blocks(self, monkeypatch): + """asap7: BLOCKS set -> BLOCKS_grid_strategy.tcl""" + clean_env(monkeypatch, "asap7", {"BLOCKS": "block1"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "BLOCKS_grid_strategy.tcl" in d["PDN_TCL"] + + +# --- Test 9: $(ADDITIONAL_LIBS) from env --- +class TestEnvVariableInclusion: + def test_nangate45_additional_libs(self, monkeypatch): + clean_env(monkeypatch, "nangate45", {"ADDITIONAL_LIBS": "/extra/lib.lib"}) + cfg = nangate45_config.get_config() + d = cfg.to_dict() + assert "/extra/lib.lib" in d["LIB_FILES"] + assert "NangateOpenCellLibrary_typical.lib" in d["LIB_FILES"] + + +# --- Test 10: $($(CORNER)_LIB_FILES) variable indirection --- +class TestVariableIndirection: + def test_gf180_bc_corner(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "BC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "ff_n40C_5v50" in d["LIB_FILES"] + + def test_gf180_wc_corner(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "WC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "ss_125C_4v50" in d["LIB_FILES"] + + def test_gf180_tc_corner(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "TC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "tt_025C_5v00" in d["LIB_FILES"] + + def test_asap7_bc_nldm_corner(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"CORNER": "BC"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "_FF_nldm_" in d["LIB_FILES"] + + def test_asap7_wc_corner(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"CORNER": "WC"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "_SS_nldm_" in d["LIB_FILES"] + + +# --- Test 11: $(subst PLACEHOLDER,...) template expansion --- +class TestPlaceholderSubstitution: + def test_asap7_placeholder_expansion(self, monkeypatch): + """asap7: $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),...) templates""" + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + # Default VT is RVT -> tag "R" + assert "PLACEHOLDER" not in d.get("BC_NLDM_DFF_LIB_FILE", "") + assert "_RVT_" in d["BC_NLDM_DFF_LIB_FILE"] + assert "_RVT_" in d["BC_NLDM_LIB_FILES"] + + +# --- Test 12: $(patsubst %VT,%,...) --- +class TestPatsubstVtTag: + def test_asap7_vt_tag_derivation(self, monkeypatch): + """RVT -> R, LVT -> L, SLVT -> SL""" + clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "LVT"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + # PRIMARY_VT=LVT -> tag L + assert "_L_" in d["SC_LEF"] or "_L_" in d["GDS_FILES"] + + def test_asap7_slvt_tag(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "SLVT"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "_SL_" in d["SC_LEF"] + + +# --- Test 13: $(word 1,...) --- +class TestWordExtraction: + def test_asap7_primary_vt_is_first(self, monkeypatch): + """PRIMARY_VT = $(word 1, $(VT_LIST))""" + clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "LVT RVT SLVT"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + # Primary should be LVT -> tag L + assert "asap7sc7p5t_28_L_" in d["SC_LEF"] + + +# --- Test 14: $(wordlist 2,N,...) --- +class TestWordlistExtraction: + def test_asap7_other_vt_is_rest(self, monkeypatch): + """OTHER_VT = $(wordlist 2, ..., $(VT_LIST))""" + clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "RVT LVT SLVT"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + # OTHER_VT = [LVT, SLVT], should appear in ADDITIONAL_LEFS + assert "asap7sc7p5t_28_L_1x" in d.get("ADDITIONAL_LEFS", "") + assert "asap7sc7p5t_28_SL_1x" in d.get("ADDITIONAL_LEFS", "") + + +# --- Test 15: $(addsuffix tag,...) --- +class TestAddsuffix: + def test_asap7_fill_cells_suffix(self, monkeypatch): + """FILL_CELLS = $(addsuffix $(PRIMARY_VT_TAG), $(FILL_CELLS_T))""" + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + # Default RVT -> tag R + assert "FILLERxp5_ASAP7_75t_R" in d["FILL_CELLS"] + assert "FILLER_ASAP7_75t_R" in d["FILL_CELLS"] + assert "DECAPx10_ASAP7_75t_R" in d["FILL_CELLS"] + + +# --- Test 16: $(if $(strip $(VAR)),...) --- +class TestIfStrip: + def test_asap7_default_vt_when_unset(self, monkeypatch): + """VT_LIST = $(if $(strip $(ASAP7_USE_VT)), ..., RVT)""" + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + # Should default to RVT -> tag R + assert "asap7sc7p5t_28_R_" in d["GDS_FILES"] + + def test_asap7_vt_when_set(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "LVT"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "asap7sc7p5t_28_L_" in d["GDS_FILES"] + + +# --- Test 17: $(foreach)/$(eval) loop --- +class TestForeachEvalVtExpansion: + def test_asap7_multi_vt_expansion(self, monkeypatch): + """foreach vt in OTHER_VT: expand templates and append""" + clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "RVT LVT SLVT"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + + # Primary VT = RVT (tag R) + assert "asap7sc7p5t_28_R_" in d["GDS_FILES"] + + # OTHER_VT = [LVT, SLVT] should be appended + assert "asap7sc7p5t_28_L_220121a.gds" in d["GDS_FILES"] + assert "asap7sc7p5t_28_SL_220121a.gds" in d["GDS_FILES"] + + # ADDITIONAL_LEFS should have OTHER_VT entries + assert "asap7sc7p5t_28_L_1x_220121a.lef" in d.get("ADDITIONAL_LEFS", "") + assert "asap7sc7p5t_28_SL_1x_220121a.lef" in d.get("ADDITIONAL_LEFS", "") + + # DFF lib files should have all 3 VTs + assert "_RVT_" in d["BC_NLDM_DFF_LIB_FILE"] + assert "_LVT_" in d["BC_NLDM_DFF_LIB_FILE"] + assert "_SLVT_" in d["BC_NLDM_DFF_LIB_FILE"] + + # FILL_CELLS should have all 3 VT suffixes + assert "FILLERxp5_ASAP7_75t_R" in d["FILL_CELLS"] + assert "FILLERxp5_ASAP7_75t_L" in d["FILL_CELLS"] + assert "FILLERxp5_ASAP7_75t_SL" in d["FILL_CELLS"] + + +# --- Test 18: $(strip ...) --- +class TestStrip: + def test_asap7_strip_asap7_use_vt(self, monkeypatch): + """Whitespace in ASAP7_USE_VT should be stripped""" + clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": " RVT "}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "asap7sc7p5t_28_R_" in d["GDS_FILES"] + + +# --- Test 19: $(shell sed ...) SDC clock period extraction --- +class TestSdcClockPeriodExtraction: + def test_ihp_sdc_clk_period(self, monkeypatch, tmp_path): + """ihp-sg13g2: extract clock period from SDC file""" + sdc = tmp_path / "constraint.sdc" + sdc.write_text("set clk_period 10.0\ncreate_clock ...\n") + clean_env(monkeypatch, "ihp-sg13g2", {"SDC_FILE": str(sdc)}) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert d["ABC_CLOCK_PERIOD_IN_PS"] == "10000.0" + + def test_ihp_sdc_period_flag(self, monkeypatch, tmp_path): + """ihp-sg13g2: extract from -period flag""" + sdc = tmp_path / "constraint.sdc" + sdc.write_text("create_clock -period 5.0 [get_ports clk]\n") + clean_env(monkeypatch, "ihp-sg13g2", {"SDC_FILE": str(sdc)}) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert d["ABC_CLOCK_PERIOD_IN_PS"] == "5000.0" + + def test_ihp_no_sdc_file(self, monkeypatch): + """No SDC file -> ABC_CLOCK_PERIOD_IN_PS not set""" + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "ABC_CLOCK_PERIOD_IN_PS" not in d + + +# --- Test 20: $(origin VAR) check --- +class TestOriginCheck: + def test_ihp_origin_undefined(self, monkeypatch, tmp_path): + """When ABC_CLOCK_PERIOD_IN_PS is not in env, extract from SDC""" + sdc = tmp_path / "constraint.sdc" + sdc.write_text("set clk_period 8.0\n") + clean_env(monkeypatch, "ihp-sg13g2", {"SDC_FILE": str(sdc)}) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert d["ABC_CLOCK_PERIOD_IN_PS"] == "8000.0" + + def test_ihp_origin_defined(self, monkeypatch, tmp_path): + """When ABC_CLOCK_PERIOD_IN_PS is in env, don't extract""" + sdc = tmp_path / "constraint.sdc" + sdc.write_text("set clk_period 8.0\n") + clean_env( + monkeypatch, + "ihp-sg13g2", + { + "SDC_FILE": str(sdc), + "ABC_CLOCK_PERIOD_IN_PS": "12345", + }, + ) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert ( + "ABC_CLOCK_PERIOD_IN_PS" not in d + or d.get("ABC_CLOCK_PERIOD_IN_PS") != "8000.0" + ) + + +# --- Test 21: $(abspath ...) --- +class TestAbspath: + def test_gf180_lib_files_absolute(self, monkeypatch): + clean_env(monkeypatch, "gf180") + cfg = gf180_config.get_config() + d = cfg.to_dict() + # BC_LIB_FILES should be absolute path + assert os.path.isabs(d["BC_LIB_FILES"]) + assert os.path.isabs(d["LIB_FILES"].split()[0]) + + +# --- Test 22: $(realpath ...) --- +class TestRealpath: + def test_asap7_db_files_realpath(self, monkeypatch): + """asap7: DB_FILES uses $(realpath ...) -- only if corner DB files exist""" + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + # DB_FILES may be empty if no corner DB files are defined + # Just verify it doesn't crash + assert isinstance(d.get("DB_FILES", ""), str) + + +# --- Test 23: -include private.mk skipped --- +class TestPrivateMkSkipped: + def test_gf180_has_private_dir_default(self, monkeypatch): + """gf180: -include private.mk is skipped, but GF180_PRIVATE_DIR is set""" + clean_env(monkeypatch, "gf180") + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["GF180_PRIVATE_DIR"] == "../../gf180-private" + + +# --- Test 24: ??= (treated as ?=) --- +class TestDoubleQuestionEquals: + def test_ihp_io_pins_default_empty(self, monkeypatch): + """ihp-sg13g2: ??= variables default to empty""" + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert d.get("IO_NORTH_PINS", "") == "" + assert d.get("IO_SOUTH_PINS", "") == "" + + def test_ihp_io_pins_override(self, monkeypatch): + """ihp-sg13g2: ??= variables can be overridden from env""" + clean_env(monkeypatch, "ihp-sg13g2", {"IO_NORTH_PINS": "pin1 pin2"}) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert d["IO_NORTH_PINS"] == "pin1 pin2" + + +# --- Test 25: Parameterized options (gf180) --- +class TestGf180ParameterizedOptions: + def test_default_options(self, monkeypatch): + clean_env(monkeypatch, "gf180") + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "5LM_1TM" in d["TECH_LEF"] + assert "9K" in d["TECH_LEF"] + assert "9t" in d["TECH_LEF"] + + def test_custom_track_option(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"TRACK_OPTION": "7t"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "7t" in d["TECH_LEF"] + assert d["PLACE_SITE"] == "GF018hv5v_mcu_sc7" + + def test_custom_metal_option(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"METAL_OPTION": "3LM_1TM"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "3LM_1TM" in d["TECH_LEF"] + + +# --- Test 26: BLOCKS conditional for PDN_TCL --- +class TestAsap7BlocksPdn: + def test_no_blocks(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "BLOCKS" not in d["PDN_TCL"] + + def test_with_blocks(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"BLOCKS": "some_block"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "BLOCKS_grid_strategy" in d["PDN_TCL"] + + +# --- Test 27: CLUSTER_FLOPS conditional --- +class TestAsap7ClusterFlops: + def test_no_cluster_flops(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "DFFHQNH2V2X" not in d.get("ADDITIONAL_LIBS", "") + + def test_with_cluster_flops(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"CLUSTER_FLOPS": "1"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "DFFHQNH2V2X" in d.get("ADDITIONAL_LIBS", "") + assert "DFFHQNV2X" in d.get("ADDITIONAL_LIBS", "") + assert "asap7sc7p5t_DFFHQNH2V2X.lef" in d.get("ADDITIONAL_LEFS", "") + assert "asap7sc7p5t_pg" in d.get("ADDITIONAL_SITES", "") + assert d.get("GDS_ALLOW_EMPTY") == "DFFHQN[VH][24].*" + + +# --- Test 28: LIB_MODEL selection --- +class TestAsap7LibModel: + def test_default_nldm(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "/NLDM/" in d["LIB_DIR"] or d["LIB_DIR"].endswith("/NLDM") + + def test_ccs_model(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"LIB_MODEL": "CCS"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "/CCS/" in d["LIB_DIR"] or d["LIB_DIR"].endswith("/CCS") + + +# --- Test 29: Corner temperature/voltage --- +class TestCornerTemperatureVoltage: + def test_asap7_bc_corner(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"CORNER": "BC"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["TEMPERATURE"] == "25C" + assert d["VOLTAGE"] == "0.77" + + def test_asap7_wc_corner(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"CORNER": "WC"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["TEMPERATURE"] == "100C" + assert d["VOLTAGE"] == "0.63" + + def test_gf180_bc_corner(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "BC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["TEMPERATURE"] == "-40c" + assert d["VOLTAGE"] == "5.5" + + def test_gf180_wc_corner(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "WC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["TEMPERATURE"] == "125c" + assert d["VOLTAGE"] == "4.5" + + +# --- Test 30: Multi-VT expansion --- +class TestAsap7MultiVt: + def test_single_vt_default(self, monkeypatch): + """Default: ASAP7_USE_VT unset -> RVT only, no OTHER_VT additions""" + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + # Only primary VT in GDS_FILES + gds = d["GDS_FILES"] + assert "28_R_" in gds + assert "28_L_" not in gds + # No ADDITIONAL_LEFS from VT loop (may have CLUSTER_FLOPS additions) + assert "28_L_1x" not in d.get("ADDITIONAL_LEFS", "") + + def test_dual_vt(self, monkeypatch): + clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "RVT LVT"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "28_R_" in d["GDS_FILES"] + assert "28_L_" in d["GDS_FILES"] + + +# --- Test 31: FOOTPRINT_TCL conditional (ihp-sg13g2) --- +class TestIhpFootprintConditional: + def test_no_footprint(self, monkeypatch): + """No FOOTPRINT_TCL -> no IO lefs/libs added""" + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "sg13g2_io.lef" not in d.get("ADDITIONAL_LEFS", "") + + def test_with_footprint(self, monkeypatch): + """FOOTPRINT_TCL set -> IO lefs/libs/gds added""" + clean_env(monkeypatch, "ihp-sg13g2", {"FOOTPRINT_TCL": "/some/file.tcl"}) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "sg13g2_io.lef" in d.get("ADDITIONAL_LEFS", "") + assert "bondpad_70x70.lef" in d.get("ADDITIONAL_LEFS", "") + assert "sg13g2_io_slow" in d.get("SLOW_LIB_FILES", "") + assert "sg13g2_io.gds" in d.get("ADDITIONAL_GDS", "") + + +# --- Test 32: $(PLATFORM) in paths --- +class TestPlatformVarInPaths: + def test_sky130hd_platform_in_klayout(self, monkeypatch): + clean_env(monkeypatch, "sky130hd") + cfg = sky130hd_config.get_config() + d = cfg.to_dict() + assert "sky130hd.lyt" in d["KLAYOUT_TECH_FILE"] + assert "sky130hd.lydrc" in d["KLAYOUT_DRC_FILE"] + assert "sky130hd.cdl" in d["CDL_FILE"] + + def test_sky130hs_platform_in_klayout(self, monkeypatch): + clean_env(monkeypatch, "sky130hs") + cfg = sky130hs_config.get_config() + d = cfg.to_dict() + assert "sky130hs.lyt" in d["KLAYOUT_TECH_FILE"] + + +# --- Test 33: Make shim round-trip --- +class TestShimRoundTrip: + """Verify config.py Make output format is consumable by foreach/eval.""" + + @pytest.mark.parametrize("platform", PLATFORMS) + def test_make_output_format(self, monkeypatch, platform, capsys): + """Each line is 'export KEY=VALUE' or 'export KEY?=VALUE' with __SPACE__""" + clean_env(monkeypatch, platform) + cfg = PLATFORM_MODULES[platform].get_config() + cfg.output_make() + out = capsys.readouterr().out + for line in out.strip().split("\n"): + assert line.startswith( + "export " + ), f"Line doesn't start with 'export ': {line}" + rest = line[7:] # strip "export " + assert "=" in rest, f"No = in: {line}" + # No actual spaces in values (should be __SPACE__) + key_op_val = rest + if "?=" in key_op_val: + key, val = key_op_val.split("?=", 1) + else: + key, val = key_op_val.split("=", 1) + assert " " not in val, f"Space in value (should be __SPACE__): {key}={val}" + + @pytest.mark.parametrize("platform", PLATFORMS) + def test_json_output_parseable(self, monkeypatch, platform, capsys): + """JSON output should be valid and parseable.""" + clean_env(monkeypatch, platform) + cfg = PLATFORM_MODULES[platform].get_config() + cfg.output_json() + out = capsys.readouterr().out + data = json.loads(out) + assert isinstance(data, dict) + assert len(data) > 0 + + +# =================================================================== +# 3. Integration findings: design-config override semantics +# =================================================================== +class TestDesignConfigOverrides: + """Tests discovered from Make integration comparison. + + When a design config.mk sets a variable with = or :=, it overrides + the platform config.py's ?= default. These tests verify the ?= + semantics work correctly end-to-end. + """ + + def test_conditional_overridden_by_immediate_assignment(self, monkeypatch): + """nangate45/gcd: 'export ADDER_MAP_FILE :=' in design clears platform ?= default. + + Make's := (immediate assignment) sets the variable even if empty. + When the platform config.py sees ADDER_MAP_FILE already in env, + its ?= is a no-op. + """ + clean_env(monkeypatch, "nangate45", {"ADDER_MAP_FILE": ""}) + cfg = nangate45_config.get_config() + d = cfg.to_dict() + # Empty env value should win over ?= default + assert d["ADDER_MAP_FILE"] == "" + + def test_design_place_density_overrides_platform(self, monkeypatch): + """asap7/gcd: design sets PLACE_DENSITY=0.35, overriding platform ?=0.60.""" + clean_env(monkeypatch, "asap7", {"PLACE_DENSITY": "0.35"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["PLACE_DENSITY"] == "0.35" + + def test_design_pdn_tcl_overrides_platform(self, monkeypatch): + """nangate45/gcd: design sets PDN_TCL, overriding platform ?= default.""" + clean_env( + monkeypatch, + "nangate45", + {"PDN_TCL": "/designs/nangate45/gcd/custom_pdn.tcl"}, + ) + cfg = nangate45_config.get_config() + d = cfg.to_dict() + assert d["PDN_TCL"] == "/designs/nangate45/gcd/custom_pdn.tcl" + + def test_ihp_design_place_density_overrides(self, monkeypatch): + """ihp-sg13g2/gcd: design sets PLACE_DENSITY?=0.88, platform has ?=0.65. + Design config is included BEFORE platform config. Since both use ?=, + the first one (design) wins.""" + clean_env(monkeypatch, "ihp-sg13g2", {"PLACE_DENSITY": "0.88"}) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert d["PLACE_DENSITY"] == "0.88" + + +class TestGf180CornerVariants: + """Tests for all 3 gf180 corners discovered from Make integration comparison.""" + + def test_bc_rcx_rules(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "BC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "bst.rules" in d["RCX_RULES"] + assert d["RCX_RC_CORNER"] == "FuncRCmin" + + def test_wc_rcx_rules(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "WC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "wst.rules" in d["RCX_RULES"] + assert d["RCX_RC_CORNER"] == "FuncRCmax" + + def test_tc_rcx_rules(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "TC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "typ.rules" in d["RCX_RULES"] + assert d["RCX_RC_CORNER"] == "FuncRCtyp" + + def test_bc_pwr_nets_uses_corner_voltage(self, monkeypatch): + """PWR_NETS_VOLTAGES should use the corner-specific voltage.""" + clean_env(monkeypatch, "gf180", {"CORNER": "BC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["PWR_NETS_VOLTAGES"] == "VDD 5.5" + + def test_wc_pwr_nets_uses_corner_voltage(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "WC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["PWR_NETS_VOLTAGES"] == "VDD 4.5" + + def test_tc_pwr_nets_uses_corner_voltage(self, monkeypatch): + clean_env(monkeypatch, "gf180", {"CORNER": "TC"}) + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["PWR_NETS_VOLTAGES"] == "VDD 5.0" + + def test_gds_layer_map_absolute_path(self, monkeypatch): + clean_env(monkeypatch, "gf180") + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert os.path.isabs(d["GDS_LAYER_MAP"]) + assert "edi2gds.layermap" in d["GDS_LAYER_MAP"] + + def test_klayout_lef_file(self, monkeypatch): + clean_env(monkeypatch, "gf180") + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert "tech_9t_5LM_1TM.lef" in d["KLAYOUT_LEF_FILE"] + + def test_tie_cell_and_endcap(self, monkeypatch): + clean_env(monkeypatch, "gf180") + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["TIE_CELL"] == "gf180mcu_fd_sc_mcu9t5v0__filltie" + assert d["ENDCAP_CELL"] == "gf180mcu_fd_sc_mcu9t5v0__endcap" + + def test_max_fanout(self, monkeypatch): + clean_env(monkeypatch, "gf180") + cfg = gf180_config.get_config() + d = cfg.to_dict() + assert d["MAX_FANOUT"] == "20" + + +class TestAsap7ExtraVarsFromIntegration: + """Tests for asap7 variables verified against Make integration output.""" + + def test_platform_tcl(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["PLATFORM_TCL"].endswith("/liberty_suppressions.tcl") + + def test_make_tracks(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["MAKE_TRACKS"].endswith("/openRoad/make_tracks.tcl") + + def test_set_rc_tcl(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["SET_RC_TCL"].endswith("/setRC.tcl") + + def test_lib_dir_default(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["LIB_DIR"].endswith("/lib/NLDM") + + def test_macro_rows_halo(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["MACRO_ROWS_HALO_X"] == "2" + assert d["MACRO_ROWS_HALO_Y"] == "2" + + def test_corner_temps_and_voltages(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["BC_TEMPERATURE"] == "25C" + assert d["TC_TEMPERATURE"] == "0C" + assert d["WC_TEMPERATURE"] == "100C" + assert d["BC_VOLTAGE"] == "0.77" + assert d["TC_VOLTAGE"] == "0.70" + assert d["WC_VOLTAGE"] == "0.63" + + def test_synth_minimum_keep_size(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert d["SYNTH_MINIMUM_KEEP_SIZE"] == "1000" + + def test_ccs_lib_files_with_bc_additional(self, monkeypatch): + """BC_CCS_LIB_FILES should include BC_ADDITIONAL_LIBS when set.""" + clean_env(monkeypatch, "asap7", {"BC_ADDITIONAL_LIBS": "/extra/bc.lib"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "/extra/bc.lib" in d["BC_CCS_LIB_FILES"] + assert "_ccs_" in d["BC_CCS_LIB_FILES"] + + def test_wc_nldm_lib_files(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "_SS_nldm_" in d["WC_NLDM_LIB_FILES"] + assert "_RVT_" in d["WC_NLDM_LIB_FILES"] + + def test_tc_nldm_lib_files(self, monkeypatch): + clean_env(monkeypatch, "asap7") + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "_TT_nldm_" in d["TC_NLDM_LIB_FILES"] + assert "_RVT_" in d["TC_NLDM_LIB_FILES"] + + def test_wc_corner_lib_files(self, monkeypatch): + """With CORNER=WC, LIB_FILES should use WC_NLDM_LIB_FILES.""" + clean_env(monkeypatch, "asap7", {"CORNER": "WC"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "_SS_nldm_" in d["LIB_FILES"] + + def test_tc_corner_lib_files(self, monkeypatch): + """With CORNER=TC, LIB_FILES should use TC_NLDM_LIB_FILES.""" + clean_env(monkeypatch, "asap7", {"CORNER": "TC"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "_TT_nldm_" in d["LIB_FILES"] + + def test_ccs_model_corner_selection(self, monkeypatch): + """With LIB_MODEL=CCS and CORNER=BC, LIB_FILES should use BC_CCS_LIB_FILES.""" + clean_env(monkeypatch, "asap7", {"LIB_MODEL": "CCS", "CORNER": "BC"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "_ccs_" in d["LIB_FILES"] + + def test_lvt_design_vars(self, monkeypatch): + """asap7/aes_lvt: ASAP7_USE_VT=LVT should set all primary VT vars to L tag.""" + clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "LVT"}) + cfg = asap7_config.get_config() + d = cfg.to_dict() + assert "asap7sc7p5t_28_L_1x" in d["SC_LEF"] + assert "asap7sc7p5t_28_L_" in d["GDS_FILES"] + assert "TIEHIx1_ASAP7_75t_L" in d["TIEHI_CELL_AND_PORT"] + assert "BUFx2_ASAP7_75t_L" in d["ABC_DRIVER_CELL"] + assert "cells_latch_L.v" in d["LATCH_MAP_FILE"] + assert "TAPCELL_ASAP7_75t_L" in d["TAP_CELL_NAME"] + assert "FILLERxp5_ASAP7_75t_L" in d["FILL_CELLS"] + + +class TestIhpExtraVarsFromIntegration: + """Tests for ihp-sg13g2 variables verified against Make integration output.""" + + def test_slow_lib_files(self, monkeypatch): + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "slow_1p08V_125C" in d["SLOW_LIB_FILES"] + + def test_fast_lib_files(self, monkeypatch): + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "fast_1p32V_m40C" in d["FAST_LIB_FILES"] + + def test_typ_lib_files(self, monkeypatch): + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "typ_1p20V_25C" in d["TYP_LIB_FILES"] + + def test_lib_files_defaults_to_typ(self, monkeypatch): + """LIB_FILES ?= $(TYP_LIB_FILES)""" + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "typ_1p20V_25C" in d["LIB_FILES"] + + def test_core_margin(self, monkeypatch): + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert d["CORE_MARGIN"] == "17.5" + + def test_io_filler_cells(self, monkeypatch): + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "sg13g2_Filler10000" in d["IO_FILLER_CELLS"] + assert "sg13g2_Filler200" in d["IO_FILLER_CELLS"] + + def test_io_bondpad_vars(self, monkeypatch): + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert d["IO_BONDPAD_SIZE"] == "70" + assert d["IO_BONDPAD_NAME"] == "bondpad_70x70" + assert d["IO_LENGTH"] == "180" + assert d["IO_WIDTH"] == "80" + assert d["IO_SEALRING_OFFSET"] == "70" + + def test_gds_allow_empty_regex(self, monkeypatch): + clean_env(monkeypatch, "ihp-sg13g2") + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "RM_IHPSG13" in d["GDS_ALLOW_EMPTY"] + assert "CORNER" in d["GDS_ALLOW_EMPTY"] + + def test_footprint_conditional_with_load_disabled(self, monkeypatch): + """FOOTPRINT_TCL set but LOAD_ADDITIONAL_FILES=0 -> no IO additions.""" + clean_env( + monkeypatch, + "ihp-sg13g2", + { + "FOOTPRINT_TCL": "/some/file.tcl", + "LOAD_ADDITIONAL_FILES": "0", + }, + ) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "sg13g2_io.lef" not in d.get("ADDITIONAL_LEFS", "") + + def test_slow_lib_with_footprint(self, monkeypatch): + """FOOTPRINT_TCL set -> SLOW_LIB_FILES includes IO lib.""" + clean_env(monkeypatch, "ihp-sg13g2", {"FOOTPRINT_TCL": "/some/file.tcl"}) + cfg = ihp_config.get_config() + d = cfg.to_dict() + assert "sg13g2_io_slow" in d["SLOW_LIB_FILES"] + assert "sg13g2_stdcell_slow" in d["SLOW_LIB_FILES"] + + +# =================================================================== +# 4. Integration tests: make clean_all metadata +# =================================================================== +INTEGRATION_DESIGNS = [ + ("nangate45", "gcd"), + ("sky130hd", "gcd"), + ("gf180", "ibex"), + ("ihp-sg13g2", "gcd"), + ("asap7", "aes-mbff"), +] + + +@pytest.mark.integration +class TestMakeIntegration: + """Run make DESIGN_CONFIG=... clean_all metadata through the shim. + + These tests verify the full config.mk shim -> config.py -> Make pipeline. + They require Make and the ORFS environment to be set up. + """ + + @pytest.mark.parametrize("platform,design", INTEGRATION_DESIGNS) + def test_make_metadata(self, platform, design): + """Run make clean_all metadata and verify it succeeds.""" + design_config = f"designs/{platform}/{design}/config.mk" + result = subprocess.run( + ["make", "clean_all", "metadata", f"DESIGN_CONFIG={design_config}"], + capture_output=True, + text=True, + cwd=os.path.abspath(FLOW_DIR), + timeout=300, + ) + assert result.returncode == 0, ( + f"make metadata failed for {platform}/{design}:\n" + f"stdout: {result.stdout[-2000:]}\n" + f"stderr: {result.stderr[-2000:]}" + ) + + +if __name__ == "__main__": + pytest.main([__file__, "-v", "-m", "not integration"]) From 081361e2d6e4856f2d9e31121402ab1e4caca884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 18 Mar 2026 23:08:27 +0100 Subject: [PATCH 4/9] flow: guard test files against missing pytest in CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI runs `python "$file"` on every .py in flow/test/. conftest.py and test_platform_config.py import pytest which isn't installed in the testUtilScripts CI environment. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- flow/test/conftest.py | 15 +++++++++------ flow/test/test_platform_config.py | 8 +++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/flow/test/conftest.py b/flow/test/conftest.py index 8d8f9a6425..2d30f8b7b9 100644 --- a/flow/test/conftest.py +++ b/flow/test/conftest.py @@ -1,7 +1,10 @@ -import pytest +try: + import pytest +except ImportError: + pass +else: - -def pytest_configure(config): - config.addinivalue_line( - "markers", "integration: mark test as integration test (requires Make)" - ) + def pytest_configure(config): + config.addinivalue_line( + "markers", "integration: mark test as integration test (requires Make)" + ) diff --git a/flow/test/test_platform_config.py b/flow/test/test_platform_config.py index 43869ca2f3..0fe6944d69 100644 --- a/flow/test/test_platform_config.py +++ b/flow/test/test_platform_config.py @@ -1195,4 +1195,10 @@ def test_make_metadata(self, platform, design): if __name__ == "__main__": - pytest.main([__file__, "-v", "-m", "not integration"]) + try: + import pytest + + pytest.main([__file__, "-v", "-m", "not integration"]) + except ImportError: + print("pytest not installed, skipping tests") + pass From ce1c3a9e5db98bce1ce4d2ece95ea7c014ccff24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 18 Mar 2026 23:13:27 +0100 Subject: [PATCH 5/9] flow: keep $(PLATFORM_DIR) and $(PLATFORM) unexpanded in config.py output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit config.py now outputs $(PLATFORM_DIR)/... and $(PLATFORM) in values instead of baking in absolute paths. Consumers expand on their end: - Make: $(eval) expands naturally - bazel-orfs: Python substitution when the rule executes Glob results are expanded at runtime for filesystem access, then unexpanded in output. to_dict() still returns expanded paths for unit test assertions. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- flow/scripts/platform_config_utils.py | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/flow/scripts/platform_config_utils.py b/flow/scripts/platform_config_utils.py index da485e3d57..cf90b13c2d 100644 --- a/flow/scripts/platform_config_utils.py +++ b/flow/scripts/platform_config_utils.py @@ -31,6 +31,9 @@ def __init__(self, platform_dir=None): os.path.abspath(sys._getframe(1).f_globals["__file__"]) ), ) + self.platform = os.environ.get( + "PLATFORM", os.path.basename(self.platform_dir) + ) self._vars = [] # ordered list of (key, value, conditional) self._index = {} # key -> index in _vars for fast lookup @@ -85,6 +88,29 @@ def wildcard_glob(self, pattern): """glob.glob(pattern) -- replaces $(wildcard ...)""" return " ".join(glob.glob(pattern)) + def _unexpand(self, value): + """Replace expanded paths with Make variable references. + + Consumers expand these on their end: + - Make: $(eval) expands $(PLATFORM_DIR) and $(PLATFORM) + - bazel-orfs: Python substitution when the rule executes + """ + # Replace platform_dir first (longer, more specific) + value = value.replace(self.platform_dir, "$(PLATFORM_DIR)") + # Replace platform name within $(PLATFORM_DIR)/... paths only + # e.g. $(PLATFORM_DIR)/sky130hd.lyt -> $(PLATFORM_DIR)/$(PLATFORM).lyt + if self.platform: + value = value.replace( + "$(PLATFORM_DIR)/" + self.platform, + "$(PLATFORM_DIR)/$(PLATFORM)", + ) + # Also in subdirectories: $(PLATFORM_DIR)/drc/sky130hd.lydrc + value = value.replace( + "/" + self.platform + ".", + "/$(PLATFORM).", + ) + return value + def output_make(self): """Print Make-compatible output lines. @@ -93,6 +119,7 @@ def output_make(self): """ for key, value, conditional in self._vars: op = "?=" if conditional else "=" + value = self._unexpand(value) encoded = value.replace(" ", "__SPACE__") print(f"export {key}{op}{encoded}") @@ -100,7 +127,7 @@ def output_json(self): """Print flat JSON dict for bazel-orfs or other consumers.""" result = {} for key, value, _conditional in self._vars: - result[key] = value + result[key] = self._unexpand(value) json.dump(result, sys.stdout, indent=2) print() # trailing newline From 11c7dfff3bfa3198ecf8560d0e36d4a32c948cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 18 Mar 2026 23:15:04 +0100 Subject: [PATCH 6/9] flow: add 18 unit tests for unexpanded $(PLATFORM_DIR) and $(PLATFORM) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Verify that config.py output (both Make and JSON) uses symbolic $(PLATFORM_DIR) and $(PLATFORM) references instead of absolute paths. Tests cover: JSON output, Make output, glob results, and $(PLATFORM) in sky130hd/sky130hs filenames. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- flow/test/test_platform_config.py | 158 ++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/flow/test/test_platform_config.py b/flow/test/test_platform_config.py index 0fe6944d69..90bacfac40 100644 --- a/flow/test/test_platform_config.py +++ b/flow/test/test_platform_config.py @@ -1194,6 +1194,164 @@ def test_make_metadata(self, platform, design): ) +ALL_PLATFORMS = ["nangate45", "sky130hd", "sky130hs", "gf180", "ihp-sg13g2", "asap7"] + + +class TestUnexpandedOutput: + """Verify config.py output uses $(PLATFORM_DIR) and $(PLATFORM) instead of absolute paths. + + bazel-orfs runs in a sandbox where platform files live at different paths. + config.py must output symbolic references so consumers can expand on their end: + - Make: $(eval) expands $(PLATFORM_DIR) and $(PLATFORM) + - bazel-orfs: Python substitution when the Bazel rule executes + """ + + @pytest.fixture(autouse=True) + def _clean_env(self, monkeypatch): + for v in [ + "ADDITIONAL_LIBS", + "ADDITIONAL_GDS", + "ADDITIONAL_LEFS", + "ADDITIONAL_SLOW_LIBS", + "ADDITIONAL_FAST_LIBS", + "ADDITIONAL_TYP_LIBS", + "BC_ADDITIONAL_LIBS", + "BLOCKS", + "CORNER", + "ASAP7_USE_VT", + "LIB_MODEL", + "CLUSTER_FLOPS", + "FOOTPRINT_TCL", + "LOAD_ADDITIONAL_FILES", + "TRACK_OPTION", + "METAL_OPTION", + "KVALUE", + "POWER_OPTION", + "SDC_FILE", + "ABC_CLOCK_PERIOD_IN_PS", + "DONT_USE_CELLS", + ]: + monkeypatch.delenv(v, raising=False) + + @pytest.mark.parametrize("platform", ALL_PLATFORMS) + def test_json_no_absolute_platform_dir(self, platform, monkeypatch, tmp_path): + """JSON output must not contain the absolute platform_dir path.""" + pd = os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) + monkeypatch.setenv("PLATFORM_DIR", pd) + monkeypatch.setenv("PLATFORM", platform) + + mod = _load_config_module(platform) + cfg = mod.get_config() + + # Capture JSON output + import io + + buf = io.StringIO() + old_stdout = sys.stdout + sys.stdout = buf + cfg.output_json() + sys.stdout = old_stdout + data = json.loads(buf.getvalue()) + + for key, value in data.items(): + assert pd not in value, ( + f"{platform}: {key} contains absolute path {pd!r} " + f"instead of $(PLATFORM_DIR). Value: {value!r}" + ) + + @pytest.mark.parametrize("platform", ALL_PLATFORMS) + def test_make_no_absolute_platform_dir(self, platform, monkeypatch): + """Make output must not contain the absolute platform_dir path.""" + pd = os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) + monkeypatch.setenv("PLATFORM_DIR", pd) + monkeypatch.setenv("PLATFORM", platform) + + mod = _load_config_module(platform) + cfg = mod.get_config() + + import io + + buf = io.StringIO() + old_stdout = sys.stdout + sys.stdout = buf + cfg.output_make() + sys.stdout = old_stdout + output = buf.getvalue() + + assert pd not in output, ( + f"{platform}: Make output contains absolute path {pd!r} " + f"instead of $(PLATFORM_DIR)" + ) + + @pytest.mark.parametrize("platform", ["nangate45", "sky130hd", "sky130hs", "gf180"]) + def test_glob_results_unexpanded(self, platform, monkeypatch): + """GDS_FILES from glob must use $(PLATFORM_DIR), not absolute paths.""" + pd = os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) + monkeypatch.setenv("PLATFORM_DIR", pd) + monkeypatch.setenv("PLATFORM", platform) + + mod = _load_config_module(platform) + cfg = mod.get_config() + + import io + + buf = io.StringIO() + old_stdout = sys.stdout + sys.stdout = buf + cfg.output_json() + sys.stdout = old_stdout + data = json.loads(buf.getvalue()) + + gds = data.get("GDS_FILES", "") + assert gds, f"{platform}: GDS_FILES is empty" + assert ( + "$(PLATFORM_DIR)" in gds + ), f"{platform}: GDS_FILES glob result missing $(PLATFORM_DIR): {gds!r}" + assert pd not in gds, f"{platform}: GDS_FILES contains absolute path: {gds!r}" + + @pytest.mark.parametrize( + "platform,keys", + [ + ( + "sky130hd", + [ + "KLAYOUT_TECH_FILE", + "KLAYOUT_DRC_FILE", + "CDL_FILE", + "KLAYOUT_LVS_FILE", + ], + ), + ("sky130hs", ["KLAYOUT_TECH_FILE"]), + ], + ) + def test_platform_name_unexpanded(self, platform, keys, monkeypatch): + """Variables using $(PLATFORM) in filenames must not expand it.""" + pd = os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) + monkeypatch.setenv("PLATFORM_DIR", pd) + monkeypatch.setenv("PLATFORM", platform) + + mod = _load_config_module(platform) + cfg = mod.get_config() + + import io + + buf = io.StringIO() + old_stdout = sys.stdout + sys.stdout = buf + cfg.output_json() + sys.stdout = old_stdout + data = json.loads(buf.getvalue()) + + for key in keys: + value = data.get(key, "") + assert ( + "$(PLATFORM)" in value + ), f"{platform}: {key} should contain $(PLATFORM), got: {value!r}" + assert ( + f"/{platform}." not in value + ), f"{platform}: {key} contains expanded platform name: {value!r}" + + if __name__ == "__main__": try: import pytest From eec7e34b251872e096440d9003d9059aa806a6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 18 Mar 2026 23:15:51 +0100 Subject: [PATCH 7/9] flow: document config.py variable rules in variables.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Documents: symbolic path references, assignment semantics, glob handling, env var inputs, why variables.mk doesn't need porting, and the Make functions already resolved by config.py. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- flow/scripts/variables.md | 113 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 flow/scripts/variables.md diff --git a/flow/scripts/variables.md b/flow/scripts/variables.md new file mode 100644 index 0000000000..334643dada --- /dev/null +++ b/flow/scripts/variables.md @@ -0,0 +1,113 @@ +# Platform config.py variable rules + +Rules for writing and consuming platform `config.py` files. + +## Path variables must stay symbolic + +Output values must use `$(PLATFORM_DIR)/...` and `$(PLATFORM)`, never +baked-in absolute paths. Consumers expand on their end: + +- **Make shim**: `$(eval)` expands `$(PLATFORM_DIR)` and `$(PLATFORM)` + naturally, matching the original config.mk behavior. +- **bazel-orfs**: Python string substitution when the Bazel rule + executes. The sandbox has platform files at a different path than + the developer's machine. + +`PlatformConfig._unexpand()` handles this automatically at output time. + +### Variables that use $(PLATFORM_DIR) + +All 6 platforms. Every path-valued variable: `TECH_LEF`, `SC_LEF`, +`LIB_FILES`, `GDS_FILES`, `PDN_TCL`, `TAPCELL_TCL`, `FASTROUTE_TCL`, +`KLAYOUT_TECH_FILE`, `RCX_RULES`, `LATCH_MAP_FILE`, etc. + +### Variables that use $(PLATFORM) + +sky130hd, sky130hs only. Used in filenames within `$(PLATFORM_DIR)`: +`KLAYOUT_TECH_FILE`, `KLAYOUT_DRC_FILE`, `CDL_FILE`, `KLAYOUT_LVS_FILE`. + +Example: `$(PLATFORM_DIR)/$(PLATFORM).lyt` not `$(PLATFORM_DIR)/sky130hd.lyt`. + +## Assignment semantics + +| Syntax | PlatformConfig method | Behavior | +|--------|----------------------|----------| +| `=` | `cfg.set(key, val)` | Unconditional. Always sets. | +| `?=` | `cfg.set(key, val, conditional=True)` | Set only if not already defined (internally or in env). | +| `+=` | `cfg.append(key, val)` | Append to existing value. Reads env if not set internally. | + +## Glob results + +`$(sort $(wildcard ...))` and `$(wildcard ...)` require real filesystem +paths at config.py runtime. `PlatformConfig.sorted_glob()` and +`wildcard_glob()` use the real `platform_dir` for glob operations. +The `_unexpand()` step replaces the prefix back to `$(PLATFORM_DIR)` +in output. + +## Environment variable inputs + +These env vars are **read** by config.py to control logic but do NOT +appear as `$(...)` references in output: + +| Input | Platforms | Purpose | +|-------|-----------|---------| +| `CORNER` | asap7, gf180 | Select lib files (BC/WC/TC) | +| `TRACK_OPTION` | gf180 | Track variant (9t/7t) | +| `METAL_OPTION` | gf180 | Metal stack (5LM_1TM) | +| `KVALUE` | gf180 | K value (9/11) | +| `POWER_OPTION` | gf180 | Power variant (5v0/3v3) | +| `LIB_MODEL` | asap7 | NLDM or CCS | +| `ASAP7_USE_VT` | asap7 | VT list (RVT LVT SLVT) | +| `CLUSTER_FLOPS` | asap7 | Enable flop clustering | +| `BLOCKS` | asap7 | Hierarchical block PDN | +| `FOOTPRINT_TCL` | ihp-sg13g2 | IO placement file | +| `LOAD_ADDITIONAL_FILES` | ihp-sg13g2 | Enable IO libs/lefs | +| `SDC_FILE` | ihp-sg13g2 | Parsed for clock period | +| `ABC_CLOCK_PERIOD_IN_PS` | ihp-sg13g2 | Override clock period | + +These env vars are **concatenated into output values** (their content +is embedded in variables like `LIB_FILES`, `GDS_FILES`): + +| Input | Output vars | Platforms | +|-------|-------------|-----------| +| `ADDITIONAL_LIBS` | `LIB_FILES` | all 6 | +| `ADDITIONAL_GDS` | `GDS_FILES` | all 6 | +| `ADDITIONAL_LEFS` | `ADDITIONAL_LEFS` | ihp-sg13g2, asap7 | +| `ADDITIONAL_SLOW_LIBS` | `SLOW_LIB_FILES` | ihp-sg13g2 | +| `ADDITIONAL_FAST_LIBS` | `FAST_LIB_FILES` | ihp-sg13g2 | +| `ADDITIONAL_TYP_LIBS` | `TYP_LIB_FILES` | ihp-sg13g2 | +| `BC_ADDITIONAL_LIBS` | `BC_CCS_LIB_FILES` | asap7 | + +In Make, these come from design configs as concrete paths. In bazel-orfs, +the Bazel rule provides them — no `$(...)` syntax. + +## Why variables.mk does not need porting + +`variables.mk` computes tool paths (`OPENROAD_EXE`, `YOSYS_EXE`, +`KLAYOUT_CMD`), output directories (`LOG_DIR`, `RESULTS_DIR`), macro +wrappers (`WRAPPED_LEFS`), stream format selection (`GDS` vs `OAS`), +and Make debugging introspection. This is Make-flow plumbing that +bazel-orfs replaces with Bazel-native equivalents. The only shared +concern is platform config variables, which `config.py` provides. + +## Make functions already resolved by config.py + +These Make constructs appeared in the original config.mk files. config.py +resolves all of them — none leak into output: + +| Make function | Python equivalent | Platforms | +|---------------|-------------------|-----------| +| `$(sort $(wildcard ...))` | `sorted_glob()` | nangate45 | +| `$(wildcard ...)` | `wildcard_glob()` | sky130hd, sky130hs, gf180 | +| `$(abspath ...)` | `os.path.abspath()` | gf180 | +| `$(realpath ...)` | `os.path.realpath()` | asap7 | +| `$(origin VAR)` | `"VAR" in os.environ` | ihp-sg13g2 | +| `$(shell sed ...)` | `re.search()` | ihp-sg13g2 | +| `$(foreach)/$(eval)` | `for` loop | asap7 | +| `$(subst ...)` | `str.replace()` | asap7 | +| `$(patsubst ...)` | `str.replace()` | asap7 | +| `$(addsuffix ...)` | string concat | asap7 | +| `$(word N,...)` | `str.split()[N]` | asap7 | +| `$(wordlist ...)` | `str.split()[N:]` | asap7 | +| `$(strip ...)` | `str.strip()` | asap7 | +| `$(if ...)` | `if` statement | asap7 | From f9c801e806c63b5a23e8a8fbb448c3b075390c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 18 Mar 2026 23:37:50 +0100 Subject: [PATCH 8/9] flow: convert platform config tests from pytest to unittest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All other test files in flow/test/ use stdlib unittest. Convert test_platform_config.py to match and remove the pytest dependency that broke CI (ModuleNotFoundError: No module named 'pytest'). Delete conftest.py which only existed for pytest marker config. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- flow/test/conftest.py | 10 - flow/test/test_platform_config.py | 1703 +++++++++++++---------------- 2 files changed, 753 insertions(+), 960 deletions(-) delete mode 100644 flow/test/conftest.py diff --git a/flow/test/conftest.py b/flow/test/conftest.py deleted file mode 100644 index 2d30f8b7b9..0000000000 --- a/flow/test/conftest.py +++ /dev/null @@ -1,10 +0,0 @@ -try: - import pytest -except ImportError: - pass -else: - - def pytest_configure(config): - config.addinivalue_line( - "markers", "integration: mark test as integration test (requires Make)" - ) diff --git a/flow/test/test_platform_config.py b/flow/test/test_platform_config.py index 90bacfac40..88d6638adb 100644 --- a/flow/test/test_platform_config.py +++ b/flow/test/test_platform_config.py @@ -4,17 +4,21 @@ Covers every Make construct used across all 6 platform config.mk files. Tests are organized by use-case (Make construct) and by platform. -Run: pytest flow/test/test_platform_config.py -v -Integration: pytest flow/test/test_platform_config.py -v -m integration +Run: python -m unittest flow.test.test_platform_config -v +Integration: RUN_INTEGRATION=1 python -m unittest flow.test.test_platform_config -v """ +import io import json import os +import shutil import subprocess import sys +import tempfile import textwrap - -import pytest +import unittest +from contextlib import redirect_stdout +from unittest.mock import patch # Add scripts dir to path for imports FLOW_DIR = os.path.join(os.path.dirname(__file__), "..") @@ -66,6 +70,31 @@ def _load_config_module(platform_name): "asap7": asap7_config, } +# Environment variables to clean before each test +ENV_VARS_TO_CLEAN = [ + "ADDITIONAL_LIBS", + "ADDITIONAL_GDS", + "ADDITIONAL_LEFS", + "BLOCKS", + "CORNER", + "ASAP7_USE_VT", + "LIB_MODEL", + "CLUSTER_FLOPS", + "FOOTPRINT_TCL", + "LOAD_ADDITIONAL_FILES", + "TRACK_OPTION", + "METAL_OPTION", + "KVALUE", + "POWER_OPTION", + "SDC_FILE", + "ABC_CLOCK_PERIOD_IN_PS", + "DONT_USE_CELLS", + "BC_ADDITIONAL_LIBS", + "ADDITIONAL_SLOW_LIBS", + "ADDITIONAL_FAST_LIBS", + "ADDITIONAL_TYP_LIBS", +] + # --------------------------------------------------------------------------- # Helpers @@ -74,141 +103,152 @@ def get_platform_dir(platform): return os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) -def clean_env(monkeypatch, platform, extras=None): - """Set up a clean environment for testing a platform config.""" - pd = get_platform_dir(platform) - monkeypatch.setenv("PLATFORM_DIR", pd) - monkeypatch.setenv("PLATFORM", platform) - # Remove variables that might leak from the real environment - for var in [ - "ADDITIONAL_LIBS", - "ADDITIONAL_GDS", - "ADDITIONAL_LEFS", - "BLOCKS", - "CORNER", - "ASAP7_USE_VT", - "LIB_MODEL", - "CLUSTER_FLOPS", - "FOOTPRINT_TCL", - "LOAD_ADDITIONAL_FILES", - "TRACK_OPTION", - "METAL_OPTION", - "KVALUE", - "POWER_OPTION", - "SDC_FILE", - "ABC_CLOCK_PERIOD_IN_PS", - "DONT_USE_CELLS", - "BC_ADDITIONAL_LIBS", - "ADDITIONAL_SLOW_LIBS", - "ADDITIONAL_FAST_LIBS", - "ADDITIONAL_TYP_LIBS", - ]: - monkeypatch.delenv(var, raising=False) +def make_clean_env(platform, extras=None): + """Return an env dict for use with patch.dict(os.environ, ...).""" + env = { + "PLATFORM_DIR": get_platform_dir(platform), + "PLATFORM": platform, + } if extras: - for k, v in extras.items(): - monkeypatch.setenv(k, v) + env.update(extras) + return env + + +def clean_and_get_config(platform, extras=None): + """Clean env, run get_config, return dict. Must be called inside patch.dict.""" + cfg = PLATFORM_MODULES[platform].get_config() + return cfg.to_dict() + + +class PlatformTestCase(unittest.TestCase): + """Base class that cleans environment variables in setUp.""" + + def setUp(self): + self._saved_env = {} + for var in ENV_VARS_TO_CLEAN: + if var in os.environ: + self._saved_env[var] = os.environ.pop(var) + + def tearDown(self): + # Remove any vars we may have set + for var in ENV_VARS_TO_CLEAN: + os.environ.pop(var, None) + # Restore original values + os.environ.update(self._saved_env) + + def run_with_env(self, platform, extras=None): + """Set up env and return config dict.""" + env = make_clean_env(platform, extras) + os.environ.update(env) + return clean_and_get_config(platform, extras) # =================================================================== # 1. PlatformConfig utility tests # =================================================================== -class TestPlatformConfigUtility: - """Test the shared PlatformConfig class in isolation.""" - +class TestPlatformConfigUtility(unittest.TestCase): def test_set_unconditional(self): cfg = PlatformConfig(platform_dir="/fake") cfg.set("FOO", "bar") d = cfg.to_dict() - assert d["FOO"] == "bar" + self.assertEqual(d["FOO"], "bar") def test_set_conditional_default(self): cfg = PlatformConfig(platform_dir="/fake") cfg.set("FOO", "default_val", conditional=True) d = cfg.to_dict() - assert d["FOO"] == "default_val" + self.assertEqual(d["FOO"], "default_val") - def test_set_conditional_override_from_env(self, monkeypatch): - monkeypatch.setenv("FOO", "from_env") - cfg = PlatformConfig(platform_dir="/fake") - cfg.set("FOO", "default_val", conditional=True) - d = cfg.to_dict() - assert d["FOO"] == "from_env" + def test_set_conditional_override_from_env(self): + with patch.dict(os.environ, {"FOO": "from_env"}): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "default_val", conditional=True) + d = cfg.to_dict() + self.assertEqual(d["FOO"], "from_env") def test_set_conditional_does_not_overwrite_internal(self): cfg = PlatformConfig(platform_dir="/fake") cfg.set("FOO", "first") cfg.set("FOO", "second", conditional=True) d = cfg.to_dict() - assert d["FOO"] == "first" + self.assertEqual(d["FOO"], "first") def test_append_internal(self): cfg = PlatformConfig(platform_dir="/fake") cfg.set("FOO", "a b") cfg.append("FOO", "c d") d = cfg.to_dict() - assert d["FOO"] == "a b c d" + self.assertEqual(d["FOO"], "a b c d") - def test_append_from_env(self, monkeypatch): - monkeypatch.setenv("FOO", "from_env") - cfg = PlatformConfig(platform_dir="/fake") - cfg.append("FOO", "extra") - d = cfg.to_dict() - assert d["FOO"] == "from_env extra" + def test_append_from_env(self): + with patch.dict(os.environ, {"FOO": "from_env"}): + cfg = PlatformConfig(platform_dir="/fake") + cfg.append("FOO", "extra") + d = cfg.to_dict() + self.assertEqual(d["FOO"], "from_env extra") def test_append_new_var(self): cfg = PlatformConfig(platform_dir="/fake") cfg.append("FOO", "value") d = cfg.to_dict() - assert d["FOO"] == "value" + self.assertEqual(d["FOO"], "value") def test_get(self): cfg = PlatformConfig(platform_dir="/fake") cfg.set("FOO", "bar") - assert cfg.get("FOO") == "bar" - assert cfg.get("MISSING", "default") == "default" + self.assertEqual(cfg.get("FOO"), "bar") + self.assertEqual(cfg.get("MISSING", "default"), "default") - def test_output_make(self, capsys): + def test_output_make(self): cfg = PlatformConfig(platform_dir="/fake") cfg.set("SIMPLE", "value") cfg.set("SPACES", "a b c") cfg.set("COND", "default", conditional=True) - cfg.output_make() - out = capsys.readouterr().out - lines = out.strip().split("\n") - assert "export SIMPLE=value" in lines - assert "export SPACES=a__SPACE__b__SPACE__c" in lines - assert "export COND?=default" in lines - - def test_output_json(self, capsys): + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_make() + lines = buf.getvalue().strip().split("\n") + self.assertIn("export SIMPLE=value", lines) + self.assertIn("export SPACES=a__SPACE__b__SPACE__c", lines) + self.assertIn("export COND?=default", lines) + + def test_output_json(self): cfg = PlatformConfig(platform_dir="/fake") cfg.set("KEY1", "val1") cfg.set("KEY2", "val2") - cfg.output_json() - out = capsys.readouterr().out - data = json.loads(out) - assert data["KEY1"] == "val1" - assert data["KEY2"] == "val2" - - def test_sorted_glob(self, tmp_path): - # Create some files - (tmp_path / "c.gds").touch() - (tmp_path / "a.gds").touch() - (tmp_path / "b.gds").touch() - cfg = PlatformConfig(platform_dir="/fake") - result = cfg.sorted_glob(str(tmp_path / "*.gds")) - files = result.split() - assert len(files) == 3 - assert files[0].endswith("a.gds") - assert files[1].endswith("b.gds") - assert files[2].endswith("c.gds") - - def test_wildcard_glob(self, tmp_path): - (tmp_path / "x.gds").touch() - (tmp_path / "y.gds").touch() - cfg = PlatformConfig(platform_dir="/fake") - result = cfg.wildcard_glob(str(tmp_path / "*.gds")) - files = result.split() - assert len(files) == 2 + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + self.assertEqual(data["KEY1"], "val1") + self.assertEqual(data["KEY2"], "val2") + + def test_sorted_glob(self): + tmp = tempfile.mkdtemp() + try: + for name in ["c.gds", "a.gds", "b.gds"]: + open(os.path.join(tmp, name), "w").close() + cfg = PlatformConfig(platform_dir="/fake") + result = cfg.sorted_glob(os.path.join(tmp, "*.gds")) + files = result.split() + self.assertEqual(len(files), 3) + self.assertTrue(files[0].endswith("a.gds")) + self.assertTrue(files[1].endswith("b.gds")) + self.assertTrue(files[2].endswith("c.gds")) + finally: + shutil.rmtree(tmp) + + def test_wildcard_glob(self): + tmp = tempfile.mkdtemp() + try: + for name in ["x.gds", "y.gds"]: + open(os.path.join(tmp, name), "w").close() + cfg = PlatformConfig(platform_dir="/fake") + result = cfg.wildcard_glob(os.path.join(tmp, "*.gds")) + files = result.split() + self.assertEqual(len(files), 2) + finally: + shutil.rmtree(tmp) # =================================================================== @@ -217,638 +257,526 @@ def test_wildcard_glob(self, tmp_path): # --- Test 1: Unconditional assignment (export VAR = value) --- -class TestUnconditionalAssignment: - @pytest.mark.parametrize( - "platform,key,expected_substr", - [ +class TestUnconditionalAssignment(PlatformTestCase): + def test_unconditional_assignment(self): + cases = [ ("nangate45", "PROCESS", "45"), ("sky130hs", "PROCESS", "130"), ("sky130hd", "PROCESS", "130"), ("gf180", "PROCESS", "180"), ("ihp-sg13g2", "PROCESS", "ihp-sg13g2"), ("asap7", "PROCESS", "7"), - ], - ) - def test_unconditional_assignment( - self, monkeypatch, platform, key, expected_substr - ): - clean_env(monkeypatch, platform) - cfg = PLATFORM_MODULES[platform].get_config() - d = cfg.to_dict() - assert d[key] == expected_substr + ] + for platform, key, expected_substr in cases: + with self.subTest(platform=platform, key=key): + d = self.run_with_env(platform) + self.assertEqual(d[key], expected_substr) # --- Test 2: Conditional assignment (export VAR ?= value) --- -class TestConditionalAssignment: - @pytest.mark.parametrize( - "platform,key,default_val", - [ +class TestConditionalAssignment(PlatformTestCase): + def test_conditional_assignment_default(self): + cases = [ ("nangate45", "PLACE_DENSITY", "0.30"), ("sky130hs", "PLACE_DENSITY", "0.50"), ("sky130hd", "PLACE_DENSITY", "0.60"), ("gf180", "PLACE_DENSITY", "0.40"), ("ihp-sg13g2", "PLACE_DENSITY", "0.65"), ("asap7", "PLACE_DENSITY", "0.60"), - ], - ) - def test_conditional_assignment_default( - self, monkeypatch, platform, key, default_val - ): - clean_env(monkeypatch, platform) - cfg = PLATFORM_MODULES[platform].get_config() - d = cfg.to_dict() - assert d[key] == default_val + ] + for platform, key, default_val in cases: + with self.subTest(platform=platform): + d = self.run_with_env(platform) + self.assertEqual(d[key], default_val) - @pytest.mark.parametrize("platform", PLATFORMS) - def test_conditional_assignment_override(self, monkeypatch, platform): - clean_env(monkeypatch, platform, {"PLACE_DENSITY": "0.99"}) - cfg = PLATFORM_MODULES[platform].get_config() - d = cfg.to_dict() - assert d["PLACE_DENSITY"] == "0.99" + def test_conditional_assignment_override(self): + for platform in PLATFORMS: + with self.subTest(platform=platform): + d = self.run_with_env(platform, {"PLACE_DENSITY": "0.99"}) + self.assertEqual(d["PLACE_DENSITY"], "0.99") # --- Test 3: Internal append (VAR += value within same config) --- -class TestInternalAppend: - def test_asap7_dont_use_cells_internal_append(self, monkeypatch): +class TestInternalAppend(PlatformTestCase): + def test_asap7_dont_use_cells_internal_append(self): """asap7: DONT_USE_CELLS = X then DONT_USE_CELLS += SDF* ICG*""" - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "*x1p*_ASAP7*" in d["DONT_USE_CELLS"] - assert "SDF*" in d["DONT_USE_CELLS"] - assert "ICG*" in d["DONT_USE_CELLS"] + d = self.run_with_env("asap7") + self.assertIn("*x1p*_ASAP7*", d["DONT_USE_CELLS"]) + self.assertIn("SDF*", d["DONT_USE_CELLS"]) + self.assertIn("ICG*", d["DONT_USE_CELLS"]) # --- Test 4: External append (VAR += from env) --- -class TestExternalAppend: - def test_sky130hd_dont_use_cells_from_env(self, monkeypatch): +class TestExternalAppend(PlatformTestCase): + def test_sky130hd_dont_use_cells_from_env(self): """sky130hd: DONT_USE_CELLS += list (appends to env value)""" - clean_env(monkeypatch, "sky130hd", {"DONT_USE_CELLS": "EXISTING_CELL"}) - cfg = sky130hd_config.get_config() - d = cfg.to_dict() - assert "EXISTING_CELL" in d["DONT_USE_CELLS"] - assert "sky130_fd_sc_hd__probe_p_8" in d["DONT_USE_CELLS"] + d = self.run_with_env("sky130hd", {"DONT_USE_CELLS": "EXISTING_CELL"}) + self.assertIn("EXISTING_CELL", d["DONT_USE_CELLS"]) + self.assertIn("sky130_fd_sc_hd__probe_p_8", d["DONT_USE_CELLS"]) - def test_ihp_dont_use_cells_from_env(self, monkeypatch): + def test_ihp_dont_use_cells_from_env(self): """ihp-sg13g2: DONT_USE_CELLS += list (appends to env value)""" - clean_env(monkeypatch, "ihp-sg13g2", {"DONT_USE_CELLS": "EXISTING"}) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "EXISTING" in d["DONT_USE_CELLS"] - assert "sg13g2_lgcp_1" in d["DONT_USE_CELLS"] + d = self.run_with_env("ihp-sg13g2", {"DONT_USE_CELLS": "EXISTING"}) + self.assertIn("EXISTING", d["DONT_USE_CELLS"]) + self.assertIn("sg13g2_lgcp_1", d["DONT_USE_CELLS"]) # --- Test 5: $(PLATFORM_DIR)/path expansion --- -class TestPlatformDirExpansion: - @pytest.mark.parametrize( - "platform,key,suffix", - [ +class TestPlatformDirExpansion(PlatformTestCase): + def test_platform_dir_expansion(self): + cases = [ ("nangate45", "TECH_LEF", "/lef/NangateOpenCellLibrary.tech.lef"), ("sky130hd", "TECH_LEF", "/lef/sky130_fd_sc_hd.tlef"), ("asap7", "TECH_LEF", "/lef/asap7_tech_1x_201209.lef"), - ], - ) - def test_platform_dir_expansion(self, monkeypatch, platform, key, suffix): - clean_env(monkeypatch, platform) - cfg = PLATFORM_MODULES[platform].get_config() - d = cfg.to_dict() - assert d[key].endswith(suffix) - assert get_platform_dir(platform) in d[key] + ] + for platform, key, suffix in cases: + with self.subTest(platform=platform): + d = self.run_with_env(platform) + self.assertTrue(d[key].endswith(suffix)) + self.assertIn(get_platform_dir(platform), d[key]) # --- Test 6: $(sort $(wildcard ...)) --- -class TestSortedGlob: - def test_nangate45_gds_files_sorted(self, monkeypatch): - clean_env(monkeypatch, "nangate45") - cfg = nangate45_config.get_config() - d = cfg.to_dict() +class TestSortedGlob(PlatformTestCase): + def test_nangate45_gds_files_sorted(self): + d = self.run_with_env("nangate45") gds = d["GDS_FILES"].split() - # Verify files are sorted - assert gds == sorted(gds) + self.assertEqual(gds, sorted(gds)) # --- Test 7: $(wildcard ...) --- -class TestWildcardGlob: - def test_sky130hd_gds_files(self, monkeypatch): - clean_env(monkeypatch, "sky130hd") - cfg = sky130hd_config.get_config() - d = cfg.to_dict() - # GDS_FILES should contain at least one .gds file +class TestWildcardGlob(PlatformTestCase): + def test_sky130hd_gds_files(self): + d = self.run_with_env("sky130hd") if d["GDS_FILES"].strip(): - assert ".gds" in d["GDS_FILES"] + self.assertIn(".gds", d["GDS_FILES"]) # --- Test 8: ifeq/ifneq conditionals --- -class TestConditionalIfeq: - def test_gf180_place_site_9t(self, monkeypatch): +class TestConditionalIfeq(PlatformTestCase): + def test_gf180_place_site_9t(self): """gf180: ifeq ($(TRACK_OPTION),9t) -> GF018hv5v_green_sc9""" - clean_env(monkeypatch, "gf180") - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["PLACE_SITE"] == "GF018hv5v_green_sc9" + d = self.run_with_env("gf180") + self.assertEqual(d["PLACE_SITE"], "GF018hv5v_green_sc9") - def test_gf180_place_site_7t(self, monkeypatch): + def test_gf180_place_site_7t(self): """gf180: else -> GF018hv5v_mcu_sc7""" - clean_env(monkeypatch, "gf180", {"TRACK_OPTION": "7t"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["PLACE_SITE"] == "GF018hv5v_mcu_sc7" + d = self.run_with_env("gf180", {"TRACK_OPTION": "7t"}) + self.assertEqual(d["PLACE_SITE"], "GF018hv5v_mcu_sc7") - def test_asap7_pdn_no_blocks(self, monkeypatch): + def test_asap7_pdn_no_blocks(self): """asap7: ifeq ($(BLOCKS),) -> grid_strategy-M1-M2-M5-M6.tcl""" - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "grid_strategy-M1-M2-M5-M6.tcl" in d["PDN_TCL"] + d = self.run_with_env("asap7") + self.assertIn("grid_strategy-M1-M2-M5-M6.tcl", d["PDN_TCL"]) - def test_asap7_pdn_with_blocks(self, monkeypatch): + def test_asap7_pdn_with_blocks(self): """asap7: BLOCKS set -> BLOCKS_grid_strategy.tcl""" - clean_env(monkeypatch, "asap7", {"BLOCKS": "block1"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "BLOCKS_grid_strategy.tcl" in d["PDN_TCL"] + d = self.run_with_env("asap7", {"BLOCKS": "block1"}) + self.assertIn("BLOCKS_grid_strategy.tcl", d["PDN_TCL"]) # --- Test 9: $(ADDITIONAL_LIBS) from env --- -class TestEnvVariableInclusion: - def test_nangate45_additional_libs(self, monkeypatch): - clean_env(monkeypatch, "nangate45", {"ADDITIONAL_LIBS": "/extra/lib.lib"}) - cfg = nangate45_config.get_config() - d = cfg.to_dict() - assert "/extra/lib.lib" in d["LIB_FILES"] - assert "NangateOpenCellLibrary_typical.lib" in d["LIB_FILES"] +class TestEnvVariableInclusion(PlatformTestCase): + def test_nangate45_additional_libs(self): + d = self.run_with_env("nangate45", {"ADDITIONAL_LIBS": "/extra/lib.lib"}) + self.assertIn("/extra/lib.lib", d["LIB_FILES"]) + self.assertIn("NangateOpenCellLibrary_typical.lib", d["LIB_FILES"]) # --- Test 10: $($(CORNER)_LIB_FILES) variable indirection --- -class TestVariableIndirection: - def test_gf180_bc_corner(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "BC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "ff_n40C_5v50" in d["LIB_FILES"] +class TestVariableIndirection(PlatformTestCase): + def test_gf180_bc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "BC"}) + self.assertIn("ff_n40C_5v50", d["LIB_FILES"]) - def test_gf180_wc_corner(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "WC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "ss_125C_4v50" in d["LIB_FILES"] + def test_gf180_wc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "WC"}) + self.assertIn("ss_125C_4v50", d["LIB_FILES"]) - def test_gf180_tc_corner(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "TC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "tt_025C_5v00" in d["LIB_FILES"] + def test_gf180_tc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "TC"}) + self.assertIn("tt_025C_5v00", d["LIB_FILES"]) - def test_asap7_bc_nldm_corner(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"CORNER": "BC"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "_FF_nldm_" in d["LIB_FILES"] + def test_asap7_bc_nldm_corner(self): + d = self.run_with_env("asap7", {"CORNER": "BC"}) + self.assertIn("_FF_nldm_", d["LIB_FILES"]) - def test_asap7_wc_corner(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"CORNER": "WC"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "_SS_nldm_" in d["LIB_FILES"] + def test_asap7_wc_corner(self): + d = self.run_with_env("asap7", {"CORNER": "WC"}) + self.assertIn("_SS_nldm_", d["LIB_FILES"]) # --- Test 11: $(subst PLACEHOLDER,...) template expansion --- -class TestPlaceholderSubstitution: - def test_asap7_placeholder_expansion(self, monkeypatch): +class TestPlaceholderSubstitution(PlatformTestCase): + def test_asap7_placeholder_expansion(self): """asap7: $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),...) templates""" - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - # Default VT is RVT -> tag "R" - assert "PLACEHOLDER" not in d.get("BC_NLDM_DFF_LIB_FILE", "") - assert "_RVT_" in d["BC_NLDM_DFF_LIB_FILE"] - assert "_RVT_" in d["BC_NLDM_LIB_FILES"] + d = self.run_with_env("asap7") + self.assertNotIn("PLACEHOLDER", d.get("BC_NLDM_DFF_LIB_FILE", "")) + self.assertIn("_RVT_", d["BC_NLDM_DFF_LIB_FILE"]) + self.assertIn("_RVT_", d["BC_NLDM_LIB_FILES"]) # --- Test 12: $(patsubst %VT,%,...) --- -class TestPatsubstVtTag: - def test_asap7_vt_tag_derivation(self, monkeypatch): +class TestPatsubstVtTag(PlatformTestCase): + def test_asap7_vt_tag_derivation(self): """RVT -> R, LVT -> L, SLVT -> SL""" - clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "LVT"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - # PRIMARY_VT=LVT -> tag L - assert "_L_" in d["SC_LEF"] or "_L_" in d["GDS_FILES"] + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "LVT"}) + self.assertTrue("_L_" in d["SC_LEF"] or "_L_" in d["GDS_FILES"]) - def test_asap7_slvt_tag(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "SLVT"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "_SL_" in d["SC_LEF"] + def test_asap7_slvt_tag(self): + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "SLVT"}) + self.assertIn("_SL_", d["SC_LEF"]) # --- Test 13: $(word 1,...) --- -class TestWordExtraction: - def test_asap7_primary_vt_is_first(self, monkeypatch): +class TestWordExtraction(PlatformTestCase): + def test_asap7_primary_vt_is_first(self): """PRIMARY_VT = $(word 1, $(VT_LIST))""" - clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "LVT RVT SLVT"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - # Primary should be LVT -> tag L - assert "asap7sc7p5t_28_L_" in d["SC_LEF"] + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "LVT RVT SLVT"}) + self.assertIn("asap7sc7p5t_28_L_", d["SC_LEF"]) # --- Test 14: $(wordlist 2,N,...) --- -class TestWordlistExtraction: - def test_asap7_other_vt_is_rest(self, monkeypatch): +class TestWordlistExtraction(PlatformTestCase): + def test_asap7_other_vt_is_rest(self): """OTHER_VT = $(wordlist 2, ..., $(VT_LIST))""" - clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "RVT LVT SLVT"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - # OTHER_VT = [LVT, SLVT], should appear in ADDITIONAL_LEFS - assert "asap7sc7p5t_28_L_1x" in d.get("ADDITIONAL_LEFS", "") - assert "asap7sc7p5t_28_SL_1x" in d.get("ADDITIONAL_LEFS", "") + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "RVT LVT SLVT"}) + self.assertIn("asap7sc7p5t_28_L_1x", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("asap7sc7p5t_28_SL_1x", d.get("ADDITIONAL_LEFS", "")) # --- Test 15: $(addsuffix tag,...) --- -class TestAddsuffix: - def test_asap7_fill_cells_suffix(self, monkeypatch): +class TestAddsuffix(PlatformTestCase): + def test_asap7_fill_cells_suffix(self): """FILL_CELLS = $(addsuffix $(PRIMARY_VT_TAG), $(FILL_CELLS_T))""" - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - # Default RVT -> tag R - assert "FILLERxp5_ASAP7_75t_R" in d["FILL_CELLS"] - assert "FILLER_ASAP7_75t_R" in d["FILL_CELLS"] - assert "DECAPx10_ASAP7_75t_R" in d["FILL_CELLS"] + d = self.run_with_env("asap7") + self.assertIn("FILLERxp5_ASAP7_75t_R", d["FILL_CELLS"]) + self.assertIn("FILLER_ASAP7_75t_R", d["FILL_CELLS"]) + self.assertIn("DECAPx10_ASAP7_75t_R", d["FILL_CELLS"]) # --- Test 16: $(if $(strip $(VAR)),...) --- -class TestIfStrip: - def test_asap7_default_vt_when_unset(self, monkeypatch): +class TestIfStrip(PlatformTestCase): + def test_asap7_default_vt_when_unset(self): """VT_LIST = $(if $(strip $(ASAP7_USE_VT)), ..., RVT)""" - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - # Should default to RVT -> tag R - assert "asap7sc7p5t_28_R_" in d["GDS_FILES"] + d = self.run_with_env("asap7") + self.assertIn("asap7sc7p5t_28_R_", d["GDS_FILES"]) - def test_asap7_vt_when_set(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "LVT"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "asap7sc7p5t_28_L_" in d["GDS_FILES"] + def test_asap7_vt_when_set(self): + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "LVT"}) + self.assertIn("asap7sc7p5t_28_L_", d["GDS_FILES"]) # --- Test 17: $(foreach)/$(eval) loop --- -class TestForeachEvalVtExpansion: - def test_asap7_multi_vt_expansion(self, monkeypatch): +class TestForeachEvalVtExpansion(PlatformTestCase): + def test_asap7_multi_vt_expansion(self): """foreach vt in OTHER_VT: expand templates and append""" - clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "RVT LVT SLVT"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "RVT LVT SLVT"}) # Primary VT = RVT (tag R) - assert "asap7sc7p5t_28_R_" in d["GDS_FILES"] + self.assertIn("asap7sc7p5t_28_R_", d["GDS_FILES"]) # OTHER_VT = [LVT, SLVT] should be appended - assert "asap7sc7p5t_28_L_220121a.gds" in d["GDS_FILES"] - assert "asap7sc7p5t_28_SL_220121a.gds" in d["GDS_FILES"] + self.assertIn("asap7sc7p5t_28_L_220121a.gds", d["GDS_FILES"]) + self.assertIn("asap7sc7p5t_28_SL_220121a.gds", d["GDS_FILES"]) # ADDITIONAL_LEFS should have OTHER_VT entries - assert "asap7sc7p5t_28_L_1x_220121a.lef" in d.get("ADDITIONAL_LEFS", "") - assert "asap7sc7p5t_28_SL_1x_220121a.lef" in d.get("ADDITIONAL_LEFS", "") + self.assertIn("asap7sc7p5t_28_L_1x_220121a.lef", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("asap7sc7p5t_28_SL_1x_220121a.lef", d.get("ADDITIONAL_LEFS", "")) # DFF lib files should have all 3 VTs - assert "_RVT_" in d["BC_NLDM_DFF_LIB_FILE"] - assert "_LVT_" in d["BC_NLDM_DFF_LIB_FILE"] - assert "_SLVT_" in d["BC_NLDM_DFF_LIB_FILE"] + self.assertIn("_RVT_", d["BC_NLDM_DFF_LIB_FILE"]) + self.assertIn("_LVT_", d["BC_NLDM_DFF_LIB_FILE"]) + self.assertIn("_SLVT_", d["BC_NLDM_DFF_LIB_FILE"]) # FILL_CELLS should have all 3 VT suffixes - assert "FILLERxp5_ASAP7_75t_R" in d["FILL_CELLS"] - assert "FILLERxp5_ASAP7_75t_L" in d["FILL_CELLS"] - assert "FILLERxp5_ASAP7_75t_SL" in d["FILL_CELLS"] + self.assertIn("FILLERxp5_ASAP7_75t_R", d["FILL_CELLS"]) + self.assertIn("FILLERxp5_ASAP7_75t_L", d["FILL_CELLS"]) + self.assertIn("FILLERxp5_ASAP7_75t_SL", d["FILL_CELLS"]) # --- Test 18: $(strip ...) --- -class TestStrip: - def test_asap7_strip_asap7_use_vt(self, monkeypatch): +class TestStrip(PlatformTestCase): + def test_asap7_strip_asap7_use_vt(self): """Whitespace in ASAP7_USE_VT should be stripped""" - clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": " RVT "}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "asap7sc7p5t_28_R_" in d["GDS_FILES"] + d = self.run_with_env("asap7", {"ASAP7_USE_VT": " RVT "}) + self.assertIn("asap7sc7p5t_28_R_", d["GDS_FILES"]) # --- Test 19: $(shell sed ...) SDC clock period extraction --- -class TestSdcClockPeriodExtraction: - def test_ihp_sdc_clk_period(self, monkeypatch, tmp_path): +class TestSdcClockPeriodExtraction(PlatformTestCase): + def test_ihp_sdc_clk_period(self): """ihp-sg13g2: extract clock period from SDC file""" - sdc = tmp_path / "constraint.sdc" - sdc.write_text("set clk_period 10.0\ncreate_clock ...\n") - clean_env(monkeypatch, "ihp-sg13g2", {"SDC_FILE": str(sdc)}) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert d["ABC_CLOCK_PERIOD_IN_PS"] == "10000.0" - - def test_ihp_sdc_period_flag(self, monkeypatch, tmp_path): + tmp = tempfile.mkdtemp() + try: + sdc = os.path.join(tmp, "constraint.sdc") + with open(sdc, "w") as f: + f.write("set clk_period 10.0\ncreate_clock ...\n") + d = self.run_with_env("ihp-sg13g2", {"SDC_FILE": sdc}) + self.assertEqual(d["ABC_CLOCK_PERIOD_IN_PS"], "10000.0") + finally: + shutil.rmtree(tmp) + + def test_ihp_sdc_period_flag(self): """ihp-sg13g2: extract from -period flag""" - sdc = tmp_path / "constraint.sdc" - sdc.write_text("create_clock -period 5.0 [get_ports clk]\n") - clean_env(monkeypatch, "ihp-sg13g2", {"SDC_FILE": str(sdc)}) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert d["ABC_CLOCK_PERIOD_IN_PS"] == "5000.0" - - def test_ihp_no_sdc_file(self, monkeypatch): + tmp = tempfile.mkdtemp() + try: + sdc = os.path.join(tmp, "constraint.sdc") + with open(sdc, "w") as f: + f.write("create_clock -period 5.0 [get_ports clk]\n") + d = self.run_with_env("ihp-sg13g2", {"SDC_FILE": sdc}) + self.assertEqual(d["ABC_CLOCK_PERIOD_IN_PS"], "5000.0") + finally: + shutil.rmtree(tmp) + + def test_ihp_no_sdc_file(self): """No SDC file -> ABC_CLOCK_PERIOD_IN_PS not set""" - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "ABC_CLOCK_PERIOD_IN_PS" not in d + d = self.run_with_env("ihp-sg13g2") + self.assertNotIn("ABC_CLOCK_PERIOD_IN_PS", d) # --- Test 20: $(origin VAR) check --- -class TestOriginCheck: - def test_ihp_origin_undefined(self, monkeypatch, tmp_path): +class TestOriginCheck(PlatformTestCase): + def test_ihp_origin_undefined(self): """When ABC_CLOCK_PERIOD_IN_PS is not in env, extract from SDC""" - sdc = tmp_path / "constraint.sdc" - sdc.write_text("set clk_period 8.0\n") - clean_env(monkeypatch, "ihp-sg13g2", {"SDC_FILE": str(sdc)}) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert d["ABC_CLOCK_PERIOD_IN_PS"] == "8000.0" - - def test_ihp_origin_defined(self, monkeypatch, tmp_path): + tmp = tempfile.mkdtemp() + try: + sdc = os.path.join(tmp, "constraint.sdc") + with open(sdc, "w") as f: + f.write("set clk_period 8.0\n") + d = self.run_with_env("ihp-sg13g2", {"SDC_FILE": sdc}) + self.assertEqual(d["ABC_CLOCK_PERIOD_IN_PS"], "8000.0") + finally: + shutil.rmtree(tmp) + + def test_ihp_origin_defined(self): """When ABC_CLOCK_PERIOD_IN_PS is in env, don't extract""" - sdc = tmp_path / "constraint.sdc" - sdc.write_text("set clk_period 8.0\n") - clean_env( - monkeypatch, - "ihp-sg13g2", - { - "SDC_FILE": str(sdc), - "ABC_CLOCK_PERIOD_IN_PS": "12345", - }, - ) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert ( - "ABC_CLOCK_PERIOD_IN_PS" not in d - or d.get("ABC_CLOCK_PERIOD_IN_PS") != "8000.0" - ) + tmp = tempfile.mkdtemp() + try: + sdc = os.path.join(tmp, "constraint.sdc") + with open(sdc, "w") as f: + f.write("set clk_period 8.0\n") + d = self.run_with_env( + "ihp-sg13g2", + {"SDC_FILE": sdc, "ABC_CLOCK_PERIOD_IN_PS": "12345"}, + ) + self.assertTrue( + "ABC_CLOCK_PERIOD_IN_PS" not in d + or d.get("ABC_CLOCK_PERIOD_IN_PS") != "8000.0" + ) + finally: + shutil.rmtree(tmp) # --- Test 21: $(abspath ...) --- -class TestAbspath: - def test_gf180_lib_files_absolute(self, monkeypatch): - clean_env(monkeypatch, "gf180") - cfg = gf180_config.get_config() - d = cfg.to_dict() - # BC_LIB_FILES should be absolute path - assert os.path.isabs(d["BC_LIB_FILES"]) - assert os.path.isabs(d["LIB_FILES"].split()[0]) +class TestAbspath(PlatformTestCase): + def test_gf180_lib_files_absolute(self): + d = self.run_with_env("gf180") + self.assertTrue(os.path.isabs(d["BC_LIB_FILES"])) + self.assertTrue(os.path.isabs(d["LIB_FILES"].split()[0])) # --- Test 22: $(realpath ...) --- -class TestRealpath: - def test_asap7_db_files_realpath(self, monkeypatch): +class TestRealpath(PlatformTestCase): + def test_asap7_db_files_realpath(self): """asap7: DB_FILES uses $(realpath ...) -- only if corner DB files exist""" - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - # DB_FILES may be empty if no corner DB files are defined - # Just verify it doesn't crash - assert isinstance(d.get("DB_FILES", ""), str) + d = self.run_with_env("asap7") + self.assertIsInstance(d.get("DB_FILES", ""), str) # --- Test 23: -include private.mk skipped --- -class TestPrivateMkSkipped: - def test_gf180_has_private_dir_default(self, monkeypatch): +class TestPrivateMkSkipped(PlatformTestCase): + def test_gf180_has_private_dir_default(self): """gf180: -include private.mk is skipped, but GF180_PRIVATE_DIR is set""" - clean_env(monkeypatch, "gf180") - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["GF180_PRIVATE_DIR"] == "../../gf180-private" + d = self.run_with_env("gf180") + self.assertEqual(d["GF180_PRIVATE_DIR"], "../../gf180-private") # --- Test 24: ??= (treated as ?=) --- -class TestDoubleQuestionEquals: - def test_ihp_io_pins_default_empty(self, monkeypatch): +class TestDoubleQuestionEquals(PlatformTestCase): + def test_ihp_io_pins_default_empty(self): """ihp-sg13g2: ??= variables default to empty""" - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert d.get("IO_NORTH_PINS", "") == "" - assert d.get("IO_SOUTH_PINS", "") == "" + d = self.run_with_env("ihp-sg13g2") + self.assertEqual(d.get("IO_NORTH_PINS", ""), "") + self.assertEqual(d.get("IO_SOUTH_PINS", ""), "") - def test_ihp_io_pins_override(self, monkeypatch): + def test_ihp_io_pins_override(self): """ihp-sg13g2: ??= variables can be overridden from env""" - clean_env(monkeypatch, "ihp-sg13g2", {"IO_NORTH_PINS": "pin1 pin2"}) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert d["IO_NORTH_PINS"] == "pin1 pin2" + d = self.run_with_env("ihp-sg13g2", {"IO_NORTH_PINS": "pin1 pin2"}) + self.assertEqual(d["IO_NORTH_PINS"], "pin1 pin2") # --- Test 25: Parameterized options (gf180) --- -class TestGf180ParameterizedOptions: - def test_default_options(self, monkeypatch): - clean_env(monkeypatch, "gf180") - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "5LM_1TM" in d["TECH_LEF"] - assert "9K" in d["TECH_LEF"] - assert "9t" in d["TECH_LEF"] +class TestGf180ParameterizedOptions(PlatformTestCase): + def test_default_options(self): + d = self.run_with_env("gf180") + self.assertIn("5LM_1TM", d["TECH_LEF"]) + self.assertIn("9K", d["TECH_LEF"]) + self.assertIn("9t", d["TECH_LEF"]) - def test_custom_track_option(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"TRACK_OPTION": "7t"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "7t" in d["TECH_LEF"] - assert d["PLACE_SITE"] == "GF018hv5v_mcu_sc7" + def test_custom_track_option(self): + d = self.run_with_env("gf180", {"TRACK_OPTION": "7t"}) + self.assertIn("7t", d["TECH_LEF"]) + self.assertEqual(d["PLACE_SITE"], "GF018hv5v_mcu_sc7") - def test_custom_metal_option(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"METAL_OPTION": "3LM_1TM"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "3LM_1TM" in d["TECH_LEF"] + def test_custom_metal_option(self): + d = self.run_with_env("gf180", {"METAL_OPTION": "3LM_1TM"}) + self.assertIn("3LM_1TM", d["TECH_LEF"]) # --- Test 26: BLOCKS conditional for PDN_TCL --- -class TestAsap7BlocksPdn: - def test_no_blocks(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "BLOCKS" not in d["PDN_TCL"] +class TestAsap7BlocksPdn(PlatformTestCase): + def test_no_blocks(self): + d = self.run_with_env("asap7") + self.assertNotIn("BLOCKS", d["PDN_TCL"]) - def test_with_blocks(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"BLOCKS": "some_block"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "BLOCKS_grid_strategy" in d["PDN_TCL"] + def test_with_blocks(self): + d = self.run_with_env("asap7", {"BLOCKS": "some_block"}) + self.assertIn("BLOCKS_grid_strategy", d["PDN_TCL"]) # --- Test 27: CLUSTER_FLOPS conditional --- -class TestAsap7ClusterFlops: - def test_no_cluster_flops(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "DFFHQNH2V2X" not in d.get("ADDITIONAL_LIBS", "") +class TestAsap7ClusterFlops(PlatformTestCase): + def test_no_cluster_flops(self): + d = self.run_with_env("asap7") + self.assertNotIn("DFFHQNH2V2X", d.get("ADDITIONAL_LIBS", "")) - def test_with_cluster_flops(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"CLUSTER_FLOPS": "1"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "DFFHQNH2V2X" in d.get("ADDITIONAL_LIBS", "") - assert "DFFHQNV2X" in d.get("ADDITIONAL_LIBS", "") - assert "asap7sc7p5t_DFFHQNH2V2X.lef" in d.get("ADDITIONAL_LEFS", "") - assert "asap7sc7p5t_pg" in d.get("ADDITIONAL_SITES", "") - assert d.get("GDS_ALLOW_EMPTY") == "DFFHQN[VH][24].*" + def test_with_cluster_flops(self): + d = self.run_with_env("asap7", {"CLUSTER_FLOPS": "1"}) + self.assertIn("DFFHQNH2V2X", d.get("ADDITIONAL_LIBS", "")) + self.assertIn("DFFHQNV2X", d.get("ADDITIONAL_LIBS", "")) + self.assertIn("asap7sc7p5t_DFFHQNH2V2X.lef", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("asap7sc7p5t_pg", d.get("ADDITIONAL_SITES", "")) + self.assertEqual(d.get("GDS_ALLOW_EMPTY"), "DFFHQN[VH][24].*") # --- Test 28: LIB_MODEL selection --- -class TestAsap7LibModel: - def test_default_nldm(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "/NLDM/" in d["LIB_DIR"] or d["LIB_DIR"].endswith("/NLDM") +class TestAsap7LibModel(PlatformTestCase): + def test_default_nldm(self): + d = self.run_with_env("asap7") + self.assertTrue("/NLDM/" in d["LIB_DIR"] or d["LIB_DIR"].endswith("/NLDM")) - def test_ccs_model(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"LIB_MODEL": "CCS"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "/CCS/" in d["LIB_DIR"] or d["LIB_DIR"].endswith("/CCS") + def test_ccs_model(self): + d = self.run_with_env("asap7", {"LIB_MODEL": "CCS"}) + self.assertTrue("/CCS/" in d["LIB_DIR"] or d["LIB_DIR"].endswith("/CCS")) # --- Test 29: Corner temperature/voltage --- -class TestCornerTemperatureVoltage: - def test_asap7_bc_corner(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"CORNER": "BC"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["TEMPERATURE"] == "25C" - assert d["VOLTAGE"] == "0.77" +class TestCornerTemperatureVoltage(PlatformTestCase): + def test_asap7_bc_corner(self): + d = self.run_with_env("asap7", {"CORNER": "BC"}) + self.assertEqual(d["TEMPERATURE"], "25C") + self.assertEqual(d["VOLTAGE"], "0.77") - def test_asap7_wc_corner(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"CORNER": "WC"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["TEMPERATURE"] == "100C" - assert d["VOLTAGE"] == "0.63" + def test_asap7_wc_corner(self): + d = self.run_with_env("asap7", {"CORNER": "WC"}) + self.assertEqual(d["TEMPERATURE"], "100C") + self.assertEqual(d["VOLTAGE"], "0.63") - def test_gf180_bc_corner(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "BC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["TEMPERATURE"] == "-40c" - assert d["VOLTAGE"] == "5.5" + def test_gf180_bc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "BC"}) + self.assertEqual(d["TEMPERATURE"], "-40c") + self.assertEqual(d["VOLTAGE"], "5.5") - def test_gf180_wc_corner(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "WC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["TEMPERATURE"] == "125c" - assert d["VOLTAGE"] == "4.5" + def test_gf180_wc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "WC"}) + self.assertEqual(d["TEMPERATURE"], "125c") + self.assertEqual(d["VOLTAGE"], "4.5") # --- Test 30: Multi-VT expansion --- -class TestAsap7MultiVt: - def test_single_vt_default(self, monkeypatch): +class TestAsap7MultiVt(PlatformTestCase): + def test_single_vt_default(self): """Default: ASAP7_USE_VT unset -> RVT only, no OTHER_VT additions""" - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - # Only primary VT in GDS_FILES + d = self.run_with_env("asap7") gds = d["GDS_FILES"] - assert "28_R_" in gds - assert "28_L_" not in gds - # No ADDITIONAL_LEFS from VT loop (may have CLUSTER_FLOPS additions) - assert "28_L_1x" not in d.get("ADDITIONAL_LEFS", "") - - def test_dual_vt(self, monkeypatch): - clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "RVT LVT"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "28_R_" in d["GDS_FILES"] - assert "28_L_" in d["GDS_FILES"] + self.assertIn("28_R_", gds) + self.assertNotIn("28_L_", gds) + self.assertNotIn("28_L_1x", d.get("ADDITIONAL_LEFS", "")) + + def test_dual_vt(self): + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "RVT LVT"}) + self.assertIn("28_R_", d["GDS_FILES"]) + self.assertIn("28_L_", d["GDS_FILES"]) # --- Test 31: FOOTPRINT_TCL conditional (ihp-sg13g2) --- -class TestIhpFootprintConditional: - def test_no_footprint(self, monkeypatch): +class TestIhpFootprintConditional(PlatformTestCase): + def test_no_footprint(self): """No FOOTPRINT_TCL -> no IO lefs/libs added""" - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "sg13g2_io.lef" not in d.get("ADDITIONAL_LEFS", "") + d = self.run_with_env("ihp-sg13g2") + self.assertNotIn("sg13g2_io.lef", d.get("ADDITIONAL_LEFS", "")) - def test_with_footprint(self, monkeypatch): + def test_with_footprint(self): """FOOTPRINT_TCL set -> IO lefs/libs/gds added""" - clean_env(monkeypatch, "ihp-sg13g2", {"FOOTPRINT_TCL": "/some/file.tcl"}) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "sg13g2_io.lef" in d.get("ADDITIONAL_LEFS", "") - assert "bondpad_70x70.lef" in d.get("ADDITIONAL_LEFS", "") - assert "sg13g2_io_slow" in d.get("SLOW_LIB_FILES", "") - assert "sg13g2_io.gds" in d.get("ADDITIONAL_GDS", "") + d = self.run_with_env("ihp-sg13g2", {"FOOTPRINT_TCL": "/some/file.tcl"}) + self.assertIn("sg13g2_io.lef", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("bondpad_70x70.lef", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("sg13g2_io_slow", d.get("SLOW_LIB_FILES", "")) + self.assertIn("sg13g2_io.gds", d.get("ADDITIONAL_GDS", "")) # --- Test 32: $(PLATFORM) in paths --- -class TestPlatformVarInPaths: - def test_sky130hd_platform_in_klayout(self, monkeypatch): - clean_env(monkeypatch, "sky130hd") - cfg = sky130hd_config.get_config() - d = cfg.to_dict() - assert "sky130hd.lyt" in d["KLAYOUT_TECH_FILE"] - assert "sky130hd.lydrc" in d["KLAYOUT_DRC_FILE"] - assert "sky130hd.cdl" in d["CDL_FILE"] +class TestPlatformVarInPaths(PlatformTestCase): + def test_sky130hd_platform_in_klayout(self): + d = self.run_with_env("sky130hd") + self.assertIn("sky130hd.lyt", d["KLAYOUT_TECH_FILE"]) + self.assertIn("sky130hd.lydrc", d["KLAYOUT_DRC_FILE"]) + self.assertIn("sky130hd.cdl", d["CDL_FILE"]) - def test_sky130hs_platform_in_klayout(self, monkeypatch): - clean_env(monkeypatch, "sky130hs") - cfg = sky130hs_config.get_config() - d = cfg.to_dict() - assert "sky130hs.lyt" in d["KLAYOUT_TECH_FILE"] + def test_sky130hs_platform_in_klayout(self): + d = self.run_with_env("sky130hs") + self.assertIn("sky130hs.lyt", d["KLAYOUT_TECH_FILE"]) # --- Test 33: Make shim round-trip --- -class TestShimRoundTrip: +class TestShimRoundTrip(PlatformTestCase): """Verify config.py Make output format is consumable by foreach/eval.""" - @pytest.mark.parametrize("platform", PLATFORMS) - def test_make_output_format(self, monkeypatch, platform, capsys): + def test_make_output_format(self): """Each line is 'export KEY=VALUE' or 'export KEY?=VALUE' with __SPACE__""" - clean_env(monkeypatch, platform) - cfg = PLATFORM_MODULES[platform].get_config() - cfg.output_make() - out = capsys.readouterr().out - for line in out.strip().split("\n"): - assert line.startswith( - "export " - ), f"Line doesn't start with 'export ': {line}" - rest = line[7:] # strip "export " - assert "=" in rest, f"No = in: {line}" - # No actual spaces in values (should be __SPACE__) - key_op_val = rest - if "?=" in key_op_val: - key, val = key_op_val.split("?=", 1) - else: - key, val = key_op_val.split("=", 1) - assert " " not in val, f"Space in value (should be __SPACE__): {key}={val}" - - @pytest.mark.parametrize("platform", PLATFORMS) - def test_json_output_parseable(self, monkeypatch, platform, capsys): + for platform in PLATFORMS: + with self.subTest(platform=platform): + d = self.run_with_env(platform) + cfg = PLATFORM_MODULES[platform].get_config() + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_make() + for line in buf.getvalue().strip().split("\n"): + self.assertTrue( + line.startswith("export "), + f"Line doesn't start with 'export ': {line}", + ) + rest = line[7:] # strip "export " + self.assertIn("=", rest, f"No = in: {line}") + if "?=" in rest: + key, val = rest.split("?=", 1) + else: + key, val = rest.split("=", 1) + self.assertNotIn( + " ", + val, + f"Space in value (should be __SPACE__): {key}={val}", + ) + + def test_json_output_parseable(self): """JSON output should be valid and parseable.""" - clean_env(monkeypatch, platform) - cfg = PLATFORM_MODULES[platform].get_config() - cfg.output_json() - out = capsys.readouterr().out - data = json.loads(out) - assert isinstance(data, dict) - assert len(data) > 0 + for platform in PLATFORMS: + with self.subTest(platform=platform): + self.run_with_env(platform) + cfg = PLATFORM_MODULES[platform].get_config() + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + self.assertIsInstance(data, dict) + self.assertGreater(len(data), 0) # =================================================================== # 3. Integration findings: design-config override semantics # =================================================================== -class TestDesignConfigOverrides: +class TestDesignConfigOverrides(PlatformTestCase): """Tests discovered from Make integration comparison. When a design config.mk sets a variable with = or :=, it overrides @@ -856,304 +784,214 @@ class TestDesignConfigOverrides: semantics work correctly end-to-end. """ - def test_conditional_overridden_by_immediate_assignment(self, monkeypatch): - """nangate45/gcd: 'export ADDER_MAP_FILE :=' in design clears platform ?= default. - - Make's := (immediate assignment) sets the variable even if empty. - When the platform config.py sees ADDER_MAP_FILE already in env, - its ?= is a no-op. - """ - clean_env(monkeypatch, "nangate45", {"ADDER_MAP_FILE": ""}) - cfg = nangate45_config.get_config() - d = cfg.to_dict() - # Empty env value should win over ?= default - assert d["ADDER_MAP_FILE"] == "" + def test_conditional_overridden_by_immediate_assignment(self): + """nangate45/gcd: 'export ADDER_MAP_FILE :=' in design clears platform ?= default.""" + d = self.run_with_env("nangate45", {"ADDER_MAP_FILE": ""}) + self.assertEqual(d["ADDER_MAP_FILE"], "") - def test_design_place_density_overrides_platform(self, monkeypatch): + def test_design_place_density_overrides_platform(self): """asap7/gcd: design sets PLACE_DENSITY=0.35, overriding platform ?=0.60.""" - clean_env(monkeypatch, "asap7", {"PLACE_DENSITY": "0.35"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["PLACE_DENSITY"] == "0.35" + d = self.run_with_env("asap7", {"PLACE_DENSITY": "0.35"}) + self.assertEqual(d["PLACE_DENSITY"], "0.35") - def test_design_pdn_tcl_overrides_platform(self, monkeypatch): + def test_design_pdn_tcl_overrides_platform(self): """nangate45/gcd: design sets PDN_TCL, overriding platform ?= default.""" - clean_env( - monkeypatch, - "nangate45", - {"PDN_TCL": "/designs/nangate45/gcd/custom_pdn.tcl"}, + d = self.run_with_env( + "nangate45", {"PDN_TCL": "/designs/nangate45/gcd/custom_pdn.tcl"} ) - cfg = nangate45_config.get_config() - d = cfg.to_dict() - assert d["PDN_TCL"] == "/designs/nangate45/gcd/custom_pdn.tcl" - - def test_ihp_design_place_density_overrides(self, monkeypatch): - """ihp-sg13g2/gcd: design sets PLACE_DENSITY?=0.88, platform has ?=0.65. - Design config is included BEFORE platform config. Since both use ?=, - the first one (design) wins.""" - clean_env(monkeypatch, "ihp-sg13g2", {"PLACE_DENSITY": "0.88"}) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert d["PLACE_DENSITY"] == "0.88" + self.assertEqual(d["PDN_TCL"], "/designs/nangate45/gcd/custom_pdn.tcl") + def test_ihp_design_place_density_overrides(self): + """ihp-sg13g2/gcd: design sets PLACE_DENSITY?=0.88, platform has ?=0.65.""" + d = self.run_with_env("ihp-sg13g2", {"PLACE_DENSITY": "0.88"}) + self.assertEqual(d["PLACE_DENSITY"], "0.88") -class TestGf180CornerVariants: + +class TestGf180CornerVariants(PlatformTestCase): """Tests for all 3 gf180 corners discovered from Make integration comparison.""" - def test_bc_rcx_rules(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "BC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "bst.rules" in d["RCX_RULES"] - assert d["RCX_RC_CORNER"] == "FuncRCmin" + def test_bc_rcx_rules(self): + d = self.run_with_env("gf180", {"CORNER": "BC"}) + self.assertIn("bst.rules", d["RCX_RULES"]) + self.assertEqual(d["RCX_RC_CORNER"], "FuncRCmin") - def test_wc_rcx_rules(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "WC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "wst.rules" in d["RCX_RULES"] - assert d["RCX_RC_CORNER"] == "FuncRCmax" + def test_wc_rcx_rules(self): + d = self.run_with_env("gf180", {"CORNER": "WC"}) + self.assertIn("wst.rules", d["RCX_RULES"]) + self.assertEqual(d["RCX_RC_CORNER"], "FuncRCmax") - def test_tc_rcx_rules(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "TC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "typ.rules" in d["RCX_RULES"] - assert d["RCX_RC_CORNER"] == "FuncRCtyp" + def test_tc_rcx_rules(self): + d = self.run_with_env("gf180", {"CORNER": "TC"}) + self.assertIn("typ.rules", d["RCX_RULES"]) + self.assertEqual(d["RCX_RC_CORNER"], "FuncRCtyp") - def test_bc_pwr_nets_uses_corner_voltage(self, monkeypatch): + def test_bc_pwr_nets_uses_corner_voltage(self): """PWR_NETS_VOLTAGES should use the corner-specific voltage.""" - clean_env(monkeypatch, "gf180", {"CORNER": "BC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["PWR_NETS_VOLTAGES"] == "VDD 5.5" + d = self.run_with_env("gf180", {"CORNER": "BC"}) + self.assertEqual(d["PWR_NETS_VOLTAGES"], "VDD 5.5") - def test_wc_pwr_nets_uses_corner_voltage(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "WC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["PWR_NETS_VOLTAGES"] == "VDD 4.5" + def test_wc_pwr_nets_uses_corner_voltage(self): + d = self.run_with_env("gf180", {"CORNER": "WC"}) + self.assertEqual(d["PWR_NETS_VOLTAGES"], "VDD 4.5") - def test_tc_pwr_nets_uses_corner_voltage(self, monkeypatch): - clean_env(monkeypatch, "gf180", {"CORNER": "TC"}) - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["PWR_NETS_VOLTAGES"] == "VDD 5.0" + def test_tc_pwr_nets_uses_corner_voltage(self): + d = self.run_with_env("gf180", {"CORNER": "TC"}) + self.assertEqual(d["PWR_NETS_VOLTAGES"], "VDD 5.0") - def test_gds_layer_map_absolute_path(self, monkeypatch): - clean_env(monkeypatch, "gf180") - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert os.path.isabs(d["GDS_LAYER_MAP"]) - assert "edi2gds.layermap" in d["GDS_LAYER_MAP"] + def test_gds_layer_map_absolute_path(self): + d = self.run_with_env("gf180") + self.assertTrue(os.path.isabs(d["GDS_LAYER_MAP"])) + self.assertIn("edi2gds.layermap", d["GDS_LAYER_MAP"]) - def test_klayout_lef_file(self, monkeypatch): - clean_env(monkeypatch, "gf180") - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert "tech_9t_5LM_1TM.lef" in d["KLAYOUT_LEF_FILE"] + def test_klayout_lef_file(self): + d = self.run_with_env("gf180") + self.assertIn("tech_9t_5LM_1TM.lef", d["KLAYOUT_LEF_FILE"]) - def test_tie_cell_and_endcap(self, monkeypatch): - clean_env(monkeypatch, "gf180") - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["TIE_CELL"] == "gf180mcu_fd_sc_mcu9t5v0__filltie" - assert d["ENDCAP_CELL"] == "gf180mcu_fd_sc_mcu9t5v0__endcap" + def test_tie_cell_and_endcap(self): + d = self.run_with_env("gf180") + self.assertEqual(d["TIE_CELL"], "gf180mcu_fd_sc_mcu9t5v0__filltie") + self.assertEqual(d["ENDCAP_CELL"], "gf180mcu_fd_sc_mcu9t5v0__endcap") - def test_max_fanout(self, monkeypatch): - clean_env(monkeypatch, "gf180") - cfg = gf180_config.get_config() - d = cfg.to_dict() - assert d["MAX_FANOUT"] == "20" + def test_max_fanout(self): + d = self.run_with_env("gf180") + self.assertEqual(d["MAX_FANOUT"], "20") -class TestAsap7ExtraVarsFromIntegration: +class TestAsap7ExtraVarsFromIntegration(PlatformTestCase): """Tests for asap7 variables verified against Make integration output.""" - def test_platform_tcl(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["PLATFORM_TCL"].endswith("/liberty_suppressions.tcl") - - def test_make_tracks(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["MAKE_TRACKS"].endswith("/openRoad/make_tracks.tcl") - - def test_set_rc_tcl(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["SET_RC_TCL"].endswith("/setRC.tcl") - - def test_lib_dir_default(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["LIB_DIR"].endswith("/lib/NLDM") - - def test_macro_rows_halo(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["MACRO_ROWS_HALO_X"] == "2" - assert d["MACRO_ROWS_HALO_Y"] == "2" - - def test_corner_temps_and_voltages(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["BC_TEMPERATURE"] == "25C" - assert d["TC_TEMPERATURE"] == "0C" - assert d["WC_TEMPERATURE"] == "100C" - assert d["BC_VOLTAGE"] == "0.77" - assert d["TC_VOLTAGE"] == "0.70" - assert d["WC_VOLTAGE"] == "0.63" - - def test_synth_minimum_keep_size(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert d["SYNTH_MINIMUM_KEEP_SIZE"] == "1000" - - def test_ccs_lib_files_with_bc_additional(self, monkeypatch): + def test_platform_tcl(self): + d = self.run_with_env("asap7") + self.assertTrue(d["PLATFORM_TCL"].endswith("/liberty_suppressions.tcl")) + + def test_make_tracks(self): + d = self.run_with_env("asap7") + self.assertTrue(d["MAKE_TRACKS"].endswith("/openRoad/make_tracks.tcl")) + + def test_set_rc_tcl(self): + d = self.run_with_env("asap7") + self.assertTrue(d["SET_RC_TCL"].endswith("/setRC.tcl")) + + def test_lib_dir_default(self): + d = self.run_with_env("asap7") + self.assertTrue(d["LIB_DIR"].endswith("/lib/NLDM")) + + def test_macro_rows_halo(self): + d = self.run_with_env("asap7") + self.assertEqual(d["MACRO_ROWS_HALO_X"], "2") + self.assertEqual(d["MACRO_ROWS_HALO_Y"], "2") + + def test_corner_temps_and_voltages(self): + d = self.run_with_env("asap7") + self.assertEqual(d["BC_TEMPERATURE"], "25C") + self.assertEqual(d["TC_TEMPERATURE"], "0C") + self.assertEqual(d["WC_TEMPERATURE"], "100C") + self.assertEqual(d["BC_VOLTAGE"], "0.77") + self.assertEqual(d["TC_VOLTAGE"], "0.70") + self.assertEqual(d["WC_VOLTAGE"], "0.63") + + def test_synth_minimum_keep_size(self): + d = self.run_with_env("asap7") + self.assertEqual(d["SYNTH_MINIMUM_KEEP_SIZE"], "1000") + + def test_ccs_lib_files_with_bc_additional(self): """BC_CCS_LIB_FILES should include BC_ADDITIONAL_LIBS when set.""" - clean_env(monkeypatch, "asap7", {"BC_ADDITIONAL_LIBS": "/extra/bc.lib"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "/extra/bc.lib" in d["BC_CCS_LIB_FILES"] - assert "_ccs_" in d["BC_CCS_LIB_FILES"] + d = self.run_with_env("asap7", {"BC_ADDITIONAL_LIBS": "/extra/bc.lib"}) + self.assertIn("/extra/bc.lib", d["BC_CCS_LIB_FILES"]) + self.assertIn("_ccs_", d["BC_CCS_LIB_FILES"]) - def test_wc_nldm_lib_files(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "_SS_nldm_" in d["WC_NLDM_LIB_FILES"] - assert "_RVT_" in d["WC_NLDM_LIB_FILES"] + def test_wc_nldm_lib_files(self): + d = self.run_with_env("asap7") + self.assertIn("_SS_nldm_", d["WC_NLDM_LIB_FILES"]) + self.assertIn("_RVT_", d["WC_NLDM_LIB_FILES"]) - def test_tc_nldm_lib_files(self, monkeypatch): - clean_env(monkeypatch, "asap7") - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "_TT_nldm_" in d["TC_NLDM_LIB_FILES"] - assert "_RVT_" in d["TC_NLDM_LIB_FILES"] + def test_tc_nldm_lib_files(self): + d = self.run_with_env("asap7") + self.assertIn("_TT_nldm_", d["TC_NLDM_LIB_FILES"]) + self.assertIn("_RVT_", d["TC_NLDM_LIB_FILES"]) - def test_wc_corner_lib_files(self, monkeypatch): + def test_wc_corner_lib_files(self): """With CORNER=WC, LIB_FILES should use WC_NLDM_LIB_FILES.""" - clean_env(monkeypatch, "asap7", {"CORNER": "WC"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "_SS_nldm_" in d["LIB_FILES"] + d = self.run_with_env("asap7", {"CORNER": "WC"}) + self.assertIn("_SS_nldm_", d["LIB_FILES"]) - def test_tc_corner_lib_files(self, monkeypatch): + def test_tc_corner_lib_files(self): """With CORNER=TC, LIB_FILES should use TC_NLDM_LIB_FILES.""" - clean_env(monkeypatch, "asap7", {"CORNER": "TC"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "_TT_nldm_" in d["LIB_FILES"] + d = self.run_with_env("asap7", {"CORNER": "TC"}) + self.assertIn("_TT_nldm_", d["LIB_FILES"]) - def test_ccs_model_corner_selection(self, monkeypatch): + def test_ccs_model_corner_selection(self): """With LIB_MODEL=CCS and CORNER=BC, LIB_FILES should use BC_CCS_LIB_FILES.""" - clean_env(monkeypatch, "asap7", {"LIB_MODEL": "CCS", "CORNER": "BC"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "_ccs_" in d["LIB_FILES"] + d = self.run_with_env("asap7", {"LIB_MODEL": "CCS", "CORNER": "BC"}) + self.assertIn("_ccs_", d["LIB_FILES"]) - def test_lvt_design_vars(self, monkeypatch): + def test_lvt_design_vars(self): """asap7/aes_lvt: ASAP7_USE_VT=LVT should set all primary VT vars to L tag.""" - clean_env(monkeypatch, "asap7", {"ASAP7_USE_VT": "LVT"}) - cfg = asap7_config.get_config() - d = cfg.to_dict() - assert "asap7sc7p5t_28_L_1x" in d["SC_LEF"] - assert "asap7sc7p5t_28_L_" in d["GDS_FILES"] - assert "TIEHIx1_ASAP7_75t_L" in d["TIEHI_CELL_AND_PORT"] - assert "BUFx2_ASAP7_75t_L" in d["ABC_DRIVER_CELL"] - assert "cells_latch_L.v" in d["LATCH_MAP_FILE"] - assert "TAPCELL_ASAP7_75t_L" in d["TAP_CELL_NAME"] - assert "FILLERxp5_ASAP7_75t_L" in d["FILL_CELLS"] + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "LVT"}) + self.assertIn("asap7sc7p5t_28_L_1x", d["SC_LEF"]) + self.assertIn("asap7sc7p5t_28_L_", d["GDS_FILES"]) + self.assertIn("TIEHIx1_ASAP7_75t_L", d["TIEHI_CELL_AND_PORT"]) + self.assertIn("BUFx2_ASAP7_75t_L", d["ABC_DRIVER_CELL"]) + self.assertIn("cells_latch_L.v", d["LATCH_MAP_FILE"]) + self.assertIn("TAPCELL_ASAP7_75t_L", d["TAP_CELL_NAME"]) + self.assertIn("FILLERxp5_ASAP7_75t_L", d["FILL_CELLS"]) -class TestIhpExtraVarsFromIntegration: +class TestIhpExtraVarsFromIntegration(PlatformTestCase): """Tests for ihp-sg13g2 variables verified against Make integration output.""" - def test_slow_lib_files(self, monkeypatch): - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "slow_1p08V_125C" in d["SLOW_LIB_FILES"] + def test_slow_lib_files(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("slow_1p08V_125C", d["SLOW_LIB_FILES"]) - def test_fast_lib_files(self, monkeypatch): - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "fast_1p32V_m40C" in d["FAST_LIB_FILES"] + def test_fast_lib_files(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("fast_1p32V_m40C", d["FAST_LIB_FILES"]) - def test_typ_lib_files(self, monkeypatch): - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "typ_1p20V_25C" in d["TYP_LIB_FILES"] + def test_typ_lib_files(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("typ_1p20V_25C", d["TYP_LIB_FILES"]) - def test_lib_files_defaults_to_typ(self, monkeypatch): + def test_lib_files_defaults_to_typ(self): """LIB_FILES ?= $(TYP_LIB_FILES)""" - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "typ_1p20V_25C" in d["LIB_FILES"] - - def test_core_margin(self, monkeypatch): - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert d["CORE_MARGIN"] == "17.5" - - def test_io_filler_cells(self, monkeypatch): - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "sg13g2_Filler10000" in d["IO_FILLER_CELLS"] - assert "sg13g2_Filler200" in d["IO_FILLER_CELLS"] - - def test_io_bondpad_vars(self, monkeypatch): - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert d["IO_BONDPAD_SIZE"] == "70" - assert d["IO_BONDPAD_NAME"] == "bondpad_70x70" - assert d["IO_LENGTH"] == "180" - assert d["IO_WIDTH"] == "80" - assert d["IO_SEALRING_OFFSET"] == "70" - - def test_gds_allow_empty_regex(self, monkeypatch): - clean_env(monkeypatch, "ihp-sg13g2") - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "RM_IHPSG13" in d["GDS_ALLOW_EMPTY"] - assert "CORNER" in d["GDS_ALLOW_EMPTY"] - - def test_footprint_conditional_with_load_disabled(self, monkeypatch): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("typ_1p20V_25C", d["LIB_FILES"]) + + def test_core_margin(self): + d = self.run_with_env("ihp-sg13g2") + self.assertEqual(d["CORE_MARGIN"], "17.5") + + def test_io_filler_cells(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("sg13g2_Filler10000", d["IO_FILLER_CELLS"]) + self.assertIn("sg13g2_Filler200", d["IO_FILLER_CELLS"]) + + def test_io_bondpad_vars(self): + d = self.run_with_env("ihp-sg13g2") + self.assertEqual(d["IO_BONDPAD_SIZE"], "70") + self.assertEqual(d["IO_BONDPAD_NAME"], "bondpad_70x70") + self.assertEqual(d["IO_LENGTH"], "180") + self.assertEqual(d["IO_WIDTH"], "80") + self.assertEqual(d["IO_SEALRING_OFFSET"], "70") + + def test_gds_allow_empty_regex(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("RM_IHPSG13", d["GDS_ALLOW_EMPTY"]) + self.assertIn("CORNER", d["GDS_ALLOW_EMPTY"]) + + def test_footprint_conditional_with_load_disabled(self): """FOOTPRINT_TCL set but LOAD_ADDITIONAL_FILES=0 -> no IO additions.""" - clean_env( - monkeypatch, + d = self.run_with_env( "ihp-sg13g2", - { - "FOOTPRINT_TCL": "/some/file.tcl", - "LOAD_ADDITIONAL_FILES": "0", - }, + {"FOOTPRINT_TCL": "/some/file.tcl", "LOAD_ADDITIONAL_FILES": "0"}, ) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "sg13g2_io.lef" not in d.get("ADDITIONAL_LEFS", "") + self.assertNotIn("sg13g2_io.lef", d.get("ADDITIONAL_LEFS", "")) - def test_slow_lib_with_footprint(self, monkeypatch): + def test_slow_lib_with_footprint(self): """FOOTPRINT_TCL set -> SLOW_LIB_FILES includes IO lib.""" - clean_env(monkeypatch, "ihp-sg13g2", {"FOOTPRINT_TCL": "/some/file.tcl"}) - cfg = ihp_config.get_config() - d = cfg.to_dict() - assert "sg13g2_io_slow" in d["SLOW_LIB_FILES"] - assert "sg13g2_stdcell_slow" in d["SLOW_LIB_FILES"] + d = self.run_with_env("ihp-sg13g2", {"FOOTPRINT_TCL": "/some/file.tcl"}) + self.assertIn("sg13g2_io_slow", d["SLOW_LIB_FILES"]) + self.assertIn("sg13g2_stdcell_slow", d["SLOW_LIB_FILES"]) # =================================================================== @@ -1168,36 +1006,44 @@ def test_slow_lib_with_footprint(self, monkeypatch): ] -@pytest.mark.integration -class TestMakeIntegration: +@unittest.skipUnless(os.environ.get("RUN_INTEGRATION"), "set RUN_INTEGRATION=1 to run") +class TestMakeIntegration(unittest.TestCase): """Run make DESIGN_CONFIG=... clean_all metadata through the shim. These tests verify the full config.mk shim -> config.py -> Make pipeline. They require Make and the ORFS environment to be set up. """ - @pytest.mark.parametrize("platform,design", INTEGRATION_DESIGNS) - def test_make_metadata(self, platform, design): + def test_make_metadata(self): """Run make clean_all metadata and verify it succeeds.""" - design_config = f"designs/{platform}/{design}/config.mk" - result = subprocess.run( - ["make", "clean_all", "metadata", f"DESIGN_CONFIG={design_config}"], - capture_output=True, - text=True, - cwd=os.path.abspath(FLOW_DIR), - timeout=300, - ) - assert result.returncode == 0, ( - f"make metadata failed for {platform}/{design}:\n" - f"stdout: {result.stdout[-2000:]}\n" - f"stderr: {result.stderr[-2000:]}" - ) + for platform, design in INTEGRATION_DESIGNS: + with self.subTest(platform=platform, design=design): + design_config = f"designs/{platform}/{design}/config.mk" + result = subprocess.run( + [ + "make", + "clean_all", + "metadata", + f"DESIGN_CONFIG={design_config}", + ], + capture_output=True, + text=True, + cwd=os.path.abspath(FLOW_DIR), + timeout=300, + ) + self.assertEqual( + result.returncode, + 0, + f"make metadata failed for {platform}/{design}:\n" + f"stdout: {result.stdout[-2000:]}\n" + f"stderr: {result.stderr[-2000:]}", + ) ALL_PLATFORMS = ["nangate45", "sky130hd", "sky130hs", "gf180", "ihp-sg13g2", "asap7"] -class TestUnexpandedOutput: +class TestUnexpandedOutput(PlatformTestCase): """Verify config.py output uses $(PLATFORM_DIR) and $(PLATFORM) instead of absolute paths. bazel-orfs runs in a sandbox where platform files live at different paths. @@ -1206,112 +1052,79 @@ class TestUnexpandedOutput: - bazel-orfs: Python substitution when the Bazel rule executes """ - @pytest.fixture(autouse=True) - def _clean_env(self, monkeypatch): - for v in [ - "ADDITIONAL_LIBS", - "ADDITIONAL_GDS", - "ADDITIONAL_LEFS", - "ADDITIONAL_SLOW_LIBS", - "ADDITIONAL_FAST_LIBS", - "ADDITIONAL_TYP_LIBS", - "BC_ADDITIONAL_LIBS", - "BLOCKS", - "CORNER", - "ASAP7_USE_VT", - "LIB_MODEL", - "CLUSTER_FLOPS", - "FOOTPRINT_TCL", - "LOAD_ADDITIONAL_FILES", - "TRACK_OPTION", - "METAL_OPTION", - "KVALUE", - "POWER_OPTION", - "SDC_FILE", - "ABC_CLOCK_PERIOD_IN_PS", - "DONT_USE_CELLS", - ]: - monkeypatch.delenv(v, raising=False) - - @pytest.mark.parametrize("platform", ALL_PLATFORMS) - def test_json_no_absolute_platform_dir(self, platform, monkeypatch, tmp_path): + def test_json_no_absolute_platform_dir(self): """JSON output must not contain the absolute platform_dir path.""" - pd = os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) - monkeypatch.setenv("PLATFORM_DIR", pd) - monkeypatch.setenv("PLATFORM", platform) - - mod = _load_config_module(platform) - cfg = mod.get_config() - - # Capture JSON output - import io - - buf = io.StringIO() - old_stdout = sys.stdout - sys.stdout = buf - cfg.output_json() - sys.stdout = old_stdout - data = json.loads(buf.getvalue()) - - for key, value in data.items(): - assert pd not in value, ( - f"{platform}: {key} contains absolute path {pd!r} " - f"instead of $(PLATFORM_DIR). Value: {value!r}" - ) - - @pytest.mark.parametrize("platform", ALL_PLATFORMS) - def test_make_no_absolute_platform_dir(self, platform, monkeypatch): + for platform in ALL_PLATFORMS: + with self.subTest(platform=platform): + pd = get_platform_dir(platform) + d = self.run_with_env(platform) + mod = _load_config_module(platform) + cfg = mod.get_config() + + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + + for key, value in data.items(): + self.assertNotIn( + pd, + value, + f"{platform}: {key} contains absolute path {pd!r} " + f"instead of $(PLATFORM_DIR). Value: {value!r}", + ) + + def test_make_no_absolute_platform_dir(self): """Make output must not contain the absolute platform_dir path.""" - pd = os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) - monkeypatch.setenv("PLATFORM_DIR", pd) - monkeypatch.setenv("PLATFORM", platform) - - mod = _load_config_module(platform) - cfg = mod.get_config() - - import io - - buf = io.StringIO() - old_stdout = sys.stdout - sys.stdout = buf - cfg.output_make() - sys.stdout = old_stdout - output = buf.getvalue() - - assert pd not in output, ( - f"{platform}: Make output contains absolute path {pd!r} " - f"instead of $(PLATFORM_DIR)" - ) - - @pytest.mark.parametrize("platform", ["nangate45", "sky130hd", "sky130hs", "gf180"]) - def test_glob_results_unexpanded(self, platform, monkeypatch): + for platform in ALL_PLATFORMS: + with self.subTest(platform=platform): + pd = get_platform_dir(platform) + self.run_with_env(platform) + mod = _load_config_module(platform) + cfg = mod.get_config() + + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_make() + output = buf.getvalue() + + self.assertNotIn( + pd, + output, + f"{platform}: Make output contains absolute path {pd!r} " + f"instead of $(PLATFORM_DIR)", + ) + + def test_glob_results_unexpanded(self): """GDS_FILES from glob must use $(PLATFORM_DIR), not absolute paths.""" - pd = os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) - monkeypatch.setenv("PLATFORM_DIR", pd) - monkeypatch.setenv("PLATFORM", platform) - - mod = _load_config_module(platform) - cfg = mod.get_config() - - import io - - buf = io.StringIO() - old_stdout = sys.stdout - sys.stdout = buf - cfg.output_json() - sys.stdout = old_stdout - data = json.loads(buf.getvalue()) - - gds = data.get("GDS_FILES", "") - assert gds, f"{platform}: GDS_FILES is empty" - assert ( - "$(PLATFORM_DIR)" in gds - ), f"{platform}: GDS_FILES glob result missing $(PLATFORM_DIR): {gds!r}" - assert pd not in gds, f"{platform}: GDS_FILES contains absolute path: {gds!r}" - - @pytest.mark.parametrize( - "platform,keys", - [ + for platform in ["nangate45", "sky130hd", "sky130hs", "gf180"]: + with self.subTest(platform=platform): + pd = get_platform_dir(platform) + self.run_with_env(platform) + mod = _load_config_module(platform) + cfg = mod.get_config() + + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + + gds = data.get("GDS_FILES", "") + self.assertTrue(gds, f"{platform}: GDS_FILES is empty") + self.assertIn( + "$(PLATFORM_DIR)", + gds, + f"{platform}: GDS_FILES glob result missing $(PLATFORM_DIR): {gds!r}", + ) + self.assertNotIn( + pd, + gds, + f"{platform}: GDS_FILES contains absolute path: {gds!r}", + ) + + def test_platform_name_unexpanded(self): + """Variables using $(PLATFORM) in filenames must not expand it.""" + cases = [ ( "sky130hd", [ @@ -1322,41 +1135,31 @@ def test_glob_results_unexpanded(self, platform, monkeypatch): ], ), ("sky130hs", ["KLAYOUT_TECH_FILE"]), - ], - ) - def test_platform_name_unexpanded(self, platform, keys, monkeypatch): - """Variables using $(PLATFORM) in filenames must not expand it.""" - pd = os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) - monkeypatch.setenv("PLATFORM_DIR", pd) - monkeypatch.setenv("PLATFORM", platform) - - mod = _load_config_module(platform) - cfg = mod.get_config() - - import io - - buf = io.StringIO() - old_stdout = sys.stdout - sys.stdout = buf - cfg.output_json() - sys.stdout = old_stdout - data = json.loads(buf.getvalue()) - - for key in keys: - value = data.get(key, "") - assert ( - "$(PLATFORM)" in value - ), f"{platform}: {key} should contain $(PLATFORM), got: {value!r}" - assert ( - f"/{platform}." not in value - ), f"{platform}: {key} contains expanded platform name: {value!r}" + ] + for platform, keys in cases: + with self.subTest(platform=platform): + self.run_with_env(platform) + mod = _load_config_module(platform) + cfg = mod.get_config() + + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + + for key in keys: + value = data.get(key, "") + self.assertIn( + "$(PLATFORM)", + value, + f"{platform}: {key} should contain $(PLATFORM), got: {value!r}", + ) + self.assertNotIn( + f"/{platform}.", + value, + f"{platform}: {key} contains expanded platform name: {value!r}", + ) if __name__ == "__main__": - try: - import pytest - - pytest.main([__file__, "-v", "-m", "not integration"]) - except ImportError: - print("pytest not installed, skipping tests") - pass + unittest.main() From b6f53481453fd2dbdc9757d66cb8ccba3ce631ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 18 Mar 2026 23:38:02 +0100 Subject: [PATCH 9/9] flow: run black on platform_config_utils.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- flow/scripts/platform_config_utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flow/scripts/platform_config_utils.py b/flow/scripts/platform_config_utils.py index cf90b13c2d..717b1cc0ab 100644 --- a/flow/scripts/platform_config_utils.py +++ b/flow/scripts/platform_config_utils.py @@ -31,9 +31,7 @@ def __init__(self, platform_dir=None): os.path.abspath(sys._getframe(1).f_globals["__file__"]) ), ) - self.platform = os.environ.get( - "PLATFORM", os.path.basename(self.platform_dir) - ) + self.platform = os.environ.get("PLATFORM", os.path.basename(self.platform_dir)) self._vars = [] # ordered list of (key, value, conditional) self._index = {} # key -> index in _vars for fast lookup