2019-06-25 18:19:37 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# See LICENSE for licensing information.
|
|
|
|
|
#
|
|
|
|
|
# Copyright (c) 2016-2019 Regents of the University of California
|
|
|
|
|
# All rights reserved.
|
|
|
|
|
#
|
|
|
|
|
"""
|
|
|
|
|
Run regression tests/pex test on an extracted pinv to ensure pex functionality
|
|
|
|
|
with Ngspice.
|
|
|
|
|
"""
|
|
|
|
|
import unittest
|
|
|
|
|
from testutils import header,openram_test
|
|
|
|
|
import sys,os
|
|
|
|
|
sys.path.append(os.path.join(sys.path[0],".."))
|
|
|
|
|
import globals
|
|
|
|
|
from globals import OPTS
|
|
|
|
|
import debug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ngspice_pex_pinv_test(openram_test):
|
|
|
|
|
def runTest(self):
|
2019-11-17 01:44:31 +01:00
|
|
|
config_file = "{}/tests/configs/config".format(os.getenv("OPENRAM_HOME"))
|
2019-11-15 19:47:59 +01:00
|
|
|
globals.init_openram(config_file)
|
2019-06-25 18:19:37 +02:00
|
|
|
import pinv
|
|
|
|
|
|
2019-07-10 13:39:40 +02:00
|
|
|
# load the ngspice
|
|
|
|
|
OPTS.spice_name="ngspice"
|
|
|
|
|
OPTS.analytical_delay = False
|
|
|
|
|
|
|
|
|
|
# This is a hack to reload the characterizer __init__ with the spice version
|
|
|
|
|
from importlib import reload
|
|
|
|
|
import characterizer
|
|
|
|
|
reload(characterizer)
|
2019-06-25 18:19:37 +02:00
|
|
|
|
2019-06-30 09:16:04 +02:00
|
|
|
# generate the pinv module
|
|
|
|
|
prev_purge_value = OPTS.purge_temp
|
2020-10-01 20:10:18 +02:00
|
|
|
OPTS.purge_temp = False # force set purge to false to save the sp file
|
2019-06-30 09:16:04 +02:00
|
|
|
debug.info(2, "Checking 1x size inverter")
|
|
|
|
|
tx = pinv.pinv(name="pinv", size=1)
|
2020-10-01 20:10:18 +02:00
|
|
|
tempgds = "{0}{1}.gds".format(OPTS.openram_temp, tx.name)
|
2019-06-30 09:16:04 +02:00
|
|
|
tx.gds_write(tempgds)
|
2020-10-01 20:10:18 +02:00
|
|
|
tempsp = "{0}{1}.sp".format(OPTS.openram_temp, tx.name)
|
2019-06-30 09:16:04 +02:00
|
|
|
tx.sp_write(tempsp)
|
2019-06-25 18:19:37 +02:00
|
|
|
|
|
|
|
|
# make sure that the library simulation is successful
|
2020-10-01 20:10:18 +02:00
|
|
|
sp_delay = self.simulate_delay(test_module=tempsp,
|
|
|
|
|
top_level_name=tx.name)
|
|
|
|
|
if sp_delay == "Failed":
|
2019-06-30 09:16:04 +02:00
|
|
|
self.fail('Library Spice module did not behave as expected')
|
2019-06-25 18:19:37 +02:00
|
|
|
|
2019-06-30 09:16:04 +02:00
|
|
|
# now generate its pex file
|
|
|
|
|
pex_file = self.run_pex(tx)
|
2020-10-01 20:10:18 +02:00
|
|
|
# restore the old purge value
|
|
|
|
|
OPTS.purge_temp = prev_purge_value
|
2019-06-25 18:19:37 +02:00
|
|
|
# generate simulation for pex, make sure the simulation is successful
|
2020-10-01 20:10:18 +02:00
|
|
|
pex_delay = self.simulate_delay(test_module=pex_file,
|
|
|
|
|
top_level_name=tx.name)
|
2019-06-25 18:19:37 +02:00
|
|
|
# make sure the extracted spice simulated
|
2020-10-01 20:10:18 +02:00
|
|
|
if pex_delay == "Failed":
|
2019-06-30 09:16:04 +02:00
|
|
|
self.fail('Pex file did not behave as expected')
|
2019-06-25 18:19:37 +02:00
|
|
|
|
|
|
|
|
# if pex data is bigger than original spice file then result is ok
|
2019-06-30 09:16:04 +02:00
|
|
|
# However this may not always be true depending on the netlist provided
|
2019-06-25 18:19:37 +02:00
|
|
|
# comment out for now
|
2020-10-01 20:10:18 +02:00
|
|
|
# debug.info(2,"pex_delay: {0}".format(pex_delay))
|
|
|
|
|
# debug.info(2,"sp_delay: {0}".format(sp_delay))
|
2019-06-25 18:19:37 +02:00
|
|
|
|
2020-10-01 20:10:18 +02:00
|
|
|
# assert pex_delay > sp_delay, "pex delay {0} is smaller than sp_delay {1}"\
|
|
|
|
|
# .format(pex_delay,sp_delay)
|
2019-06-25 18:19:37 +02:00
|
|
|
|
|
|
|
|
globals.end_openram()
|
|
|
|
|
|
2019-06-30 09:16:04 +02:00
|
|
|
def simulate_delay(self, test_module, top_level_name):
|
|
|
|
|
from charutils import parse_spice_list
|
|
|
|
|
# setup simulation
|
|
|
|
|
sim_file = OPTS.openram_temp + "stim.sp"
|
|
|
|
|
log_file_name = "timing"
|
|
|
|
|
test_sim = self.write_simulation(sim_file, test_module, top_level_name)
|
|
|
|
|
test_sim.run_sim()
|
|
|
|
|
delay = parse_spice_list(log_file_name, "pinv_delay")
|
|
|
|
|
return delay
|
|
|
|
|
|
|
|
|
|
def write_simulation(self, sim_file, cir_file, top_module_name):
|
2019-06-25 18:19:37 +02:00
|
|
|
""" write pex spice simulation for a pinv test"""
|
|
|
|
|
import tech
|
|
|
|
|
from characterizer import measurements, stimuli
|
|
|
|
|
corner = (OPTS.process_corners[0], OPTS.supply_voltages[0], OPTS.temperatures[0])
|
|
|
|
|
sim_file = open(sim_file, "w")
|
2020-10-01 20:10:18 +02:00
|
|
|
simulation = stimuli(sim_file, corner)
|
2019-06-25 18:19:37 +02:00
|
|
|
|
|
|
|
|
# library files
|
2019-06-30 09:16:04 +02:00
|
|
|
simulation.write_include(cir_file)
|
2019-06-25 18:19:37 +02:00
|
|
|
|
|
|
|
|
# supply voltages
|
2020-10-01 20:10:18 +02:00
|
|
|
simulation.gen_constant(sig_name="vdd",
|
|
|
|
|
v_val=tech.spice["nom_supply_voltage"])
|
2019-06-25 18:19:37 +02:00
|
|
|
# The scn4m_subm and ngspice combination will have a gnd source error:
|
|
|
|
|
# "Fatal error: instance vgnd is a shorted VSRC"
|
|
|
|
|
# However, remove gnd power for all techa pass for this test
|
2019-06-30 09:16:04 +02:00
|
|
|
# simulation.gen_constant(sig_name = "gnd",
|
2019-06-25 18:19:37 +02:00
|
|
|
# v_val = "0v")
|
|
|
|
|
|
2019-06-30 09:16:04 +02:00
|
|
|
run_time = tech.spice["feasible_period"] * 4
|
2019-06-25 18:19:37 +02:00
|
|
|
# input voltage
|
2019-06-30 09:16:04 +02:00
|
|
|
clk_period = tech.spice["feasible_period"]
|
2020-10-01 20:10:18 +02:00
|
|
|
simulation.gen_pwl(sig_name="input",
|
|
|
|
|
clk_times=[clk_period, clk_period],
|
|
|
|
|
data_values=[1, 0],
|
|
|
|
|
period=clk_period,
|
|
|
|
|
slew=0.001 * tech.spice["feasible_period"],
|
|
|
|
|
setup=0)
|
2019-06-25 18:19:37 +02:00
|
|
|
|
|
|
|
|
# instantiation of simulated pinv
|
2020-10-01 20:10:18 +02:00
|
|
|
simulation.inst_model(pins=["input", "output", "vdd", "gnd"],
|
|
|
|
|
model_name=top_module_name)
|
2019-06-25 18:19:37 +02:00
|
|
|
|
|
|
|
|
# delay measurement
|
2020-10-01 20:10:18 +02:00
|
|
|
delay_measure = measurements.delay_measure(measure_name="pinv_delay",
|
|
|
|
|
trig_name="input",
|
|
|
|
|
targ_name="output",
|
|
|
|
|
trig_dir_str="FALL",
|
|
|
|
|
targ_dir_str="RISE",
|
|
|
|
|
has_port=False)
|
2019-06-25 18:19:37 +02:00
|
|
|
trig_td = trag_td = 0.01 * run_time
|
2020-10-01 20:10:18 +02:00
|
|
|
rest_info = trig_td, trag_td, tech.spice["nom_supply_voltage"]
|
2019-06-30 09:16:04 +02:00
|
|
|
delay_measure.write_measure(simulation, rest_info)
|
2019-06-25 18:19:37 +02:00
|
|
|
|
2020-10-01 20:10:18 +02:00
|
|
|
simulation.write_control(end_time=run_time)
|
2019-06-25 18:19:37 +02:00
|
|
|
sim_file.close()
|
2019-06-30 09:16:04 +02:00
|
|
|
return simulation
|
2019-06-25 18:19:37 +02:00
|
|
|
|
|
|
|
|
# run the test from the command line
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
(OPTS, args) = globals.parse_args()
|
|
|
|
|
del sys.argv[1:]
|
|
|
|
|
header(__file__, OPTS.tech_name)
|
|
|
|
|
unittest.main()
|