OpenRAM/compiler/tests/30_memchar_test.py

100 lines
3.7 KiB
Python
Raw Normal View History

2022-04-21 22:06:13 +02:00
#!/usr/bin/env python3
# See LICENSE for licensing information.
#
2023-02-21 22:52:21 +01:00
# Copyright (c) 2016-2023 Regents of the University of California and The Board
2022-04-21 22:06:13 +02:00
# of Regents for the Oklahoma Agricultural and Mechanical College
# (acting for and on behalf of Oklahoma State University)
# All rights reserved.
#
2023-04-19 21:41:39 +02:00
import sys, os, re
import shutil
import getpass
2022-04-21 22:06:13 +02:00
import unittest
from testutils import *
2023-04-19 21:41:39 +02:00
import openram
from openram import debug
from openram import OPTS
2022-04-21 22:06:13 +02:00
2023-04-19 21:41:39 +02:00
class sram_char_test(openram_test):
2022-04-21 22:06:13 +02:00
2023-04-19 21:41:39 +02:00
def runTest(self):
global OPTS
2022-04-21 22:06:13 +02:00
out_file = "testsram"
out_path = "/tmp/testsram_{0}_{1}_{2}".format(OPTS.tech_name, getpass.getuser(), os.getpid())
2023-04-19 21:41:39 +02:00
OPTS.output_name = out_file
OPTS.output_path = out_path
OPENRAM_HOME = os.path.abspath(os.environ.get("OPENRAM_HOME"))
config_file = "{}/tests/configs/config_mem_char_func".format(OPENRAM_HOME)
openram.init_openram(config_file, is_unit_test=False)
sp_file = "{0}/tests/sp_files/sram_2_16_1_{1}.sp".format(OPENRAM_HOME, OPTS.tech_name)
debug.info(1, "Testing commandline characterizer script sram_char.py with 2-bit, 16 word SRAM.")
2022-04-21 22:06:13 +02:00
# make sure we start without the files existing
if os.path.exists(out_path):
shutil.rmtree(out_path, ignore_errors=True)
self.assertEqual(os.path.exists(out_path), False)
try:
os.makedirs(out_path, 0o0750)
except OSError as e:
if e.errno == 17: # errno.EEXIST
os.chmod(out_path, 0o0750)
# specify the same verbosity for the system call
options = ""
for i in range(OPTS.verbose_level):
options += " -v"
if OPTS.spice_name:
options += " -s {}".format(OPTS.spice_name)
if OPTS.tech_name:
options += " -t {}".format(OPTS.tech_name)
options += " -j 2"
# Always perform code coverage
if OPTS.coverage == 0:
debug.warning("Failed to find coverage installation. This can be installed with pip3 install coverage")
2023-04-19 21:41:39 +02:00
exe_name = "{0}/../sram_char.py ".format(OPENRAM_HOME)
2022-04-21 22:06:13 +02:00
else:
2023-04-19 21:41:39 +02:00
exe_name = "{0}{1}/../sram_char.py ".format(OPTS.coverage_exe, OPENRAM_HOME)
2022-04-21 22:06:13 +02:00
config_name = "{0}/tests/configs/config_mem_char_func.py".format(OPENRAM_HOME)
2023-04-19 21:41:39 +02:00
cmd = "{0} -n -o {1} -p {2} {3} {4} {5} 2>&1 > {6}/output.log".format(exe_name,
out_file,
out_path,
options,
config_name,
sp_file,
out_path)
2022-04-21 22:06:13 +02:00
debug.info(1, cmd)
os.system(cmd)
# grep any errors from the output
2023-04-19 21:41:39 +02:00
output_log = open("{0}/{1}.log".format(out_path, out_file), "r")
2022-04-21 22:06:13 +02:00
output = output_log.read()
output_log.close()
self.assertEqual(len(re.findall('ERROR', output)), 0)
self.assertEqual(len(re.findall('WARNING', output)), 0)
# now clean up the directory
if not OPTS.keep_temp:
if os.path.exists(out_path):
shutil.rmtree(out_path, ignore_errors=True)
self.assertEqual(os.path.exists(out_path), False)
2023-04-19 21:41:39 +02:00
openram.end_openram()
2022-04-21 22:06:13 +02:00
# run the test from the command line
if __name__ == "__main__":
2023-04-19 21:41:39 +02:00
(OPTS, args) = openram.parse_args()
2022-04-21 22:06:13 +02:00
del sys.argv[1:]
header(__file__, OPTS.tech_name)
unittest.main(testRunner=debugTestRunner())