Skip to content

Commit 00f60cf

Browse files
committed
feat: cocotb test for example 2
1 parent 64d2db0 commit 00f60cf

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

.github/workflows/cocotb_unit_test.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ jobs:
2121
- name: Install cocotb
2222
run: pip install cocotb
2323

24-
- name: Run cocotb test
24+
- name: Run cocotb unit test [ex01_and_gate]
2525
run: |
2626
cd ex01_and_gate/test
2727
make
2828
! grep failure results.xml
29+
cd ../..
30+
31+
- name: Run cocotb unit test [ex02_1_bit_full_adder]
32+
run: |
33+
cd ex02_1_bit_full_adder/test
34+
make
35+
! grep failure results.xml
36+
cd ../..
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Simulator
2+
SIM ?= icarus
3+
4+
# Top level language
5+
TOPLEVEL_LANG ?= verilog
6+
7+
# Files
8+
VERILOG_SOURCES = $(shell pwd)/../full_adder.v
9+
10+
# TOPLEVEL is the name of the toplevel module in your Verilog or VHDL file
11+
TOPLEVEL = full_adder
12+
13+
# MODULE is the basename of the Python test file
14+
MODULE = full_adder_test
15+
16+
# include cocotb's make rules to take care of the simulator setup
17+
include $(shell cocotb-config --makefiles)/Makefile.sim
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import cocotb
2+
from cocotb.triggers import Timer
3+
4+
@cocotb.test()
5+
async def full_adder_test(dut):
6+
a = (0, 0, 1, 1, 0, 0, 1, 1)
7+
b = (0, 1, 0, 1, 0, 1, 0, 1)
8+
cin = (0, 0, 0, 0, 1, 1, 1, 1)
9+
10+
s = (0, 1, 1, 0, 1, 0, 0, 1)
11+
cout = (0, 0, 0, 1, 0, 1, 1, 1)
12+
13+
for i in range(8):
14+
dut.a.value = a[i]
15+
dut.b.value = b[i]
16+
dut.cin.value = cin[i]
17+
await Timer(1, units='ns')
18+
assert dut.s.value == s[i] and dut.cout.value == cout[i], f"[Iteration {i}] output is (s,cout) = ({dut.s.value},{dut.cout.value}), expected ({s[i]},{cout[i]})"

0 commit comments

Comments
 (0)