From 0d7aa7494f6d9937ceaab5c83b9d604ac42fcf57 Mon Sep 17 00:00:00 2001 From: ShinyMiraidon Date: Tue, 13 Feb 2024 15:50:48 -0500 Subject: [PATCH] test(pipeline_reset.cpp): Updated --- dv/pipeline_reset.cpp | 68 ++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/dv/pipeline_reset.cpp b/dv/pipeline_reset.cpp index 0a778c73..934c19db 100644 --- a/dv/pipeline_reset.cpp +++ b/dv/pipeline_reset.cpp @@ -1,55 +1,51 @@ +#include + #include +#include #include -#include -#include -#include + /* Note: The tests do not currently distinguish between High Z and 0 due to limitations of Verilator. The module could be modified to provide a test output that is 0 when rstn is 0 and 1 when rstn is High Z, -but given the simplicity of this module that doesn't seem warrented at this point. +but given the simplicity of this module that doesn't seem warranted at this point. */ +static void eval(std::uint32_t npc_in, std::uint32_t npc_corr, bool flush) { + auto& pipe {nyu::getDUT()}; + pipe.npc_in = npc_in; + pipe.npc_corr = npc_corr; + pipe.flush = flush; + nyu::eval(pipe); -TEST_CASE("flush == 0") { - VPipeline_Reset model; - - uint32_t npc_in; - uint32_t npc_corr; + INFO("Testing npc_in = " << npc_in << "and npc_corr = " << npc_corr); - for (int i = 0; i < 1000; i++) { - npc_in = rand() % (int) (pow(2, 32)); - npc_corr = rand() % (int) (pow(2, 32)); - - model.flush = 0; - model.npc_in = npc_in; - model.npc_corr = npc_corr; - model.eval(); - - REQUIRE((uint32_t) model.npc == (uint32_t) npc_in); - REQUIRE(model.rstn_out == 0); //Verilator translates High Z outputs to 0 + if(!flush) { + REQUIRE((uint32_t) pipe.npc == (uint32_t) npc_in); + REQUIRE(pipe.rstn_out == 0); //Verilator translates High Z outputs to 0 + } + else { + REQUIRE((uint32_t) pipe.npc == (uint32_t) npc_corr); + REQUIRE(pipe.rstn_out == 0); //Expect actual 0 output here, not High Z } } -TEST_CASE("flush == 1") { - VPipeline_Reset model; - - uint32_t npc_in; - uint32_t npc_corr; - - for (int i = 0; i < 1000; i++) { - npc_in = rand() % (int) (pow(2, 32)); - npc_corr = rand() % (int) (pow(2, 32)); +static void test(bool flush) { + for(std::uint32_t npc_in {0}; npc_in < 512; ++npc_in) + for(std::uint32_t npc_corr {0}; npc_corr < 512; ++npc_corr) + eval(npc_in, npc_corr, flush); - model.flush = 1; - model.npc_in = npc_in; - model.npc_corr = npc_corr; - model.eval(); + for(std::uint32_t npc_in {1}; npc_in; npc_in <<= 1) + for(std::uint32_t npc_corr {1}; npc_corr; npc_corr <<= 1) + eval(npc_in, npc_corr, flush); +} - REQUIRE((uint32_t) model.npc == (uint32_t) npc_corr); - REQUIRE(model.rstn_out == 0); //Expect actual 0 output here, not High Z +TEST_CASE("Pipeline Reset, flush == 0") { + test(0); +} - } +TEST_CASE("Pipeline Reset, flush == 1") { + test(1); }