Skip to content

Commit b7bd30a

Browse files
committed
Added support for VCI and VC belonging to different libraries.
Improved compliance tests to detect lack of as_sync function and added missing functions to VUnit VCIs
1 parent fc081af commit b7bd30a

File tree

8 files changed

+69
-18
lines changed

8 files changed

+69
-18
lines changed

tests/unit/test_compliance_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,11 @@ def test_create_vhdl_testbench_template_references(self):
472472

473473
vc_path = self.make_file("vc2.vhd", vc_contents)
474474
template, _ = VerificationComponent.create_vhdl_testbench_template(
475-
"vc_lib", vc_path, self.vci_path
475+
"vc_lib", "vc_lib", vc_path, self.vci_path
476476
)
477477
template = VHDLDesignFile.parse(template)
478478
refs = template.references
479-
self.assertEqual(len(refs), 13)
479+
self.assertEqual(len(refs), 14)
480480
self.assertIn(VHDLReference("library", "vunit_lib"), refs)
481481
self.assertIn(VHDLReference("library", "vc_lib"), refs)
482482
self.assertIn(VHDLReference("library", "a_lib"), refs)
@@ -485,6 +485,7 @@ def test_create_vhdl_testbench_template_references(self):
485485
self.assertIn(VHDLReference("package", "vc_lib", "vc_pkg", "all"), refs)
486486
self.assertIn(VHDLReference("package", "a_lib", "x", "y"), refs)
487487
self.assertIn(VHDLReference("package", "vunit_lib", "sync_pkg", "all"), refs)
488+
self.assertIn(VHDLReference("package", "vunit_lib", "vc_pkg", "all"), refs)
488489
self.assertIn(VHDLReference("context", "vc_lib", "spam"), refs)
489490
self.assertIn(VHDLReference("context", "a_lib", "eggs"), refs)
490491
self.assertIn(VHDLReference("context", "vunit_lib", "vunit_context"), refs)
@@ -667,7 +668,9 @@ def test_creating_template_with_specified_vc_lib(self):
667668
[
668669
"compliance_test.py",
669670
"create-vc",
670-
"-l",
671+
"--vc-lib-name",
672+
"my_vc_lib",
673+
"--vci-lib-name",
671674
"my_vc_lib",
672675
self.vc_path,
673676
self.vci_path,

vunit/vc/compliance_test.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
def _create_vc_template(args):
1919
"""Creates VC testbench template from args."""
2020
template_code, vc_name = VerificationComponent.create_vhdl_testbench_template(
21-
args.vc_lib_name, args.vc_path, args.vci_path
21+
args.vc_lib_name, args.vci_lib_name, args.vc_path, args.vci_path
2222
)
2323
if not template_code or not vc_name:
2424
sys.exit(1)
@@ -46,21 +46,21 @@ def _create_vci_template(args):
4646
template_code,
4747
vci_name,
4848
) = VerificationComponentInterface.create_vhdl_testbench_template(
49-
args.vc_lib_name, args.vci_path, args.vc_handle_t
49+
args.vci_lib_name, args.vci_path, args.vc_handle_t
5050
)
5151
if not template_code or not vci_name:
5252
sys.exit(1)
5353

5454
if not args.output_path:
55-
output_dir = args.vci_path.parent / ".vc" / vci_name
55+
output_dir = args.vc_path.parent / ".vc" / vci_name
5656
if not output_dir.exists():
5757
output_dir.mkdir(parents=True)
5858

5959
output_path = output_dir / ("tb_%s_compliance_template.vhd" % args.vc_handle_t)
6060
elif args.output_path.is_dir():
6161
output_dir = args.output_path / vci_name
6262
if not output_dir.exists():
63-
output_dir.mkdir(parents=True)
63+
output_dir.exists(parents=True)
6464
output_path = output_dir / ("tb_%s_compliance_template.vhd" % args.vc_handle_t)
6565
else:
6666
output_path = args.output_path
@@ -79,9 +79,13 @@ def create_vc_parser(subparsers):
7979
"create-vc", help="Creates a VC compliance test template"
8080
)
8181
parser.add_argument(
82-
"-l",
8382
"--vc-lib-name",
84-
help="Name of library hosting the VC and the VCI (default: vc_lib)",
83+
help="Name of library hosting the VC (default: vc_lib)",
84+
default="vc_lib",
85+
)
86+
parser.add_argument(
87+
"--vci-lib-name",
88+
help="Name of library hosting the VCI (default: vc_lib)",
8589
default="vc_lib",
8690
)
8791
parser.add_argument(
@@ -102,9 +106,8 @@ def create_vci_parser(subparsers):
102106
"create-vci", help="Creates a VCI compliance test template"
103107
)
104108
parser.add_argument(
105-
"-l",
106-
"--vc-lib-name",
107-
help="Name of library hosting the VC and the VCI (default: vc_lib)",
109+
"--vci-lib-name",
110+
help="Name of library hosting the VCI (default: vc_lib)",
108111
default="vc_lib",
109112
)
110113
parser.add_argument(

vunit/vc/verification_component.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ def validate(vc_path):
9999
return vc_code
100100

101101
@staticmethod
102-
def create_vhdl_testbench_template(vc_lib_name, vc_path, vci_path):
102+
def create_vhdl_testbench_template(vc_lib_name, vci_lib_name, vc_path, vci_path):
103103
"""
104104
Creates a template for a VC compliance testbench.
105105
106-
:param vc_lib_name: Name of the library containing the verification component and its interface.
106+
:param vc_lib_name: Name of the library containing the verification component.
107+
:param vci_lib_name: Name of the library containing the verification component interface.
107108
:param vc_path: Path to the file containing the verification component entity.
108109
:param vci_path: Path to the file containing the verification component interface package.
109110
@@ -209,8 +210,9 @@ def create_signal_declarations_and_vc_instantiation(vc_entity, vc_lib_name):
209210

210211
initial_package_refs = set(
211212
[
213+
"vunit_lib.vc_pkg.all",
212214
"vunit_lib.sync_pkg.all",
213-
"%s.%s.all" % (vc_lib_name, vci_code.packages[0].identifier),
215+
"%s.%s.all" % (vci_lib_name, vci_code.packages[0].identifier),
214216
]
215217
)
216218
context_items = create_context_items(
@@ -385,6 +387,7 @@ def update_generics(code):
385387
else:
386388
template_code, _ = self.create_vhdl_testbench_template(
387389
self.vc_facade.library,
390+
self.vci.vci_facade.library,
388391
self.vc_facade.source_file.name,
389392
self.vci.vci_facade.source_file.name,
390393
)

vunit/vc/verification_component_interface.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ class VerificationComponentInterface:
5757
"""Represents a Verification Component Interface (VCI)."""
5858

5959
@classmethod
60-
def find(cls, vc_lib, vci_name, vc_handle_t):
60+
def find(cls, vci_lib, vci_name, vc_handle_t):
6161
"""Finds the specified VCI if present.
6262
63-
:param vc_lib: Library object containing the VCI.
63+
:param vci_lib: Library object containing the VCI.
6464
:param vci_name: Name of VCI package.
6565
:param vc_handle_t: Name of VC handle type.
6666
6767
:returns: A VerificationComponentInterface object.
6868
"""
6969

7070
try:
71-
vci_facade = vc_lib.package(vci_name)
71+
vci_facade = vci_lib.package(vci_name)
7272
except KeyError:
7373
LOGGER.error("Failed to find VCI %s", vci_name)
7474
sys.exit(1)
@@ -91,6 +91,10 @@ def validate(cls, vci_path, vc_handle_t):
9191
LOGGER.error("%s must contain a single VCI package", vci_path)
9292
return None, None
9393

94+
if not cls._validate_as_sync(code, vc_handle_t):
95+
LOGGER.error("%s must provide an as_sync function", vci_path)
96+
return None, None
97+
9498
vc_constructor = cls._validate_constructor(code, vc_handle_t)
9599
if not cls._validate_handle(code, vc_handle_t):
96100
vc_constructor = None
@@ -101,6 +105,30 @@ def __init__(self, vci_facade, vc_constructor):
101105
self.vci_facade = vci_facade
102106
self.vc_constructor = vc_constructor
103107

108+
@staticmethod
109+
def _validate_as_sync(code, vc_handle_t):
110+
"""Validates the existence and format of the as_sync function."""
111+
112+
for func in VHDLFunctionSpecification.find(code):
113+
if not func.identifier.startswith("as_sync"):
114+
continue
115+
116+
if func.return_type_mark != "sync_handle_t":
117+
continue
118+
119+
if len(func.parameter_list) != 1:
120+
continue
121+
122+
if len(func.parameter_list[0].identifier_list) != 1:
123+
continue
124+
125+
if func.parameter_list[0].subtype_indication.type_mark != vc_handle_t:
126+
continue
127+
128+
return func
129+
130+
return None
131+
104132
@staticmethod
105133
def _validate_constructor(code, vc_handle_t):
106134
"""Validates the existence and format of the verification component constructor."""

vunit/vhdl/verification_components/src/stream_master_pkg-body.vhd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ package body stream_master_pkg is
3030
return master.p_std_cfg;
3131
end;
3232

33+
impure function as_sync(master : stream_master_t) return sync_handle_t is
34+
begin
35+
return get_actor(master.p_std_cfg);
36+
end;
37+
3338
procedure push_stream(signal net : inout network_t;
3439
stream : stream_master_t;
3540
data : std_logic_vector;

vunit/vhdl/verification_components/src/stream_master_pkg.vhd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use ieee.std_logic_1164.all;
1212
context work.vunit_context;
1313
context work.com_context;
1414
use work.vc_pkg.all;
15+
use work.sync_pkg.all;
1516

1617
package stream_master_pkg is
1718
-- Stream master handle
@@ -31,6 +32,7 @@ package stream_master_pkg is
3132
) return stream_master_t;
3233

3334
function get_std_cfg(master : stream_master_t) return std_cfg_t;
35+
impure function as_sync(master : stream_master_t) return sync_handle_t;
3436

3537
-- Push a data value to the stream
3638
procedure push_stream(signal net : inout network_t;

vunit/vhdl/verification_components/src/stream_slave_pkg-body.vhd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ package body stream_slave_pkg is
2525
return slave.p_std_cfg;
2626
end;
2727

28+
impure function as_sync(slave : stream_slave_t) return sync_handle_t is
29+
begin
30+
return get_actor(slave.p_std_cfg);
31+
end;
32+
2833
procedure pop_stream(signal net : inout network_t;
2934
stream : stream_slave_t;
3035
variable reference : inout stream_reference_t) is

vunit/vhdl/verification_components/src/stream_slave_pkg.vhd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ context work.vunit_context;
1313
context work.com_context;
1414

1515
use work.vc_pkg.all;
16+
use work.sync_pkg.all;
1617

1718
package stream_slave_pkg is
1819
-- Stream slave handle
@@ -32,6 +33,7 @@ package stream_slave_pkg is
3233
) return stream_slave_t;
3334

3435
function get_std_cfg(slave : stream_slave_t) return std_cfg_t;
36+
impure function as_sync(slave : stream_slave_t) return sync_handle_t;
3537

3638
-- Reference to future stream result
3739
alias stream_reference_t is msg_t;

0 commit comments

Comments
 (0)