2019-04-27 00:43:46 +02:00
|
|
|
# See LICENSE for licensing information.
|
|
|
|
|
#
|
2022-11-30 23:50:43 +01:00
|
|
|
# Copyright (c) 2016-2022 Regents of the University of California and The Board
|
2019-06-14 17:43:41 +02:00
|
|
|
# of Regents for the Oklahoma Agricultural and Mechanical College
|
|
|
|
|
# (acting for and on behalf of Oklahoma State University)
|
|
|
|
|
# All rights reserved.
|
2019-04-27 00:43:46 +02:00
|
|
|
#
|
|
|
|
|
"""
|
|
|
|
|
Some baseline functions to run scripts.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import os
|
2020-11-29 21:59:17 +01:00
|
|
|
import subprocess
|
|
|
|
|
import time
|
2022-11-27 22:01:20 +01:00
|
|
|
from openram import debug
|
|
|
|
|
from openram import OPTS
|
2019-04-27 00:43:46 +02:00
|
|
|
|
2020-11-09 20:12:31 +01:00
|
|
|
|
2019-04-27 00:43:46 +02:00
|
|
|
def run_script(cell_name, script="lvs"):
|
|
|
|
|
""" Run script and create output files. """
|
|
|
|
|
|
2020-12-02 02:12:17 +01:00
|
|
|
echo_cmd_output = OPTS.verbose_level > 1
|
2020-11-29 21:59:17 +01:00
|
|
|
|
2019-04-27 00:43:46 +02:00
|
|
|
cwd = os.getcwd()
|
|
|
|
|
os.chdir(OPTS.openram_temp)
|
|
|
|
|
errfile = "{0}{1}.{2}.err".format(OPTS.openram_temp, cell_name, script)
|
|
|
|
|
outfile = "{0}{1}.{2}.out".format(OPTS.openram_temp, cell_name, script)
|
|
|
|
|
resultsfile = "{0}{1}.{2}.report".format(OPTS.openram_temp, cell_name, script)
|
|
|
|
|
|
2020-11-29 21:59:17 +01:00
|
|
|
scriptpath = '{0}run_{1}.sh'.format(OPTS.openram_temp, script)
|
|
|
|
|
|
|
|
|
|
debug.info(2, "Starting {}".format(scriptpath))
|
|
|
|
|
start = time.time()
|
|
|
|
|
with open(outfile, 'wb') as fo, open(errfile, 'wb') as fe:
|
|
|
|
|
p = subprocess.Popen(
|
|
|
|
|
[scriptpath], stdout=fo, stderr=fe, cwd=OPTS.openram_temp)
|
|
|
|
|
|
|
|
|
|
if echo_cmd_output:
|
|
|
|
|
tailo = subprocess.Popen([
|
|
|
|
|
'tail',
|
|
|
|
|
'-f', # Follow the output
|
|
|
|
|
'--pid', str(p.pid), # Close when this pid exits
|
|
|
|
|
outfile,
|
|
|
|
|
])
|
|
|
|
|
taile = subprocess.Popen([
|
|
|
|
|
'tail',
|
|
|
|
|
'-f', # Follow the output
|
|
|
|
|
'--pid', str(p.pid), # Close when this pid exits
|
|
|
|
|
errfile,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
lastoutput = start
|
|
|
|
|
while p.poll() == None:
|
|
|
|
|
runningfor = time.time() - start
|
|
|
|
|
outputdelta = time.time() - lastoutput
|
|
|
|
|
if outputdelta > 30:
|
|
|
|
|
lastoutput = time.time()
|
|
|
|
|
debug.info(1, "Still running {} ({:.0f} seconds)".format(scriptpath, runningfor))
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
assert p.poll() != None, (p.poll(), p)
|
|
|
|
|
p.wait()
|
|
|
|
|
|
|
|
|
|
# Kill the tail commands if they haven't finished.
|
2020-11-30 18:38:42 +01:00
|
|
|
if echo_cmd_output:
|
2020-11-29 21:59:17 +01:00
|
|
|
if tailo.poll() != None:
|
|
|
|
|
tailo.kill()
|
|
|
|
|
tailo.wait()
|
|
|
|
|
if taile.poll() != None:
|
|
|
|
|
taile.kill()
|
|
|
|
|
taile.wait()
|
|
|
|
|
|
|
|
|
|
debug.info(2, "Finished {} with {}".format(scriptpath, p.returncode))
|
|
|
|
|
|
2019-04-27 00:43:46 +02:00
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
2020-11-09 20:12:31 +01:00
|
|
|
return (outfile, errfile, resultsfile)
|
2019-04-27 00:43:46 +02:00
|
|
|
|