-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new test that breaks current conversion
- Loading branch information
1 parent
626496a
commit 6317b89
Showing
9 changed files
with
184 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Fixtures for testing""" | ||
import pytest | ||
from util.conf import LLNLExampleTestingConfigurations | ||
import driver as drv | ||
|
||
|
||
@pytest.fixture | ||
def llnldriver(): | ||
"""fixture for llnl example driver""" | ||
conf = LLNLExampleTestingConfigurations() | ||
llnl_driver = drv.SystemCClangDriver(conf) | ||
return llnl_driver | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--tool-output", action="store_true") | ||
|
||
|
||
def pytest_generate_tests(metafunc): | ||
# This is called for every test. Only get/set command line arguments | ||
# if the argument is specified in the list of test "fixturenames". | ||
if 'tool_output' in metafunc.fixturenames: | ||
if metafunc.config.getoption("tool_output"): | ||
verbose = True | ||
else: | ||
verbose = False | ||
metafunc.parametrize("tool_output", [verbose]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,67 @@ | ||
import os | ||
import sys | ||
import pytest | ||
from llnl import run_verilog_matched_test, run_sexp_matched_test | ||
from util.sexpdiff import sexpdiff | ||
from util.vparser import VerilogParser | ||
from shutil import copy | ||
|
||
@pytest.mark.xfail(reason="the golden standard now is incorrect") | ||
def test_sreg_sexp(args=None): | ||
assert run_sexp_matched_test('sreg', args), "sreg sexp should match golden standard" | ||
|
||
@pytest.mark.skip(reason="no golden standard available for now") | ||
def test_sreg_verilog(args=None): | ||
assert run_verilog_matched_test('sreg', args), "sreg verilog should match golden standard" | ||
def test_sreg_sexp(tmpdir, llnldriver, tool_output): | ||
conf = llnldriver.conf | ||
filename = conf.get_module_name('sreg.cpp') | ||
output_folder = tmpdir | ||
res, filename = llnldriver.generate_sexp( | ||
path=filename, | ||
output_folder=output_folder, | ||
verbose=tool_output, | ||
keep_sexp=True | ||
) | ||
assert res, "should convert to sexpression" | ||
diff_res, diff_str = sexpdiff( | ||
filename, | ||
conf.get_golden_sexp_name('sreg_hdl.txt') | ||
) | ||
if diff_res: | ||
print(diff_str) | ||
assert not diff_res, 'should match golden standard' | ||
|
||
|
||
def test_sreg_verilog(tmpdir, llnldriver, tool_output): | ||
conf = llnldriver.conf | ||
filename = conf.get_module_name('sreg.cpp') | ||
output_folder = tmpdir | ||
res, filename = llnldriver.generate_verilog( | ||
path=filename, | ||
output_folder=output_folder, | ||
verbose=tool_output | ||
) | ||
assert res, "should convert to Verilog from cpp" | ||
diff_info = VerilogParser.diff( | ||
filename, | ||
conf.get_golden_verilog_name('sreg_hdl.txt.v') | ||
) | ||
print(str(diff_info)) | ||
assert diff_info is None, 'should be no diff in Verilog' | ||
|
||
def test_sreg_sexp_to_verilog(tmpdir, llnldriver, tool_output): | ||
conf = llnldriver.conf | ||
filename = conf.get_golden_sexp_name('sreg_hdl.txt') | ||
output_folder = tmpdir | ||
copy(filename, str(output_folder) + '/') | ||
res, filename = llnldriver.generate_verilog_from_sexp( | ||
path=str(output_folder) + '/sreg_hdl.txt', | ||
output_folder=output_folder, | ||
keep_v=True, | ||
verbose=tool_output | ||
) | ||
assert res, "should convert to Verilog from sexp" | ||
print('filename: ', filename) | ||
print('golden: ', conf.get_golden_verilog_name('sreg_hdl.txt.v')) | ||
diff_info = VerilogParser.diff( | ||
filename, | ||
conf.get_golden_verilog_name('sreg_hdl.txt.v') | ||
) | ||
print(str(diff_info)) | ||
assert diff_info is None, 'should be no diff in Verilog' | ||
|
||
if __name__ == '__main__': | ||
test_sreg_verilog(args) | ||
test_sreg_sexp(args) | ||
test_sreg_verilog() | ||
test_sreg_sexp() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Configuration classes for handling directories etc""" | ||
import os | ||
|
||
|
||
class TestingConfigurations(object): | ||
"""parameters in this configuration might change""" | ||
TEST_DATA_ROOT = os.environ['SYSTEMC_CLANG_BUILD_DIR'] + "../systemc-clang/examples/" | ||
|
||
@property | ||
def extra_header_folders(self): | ||
"""acessor for header folders""" | ||
# SystemC Clang build llnl-examples | ||
return self.header_folders | ||
|
||
@property | ||
def positional_arguments(self): | ||
"""positional arguments for the systemc-clang command""" | ||
headers = [] | ||
extra_header_folders = self.extra_header_folders | ||
for header in extra_header_folders: | ||
headers.extend(["-I", header]) | ||
return headers | ||
|
||
def get_module_name(self, basename): | ||
return self.root_folder + '/' + basename | ||
|
||
def get_golden_sexp_name(self, basename): | ||
return self.golden_folder + '/' + basename | ||
|
||
def get_golden_verilog_name(self, basename): | ||
return self.golden_folder + '/' + basename | ||
|
||
def __init__(self, root_folder, golden_folder, header_folders): | ||
self.header_folders = header_folders | ||
self.root_folder = root_folder | ||
self.golden_folder = golden_folder | ||
|
||
|
||
class LLNLExampleTestingConfigurations(TestingConfigurations): | ||
"""parameters for LLNL examples""" | ||
|
||
def __init__(self, header_folders=None): | ||
if header_folders is None: | ||
header_folders = [] | ||
this_folders = header_folders + [ | ||
'{}/llnl-examples/'.format(TestingConfigurations.TEST_DATA_ROOT) | ||
] | ||
root_folder = os.environ['SYSTEMC_CLANG_BUILD_DIR'] + '/' + 'tests/data/verilog-conversion/llnl-examples/' | ||
golden_folder = root_folder + 'handcrafted/' | ||
super(LLNLExampleTestingConfigurations, self).__init__(root_folder, golden_folder, this_folders) | ||
|
||
|
||
class ExampleTestingConfigurations(TestingConfigurations): | ||
"""parameters for ex_* examples""" | ||
|
||
def __init__(self, root_folder, ex_id, header_folders=None): | ||
if header_folders is None: | ||
header_folders = [] | ||
this_folders = header_folders + [ | ||
'{}/ex_{}/'.format(TestingConfigurations.TEST_DATA_ROOT, ex_id) | ||
] | ||
root_folder = '{}/ex_{}/'.format(TestingConfigurations.TEST_DATA_ROOT, ex_id) | ||
golden_folder = root_folder + 'handcrafted/' | ||
super(ExampleTestingConfigurations, self).__init__(root_folder, golden_folder, this_folders) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import difflib | ||
|
||
def sexpdiff(this_filename, that_filename): | ||
# Test the equality of golden versus the generated | ||
with open(this_filename, 'r') as f: | ||
sexp_lines = f.readlines() | ||
with open(that_filename, 'r') as f: | ||
golden_lines = f.readlines() | ||
|
||
diff_res = difflib.ndiff(golden_lines, sexp_lines) | ||
diff_only = list(filter(lambda x: x[0] != ' ', diff_res)) | ||
if diff_only: | ||
diff_str = ''.join(diff_res) | ||
else: | ||
diff_str = None | ||
return len(diff_only) != 0, diff_str | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters