Skip to content

Commit 05fdf9c

Browse files
committed
cocotb: Adjust cocotb_wrapper script to the bumped cocotb package
Provide a way to specify timescale and make waves option available for a Cocotb Runner build function. Internal-tag: [#46586] Signed-off-by: Robert Winkler <[email protected]>
1 parent 0dd5aec commit 05fdf9c

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

cocotb/cocotb.bzl

+17
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ def _get_test_command(ctx, verilog_files, vhdl_files):
131131
waves_args = " --waves" if ctx.attr.waves else ""
132132
seed_args = " --seed {}".format(ctx.attr.seed) if ctx.attr.seed != "" else ""
133133

134+
timescale_args = ""
135+
if ctx.attr.timescale:
136+
if "unit" not in ctx.attr.timescale:
137+
fail("Time unit not specified for the timescale attribute")
138+
if "precision" not in ctx.attr.timescale:
139+
fail("Time precision not specified for the timescale attribute")
140+
141+
timescale_args = " --timescale='({},{})'".format(
142+
ctx.attr.timescale["unit"],
143+
ctx.attr.timescale["precision"],
144+
)
145+
134146
test_module_args = _pymodules_to_argstring(ctx.files.test_module, "test_module")
135147

136148
command = (
@@ -154,6 +166,7 @@ def _get_test_command(ctx, verilog_files, vhdl_files):
154166
verbose_args +
155167
waves_args +
156168
seed_args +
169+
timescale_args +
157170
test_module_args
158171
)
159172

@@ -280,6 +293,10 @@ _cocotb_test_attrs = {
280293
doc = "Record signal traces",
281294
default = True,
282295
),
296+
"timescale": attr.string_dict(
297+
doc = "Contains time unit and time precision for the simulator",
298+
default = {},
299+
),
283300
"deps": attr.label_list(
284301
doc = "The list of python libraries to be linked in to the simulation target",
285302
providers = [PyInfo],

cocotb/cocotb_wrapper.py

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"always",
2929
"build_dir",
3030
"verbose",
31+
"timescale",
32+
"waves",
3133
]
3234

3335

@@ -64,6 +66,9 @@ def __call__(self, parser, namespace, values, option_string=None):
6466
key, value = value.split("=")
6567
getattr(namespace, self.dest)[key] = value
6668

69+
def tuple_type(strings):
70+
return tuple(strings.replace("(", "").replace(")", "").split(","))
71+
6772
parser = argparse.ArgumentParser(description="Runs the Cocotb framework from Bazel")
6873

6974
parser.add_argument("--sim", default="icarus", help="Dafault simulator")
@@ -155,6 +160,12 @@ def __call__(self, parser, namespace, values, option_string=None):
155160
default="results.xml",
156161
help="Name of xUnit XML file to store test results in",
157162
)
163+
parser.add_argument(
164+
"--timescale",
165+
default=None,
166+
type=tuple_type,
167+
help="Tuple containing time unit and time precision for simulation",
168+
)
158169

159170
return parser
160171

cocotb/tests/BUILD

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ cocotb_test(
2929
parameters = {"COUNTER_WIDTH": "8"},
3030
seed = "1234567890",
3131
test_module = ["cocotb_counter.py"],
32+
timescale = {
33+
"unit": "1ns",
34+
"precision": "1ps"
35+
},
3236
verilog_sources = [
3337
":counter",
34-
"wavedump.v",
3538
],
39+
waves = True,
3640
deps = [requirement("cocotb")],
3741
)

cocotb/tests/counter.v

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
`timescale 1us/1us
16-
1715
module counter #(
1816
parameter COUNTER_WIDTH = 32
1917
) (

cocotb/tests/wavedump.v

-20
This file was deleted.

0 commit comments

Comments
 (0)