From 0dd5aec93d85b427eef04b46125d0a1d5842e003 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Tue, 22 Aug 2023 11:59:59 +0200 Subject: [PATCH 1/2] dependency_support: Bump cocotb Bump Cocotb to the version supporting specifying timescale and dumping waveforms using Icarus Verilog. Internal-tag: [#46586] Signed-off-by: Robert Winkler --- dependency_support/pip_requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dependency_support/pip_requirements.txt b/dependency_support/pip_requirements.txt index b58f61ac..3eaaccee 100644 --- a/dependency_support/pip_requirements.txt +++ b/dependency_support/pip_requirements.txt @@ -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 From 8029db685ab4ec5fc0aeee563f98c3559f580d76 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Tue, 22 Aug 2023 12:13:38 +0200 Subject: [PATCH 2/2] 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 --- cocotb/cocotb.bzl | 17 +++++++++++++++++ cocotb/cocotb_wrapper.py | 11 +++++++++++ cocotb/tests/BUILD | 6 +++++- cocotb/tests/counter.v | 2 -- cocotb/tests/wavedump.v | 20 -------------------- 5 files changed, 33 insertions(+), 23 deletions(-) delete mode 100644 cocotb/tests/wavedump.v diff --git a/cocotb/cocotb.bzl b/cocotb/cocotb.bzl index 6d8e18b8..497bfb06 100644 --- a/cocotb/cocotb.bzl +++ b/cocotb/cocotb.bzl @@ -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 = ( @@ -154,6 +166,7 @@ def _get_test_command(ctx, verilog_files, vhdl_files): verbose_args + waves_args + seed_args + + timescale_args + test_module_args ) @@ -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], diff --git a/cocotb/cocotb_wrapper.py b/cocotb/cocotb_wrapper.py index 1b8db1d0..82c7fa73 100644 --- a/cocotb/cocotb_wrapper.py +++ b/cocotb/cocotb_wrapper.py @@ -28,6 +28,8 @@ "always", "build_dir", "verbose", + "timescale", + "waves", ] @@ -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") @@ -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 diff --git a/cocotb/tests/BUILD b/cocotb/tests/BUILD index a5a6d00c..681babc1 100644 --- a/cocotb/tests/BUILD +++ b/cocotb/tests/BUILD @@ -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")], ) diff --git a/cocotb/tests/counter.v b/cocotb/tests/counter.v index 222bf47f..69eaf2e0 100644 --- a/cocotb/tests/counter.v +++ b/cocotb/tests/counter.v @@ -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 ) ( diff --git a/cocotb/tests/wavedump.v b/cocotb/tests/wavedump.v deleted file mode 100644 index bb5e18bc..00000000 --- a/cocotb/tests/wavedump.v +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2023 Antmicro -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -module wavedump(); -initial begin - $dumpfile("dump.vcd"); - $dumpvars(0, counter); -end -endmodule