Skip to content

Commit

Permalink
Merge pull request #24 from riscv-software-src/arch-test-release
Browse files Browse the repository at this point in the history
Add support for new RVTEST_ISA macro.
  • Loading branch information
neelgala authored Oct 14, 2021
2 parents c2a1346 + 7880ac4 commit c8dfdc4
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.23.0] - 2021-10-14
- Added support for new RVTEST_ISA macro
- Fixed decode error in Command util.

## [1.22.1] - 2021-09-13
- Added return code of 1 on error

Expand Down
2 changes: 1 addition & 1 deletion riscof/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__author__ = """InCore Semiconductors Pvt Ltd"""
__email__ = 'info@incoresemi.com'
__version__ = '1.22.1'
__version__ = '1.23.0'
4 changes: 2 additions & 2 deletions riscof/dbgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def createdict(file):
continue
re_search = isa_regex.search(line)
if re_search is not None:
isa = re_search.group('isa')
isa = [x.strip() for x in (re_search.group('isa')).split(",")]
if "RVTEST_CASE(" in line:
temp = ''
lno = i
Expand Down Expand Up @@ -132,7 +132,7 @@ def createdict(file):
if len(part_dict.keys()) == 0:
logger.warning("{}: Atleast one part must exist in the test.".format(file))
raise DbgenError
return {'isa': str(isa), 'parts': orderdict(part_dict)}
return {'isa': [str(x) for x in isa], 'parts': orderdict(part_dict)}

def check_commit(repo, fpath, old_commit):
commit = next(
Expand Down
81 changes: 74 additions & 7 deletions riscof/framework/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

logger = logging.getLogger(__name__)

class TestSelectError(Exception):
"Raised on an error while selecting Tests."
pass

def compare_signature(file1, file2):
'''
Expand Down Expand Up @@ -222,6 +225,69 @@ def eval_macro(macro, spec):
else:
return (False,[])

def isa_set(string):
str_match = re.findall(r'([^\d]*?)(?!_)*(Z.*?)*(_|$)',string,re.M)
extension_list= []
for match in str_match:
stdisa, z, ignore = match
if stdisa != '':
for e in stdisa:
extension_list.append(e)
if z != '':
extension_list.append(z)
return set(extension_list)

def canonicalise(isa):
all_ext = ["M","A","F","D","Q","L","C","B","J","K","T","P","V","N","S","H","U","Zicsr",
"Zifencei","Zihintpause","Zmmul","Zam","Zbc","Zbb","Zbp","Zbm","Zbe","Zbf","Zkne",
"Zknd","Zknh","Zkse","Zksh","Zkg","Zkb","Zkr","Zks","Zkn","Ztso"]
canonical_string = ""
switch = False
for ext in all_ext:
if ext in isa:
if switch:
canonical_string += "_"
elif ext.startswith("Z"):
switch=True
canonical_string += ext
if ext.startswith("Z"):
switch=True
return canonical_string


def prod_isa(dut_isa, test_isa):
'''
Function to generate the isa a test has to be compiled with. The various possible ISAs a
test can be compiled with is compared with the ISA defined in the DUT specification.
:param dut_isa: The ISA field in the DUT specification.
:param test_isa: A list of ISA strings from the test.
:type dut_isa: str
:type test_isa: list(str)
:return: The maximal set of all the applicable ISA strings from the test in canonical form.
:raises: TestSelectError
'''
dut_exts = isa_set(re.sub("RV(64|128|32)(I|E)","",dut_isa))
isa = set([])
last_prefix = ''
for entry in test_isa:
match = re.findall("(?P<prefix>RV(64|128|32)(I|E))",entry)
prefix = match[0][0]
exts = isa_set(re.sub("RV(64|128|32)(I|E)","",entry))
overlap = dut_exts & exts
if overlap == exts:
isa = isa | overlap
if last_prefix:
if last_prefix != prefix:
raise TestSelectError("Incompatiple prefix for valid ISA strings in test.")
last_prefix = prefix
return prefix+canonicalise(isa)

def generate_test_pool(ispec, pspec, workdir, dbfile = None):
'''
Expand All @@ -236,11 +302,8 @@ def generate_test_pool(ispec, pspec, workdir, dbfile = None):
:type pspec: dict
:return: A list of 3 entry tuples. Each entry in a list corresponds to a
test which should be executed. In each tuple, the first entry is the
path to the test relative to the riscof root, the second entry is the
list of macros for the test and the third entry is the
isa(adhering to RISCV specifications) required for the test.
:return: A dictionary which contains all the necessary information for the selected tests.
Refer to Test List Format for further information.
'''
spec = {**ispec, **pspec}
Expand All @@ -267,7 +330,11 @@ def generate_test_pool(ispec, pspec, workdir, dbfile = None):
if (temp[0]):
macros.extend(temp[1])
if not macros == []:
isa = db[file]['isa']
try:
isa = prod_isa(ispec['ISA'],db[file]['isa'])
except TestSelectError as e:
logger.error("Error in test: "+str(file)+"\n"+str(e))
continue
if '32' in isa:
xlen = '32'
elif '64' in isa:
Expand All @@ -280,7 +347,7 @@ def generate_test_pool(ispec, pspec, workdir, dbfile = None):
elif re.match(r"^[^(Z,z)]+F.*$",isa):
macros.append("FLEN=32")
test_pool.append(
(file, db[file]['commit_id'], macros, db[file]['isa'],cov_labels))
(file, db[file]['commit_id'], macros,isa,cov_labels))
logger.info("Selecting Tests.")
for entry in test_pool:
# logger.info("Test file:" + entry[0])
Expand Down
2 changes: 1 addition & 1 deletion riscof/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GitPython==3.1.17
click
click>=7.1.2
Jinja2>=2.10.1
pytz>=2019.1
riscv-config>=2.10.1
Expand Down
30 changes: 22 additions & 8 deletions riscof/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,30 @@ def run(self, **kwargs):
logger.error("Process Killed.")
logger.error("Command did not exit within {0} seconds: {1}".format(timeout,cmd))

if x.returncode != 0:
if out:
logger.error(out.decode("ascii"))
if err:
logger.error(err.decode("ascii"))
else:
try:
fmt = sys.stdout.encoding if sys.stdout.encoding is not None else 'utf-8'
if out:
logger.warning(out.decode("ascii"))
if x.returncode != 0:
logger.error(out.decode(fmt))
else:
logger.debug(out.decode(fmt))
except UnicodeError:
logger.warning("Unable to decode STDOUT for launched subprocess. Output written to:"+
cwd+"/stdout.log")
with open(cwd+"/stdout.log") as f:
f.write(out)
try:
fmt = sys.stderr.encoding if sys.stdout.encoding is not None else 'utf-8'
if err:
logger.warning(err.decode("ascii"))
if x.returncode != 0:
logger.error(err.decode(fmt))
else:
logger.debug(err.decode(fmt))
except UnicodeError:
logger.warning("Unable to decode STDERR for launched subprocess. Output written to:"+
cwd+"/stderr.log")
with open(cwd+"/stderr.log") as f:
f.write(out)
return x.returncode

def _is_shell_command(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.22.1
current_version = 1.23.0
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def read_requires():
test_requirements = [ ]

setup(name="riscof",
version='1.22.1',
version='1.23.0',
description="RISC-V Architectural Test Framework",
long_description=readme + '\n\n',
classifiers=[
Expand Down

0 comments on commit c8dfdc4

Please sign in to comment.