blob: f6d9b253449a175220bb70b98de8330f434045e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include "controller.h"
#include "cache.h"
#include "dram.h"
#include "ex.h"
#include "id.h"
#include "if.h"
#include "mm.h"
#include "wb.h"
#include <algorithm>
#include <catch2/catch_test_macros.hpp>
#include <vector>
class ControllerPipeFixture
{
public:
ControllerPipeFixture()
{
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);
this->ct = new Controller(e, this->c, true);
}
~ControllerPipeFixture()
{
delete this->ct;
delete this->c;
};
Cache *c;
Dram *d;
Controller *ct;
};
TEST_CASE_METHOD(
ControllerPipeFixture,
"Contructor resets gettable fields",
"[controller_pipe]")
{
std::array<int, GPR_NUM> gprs;
gprs = this->ct->get_gprs();
CHECK(this->ct->get_clock_cycle() == 1);
CHECK(std::all_of(
gprs.begin(), gprs.end(), [](int value) { return value == 0; }));
// 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(WAIT);
REQUIRE(i == nullptr);
// fetch
i = this->ct->advance(WAIT);
REQUIRE(i == nullptr);
// decode
i = this->ct->advance(WAIT);
REQUIRE(i == nullptr);
// exec
i = this->ct->advance(WAIT);
REQUIRE(i == nullptr);
// done
i = this->ct->advance(WAIT);
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;
}
|