mirror of https://github.com/lnis-uofu/SOFA.git
77 lines
3.3 KiB
Python
77 lines
3.3 KiB
Python
#####################################################################
|
|
# Python script to run ModelSim simulations for all the post-pnr testbenches
|
|
# in a project directory
|
|
# This script will
|
|
# - Collect all the testbenches in a given directory
|
|
# For instance:
|
|
# ../k4_arch/pre_pnr/verilog_testbenches/and2_post_pnr_include_netlist.v
|
|
# - Use run_post_pnr_msim_test.py to run Modelsim simulations and check results
|
|
#####################################################################
|
|
|
|
import os
|
|
from os.path import dirname, abspath
|
|
import shutil
|
|
import re
|
|
import argparse
|
|
import logging
|
|
import subprocess
|
|
import glob
|
|
|
|
#####################################################################
|
|
# Initialize logger
|
|
#####################################################################
|
|
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
|
|
|
|
#####################################################################
|
|
# Parse the options
|
|
#####################################################################
|
|
parser = argparse.ArgumentParser(description='Run a ModelSim verification task for a tape-out FPGA')
|
|
parser.add_argument('--testbench_dir_name', required=True,
|
|
help='Specify the directory path for the Verilog testbenches')
|
|
parser.add_argument('--task_name', required=True,
|
|
help='Specify the directory path for the Verilog testbenches')
|
|
args = parser.parse_args()
|
|
|
|
#####################################################################
|
|
# Walk through the parent directory and find all the pre-PnR testbenches
|
|
#####################################################################
|
|
logging.info("Finding testbenches...");
|
|
|
|
testbench_dir_abspath = abspath(args.testbench_dir_name) + "/postpnr/verilog_testbench";
|
|
|
|
testbench_files = []
|
|
for globbed_file in glob.glob(testbench_dir_abspath + "/*_include_netlists.v"):
|
|
testbench_files.append(globbed_file)
|
|
|
|
logging.info("Found " + str(len(testbench_files)) + " testbenches")
|
|
|
|
#####################################################################
|
|
# Try to create the directory of Modelsim projects
|
|
#####################################################################
|
|
parent_dir_abspath = dirname(dirname(abspath(__file__)))
|
|
msim_task_dir_abspath = abspath(parent_dir_abspath + "/" + args.task_name) + "/postpnr/verilog_testbench";
|
|
os.makedirs(msim_task_dir_abspath, exist_ok=True)
|
|
|
|
#####################################################################
|
|
# Run ModelSim simulations for each testbench
|
|
#####################################################################
|
|
logging.info("Running Modelsim simulations...");
|
|
|
|
num_sim_finished = 0
|
|
|
|
msim_testrun_script_abspath = os.path.abspath(__file__)
|
|
msim_testrun_script_abspath = re.sub(os.path.basename(msim_testrun_script_abspath), "run_post_pnr_msim_test.py", msim_testrun_script_abspath)
|
|
|
|
for testbench_file in testbench_files:
|
|
# Find testbench name
|
|
testbench_name = re.findall("(\w+)_include_netlists.v", os.path.basename(testbench_file))[0]
|
|
cmd = "python3 " + msim_testrun_script_abspath \
|
|
+ " --verilog_testbench " + testbench_file \
|
|
+ " --project_path " + msim_task_dir_abspath + "/" + testbench_name \
|
|
+ " --testbench_name " + testbench_name + "_autocheck_top_tb"
|
|
subprocess.run(cmd, shell=True, check=True)
|
|
num_sim_finished += 1
|
|
|
|
logging.info("Done")
|
|
logging.info("Finish " + str(num_sim_finished) + " ModelSim simulations")
|