Skip to content

Commit

Permalink
Add cocotb_xls_test macro
Browse files Browse the repository at this point in the history
Creates cocotb_xls_test macro that generates a file with the
timestamp specified in the rule definition. The macro is required to
generate the timestamp for Icarus Verilog smulation in Cocotb.

Internal-tag: [#46586]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
  • Loading branch information
rw1nkler committed Jul 24, 2023
1 parent 0a9aff8 commit 23afd2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
37 changes: 37 additions & 0 deletions xls/build_rules/cocotb_xls_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2023 The XLS Authors
#
# 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.

load("@rules_hdl//cocotb:cocotb.bzl", "cocotb_test")

def cocotb_xls_test(**kwargs):
name = kwargs["name"]
top = kwargs["hdl_toplevel"]

if "timescale" in kwargs:
timescale = kwargs["timescale"]
timestamp_target = name + "-timescale"
timestamp_verilog = name + "_timescale.v"
native.genrule(
name = timestamp_target,
srcs = [],
cmd = "echo \\`timescale {}/{} > $@".format(
timescale["unit"],
timescale["precission"],
),
outs = [timestamp_verilog],
)
kwargs["verilog_sources"].insert(0, timestamp_verilog)
kwargs.pop("timescale")

cocotb_test(**kwargs)
9 changes: 6 additions & 3 deletions xls/examples/cocotb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_hdl//cocotb:cocotb.bzl", "cocotb_test")
load("@xls_pip_deps//:requirements.bzl", "requirement")
load("//xls/build_rules:xls_build_defs.bzl", "xls_dslx_verilog")
load("//xls/build_rules:cocotb_xls_test.bzl", "cocotb_xls_test")

xls_dslx_verilog(
name = "running_counter_verilog",
Expand All @@ -32,18 +32,21 @@ xls_dslx_verilog(
verilog_file = "running_counter.v",
)

cocotb_test(
cocotb_xls_test(
name = "running_counter_cocotb",
hdl_toplevel = "RunningCounter",
hdl_toplevel_lang = "verilog",
test_module = [
"cocotb_running_counter.py",
],
verilog_sources = [
"timescale.v",
"dumpvcd.v",
":running_counter.v",
],
timescale = {
"unit": "1ns",
"precission": "1ps",
},
deps = [
requirement("cocotb"),
requirement("cocotb_bus"),
Expand Down

0 comments on commit 23afd2a

Please sign in to comment.