From 8c46ba4f216aec9f512cd398317f891be9b07e84 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 30 Mar 2025 14:28:45 -0400 Subject: Add mock stage, proper decode tests --- tests/id.cc | 149 +++++++++++++++++++++++++++++++++++++----------------------- tests/if.cc | 6 +-- 2 files changed, 95 insertions(+), 60 deletions(-) (limited to 'tests') diff --git a/tests/id.cc b/tests/id.cc index 65cc16a..6d6a155 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -2,7 +2,7 @@ #include "cache.h" #include "controller.h" #include "dram.h" -#include "if.h" +#include "dum.h" #include "instr.h" #include "instrDTO.h" #include @@ -14,8 +14,8 @@ class IDFixture { this->dr = new Dram(3); this->c = new Cache(this->dr, 1); - IF *f = new IF(nullptr); - this->d = new ID(f); + this->dum = new DUM(nullptr); + this->d = new ID(dum); this->ct = new Controller(this->d, this->c, true); }; ~IDFixture() @@ -23,6 +23,12 @@ class IDFixture delete this->ct; delete this->c; }; + void prime_bits(signed int raw) + { + InstrDTO *i = new InstrDTO(); + i->set_instr_bits(raw); + this->dum->set_curr_instr(i); + } signed int encode_R_type( signed int s3, signed int s2, @@ -63,10 +69,11 @@ class IDFixture t = (t << TYPE_SIZE) + type; return t; } - + Dram *dr; Cache *c; ID *d; + DUM *dum; Controller *ct; }; @@ -82,88 +89,116 @@ TEST_CASE_METHOD(IDFixture, "Parse invalid type", "[id]") TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # one", "[id]") { - signed int s1 = -1, s2 = -1, s3 = -1; - Mnemonic m; + signed int t; + InstrDTO *i; - s1 = this->encode_R_type(0b0, 0b1, 0b10, 0b11, 0b0); - this->d->get_instr_fields(s1, s2, s3, m); + t = this->encode_R_type(0b0, 0b1, 0b10, 0b11, 0b0); + this->prime_bits(t); - CHECK(s1 == 0x00000000); // registers are empty - CHECK(s2 == 0x00000000); - CHECK(s3 == 0x00000000); - CHECK(m == MUL); + i = this->ct->advance(OK); + REQUIRE(i == nullptr); + i = this->ct->advance(OK); + REQUIRE(i != nullptr); + + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0x00000000); + CHECK(i->get_s3() == 0x00000000); + CHECK(i->get_mnemonic() == MUL); + + delete i; } TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # two", "[id]") { - signed int s1 = -1, s2 = -1, s3 = -1; - Mnemonic m; + signed int t; + InstrDTO *i; - s1 = this->encode_R_type(0b10000, 0b01000, 0b00100, 0b10, 0b0); - this->d->get_instr_fields(s1, s2, s3, m); + t = this->encode_R_type(0b10000, 0b01000, 0b00100, 0b10, 0b0); + this->prime_bits(t); + + i = this->ct->advance(OK); + REQUIRE(i == nullptr); + i = this->ct->advance(OK); + REQUIRE(i != nullptr); - CHECK(s1 == 0x00000000); // registers are empty - CHECK(s2 == 0b00000000); - CHECK(s3 == 0b00000000); - CHECK(m == SUB); + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0x00000000); + CHECK(i->get_s3() == 0x00000000); + CHECK(i->get_mnemonic() == SUB); } TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]") { - signed int s1 = -1, s2 = -1, s3 = -1; - Mnemonic m; + signed int t; + InstrDTO *i; - s1 = this->encode_I_type(0xF, 0b1, 0b10, 0b0111, 0b1); - this->d->get_instr_fields(s1, s2, s3, m); + t = this->encode_I_type(0xF, 0b1, 0b10, 0b0111, 0b1); + this->prime_bits(t); + + i = this->ct->advance(OK); + REQUIRE(i == nullptr); + i = this->ct->advance(OK); + REQUIRE(i != nullptr); - CHECK(s1 == 0x00000000); // registers are empty - CHECK(s2 == 0x00000000); - CHECK(s3 == 0xF); - CHECK(m == SFTLI); + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0x00000000); + CHECK(i->get_s3() == 0xF); + CHECK(i->get_mnemonic() == SFTLI); } TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]") { - signed int s1 = -1, s2 = -1, s3 = -1; - Mnemonic m; + signed int t; + InstrDTO *i; - s1 = this->encode_I_type(0xCC, 0b010, 0b101, 0b1011, 0b1); - this->d->get_instr_fields(s1, s2, s3, m); + t = this->encode_I_type(0xCC, 0b010, 0b101, 0b1011, 0b1); + this->prime_bits(t); - CHECK(s1 == 0x00000000); // registers are empty - CHECK(s2 == 0x00000000); - CHECK(s3 == 0xCC); - CHECK(m == STORE); + i = this->ct->advance(OK); + REQUIRE(i == nullptr); + i = this->ct->advance(OK); + REQUIRE(i != nullptr); + + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0x00000000); + CHECK(i->get_s3() == 0xCC); + CHECK(i->get_mnemonic() == STORE); } TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]") { - signed int s1 = -1, s2 = -1, s3 = -1; - Mnemonic m; + signed int t; + InstrDTO *i; - s1 = this->encode_J_type(0x3456, 0b10101, 0b0111, 0b10); - this->d->get_instr_fields(s1, s2, s3, m); + t = this->encode_J_type(0x3456, 0b10101, 0b0111, 0b10); + this->prime_bits(t); + + i = this->ct->advance(OK); + REQUIRE(i == nullptr); + i = this->ct->advance(OK); + REQUIRE(i != nullptr); - CHECK(s1 == 0x00000000); // registers are empty - CHECK(s2 == 0x3456); - CHECK(m == BOF); - // behavior does nothing - CHECK(s3 == -1); + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0x3456); + CHECK(i->get_mnemonic() == BOF); } TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") { - signed int s1 = -1, s2 = -1, s3 = -1; - Mnemonic m; + signed int t; + InstrDTO *i; - s1 = this->encode_J_type(0xBBCCF, 0b10101, 0b0011, 0b10); - this->d->get_instr_fields(s1, s2, s3, m); + t = this->encode_J_type(0xBBCCF, 0b10101, 0b0011, 0b10); + this->prime_bits(t); + + i = this->ct->advance(OK); + REQUIRE(i == nullptr); + i = this->ct->advance(OK); + REQUIRE(i != nullptr); - CHECK(s1 == 0x00000000); // registers are empty - CHECK(s2 == 0xBBCCF); - CHECK(m == JAL); - // behavior does nothing - CHECK(s3 == -1); + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0xBBCCF); + CHECK(i->get_mnemonic() == JAL); } TEST_CASE_METHOD(IDFixture, "read does not conflict with read", "[id]") @@ -221,7 +256,7 @@ TEST_CASE_METHOD(IDFixture, "read does conflict with write", "[id]") v = 0b1; r = this->d->read_guard(v); CHECK(v == 0b01); - REQUIRE(r == BLOCKED); + REQUIRE(r == STALLED); } TEST_CASE_METHOD(IDFixture, "stores indefinite conflicts", "[id]") @@ -242,10 +277,10 @@ TEST_CASE_METHOD(IDFixture, "stores indefinite conflicts", "[id]") v = 0b110; r = this->d->read_guard(v); CHECK(v == 0b110); - REQUIRE(r == BLOCKED); + REQUIRE(r == STALLED); v = 0b0; r = this->d->read_guard(v); CHECK(v == 0b0); - REQUIRE(r == BLOCKED); + REQUIRE(r == STALLED); } diff --git a/tests/if.cc b/tests/if.cc index 185a52a..1f02cb0 100644 --- a/tests/if.cc +++ b/tests/if.cc @@ -113,17 +113,17 @@ TEST_CASE_METHOD(IFPipeFixture, "fetch waits with old instruction", expected_cycles = this->m_delay + (this->c_delay * 2) + 1; for (j = 0; j < this->m_delay + 1; ++j) { - i = this->ct->advance(BLOCKED); + i = this->ct->advance(STALLED); // check response CHECK(i == nullptr); } for (j = 0; j < this->c_delay; ++j) { - i = this->ct->advance(BLOCKED); + i = this->ct->advance(STALLED); // check response CHECK(i == nullptr); } for (j = 0; j < expected_cycles - fetch_cycles; ++j) { - i = this->ct->advance(BLOCKED); + i = this->ct->advance(STALLED); // check response CHECK(i != nullptr); } -- cgit v1.2.3 From 36dabe6183af98b2e3f6d0316436dc3affc3d986 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 30 Mar 2025 14:35:27 -0400 Subject: Free everything I allocated :) --- src/sim/dum.cc | 12 +----------- tests/id.cc | 10 ++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/src/sim/dum.cc b/src/sim/dum.cc index f14c89a..dd16660 100644 --- a/src/sim/dum.cc +++ b/src/sim/dum.cc @@ -5,8 +5,6 @@ #include "stage.h" #include "utils.h" -static Logger *global_log = Logger::getInstance(); - DUM::DUM(Stage *stage) : Stage(stage) { this->id = IDLE; } InstrDTO *DUM::advance(Response p) @@ -24,15 +22,7 @@ InstrDTO *DUM::advance(Response p) return r; } -void DUM::advance_helper() -{ - if (this->curr_instr) - global_log->log( - DEBUG, string_format( - "Using bits: %i ", this->curr_instr->get_instr_bits())); - else - global_log->log(DEBUG, "curr_instr is null"); -} +void DUM::advance_helper() {} void DUM::set_curr_instr(InstrDTO *d) { diff --git a/tests/id.cc b/tests/id.cc index 6d6a155..be50ed5 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -125,6 +125,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # two", "[id]") CHECK(i->get_s2() == 0x00000000); CHECK(i->get_s3() == 0x00000000); CHECK(i->get_mnemonic() == SUB); + + delete i; } TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]") @@ -144,6 +146,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]") CHECK(i->get_s2() == 0x00000000); CHECK(i->get_s3() == 0xF); CHECK(i->get_mnemonic() == SFTLI); + + delete i; } TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]") @@ -163,6 +167,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]") CHECK(i->get_s2() == 0x00000000); CHECK(i->get_s3() == 0xCC); CHECK(i->get_mnemonic() == STORE); + + delete i; } TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]") @@ -181,6 +187,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]") CHECK(i->get_s1() == 0x00000000); // registers are empty CHECK(i->get_s2() == 0x3456); CHECK(i->get_mnemonic() == BOF); + + delete i; } TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") @@ -199,6 +207,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") CHECK(i->get_s1() == 0x00000000); // registers are empty CHECK(i->get_s2() == 0xBBCCF); CHECK(i->get_mnemonic() == JAL); + + delete i; } TEST_CASE_METHOD(IDFixture, "read does not conflict with read", "[id]") -- cgit v1.2.3