-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Nolte
committed
Jan 29, 2024
1 parent
d6c1a2e
commit 3357fa1
Showing
4 changed files
with
78 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright cocotb contributors | ||
# Licensed under the Revised BSD License, see LICENSE for details. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
||
TOPLEVEL_LANG ?= verilog | ||
|
||
ifneq ($(TOPLEVEL_LANG),verilog) | ||
|
||
all: | ||
@echo "Skipping test due to TOPLEVEL_LANG=$(TOPLEVEL_LANG) not being verilog" | ||
clean:: | ||
|
||
else | ||
|
||
include ../../designs/sample_module/Makefile | ||
MODULE:=test_struct | ||
|
||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright cocotb contributors | ||
# Licensed under the Revised BSD License, see LICENSE for details. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
import cocotb | ||
from cocotb.triggers import Timer | ||
|
||
|
||
@cocotb.test( | ||
expect_error=AttributeError | ||
if cocotb.SIM_NAME.lower().startswith(("icarus", "ghdl", "riviera", "nvc")) | ||
else (), | ||
expect_fail=cocotb.LANGUAGE == "vhdl" | ||
or cocotb.SIM_NAME.lower().startswith("modelsim"), | ||
) | ||
async def test_struct_direct(dut): | ||
"""Test getting and setting setting the value of an entire struct""" | ||
# TODO: do this through handle.py | ||
if cocotb.SIM_NAME.lower().startswith("verilator"): | ||
print(dut.inout_if) # LogicObject(sample_module.inout_if) | ||
# print(dut.inout_if.a_in) # Doesn't exist | ||
# print(dut.inout_if.b_out) # Doesn't exist | ||
|
||
print("binstr: ", dut.inout_if._handle.get_signal_val_binstr()) # 00 | ||
assert dut.inout_if._handle.get_signal_val_binstr() == "00" | ||
else: | ||
print(dut.inout_if) # HierarchyObject(sample_module.inout_if) | ||
print(dut.inout_if.a_in) # LogicObject(sample_module.inout_if.a_in) | ||
print(dut.inout_if.b_out) # LogicObject(sample_module.inout_if.b_out) | ||
|
||
# seg fault if VpiObjHdl, works on VpiSignalObjHdl | ||
# breakpoint() | ||
print("binstr: ", dut.inout_if._handle.get_signal_val_binstr()) # xx | ||
assert dut.inout_if._handle.get_signal_val_binstr() == "zz" | ||
|
||
# test struct write -> individual signals | ||
logic_obj = cocotb.handle.LogicObject(dut.inout_if._handle, dut.inout_if._path) | ||
logic_obj._set_value(0, cocotb.scheduler._schedule_write) | ||
await Timer(1000, "ns") | ||
print("binstr: ", dut.inout_if._handle.get_signal_val_binstr()) # xx | ||
assert dut.inout_if._handle.get_signal_val_binstr() == "00" | ||
assert dut.inout_if.a_in.value == 0 | ||
assert dut.inout_if.b_out.value == 0 | ||
|
||
# test signal write -> struct value | ||
dut.inout_if.a_in.value = 1 | ||
await Timer(1000, "ns") | ||
print("binstr: ", dut.inout_if._handle.get_signal_val_binstr()) | ||
assert str(logic_obj.value.binstr) == "10" | ||
|
||
dut.inout_if.b_out.value = 1 | ||
await Timer(1000, "ns") | ||
print("binstr: ", dut.inout_if._handle.get_signal_val_binstr()) | ||
assert str(logic_obj.value.binstr) == "11" |