mirror of https://github.com/VLSIDA/OpenRAM.git
Merge branch 'dev' into add_wmask
This commit is contained in:
commit
ab27c70279
|
|
@ -0,0 +1,135 @@
|
|||
#!/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 HSPICE.
|
||||
"""
|
||||
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 hspice_pex_pinv_test(openram_test):
|
||||
|
||||
def runTest(self):
|
||||
globals.init_openram("config_{0}".format(OPTS.tech_name))
|
||||
import pinv
|
||||
|
||||
# load the hspice
|
||||
OPTS.spice_name="hspice"
|
||||
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)
|
||||
|
||||
# generate the pinv
|
||||
prev_purge_value = OPTS.purge_temp
|
||||
OPTS.purge_temp = False # force set purge to false to save the sp file
|
||||
debug.info(2, "Checking 1x size inverter")
|
||||
tx = pinv.pinv(name="pinv", size=1)
|
||||
tempgds = "{0}{1}.gds".format(OPTS.openram_temp,tx.name)
|
||||
tx.gds_write(tempgds)
|
||||
tempsp = "{0}{1}.sp".format(OPTS.openram_temp,tx.name)
|
||||
tx.sp_write(tempsp)
|
||||
|
||||
# make sure that the library simulation is successful\
|
||||
sp_delay = self.simulate_delay(test_module = tempsp,
|
||||
top_level_name = tx.name)
|
||||
if sp_delay is "Failed":
|
||||
self.fail('Library Spice module did not behave as expected')
|
||||
|
||||
# now generate its pex file
|
||||
pex_file = self.run_pex(tx)
|
||||
OPTS.purge_temp = prev_purge_value # restore the old purge value
|
||||
# generate simulation for pex, make sure the simulation is successful
|
||||
pex_delay = self.simulate_delay(test_module = pex_file,
|
||||
top_level_name = tx.name)
|
||||
# make sure the extracted spice simulated
|
||||
if pex_delay is "Failed":
|
||||
self.fail('Pex file did not behave as expected')
|
||||
|
||||
# if pex data is bigger than original spice file then result is ok
|
||||
# However this may not always be true depending on the netlist provided
|
||||
# comment out for now
|
||||
#debug.info(2,"pex_delay: {0}".format(pex_delay))
|
||||
#debug.info(2,"sp_delay: {0}".format(sp_delay))
|
||||
|
||||
#assert pex_delay > sp_delay, "pex delay {0} is smaller than sp_delay {1}"\
|
||||
#.format(pex_delay,sp_delay)
|
||||
|
||||
globals.end_openram()
|
||||
|
||||
def simulate_delay(self, test_module, top_level_name):
|
||||
from characterizer import charutils
|
||||
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):
|
||||
""" 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")
|
||||
simulation = stimuli(sim_file,corner)
|
||||
|
||||
# library files
|
||||
simulation.write_include(cir_file)
|
||||
|
||||
# supply voltages
|
||||
simulation.gen_constant(sig_name ="vdd",
|
||||
v_val = tech.spice["nom_supply_voltage"])
|
||||
simulation.gen_constant(sig_name = "gnd",
|
||||
v_val = "0v")
|
||||
|
||||
run_time = tech.spice["feasible_period"] * 4
|
||||
# input voltage
|
||||
clk_period = tech.spice["feasible_period"]
|
||||
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)
|
||||
|
||||
# instantiation of simulated pinv
|
||||
simulation.inst_model(pins = ["input", "output", "vdd", "gnd"],
|
||||
model_name = top_module_name)
|
||||
|
||||
# delay measurement
|
||||
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)
|
||||
trig_td = trag_td = 0.01 * run_time
|
||||
rest_info = trig_td,trag_td,tech.spice["nom_supply_voltage"]
|
||||
delay_measure.write_measure(simulation, rest_info)
|
||||
|
||||
simulation.write_control(end_time = run_time)
|
||||
sim_file.close()
|
||||
return simulation
|
||||
|
||||
|
||||
# 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()
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
#!/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):
|
||||
globals.init_openram("config_{0}".format(OPTS.tech_name))
|
||||
import pinv
|
||||
|
||||
# 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)
|
||||
|
||||
# generate the pinv module
|
||||
prev_purge_value = OPTS.purge_temp
|
||||
OPTS.purge_temp = False # force set purge to false to save the sp file
|
||||
debug.info(2, "Checking 1x size inverter")
|
||||
tx = pinv.pinv(name="pinv", size=1)
|
||||
tempgds = "{0}{1}.gds".format(OPTS.openram_temp,tx.name)
|
||||
tx.gds_write(tempgds)
|
||||
tempsp = "{0}{1}.sp".format(OPTS.openram_temp,tx.name)
|
||||
tx.sp_write(tempsp)
|
||||
|
||||
# make sure that the library simulation is successful
|
||||
sp_delay = self.simulate_delay(test_module = tempsp,
|
||||
top_level_name = tx.name)
|
||||
if sp_delay is "Failed":
|
||||
self.fail('Library Spice module did not behave as expected')
|
||||
|
||||
# now generate its pex file
|
||||
pex_file = self.run_pex(tx)
|
||||
OPTS.purge_temp = prev_purge_value # restore the old purge value
|
||||
# generate simulation for pex, make sure the simulation is successful
|
||||
pex_delay = self.simulate_delay(test_module = pex_file,
|
||||
top_level_name = tx.name)
|
||||
# make sure the extracted spice simulated
|
||||
if pex_delay is "Failed":
|
||||
self.fail('Pex file did not behave as expected')
|
||||
|
||||
# if pex data is bigger than original spice file then result is ok
|
||||
# However this may not always be true depending on the netlist provided
|
||||
# comment out for now
|
||||
#debug.info(2,"pex_delay: {0}".format(pex_delay))
|
||||
#debug.info(2,"sp_delay: {0}".format(sp_delay))
|
||||
|
||||
#assert pex_delay > sp_delay, "pex delay {0} is smaller than sp_delay {1}"\
|
||||
#.format(pex_delay,sp_delay)
|
||||
|
||||
globals.end_openram()
|
||||
|
||||
def simulate_delay(self, test_module, top_level_name):
|
||||
from characterizer import charutils
|
||||
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):
|
||||
""" 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")
|
||||
simulation = stimuli(sim_file,corner)
|
||||
|
||||
# library files
|
||||
simulation.write_include(cir_file)
|
||||
|
||||
# supply voltages
|
||||
simulation.gen_constant(sig_name ="vdd",
|
||||
v_val = tech.spice["nom_supply_voltage"])
|
||||
# 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
|
||||
# simulation.gen_constant(sig_name = "gnd",
|
||||
# v_val = "0v")
|
||||
|
||||
|
||||
run_time = tech.spice["feasible_period"] * 4
|
||||
# input voltage
|
||||
clk_period = tech.spice["feasible_period"]
|
||||
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)
|
||||
|
||||
# instantiation of simulated pinv
|
||||
simulation.inst_model(pins = ["input", "output", "vdd", "gnd"],
|
||||
model_name = top_module_name)
|
||||
|
||||
# delay measurement
|
||||
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)
|
||||
trig_td = trag_td = 0.01 * run_time
|
||||
rest_info = trig_td,trag_td,tech.spice["nom_supply_voltage"]
|
||||
delay_measure.write_measure(simulation, rest_info)
|
||||
|
||||
simulation.write_control(end_time = run_time)
|
||||
sim_file.close()
|
||||
return simulation
|
||||
|
||||
# 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()
|
||||
|
|
@ -63,6 +63,17 @@ class openram_test(unittest.TestCase):
|
|||
if OPTS.purge_temp:
|
||||
self.cleanup()
|
||||
|
||||
def run_pex(self, a, output=None):
|
||||
if output == None:
|
||||
output = OPTS.openram_temp + a.name + ".pex.netlist"
|
||||
tempspice = "{0}{1}.sp".format(OPTS.openram_temp,a.name)
|
||||
tempgds = "{0}{1}.gds".format(OPTS.openram_temp,a.name)
|
||||
|
||||
import verify
|
||||
result=verify.run_pex(a.name, tempgds, tempspice, output=output, final_verification=False)
|
||||
if result != 0:
|
||||
self.fail("PEX ERROR: {}".format(a.name))
|
||||
return output
|
||||
|
||||
def find_feasible_test_period(self, delay_obj, sram, load, slew):
|
||||
"""Creates a delay simulation to determine a feasible period for the functional tests to run.
|
||||
|
|
@ -298,16 +309,18 @@ def header(filename, technology):
|
|||
|
||||
def debugTestRunner(post_mortem=None):
|
||||
"""unittest runner doing post mortem debugging on failing tests"""
|
||||
if post_mortem is None:
|
||||
if post_mortem is None and not OPTS.purge_temp:
|
||||
post_mortem = pdb.post_mortem
|
||||
class DebugTestResult(unittest.TextTestResult):
|
||||
def addError(self, test, err):
|
||||
# called before tearDown()
|
||||
traceback.print_exception(*err)
|
||||
if post_mortem:
|
||||
post_mortem(err[2])
|
||||
super(DebugTestResult, self).addError(test, err)
|
||||
def addFailure(self, test, err):
|
||||
traceback.print_exception(*err)
|
||||
if post_mortem:
|
||||
post_mortem(err[2])
|
||||
super(DebugTestResult, self).addFailure(test, err)
|
||||
return unittest.TextTestRunner(resultclass=DebugTestResult)
|
||||
|
|
|
|||
|
|
@ -138,9 +138,12 @@ def write_calibre_pex_script(cell_name, extract, output, final_verification):
|
|||
# check if lvs report has been done
|
||||
# if not run drc and lvs
|
||||
if not os.path.isfile(cell_name + ".lvs.report"):
|
||||
gds_name = OPTS.openram_temp +"/"+ cell_name + ".gds"
|
||||
sp_name = OPTS.openram_temp +"/"+ cell_name + ".sp"
|
||||
run_drc(cell_name, gds_name)
|
||||
run_lvs(cell_name, gds_name, sp_name)
|
||||
|
||||
from tech import drc
|
||||
pex_rules = drc["xrc_rules"]
|
||||
pex_runset = {
|
||||
'pexRulesFile': pex_rules,
|
||||
|
|
@ -317,7 +320,7 @@ def run_pex(cell_name, gds_name, sp_name, output=None, final_verification=False)
|
|||
global num_pex_runs
|
||||
num_pex_runs += 1
|
||||
|
||||
write_calibre_pex_script()
|
||||
write_calibre_pex_script(cell_name,True,output,final_verification)
|
||||
|
||||
(outfile, errfile, resultsfile) = run_script(cell_name, "pex")
|
||||
|
||||
|
|
|
|||
|
|
@ -257,9 +257,9 @@ def run_pex(name, gds_name, sp_name, output=None, final_verification=False):
|
|||
|
||||
global num_pex_runs
|
||||
num_pex_runs += 1
|
||||
|
||||
debug.warning("PEX using magic not implemented.")
|
||||
return 1
|
||||
#debug.warning("PEX using magic not implemented.")
|
||||
#return 1
|
||||
os.chdir(OPTS.openram_temp)
|
||||
|
||||
from tech import drc
|
||||
if output == None:
|
||||
|
|
@ -271,7 +271,50 @@ def run_pex(name, gds_name, sp_name, output=None, final_verification=False):
|
|||
run_drc(name, gds_name)
|
||||
run_lvs(name, gds_name, sp_name)
|
||||
|
||||
# pex_fix did run the pex using a script while dev orignial method
|
||||
# use batch mode.
|
||||
# the dev old code using batch mode does not run and is split into functions
|
||||
#pex_runset = write_batch_pex_rule(gds_name,name,sp_name,output)
|
||||
pex_runset = write_script_pex_rule(gds_name,name,output)
|
||||
|
||||
errfile = "{0}{1}.pex.err".format(OPTS.openram_temp, name)
|
||||
outfile = "{0}{1}.pex.out".format(OPTS.openram_temp, name)
|
||||
|
||||
# bash mode command from dev branch
|
||||
#batch_cmd = "{0} -gui -pex {1}pex_runset -batch 2> {2} 1> {3}".format(OPTS.pex_exe,
|
||||
# OPTS.openram_temp,
|
||||
# errfile,
|
||||
# outfile)
|
||||
script_cmd = "{0} 2> {1} 1> {2}".format(pex_runset,
|
||||
errfile,
|
||||
outfile)
|
||||
cmd = script_cmd
|
||||
debug.info(2, cmd)
|
||||
os.system(cmd)
|
||||
|
||||
# rename technology models
|
||||
pex_nelist = open(output, 'r')
|
||||
s = pex_nelist.read()
|
||||
pex_nelist.close()
|
||||
s = s.replace('pfet','p')
|
||||
s = s.replace('nfet','n')
|
||||
f = open(output, 'w')
|
||||
f.write(s)
|
||||
f.close()
|
||||
|
||||
# also check the output file
|
||||
f = open(outfile, "r")
|
||||
results = f.readlines()
|
||||
f.close()
|
||||
out_errors = find_error(results)
|
||||
debug.check(os.path.isfile(output),"Couldn't find PEX extracted output.")
|
||||
|
||||
correct_port(name,output,sp_name)
|
||||
return out_errors
|
||||
|
||||
def write_batch_pex_rule(gds_name,name,sp_name,output):
|
||||
"""
|
||||
The dev branch old batch mode runset
|
||||
2. magic can perform extraction with the following:
|
||||
#!/bin/sh
|
||||
rm -f $1.ext
|
||||
|
|
@ -289,7 +332,6 @@ def run_pex(name, gds_name, sp_name, output=None, final_verification=False):
|
|||
quit -noprompt
|
||||
EOF
|
||||
"""
|
||||
|
||||
pex_rules = drc["xrc_rules"]
|
||||
pex_runset = {
|
||||
'pexRulesFile': pex_rules,
|
||||
|
|
@ -307,42 +349,89 @@ def run_pex(name, gds_name, sp_name, output=None, final_verification=False):
|
|||
}
|
||||
|
||||
# write the runset file
|
||||
f = open(OPTS.openram_temp + "pex_runset", "w")
|
||||
for k in sorted(pex_runset.iterkeys()):
|
||||
file = OPTS.openram_temp + "pex_runset"
|
||||
f = open(file, "w")
|
||||
for k in sorted(pex_runset.keys()):
|
||||
f.write("*{0}: {1}\n".format(k, pex_runset[k]))
|
||||
f.close()
|
||||
return file
|
||||
|
||||
# run pex
|
||||
cwd = os.getcwd()
|
||||
os.chdir(OPTS.openram_temp)
|
||||
errfile = "{0}{1}.pex.err".format(OPTS.openram_temp, name)
|
||||
outfile = "{0}{1}.pex.out".format(OPTS.openram_temp, name)
|
||||
def write_script_pex_rule(gds_name,cell_name,output):
|
||||
global OPTS
|
||||
run_file = OPTS.openram_temp + "run_pex.sh"
|
||||
f = open(run_file, "w")
|
||||
f.write("#!/bin/sh\n")
|
||||
f.write("{} -dnull -noconsole << eof\n".format(OPTS.drc_exe[1]))
|
||||
f.write("gds polygon subcell true\n")
|
||||
f.write("gds warning default\n")
|
||||
f.write("gds read {}\n".format(gds_name))
|
||||
f.write("load {}\n".format(cell_name))
|
||||
f.write("select top cell\n")
|
||||
f.write("expand\n")
|
||||
f.write("port makeall\n")
|
||||
extract = True
|
||||
if not extract:
|
||||
pre = "#"
|
||||
else:
|
||||
pre = ""
|
||||
f.write(pre+"extract\n".format(cell_name))
|
||||
#f.write(pre+"ext2spice hierarchy on\n")
|
||||
#f.write(pre+"ext2spice format ngspice\n")
|
||||
#f.write(pre+"ext2spice renumber off\n")
|
||||
#f.write(pre+"ext2spice scale off\n")
|
||||
#f.write(pre+"ext2spice blackbox on\n")
|
||||
f.write(pre+"ext2spice subcircuit top on\n")
|
||||
#f.write(pre+"ext2spice global off\n")
|
||||
f.write(pre+"ext2spice {}\n".format(cell_name))
|
||||
f.write("quit -noprompt\n")
|
||||
f.write("eof\n")
|
||||
f.write("mv {0}.spice {1}\n".format(cell_name,output))
|
||||
|
||||
cmd = "{0} -gui -pex {1}pex_runset -batch 2> {2} 1> {3}".format(OPTS.pex_exe,
|
||||
OPTS.openram_temp,
|
||||
errfile,
|
||||
outfile)
|
||||
debug.info(2, cmd)
|
||||
os.system(cmd)
|
||||
os.chdir(cwd)
|
||||
|
||||
# also check the output file
|
||||
f = open(outfile, "r")
|
||||
results = f.readlines()
|
||||
f.close()
|
||||
os.system("chmod u+x {}".format(run_file))
|
||||
return run_file
|
||||
|
||||
def find_error(results):
|
||||
# Errors begin with "ERROR:"
|
||||
test = re.compile("ERROR:")
|
||||
stdouterrors = list(filter(test.search, results))
|
||||
for e in stdouterrors:
|
||||
debug.error(e.strip("\n"))
|
||||
|
||||
out_errors = len(stdouterrors)
|
||||
|
||||
debug.check(os.path.isfile(output),"Couldn't find PEX extracted output.")
|
||||
|
||||
return out_errors
|
||||
|
||||
def correct_port(name, output_file_name, ref_file_name):
|
||||
pex_file = open(output_file_name, "r")
|
||||
contents = pex_file.read()
|
||||
# locate the start of circuit definition line
|
||||
match = re.search(".subckt " + str(name) + ".*", contents)
|
||||
match_index_start = match.start()
|
||||
pex_file.seek(match_index_start)
|
||||
rest_text = pex_file.read()
|
||||
# locate the end of circuit definition line
|
||||
match = re.search(r'\n', rest_text)
|
||||
match_index_end = match.start()
|
||||
# store the unchanged part of pex file in memory
|
||||
pex_file.seek(0)
|
||||
part1 = pex_file.read(match_index_start)
|
||||
pex_file.seek(match_index_start + match_index_end)
|
||||
part2 = pex_file.read()
|
||||
pex_file.close()
|
||||
|
||||
# obtain the correct definition line from the original spice file
|
||||
sp_file = open(ref_file_name, "r")
|
||||
contents = sp_file.read()
|
||||
circuit_title = re.search(".SUBCKT " + str(name) + ".*\n", contents)
|
||||
circuit_title = circuit_title.group()
|
||||
sp_file.close()
|
||||
|
||||
# write the new pex file with info in the memory
|
||||
output_file = open(output_file_name, "w")
|
||||
output_file.write(part1)
|
||||
output_file.write(circuit_title)
|
||||
output_file.write(part2)
|
||||
output_file.close()
|
||||
|
||||
def print_drc_stats():
|
||||
debug.info(1,"DRC runs: {0}".format(num_drc_runs))
|
||||
def print_lvs_stats():
|
||||
|
|
|
|||
Loading…
Reference in New Issue