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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#include "id.h"
#include "cache.h"
#include "controller.h"
#include "dram.h"
#include "if.h"
#include "instr.h"
#include "instrDTO.h"
#include <catch2/catch_test_macros.hpp>
class IDFixture
{
public:
IDFixture()
{
Dram *dr;
dr = new Dram(3);
this->c = new Cache(dr, 1);
IF *f = new IF(nullptr);
this->d = new ID(f);
this->ct = new Controller(this->d, this->c, true);
};
~IDFixture()
{
delete this->ct;
delete this->c;
};
signed int encode_R_type(
signed int s3,
signed int s2,
signed int s1,
signed int opcode,
signed int type)
{
signed int t;
t = s3;
t = (t << REG_SIZE) + s2;
t = (t << REG_SIZE) + s1;
t = (t << R_OPCODE_SIZE) + opcode;
t = (t << TYPE_SIZE) + type;
return t;
}
signed int encode_I_type(
signed int s3,
signed int s2,
signed int s1,
signed int opcode,
signed int type)
{
signed int t;
t = s3;
t = (t << REG_SIZE) + s2;
t = (t << REG_SIZE) + s1;
t = (t << OPCODE_SIZE) + opcode;
t = (t << TYPE_SIZE) + type;
return t;
}
signed int encode_J_type(
signed int s2, signed int s1, signed int opcode, signed int type)
{
signed int t;
t = s2;
t = (t << REG_SIZE) + s1;
t = (t << OPCODE_SIZE) + opcode;
t = (t << TYPE_SIZE) + type;
return t;
}
std::vector<signed int> p;
Cache *c;
ID *d;
Controller *ct;
};
TEST_CASE_METHOD(IDFixture, "Parse invalid type", "[id]")
{
signed int s1 = 0, s2 = 0, s3 = 0;
Mnemonic m;
s1 = 0xFFFFFFFF;
this->d->get_instr_fields(s1, s2, s3, m);
CHECK(m == NOP);
}
TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # one", "[id]")
{
signed int s1 = -1, s2 = -1, s3 = -1;
Mnemonic m;
s1 = this->encode_R_type(0b0, 0b1, 0b10, 0b11, 0b0);
this->d->get_instr_fields(s1, s2, s3, m);
CHECK(s1 == 0x00000000); // registers are empty
CHECK(s2 == 0x00000000);
CHECK(s3 == 0x00000000);
CHECK(m == MUL);
}
TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # two", "[id]")
{
signed int s1 = -1, s2 = -1, s3 = -1;
Mnemonic m;
s1 = this->encode_R_type(0b10000, 0b01000, 0b00100, 0b10, 0b0);
this->d->get_instr_fields(s1, s2, s3, m);
CHECK(s1 == 0x00000000); // registers are empty
CHECK(s2 == 0b00000000);
CHECK(s3 == 0b00000000);
CHECK(m == SUB);
}
TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]")
{
signed int s1 = -1, s2 = -1, s3 = -1;
Mnemonic m;
s1 = this->encode_I_type(0xF, 0b1, 0b10, 0b0111, 0b1);
this->d->get_instr_fields(s1, s2, s3, m);
CHECK(s1 == 0x00000000); // registers are empty
CHECK(s2 == 0x00000000);
CHECK(s3 == 0xF);
CHECK(m == SFTLI);
}
TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]")
{
signed int s1 = -1, s2 = -1, s3 = -1;
Mnemonic m;
s1 = this->encode_I_type(0xCC, 0b010, 0b101, 0b1011, 0b1);
this->d->get_instr_fields(s1, s2, s3, m);
CHECK(s1 == 0x00000000); // registers are empty
CHECK(s2 == 0x00000000);
CHECK(s3 == 0xCC);
CHECK(m == STORE);
}
TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]")
{
signed int s1 = -1, s2 = -1, s3 = -1;
Mnemonic m;
s1 = this->encode_J_type(0x3456, 0b10101, 0b0111, 0b10);
this->d->get_instr_fields(s1, s2, s3, m);
CHECK(s1 == 0x00000000); // registers are empty
CHECK(s2 == 0x3456);
CHECK(m == BOF);
// behavior does nothing
CHECK(s3 == -1);
}
TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]")
{
signed int s1 = -1, s2 = -1, s3 = -1;
Mnemonic m;
s1 = this->encode_J_type(0xBBCCF, 0b10101, 0b0011, 0b10);
this->d->get_instr_fields(s1, s2, s3, m);
CHECK(s1 == 0x00000000); // registers are empty
CHECK(s2 == 0xBBCCF);
CHECK(m == JAL);
// behavior does nothing
CHECK(s3 == -1);
}
// TEST_CASE_METHOD(IDFixture, "No data hazards", "[id]") { signed int }
|