Skip to content

Commit

Permalink
cocotb: Adjust cocotb_wrapper script to the bumped cocotb package
Browse files Browse the repository at this point in the history
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 <rwinkler@antmicro.com>
  • Loading branch information
rw1nkler committed Aug 23, 2023
1 parent 0dd5aec commit 05fdf9c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
17 changes: 17 additions & 0 deletions cocotb/cocotb.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ def _get_test_command(ctx, verilog_files, vhdl_files):
waves_args = " --waves" if ctx.attr.waves else ""
seed_args = " --seed {}".format(ctx.attr.seed) if ctx.attr.seed != "" else ""

timescale_args = ""
if ctx.attr.timescale:
if "unit" not in ctx.attr.timescale:
fail("Time unit not specified for the timescale attribute")
if "precision" not in ctx.attr.timescale:
fail("Time precision not specified for the timescale attribute")

timescale_args = " --timescale='({},{})'".format(
ctx.attr.timescale["unit"],
ctx.attr.timescale["precision"],
)

test_module_args = _pymodules_to_argstring(ctx.files.test_module, "test_module")

command = (
Expand All @@ -154,6 +166,7 @@ def _get_test_command(ctx, verilog_files, vhdl_files):
verbose_args +
waves_args +
seed_args +
timescale_args +
test_module_args
)

Expand Down Expand Up @@ -280,6 +293,10 @@ _cocotb_test_attrs = {
doc = "Record signal traces",
default = True,
),
"timescale": attr.string_dict(
doc = "Contains time unit and time precision for the simulator",
default = {},
),
"deps": attr.label_list(
doc = "The list of python libraries to be linked in to the simulation target",
providers = [PyInfo],
Expand Down
11 changes: 11 additions & 0 deletions cocotb/cocotb_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"always",
"build_dir",
"verbose",
"timescale",
"waves",
]


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

def tuple_type(strings):
return tuple(strings.replace("(", "").replace(")", "").split(","))

parser = argparse.ArgumentParser(description="Runs the Cocotb framework from Bazel")

parser.add_argument("--sim", default="icarus", help="Dafault simulator")
Expand Down Expand Up @@ -155,6 +160,12 @@ def __call__(self, parser, namespace, values, option_string=None):
default="results.xml",
help="Name of xUnit XML file to store test results in",
)
parser.add_argument(
"--timescale",
default=None,
type=tuple_type,
help="Tuple containing time unit and time precision for simulation",
)

return parser

Expand Down
6 changes: 5 additions & 1 deletion cocotb/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ cocotb_test(
parameters = {"COUNTER_WIDTH": "8"},
seed = "1234567890",
test_module = ["cocotb_counter.py"],
timescale = {
"unit": "1ns",
"precision": "1ps"
},
verilog_sources = [
":counter",
"wavedump.v",
],
waves = True,
deps = [requirement("cocotb")],
)
2 changes: 0 additions & 2 deletions cocotb/tests/counter.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

`timescale 1us/1us

module counter #(
parameter COUNTER_WIDTH = 32
) (
Expand Down
20 changes: 0 additions & 20 deletions cocotb/tests/wavedump.v

This file was deleted.

0 comments on commit 05fdf9c

Please sign in to comment.