Skip to content

Commit 9634cdf

Browse files
committed
fix test issue, add more hardware, still need to write testbenches
1 parent 18547cf commit 9634cdf

File tree

14 files changed

+225
-10
lines changed

14 files changed

+225
-10
lines changed

Containerfile

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Setup dependancy versions
2-
ARG DEBIAN_VERSION=12
2+
ARG DEBIAN_VERSION=12-slim
33

44
FROM docker.io/library/debian:${DEBIAN_VERSION}
55

@@ -23,14 +23,7 @@ WORKDIR /usr/src/verilator
2323
RUN git checkout v${VERILATOR_VERSION}
2424
RUN autoconf && ./configure && make -j `nproc` && make install
2525
WORKDIR /usr/src/
26-
27-
# compile and install iverilog
28-
WORKDIR /usr/src/
29-
RUN git clone https://github.com/steveicarus/iverilog.git
30-
WORKDIR /usr/src/iverilog/
31-
RUN sh autoconf.sh && ./configure --prefix /usr && make && make install
32-
33-
WORKDIR /usr/src/
26+
3427
# setup python virtual environment
3528
ENV VIRTUAL_ENV=.venv
3629
RUN python3 -m venv ${VIRTUAL_ENV}

problems/getting-started/getting-started/tb/test_constant_one.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from cocotb.regression import TestFactory
66
from cocotb_test.simulator import run
77

8-
from top_module import TB
8+
from constant_one import TB
99

1010

1111
async def output_stays_one(dut):
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module constant_zero (
6+
output wire zero
7+
);
8+
9+
assign zero = 0;
10+
11+
endmodule
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import logging
2+
3+
4+
class DataError(Exception):
5+
pass
6+
7+
8+
class TB:
9+
def __init__(self, dut):
10+
self.dut = dut
11+
12+
# Start logging
13+
self.log = logging.getLogger("cocotb.tb")
14+
self.log.setLevel(logging.DEBUG)
15+
16+
# Simulation Signals
17+
self.get_signals()
18+
19+
def get_signals(self):
20+
self.zero = self.dut.zero
21+
22+
async def zero_check(self):
23+
if int(self.zero.value) != 0:
24+
raise DataError(f"Output should always be 0, got {self.zero.value} instead.")
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import pytest
3+
import cocotb
4+
from cocotb.clock import Timer
5+
from cocotb.regression import TestFactory
6+
from cocotb_test.simulator import run
7+
8+
from constant_zero import TB
9+
10+
11+
async def output_stays_zero(dut):
12+
tb = TB(dut)
13+
14+
tb.log.info("Checking output value...")
15+
# Await one nanosecond so the model can start.
16+
await Timer(1, units="ns")
17+
tb.zero_check()
18+
19+
20+
if cocotb.SIM_NAME:
21+
test1 = TestFactory(output_stays_zero)
22+
test1.generate_tests()
23+
24+
# cocotb-test
25+
26+
tests_dir = os.path.abspath(os.path.dirname(__file__))
27+
rtl_dir = os.path.abspath(os.path.join(tests_dir, "..", "rtl"))
28+
29+
parameter_list = [{}]
30+
31+
32+
@pytest.mark.parametrize("parameters", parameter_list)
33+
def test_constant_zero(request, parameters):
34+
dut = "constant_zero"
35+
module = os.path.splitext(os.path.basename(__file__))[0]
36+
toplevel = dut
37+
38+
verilog_sources = [
39+
os.path.join(rtl_dir, f"{dut}.v"),
40+
]
41+
42+
extra_env = {f"PARAM_{k}": str(v) for k, v in parameters.items()}
43+
44+
sim_build = os.path.join(
45+
tests_dir, "sim_build", request.node.name.replace("[", "-").replace("]", "")
46+
)
47+
48+
run(
49+
python_search=[tests_dir],
50+
verilog_sources=verilog_sources,
51+
toplevel=toplevel,
52+
module=module,
53+
parameters=parameters,
54+
sim_build=sim_build,
55+
extra_env=extra_env,
56+
compile_args=["--timing", "-O3"],
57+
waves=True,
58+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module 7458 (
6+
input wire p1a,
7+
input wire p1b,
8+
input wire p1c,
9+
input wire p1d,
10+
input wire p1e,
11+
input wire p1f,
12+
output wire p1y,
13+
14+
input wire p2a,
15+
input wire p2b,
16+
input wire p2c,
17+
input wire p2d,
18+
output wire p2y
19+
);
20+
21+
assign p1y = (p1a && p1b && p1c) || (p1d && p1e && p1f);
22+
assign p2y = (p2a && p2b) || (p2c && p2d);
23+
24+
endmodule
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module and_gate (
6+
input wire a,
7+
input wire b,
8+
output wire out
9+
);
10+
11+
assign out = a && b;
12+
13+
endmodule
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module declaring_wires (
6+
input wire a,
7+
input wire b,
8+
input wire c,
9+
input wire d,
10+
output wire out,
11+
output wire out_n
12+
);
13+
14+
wire ab;
15+
wire cd;
16+
17+
assign ab = a && b;
18+
assign cd = c && d;
19+
20+
assign out = ab || cd;
21+
assign out_n = !out;
22+
23+
endmodule
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module not_gate (
6+
input wire in,
7+
output wire out
8+
);
9+
10+
assign out = !in;
11+
12+
endmodule
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module multi_wire (
6+
input wire a,
7+
input wire b,
8+
input wire c,
9+
10+
output wire w,
11+
output wire x,
12+
output wire y,
13+
output wire z
14+
);
15+
16+
assign {w, x, y, z} = {a, b, b, c};
17+
18+
endmodule

0 commit comments

Comments
 (0)