Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cocotb #175

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

3 changes: 2 additions & 1 deletion dependency_support/pip_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ dataclasses-json==0.5.7
jwt==1.3.1
requests==2.28.2
absl-py==1.4.0
cocotb==1.8.0
klayout==0.28.8

git+https://github.com/cocotb/cocotb.git@a853db95b0019db6796a6803aa94304bde743e4e
Loading