193 lines
6 KiB
Python
193 lines
6 KiB
Python
# -----------------------------------------------------------------------------
|
|
# Title : GMA core level simulation testbench compile/run script
|
|
# Project : HMB-FD-GMA
|
|
# -----------------------------------------------------------------------------
|
|
# File : core.py
|
|
# Author : Simon Southwell
|
|
# Company : Global Inkjet Systems
|
|
# Created : 2018-01-30
|
|
# Last update: 2018-02-01
|
|
# Platform :
|
|
# Standard : Python 2.x
|
|
# -----------------------------------------------------------------------------
|
|
# Description:
|
|
# Definition of class to read JSON register definitions and generate a VHDL
|
|
# package with constant definitions for address offsets and subtypes
|
|
# for bit-slicing the sub-fields. Inherits MemMapperBase for methods
|
|
# to read JSON files and produce a model.
|
|
# -----------------------------------------------------------------------------
|
|
# Copyright (c) 2018 Global Inkjet Systems
|
|
# -----------------------------------------------------------------------------
|
|
|
|
import sys
|
|
import os
|
|
import subprocess
|
|
import shutil
|
|
|
|
test_array = dict([
|
|
('testName', ('directed_tests'))
|
|
])
|
|
|
|
# ---------------------------------------------------------
|
|
# Check the result
|
|
# ---------------------------------------------------------
|
|
|
|
def check_results(runLogName) :
|
|
|
|
failed = True
|
|
|
|
searchfile = open(runLogName, 'r')
|
|
for line in searchfile:
|
|
if 'SUCCESS' in line:
|
|
failed = False
|
|
print 'Test appears to have been successful.'
|
|
break
|
|
searchfile.close()
|
|
|
|
return failed
|
|
|
|
# ---------------------------------------------------------
|
|
# Copy the artifacts to:
|
|
# %WORKSPACE%\sim_results\<block>_<testname>\
|
|
# ---------------------------------------------------------
|
|
|
|
def copy_artifacts (ipName) :
|
|
|
|
# Create directory in WORKSPACE called sim_results
|
|
pathList = os.getcwd().split('\\firmware')
|
|
tgtDir = os.path.join(pathList[0], 'sim_results')
|
|
|
|
if not os.path.exists(tgtDir) :
|
|
print 'making directory at {}'.format(tgtDir)
|
|
os.makedirs(tgtDir)
|
|
|
|
# Create directory in there called moduleName_testName
|
|
newDirName = '_'.join([ipName, test_array['testName']])
|
|
tgtDir = os.path.join(tgtDir, newDirName)
|
|
|
|
if not os.path.exists(tgtDir) :
|
|
os.makedirs(tgtDir)
|
|
print 'making directory at {}'.format(tgtDir)
|
|
else:
|
|
for f in os.listdir(tgtDir) :
|
|
fullPathF = os.path.join(tgtDir, f)
|
|
print 'removing {}'.format(fullPathF)
|
|
os.remove(fullPathF)
|
|
|
|
# From current location copy *.txt, *.log, *.tcl, *.vstf into the directory
|
|
localDir = os.getcwd()
|
|
print 'copying relevant files from {} to {}'.format(localDir, tgtDir)
|
|
extList = ['.txt', '.log', '.tcl', '.vstf']
|
|
|
|
for f in os.listdir(localDir) :
|
|
for ext in extList:
|
|
if f.endswith(ext) :
|
|
fullPathF = os.path.join(localDir,f)
|
|
print 'copying {}'.format(fullPathF)
|
|
shutil.copy(fullPathF, tgtDir)
|
|
|
|
|
|
# ---------------------------------------------------------
|
|
# Top level run function. Compiles and runs the test bench
|
|
# using comp.do and run[_batch].do in top/sim/. The code
|
|
# is compiled into top/build/core_system/simulation/mentor
|
|
# ---------------------------------------------------------
|
|
|
|
def run () :
|
|
|
|
# ----------------------------------------------
|
|
# Initialise
|
|
|
|
thisDir = os.getcwd()
|
|
repoDir = thisDir + '/../../..'
|
|
workspace = repoDir + '/..'
|
|
autoGenToolsDir = workspace + '/fw_development_tools/logic_memory_mapper'
|
|
|
|
print 'Current dir ' + thisDir
|
|
print sys.argv
|
|
|
|
ipName = 'core'
|
|
|
|
# Setup modelsim location, or use
|
|
if 'MODEL_TECH' in os.environ :
|
|
MODEL_TECH = os.environ['MODEL_TECH']
|
|
else :
|
|
MODEL_TECH = os.environ['QUARTUS_ROOTDIR'] + '/../modelsim_ae/win32aloem'
|
|
|
|
vsimExe = MODEL_TECH + '/vsim'
|
|
python34 = os.environ['PYTHON34']
|
|
|
|
# Extract arguments
|
|
if sys.argv[1] == 'yesBatch' :
|
|
batchArg = '-c'
|
|
else :
|
|
batchArg = '';
|
|
|
|
if sys.argv[2] == 'yesQsys' :
|
|
print 'WARNING: this is not a QSYS test bench. Option is ignored.'
|
|
|
|
testName = sys.argv[3]
|
|
|
|
if testName not in test_array['testName'] :
|
|
print 'Test name \'' + testName + '\' was not found in array'
|
|
sys.exit(1)
|
|
|
|
# Define the log names to use
|
|
compLogName = 'compile.log'
|
|
runLogName = test_array['testName'] + '_run.log'
|
|
|
|
# Generate the auto-gen VHDL
|
|
subprocess.call([python34, autoGenToolsDir + '/gen_hdl.py', '-s', '_auto', '-r', repoDir])
|
|
|
|
# Define location of '.do' files for compilation and running, relative to script dir
|
|
compScriptDir = thisDir + '/../sim/'
|
|
|
|
# Make simulation directory
|
|
simDir ='../build/' + ipName + '_system/simulation/mentor/'
|
|
if not os.path.exists(simDir):
|
|
os.makedirs(simDir)
|
|
|
|
# Change directory to simulation directory
|
|
os.chdir(simDir)
|
|
|
|
# ----------------------------------------------
|
|
# Compile the testbench
|
|
status = subprocess.call([vsimExe, '-do', compScriptDir + 'comp.do', batchArg, '-l', compLogName])
|
|
|
|
if status != 0 :
|
|
return status
|
|
|
|
# ----------------------------------------------
|
|
#Run the simulation
|
|
status = subprocess.call([vsimExe, '-do', compScriptDir + 'run_batch.do', batchArg, '-l', runLogName])
|
|
|
|
if status != 0 :
|
|
return status
|
|
|
|
# ----------------------------------------------
|
|
# Check the result
|
|
|
|
failed = check_results(runLogName)
|
|
|
|
# ----------------------------------------------
|
|
# Copy results to level above firmware/,
|
|
# in a directory called sim_results/.
|
|
|
|
copy_artifacts(ipName)
|
|
|
|
# Return to the script directory
|
|
os.chdir(thisDir)
|
|
|
|
if failed :
|
|
return 1
|
|
else :
|
|
return 0
|
|
|
|
# ###############################################################
|
|
# Only run if not imported
|
|
#
|
|
if __name__ == '__main__' :
|
|
|
|
status = run()
|
|
|
|
exit(status)
|