From 7a0181160d36a43634b9c8a0cf22ec4bcd45f7f3 Mon Sep 17 00:00:00 2001 From: dpcarry Date: Wed, 21 Feb 2024 03:33:19 -0500 Subject: [PATCH] feat: incomplete testbench --- dv/ahb/SimpleDecoder/SimpleDecoder_tb.cpp | 34 ++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/dv/ahb/SimpleDecoder/SimpleDecoder_tb.cpp b/dv/ahb/SimpleDecoder/SimpleDecoder_tb.cpp index 0eb2265..3b6990b 100644 --- a/dv/ahb/SimpleDecoder/SimpleDecoder_tb.cpp +++ b/dv/ahb/SimpleDecoder/SimpleDecoder_tb.cpp @@ -1,4 +1,36 @@ #include #include -TEST_CASE("SimpleDecoder, Dummy Test") {} + +TEST_CASE("SimpleDecoder, Basic Functionality") { + VSimpleDecoder_tl* decoder = new VSimpleDecoder_tl; + Verilated::traceEverOn(true); + decoder->clk = 0; + decoder->nReset = 1; + decoder->eval(); + decoder->clk = 1; + decoder->eval(); + decoder->clk = 0; + decoder->eval(); + decoder->nReset = 0; + decoder->eval(); + decoder->clk = 1; + decoder->eval(); + + //test for addresses 1 to 20 + for (int address = 1; address <= 3; ++address) { + int expected_sel = 1 << (address - 1); + + decoder->addr = address; + decoder->eval(); + decoder->clk = 0; //falling edge + decoder->eval(); + decoder->clk = 1; //rising edge + decoder->eval(); + + CAPTURE(address, expected_sel); //capture the values + REQUIRE(decoder->sel == expected_sel); + } + decoder->final(); + delete decoder; +}