// the "macro" to dump signals
`ifdef COCOTB_SIM
initial begin
$dumpfile ("multiplier.vcd");
$dumpvars (0, multiplier);
#1;
end
`endif
# test_multiplier.py
# 2022/09/13 by marsee
import random
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import Timer, RisingEdge
@cocotb.test()
async def test_multiplier(dut):
dut.ap_rst = 1 # Reset
clock = Clock(dut.ap_clk, 10, units="ns") # Create a 10ns period clock on port clk
cocotb.start_soon(clock.start()) # Start the clock
await Timer(10, units='ns')
dut.ap_start = 1
dut.ap_rst = 0 # Normal Operation
for i in range(5):
dut.a.value = i
dut.b.value = i+1
for j in range(3):
await RisingEdge(dut.ap_clk)
await Timer(1, units='ns')
assert dut.c.value == i*(i+1), "Invalid value for multiplication {}".format(i*(i+1))
await Timer(9, units='ns')
# Makefile
# 2022/09/13 by marsee
SIM ?= icarus
VERILOG_SOURCES = $(shell pwd)/multiplier.v
VERILOG_SOURCES += $(shell pwd)/multiplier_mul_mul_16s_16s_32_4_1.v
TOPLEVEL = multiplier
MODULE = test_multiplier
include $(shell cocotb-config --makefiles)/Makefile.sim
(base) masaaki@masaaki-H110M4-M01:/media/masaaki/Ubuntu_Disk/Cocotb/multiplier$ make
rm -f results.xml
make -f Makefile results.xml
make[1]: ディレクトリ '/media/masaaki/Ubuntu_Disk/Cocotb/multiplier' に入ります
rm -f results.xml
MODULE=test_multiplier TESTCASE= TOPLEVEL=multiplier TOPLEVEL_LANG=verilog \
/usr/bin/vvp -M /home/masaaki/anaconda3/lib/python3.8/site-packages/cocotb/libs -m libcocotbvpi_icarus sim_build/sim.vvp
-.--ns INFO gpi ..mbed/gpi_embed.cpp:76 in set_program_name_in_venv Did not detect Python virtual environment. Using system-wide Python interpreter
-.--ns INFO gpi ../gpi/GpiCommon.cpp:101 in gpi_print_registered_impl VPI registered
0.00ns INFO cocotb Running on Icarus Verilog version 10.1 (stable)
0.00ns INFO cocotb Running tests with cocotb v1.7.0 from /home/masaaki/anaconda3/lib/python3.8/site-packages/cocotb
0.00ns INFO cocotb Seeding Python random module with 1663099051
0.00ns INFO cocotb.regression Found test test_multiplier.test_multiplier
0.00ns INFO cocotb.regression running test_multiplier (1/1)
/media/masaaki/Ubuntu_Disk/Cocotb/multiplier/test_multiplier.py:11: DeprecationWarning: Setting values on handles using the ``dut.handle = value`` syntax is deprecated. Instead use the ``handle.value = value`` syntax
dut.ap_rst = 1 # Reset
VCD info: dumpfile multiplier.vcd opened for output.
/media/masaaki/Ubuntu_Disk/Cocotb/multiplier/test_multiplier.py:19: DeprecationWarning: Setting values on handles using the ``dut.handle = value`` syntax is deprecated. Instead use the ``handle.value = value`` syntax
dut.ap_start = 1
/media/masaaki/Ubuntu_Disk/Cocotb/multiplier/test_multiplier.py:20: DeprecationWarning: Setting values on handles using the ``dut.handle = value`` syntax is deprecated. Instead use the ``handle.value = value`` syntax
dut.ap_rst = 0 # Normal Operation
160.00ns INFO cocotb.regression test_multiplier passed
160.00ns INFO cocotb.regression *****************************************************************************************
** TEST STATUS SIM TIME (ns) REAL TIME (s) RATIO (ns/s) **
*****************************************************************************************
** test_multiplier.test_multiplier PASS 160.00 0.00 40576.39 **
*****************************************************************************************
** TESTS=1 PASS=1 FAIL=0 SKIP=0 160.00 0.21 754.96 **
*****************************************************************************************
make[1]: ディレクトリ '/media/masaaki/Ubuntu_Disk/Cocotb/multiplier' から出ます
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | - |