Skip to content

Commit

Permalink
Support of cocotb 1.5 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
themperek authored Mar 12, 2021
1 parent f31e43d commit 86fbcfe
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 364 deletions.
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ jobs:
displayName: "Install pytest-parallel"
- script: |
conda install --yes pip && git clone -b v1.4.0 https://github.com/cocotb/cocotb.git && cd cocotb && cd .. && pip install -e cocotb
conda install --yes pip && git clone -b v1.5.0 https://github.com/cocotb/cocotb.git && cd cocotb && cd .. && pip install -e cocotb
displayName: "Install cocotb from source"
- script: |
pip install -e .
displayName: "Install cocotb-test"
- script: |
pytest -s --junitxml=test-results.xml --cocotbxml=test-cocotb.xml tests
pytest --junitxml=test-results.xml --cocotbxml=test-cocotb.xml tests
displayName: "Test with pytest"
condition: ne(variables['SIM'], 'verilator')
Expand Down
37 changes: 20 additions & 17 deletions cocotb_test/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import threading
import signal
import warnings
import cocotb._vendor.find_libpython as find_libpython
import cocotb.config

from distutils.spawn import find_executable
from distutils.sysconfig import get_config_var
Expand Down Expand Up @@ -176,6 +178,8 @@ def set_env(self):
for e in os.environ:
self.env[e] = os.environ[e]

self.env["LIBPYTHON_LOC"] = find_libpython.find_libpython()

self.env["PATH"] += os.pathsep + self.lib_dir

self.env["PYTHONPATH"] = os.pathsep.join(sys.path)
Expand Down Expand Up @@ -348,7 +352,7 @@ def compile_command(self):

def run_command(self):
return (
["vvp", "-M", self.lib_dir, "-m", "libcocotbvpi_icarus"]
["vvp", "-M", self.lib_dir, "-m", cocotb.config.lib_name("vpi", "icarus")]
+ self.simulation_args
+ [self.sim_file]
+ self.plus_args
Expand Down Expand Up @@ -450,26 +454,26 @@ def build_command(self):
RTL_LIBRARY=as_tcl_value(self.rtl_library),
TOPLEVEL=as_tcl_value(self.toplevel),
EXT_NAME=as_tcl_value(
"cocotb_init {}".format(os.path.join(self.lib_dir, "libcocotbfli_modelsim." + self.lib_ext))
"cocotb_init {}".format(cocotb.config.lib_name_path("fli", "questa"))
),
EXTRA_ARGS=" ".join(as_tcl_value(v) for v in (self.simulation_args + self.get_parameter_commands(self.parameters))),
)

if self.verilog_sources:
self.env["GPI_EXTRA"] = "cocotbvpi_modelsim:cocotbvpi_entry_point"
self.env["GPI_EXTRA"] = cocotb.config.lib_name_path("vpi", "questa")+":cocotbvpi_entry_point"

else:
do_script = "vsim -onfinish {ONFINISH} -pli {EXT_NAME} {EXTRA_ARGS} {RTL_LIBRARY}.{TOPLEVEL} {PLUS_ARGS};".format(
ONFINISH="stop" if self.gui else "exit",
RTL_LIBRARY=as_tcl_value(self.rtl_library),
TOPLEVEL=as_tcl_value(self.toplevel),
EXT_NAME=as_tcl_value(os.path.join(self.lib_dir, "libcocotbvpi_modelsim." + self.lib_ext)),
EXT_NAME=as_tcl_value(cocotb.config.lib_name_path("vpi", "questa")),
EXTRA_ARGS=" ".join(as_tcl_value(v) for v in (self.simulation_args + self.get_parameter_commands(self.parameters))),
PLUS_ARGS=" ".join(as_tcl_value(v) for v in self.plus_args),
)

if self.vhdl_sources:
self.env["GPI_EXTRA"] = "cocotbfli_modelsim:cocotbfli_entry_point"
self.env["GPI_EXTRA"] = cocotb.config.lib_name_path("fli", "questa")+":cocotbfli_entry_point"

if self.waves:
do_script += "log -recursive /*;"
Expand All @@ -486,7 +490,7 @@ class Ius(Simulator):
def __init__(self, *argv, **kwargs):
super(Ius, self).__init__(*argv, **kwargs)

self.env["GPI_EXTRA"] = "cocotbvhpi_ius:cocotbvhpi_entry_point"
self.env["GPI_EXTRA"] = cocotb.config.lib_name_path("vhpi", "ius")+":cocotbvhpi_entry_point"

def get_include_commands(self, includes):
include_cmd = []
Expand Down Expand Up @@ -532,7 +536,7 @@ def build_command(self):
"-define",
"COCOTB_SIM=1",
"-loadvpi",
os.path.join(self.lib_dir, "libcocotbvpi_ius." + self.lib_ext) + ":vlog_startup_routines_bootstrap",
cocotb.config.lib_name_path("vpi", "ius") + ":vlog_startup_routines_bootstrap",
"-plinowarn",
"-access",
"+rwc",
Expand Down Expand Up @@ -562,7 +566,7 @@ class Xcelium(Simulator):
def __init__(self, *argv, **kwargs):
super(Xcelium, self).__init__(*argv, **kwargs)

self.env["GPI_EXTRA"] = "cocotbvhpi_ius:cocotbvhpi_entry_point"
self.env["GPI_EXTRA"] = cocotb.config.lib_name_path("vhpi", "ius") + ":cocotbvhpi_entry_point"

def get_include_commands(self, includes):
include_cmd = []
Expand Down Expand Up @@ -603,12 +607,12 @@ def build_command(self):
[
"xrun",
"-64",
"-elaborate",
"-v93",
"-elaborate"
"-define",
"COCOTB_SIM=1",
"-loadvpi",
os.path.join(self.lib_dir, "libcocotbvpi_ius." + self.lib_ext) + ":vlog_startup_routines_bootstrap",
cocotb.config.lib_name_path("vpi", "ius") + ":vlog_startup_routines_bootstrap",
"-plinowarn",
"-access",
"+rwc",
Expand Down Expand Up @@ -677,7 +681,7 @@ def build_command(self):
"-sverilog",
"+define+COCOTB_SIM=1",
"-load",
os.path.join(self.lib_dir, "libcocotbvpi_vcs." + self.lib_ext),
cocotb.config.lib_name_path("vpi", "vcs"),
]
+ self.get_define_commands(self.defines)
+ self.get_include_commands(self.includes)
Expand Down Expand Up @@ -736,7 +740,7 @@ def build_command(self):
"ghdl",
"-r",
self.toplevel,
"--vpi=" + os.path.join(self.lib_dir, "libcocotbvpi_ghdl." + self.lib_ext),
"--vpi=" + cocotb.config.lib_name_path("vpi", "ghdl"),
] + self.simulation_args + self.get_parameter_commands(self.parameters)

if not self.compile_only:
Expand Down Expand Up @@ -802,21 +806,21 @@ def build_command(self):
do_script += "asim +access +w -interceptcoutput -O2 -loadvhpi {EXT_NAME} {EXTRA_ARGS} {RTL_LIBRARY}.{TOPLEVEL} \n".format(
RTL_LIBRARY=as_tcl_value(self.rtl_library),
TOPLEVEL=as_tcl_value(self.toplevel),
EXT_NAME=as_tcl_value(os.path.join(self.lib_dir, "libcocotbvhpi_aldec")),
EXT_NAME=as_tcl_value(cocotb.config.lib_name_path("vhpi", "riviera")),
EXTRA_ARGS=" ".join(as_tcl_value(v) for v in (self.simulation_args + self.get_parameter_commands(self.parameters))),
)
if self.verilog_sources:
self.env["GPI_EXTRA"] = "cocotbvpi_aldec:cocotbvpi_entry_point"
self.env["GPI_EXTRA"] = cocotb.config.lib_name_path("vpi", "riviera") + "cocotbvpi_entry_point"
else:
do_script += "asim +access +w -interceptcoutput -O2 -pli {EXT_NAME} {EXTRA_ARGS} {RTL_LIBRARY}.{TOPLEVEL} {PLUS_ARGS} \n".format(
RTL_LIBRARY=as_tcl_value(self.rtl_library),
TOPLEVEL=as_tcl_value(self.toplevel),
EXT_NAME=as_tcl_value(os.path.join(self.lib_dir, "libcocotbvpi_aldec")),
EXT_NAME=as_tcl_value(cocotb.config.lib_name_path("vpi", "riviera")),
EXTRA_ARGS=" ".join(as_tcl_value(v) for v in (self.simulation_args + self.get_parameter_commands(self.parameters))),
PLUS_ARGS=" ".join(as_tcl_value(v) for v in self.plus_args),
)
if self.vhdl_sources:
self.env["GPI_EXTRA"] = "cocotbvhpi_aldec:cocotbvhpi_entry_point"
self.env["GPI_EXTRA"] = cocotb.config.lib_name_path("vhpi", "riviera") + ":cocotbvhpi_entry_point"

if self.waves:
do_script += "log -recursive /*;"
Expand All @@ -826,7 +830,6 @@ def build_command(self):
do_file = tempfile.NamedTemporaryFile(delete=False)
do_file.write(do_script.encode())
do_file.close()
# print(do_script)

return [["vsimsa"] + ["-do"] + ["do"] + [do_file.name]]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def read_file(fname):
author="Tomasz Hemperek",
author_email="hemperek@uni-bonn.de",
packages=find_packages(),
install_requires=["cocotb==1.4.*", "pytest"],
install_requires=["cocotb>=1.5", "pytest"],
entry_points={
"console_scripts": [
"cocotb=cocotb_test.cli:config",
Expand Down
49 changes: 12 additions & 37 deletions tests/dff.v
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
// =============================================================================
// Authors: Martin Zabel
//
// Module: A simple D-FF
//
// Description:
// ------------------------------------
// A simple D-FF with an initial state of '0'.
//
// License:
// =============================================================================
// Copyright 2016 Technische Universitaet Dresden - Germany
// Chair for VLSI-Design, Diagnostics and Architecture
//
// 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.
// =============================================================================
// This file is public domain, it can be freely copied without restrictions.
// SPDX-License-Identifier: CC0-1.0

`timescale 1us/1us

module dff_test (c,d,q);
input wire c, d;
output reg q = 1'b0;
module dff_test (
input logic clk, d,
output logic q
);

always @(posedge clk) begin
q <= d;
end

always @(posedge c)
begin
// It is also possible to add an delay of less than one clock period
// here.
q <= d;
end

endmodule // dff
endmodule
49 changes: 14 additions & 35 deletions tests/dff.vhdl
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
-- =============================================================================
-- Authors: Martin Zabel
--
-- Module: A simple D-FF
--
-- Description:
-- ------------------------------------
-- A simple D-FF with an initial state of '0'.
--
-- License:
-- =============================================================================
-- Copyright 2016 Technische Universitaet Dresden - Germany
-- Chair for VLSI-Design, Diagnostics and Architecture
--
-- 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.
-- =============================================================================
-- This file is public domain, it can be freely copied without restrictions.
-- SPDX-License-Identifier: CC0-1.0

library ieee;
use ieee.std_logic_1164.all;

entity dff_test_vhdl is
port (
c : in std_logic;
d : in std_logic;
q : out std_logic := '0');
end entity dff_test_vhdl;
port(
clk: in std_logic;
d: in std_logic;
q: out std_logic);
end dff_test_vhdl;

architecture rtl of dff_test_vhdl is
architecture behavioral of dff_test_vhdl is
begin
-- It is also possible to add an delay of less than one clock period here.
q <= d when rising_edge(c);
end architecture rtl;
process (clk) begin
if rising_edge(clk) then
q <= d;
end if;
end process;
end behavioral;
Loading

0 comments on commit 86fbcfe

Please sign in to comment.