diff options
author | Siddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com> | 2025-03-30 14:02:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-30 14:02:23 -0400 |
commit | eedf9686eb60f2008e7766cc9a5d3e037b9dae64 (patch) | |
tree | 0cfa9009fe483b72940727f3b5a4236f779fe6e7 /tests | |
parent | d20623d031cf909d8892c2db38cf2e2e02bc6a9b (diff) | |
parent | 8e56373a5436852fe9c7934e03d7b57493625003 (diff) |
Merge pull request #40 from bdunahu/bdunahu
Minor simplification to API between pipeline components
-- Fixed memory leaks
Diffstat (limited to 'tests')
-rw-r--r-- | tests/id.cc | 8 | ||||
-rw-r--r-- | tests/if.cc | 82 |
2 files changed, 48 insertions, 42 deletions
diff --git a/tests/id.cc b/tests/id.cc index d9c1701..65cc16a 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -12,10 +12,8 @@ class IDFixture public: IDFixture() { - Dram *dr; - - dr = new Dram(3); - this->c = new Cache(dr, 1); + this->dr = new Dram(3); + this->c = new Cache(this->dr, 1); IF *f = new IF(nullptr); this->d = new ID(f); this->ct = new Controller(this->d, this->c, true); @@ -65,6 +63,8 @@ class IDFixture t = (t << TYPE_SIZE) + type; return t; } + + Dram *dr; Cache *c; ID *d; Controller *ct; diff --git a/tests/if.cc b/tests/if.cc index bb25afa..185a52a 100644 --- a/tests/if.cc +++ b/tests/if.cc @@ -30,35 +30,36 @@ class IFPipeFixture /** * Fetch a clean line not in cache. */ - void fetch_through(InstrDTO &instr) + InstrDTO *fetch_through() { + InstrDTO *r; int i; - Response r; for (i = 0; i < this->m_delay + 1; ++i) { - r = this->ct->advance(instr, OK); + r = this->ct->advance(OK); // check response - CHECK(r == STALLED); + CHECK(r == nullptr); } - this->fetch_cache(instr); + return this->fetch_cache(); } /** * Fetch a line in cache. */ - void fetch_cache(InstrDTO &instr) + InstrDTO *fetch_cache() { + InstrDTO *r; int i; - Response r; for (i = 0; i < this->c_delay; ++i) { - r = this->ct->advance(instr, OK); + r = this->ct->advance(OK); // check response - CHECK(r == STALLED); + CHECK(r == nullptr); } - r = this->ct->advance(instr, OK); + r = this->ct->advance(OK); // check response - CHECK(r == OK); + CHECK(r != nullptr); + return r; } int m_delay = 3; @@ -71,60 +72,65 @@ class IFPipeFixture TEST_CASE_METHOD(IFPipeFixture, "fetch returns single instuction", "[if_pipe]") { - InstrDTO instr; + InstrDTO *i; int expected_cycles; expected_cycles = this->m_delay + this->c_delay + 2; - this->fetch_through(instr); + i = this->fetch_through(); + CHECK(i->get_time_of(FETCH) == expected_cycles); + REQUIRE(i->get_instr_bits() == this->p[0]); - CHECK(instr.get_time_of(FETCH) == expected_cycles); - REQUIRE(instr.get_instr_bits() == this->p[0]); + delete i; } TEST_CASE_METHOD(IFPipeFixture, "fetch returns two instuctions", "[if_pipe]") { - InstrDTO instr; + InstrDTO *i; int expected_cycles; expected_cycles = this->m_delay + this->c_delay + 2; - this->fetch_through(instr); + i = this->fetch_through(); - CHECK(instr.get_time_of(FETCH) == expected_cycles); - REQUIRE(instr.get_instr_bits() == this->p[0]); + CHECK(i->get_time_of(FETCH) == expected_cycles); + REQUIRE(i->get_instr_bits() == this->p[0]); + delete i; expected_cycles += this->c_delay + 1; - this->fetch_cache(instr); + i = this->fetch_cache(); - CHECK(instr.get_time_of(FETCH) == expected_cycles); - REQUIRE(instr.get_instr_bits() == this->p[1]); + CHECK(i->get_time_of(FETCH) == expected_cycles); + REQUIRE(i->get_instr_bits() == this->p[1]); + delete i; } -TEST_CASE_METHOD(IFPipeFixture, "fetch waits with old instruction", "[if_pipe]") +TEST_CASE_METHOD(IFPipeFixture, "fetch waits with old instruction", +"[if_pipe]") { - Response r; - InstrDTO instr; - int i, expected_cycles, fetch_cycles; + InstrDTO *i; + int j, expected_cycles, fetch_cycles; fetch_cycles = this->m_delay + this->c_delay + 2; expected_cycles = this->m_delay + (this->c_delay * 2) + 1; - for (i = 0; i < this->m_delay + 1; ++i) { - r = this->ct->advance(instr, BLOCKED); + for (j = 0; j < this->m_delay + 1; ++j) { + i = this->ct->advance(BLOCKED); // check response - CHECK(r == STALLED); + CHECK(i == nullptr); } - for (i = 0; i < this->c_delay; ++i) { - r = this->ct->advance(instr, BLOCKED); + for (j = 0; j < this->c_delay; ++j) { + i = this->ct->advance(BLOCKED); // check response - CHECK(r == STALLED); + CHECK(i == nullptr); } - for (i = 0; i < expected_cycles - fetch_cycles; ++i) { - r = this->ct->advance(instr, BLOCKED); + for (j = 0; j < expected_cycles - fetch_cycles; ++j) { + i = this->ct->advance(BLOCKED); // check response - CHECK(r == OK); + CHECK(i != nullptr); } - r = this->ct->advance(instr, OK); - CHECK(instr.get_time_of(FETCH) == expected_cycles); - REQUIRE(instr.get_instr_bits() == this->p[0]); + i = this->ct->advance(OK); + CHECK(i->get_time_of(FETCH) == expected_cycles); + REQUIRE(i->get_instr_bits() == this->p[0]); + + delete i; } |