summaryrefslogtreecommitdiff
path: root/tests/controller.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/controller.cc')
-rw-r--r--tests/controller.cc47
1 files changed, 43 insertions, 4 deletions
diff --git a/tests/controller.cc b/tests/controller.cc
index e3b9f3c..de49629 100644
--- a/tests/controller.cc
+++ b/tests/controller.cc
@@ -8,21 +8,21 @@
#include "wb.h"
#include <algorithm>
#include <catch2/catch_test_macros.hpp>
+#include <vector>
class ControllerPipeFixture
{
public:
ControllerPipeFixture()
{
- this->c = new Cache(new Dram(3), 1);
+ this->d = new Dram(1);
+ this->c = new Cache(this->d, 0);
IF *f = new IF(nullptr);
ID *d = new ID(f);
EX *e = new EX(d);
- MM *m = new MM(e);
- WB *w = new WB(m);
- this->ct = new Controller(w, this->c, true);
+ this->ct = new Controller(e, this->c, true);
}
~ControllerPipeFixture()
{
@@ -31,6 +31,7 @@ class ControllerPipeFixture
};
Cache *c;
+ Dram *d;
Controller *ct;
};
@@ -49,3 +50,41 @@ TEST_CASE_METHOD(
// change me later
CHECK(this->ct->get_pc() == 0);
}
+
+TEST_CASE_METHOD(ControllerPipeFixture, "Add until exec", "[tmp]")
+{
+ signed int b;
+ std::vector<signed int> p;
+ InstrDTO *i;
+
+ b = 0b1010100000000001001101;
+ p = {b};
+ this->d->load(p);
+
+ // dram
+ i = this->ct->advance(OK);
+ REQUIRE(i == nullptr);
+ // fetch
+ i = this->ct->advance(OK);
+ REQUIRE(i == nullptr);
+ // decode
+ i = this->ct->advance(OK);
+ REQUIRE(i == nullptr);
+ // exec
+ i = this->ct->advance(OK);
+ REQUIRE(i == nullptr);
+ // done
+ i = this->ct->advance(OK);
+ REQUIRE(i != nullptr);
+
+ CHECK(i->get_time_of(FETCH) == 3);
+ CHECK(i->get_time_of(DCDE) == 4);
+ CHECK(i->get_time_of(EXEC) == 5);
+ CHECK(i->get_s1() == 42);
+ CHECK(i->get_s2() == 0);
+ CHECK(i->get_s3() == 42);
+ CHECK(i->get_mnemonic() == ADDI);
+ CHECK(i->get_instr_bits() == b);
+
+ delete i;
+}