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
|
#include "cache.h"
#include "definitions.h"
#include "dram.h"
#include <catch2/catch_test_macros.hpp>
TEST_CASE("Constructor singleton cache", "[cache]")
{
Cache *c = new Cache(nullptr, 0);
std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0};
std::array<signed int, LINE_SIZE> actual = c->view(0, 1)[0];
REQUIRE(expected == actual);
delete c;
}
TEST_CASE("no delay stores instantly", "[cache]")
{
int delay = 0;
Dram *d = new Dram(MEM_SIZE, delay);
Cache *c = new Cache(d, delay);
std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0};
std::array<signed int, LINE_SIZE> actual = d->view(0, 1)[0];
CHECK(expected == actual);
signed int w = 0x11223344;
Response r;
r = c->write(MEM, w, 0x0000000000000);
CHECK(r == OK);
d->resolve();
c->resolve();
actual = d->view(0, 1)[0];
// we do NOT write back now!
REQUIRE(expected == actual);
expected.at(0) = w;
actual = c->view(0, 1)[0];
REQUIRE(expected == actual);
delete d;
delete c;
}
// TEST_CASE("cache takes \"forever\"", "[cache]")
// {
// int delay = 0;
// Dram *d = new Dram(MEM_SIZE, delay);
// Cache *c = new Cache(d, delay + 2);
// std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0};
// std::array<signed int, LINE_SIZE> actual = d->view(0, 1)[0];
// CHECK(expected == actual);
// signed int w = 0x11223344;
// int i;
// Response r;
// for (i = 0; i < delay + 2; ++i) {
// r = c->write(MEM, w, 0x0000000000000);
// CHECK(r == WAIT);
// // keep dram busy
// r = d->write(MEM, w, 0x0000000000101);
// CHECK(r == OK);
// actual = c->view(0, 1)[0];
// REQUIRE(expected == actual);
// c->resolve();
// d->resolve();
// }
// r = c->write(MEM, w, 0x0000000000000);
// CHECK(r == OK);
// d->resolve();
// actual = d->view(0, 1)[0];
// // we do NOT write back now!
// REQUIRE(expected == actual);
// expected.at(1) = w;
// actual = c->view(0, 1)[0];
// REQUIRE(expected == actual);
// delete d;
// delete c;
// }
|