diff options
author | bd <bdunahu@operationnull.com> | 2025-03-09 21:39:07 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-09 21:39:07 -0400 |
commit | 95d90e454beca2e467613d0c0fbb035b02eada23 (patch) | |
tree | 3010c9f7270f7dc0374119f2bcd9b5c883f8e1b0 | |
parent | 4676d633edaea37b5661e4f91742b42fcf5b7881 (diff) |
Cache object issues with uninitialized fields, another cache test
-rw-r--r-- | src/storage/cache.cc | 19 | ||||
-rw-r--r-- | tests/cache.cc | 63 | ||||
-rw-r--r-- | tests/dram.cc | 2 |
3 files changed, 64 insertions, 20 deletions
diff --git a/src/storage/cache.cc b/src/storage/cache.cc index f1ae238..52f13b9 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -8,9 +8,12 @@ Cache::Cache(Storage *lower, int delay) { this->data = new std::vector<std::array<signed int, LINE_SIZE>>; this->data->resize(L1_CACHE_SIZE); - this->lower = lower; this->delay = delay; - this->meta.fill({-1}); + this->is_waiting = false; + this->lower = lower; + this->meta.fill({-1, -1}); + this->requester = IDLE; + this->wait_time = this->delay; } Cache::~Cache() { delete this->data; } @@ -25,13 +28,12 @@ Response Cache::write(Accessor accessor, signed int data, int address) if (this->requester == accessor) { fetch_resource(address); - if (this->is_waiting == true) + if (this->is_waiting) r = BLOCKED; else if (this->wait_time == 0) { int tag, index, offset; get_bit_fields(address, &tag, &index, &offset); this->data->at(index).at(offset) = data; - r = OK; } } @@ -48,16 +50,16 @@ Response Cache::read( void Cache::fetch_resource(int expected) { Response r = OK; - int etag, index, eoffset, atag; + int tag, index, offset; std::array<signed int, LINE_SIZE> actual; std::array<int, 2> meta; - get_bit_fields(expected, &etag, &index, &eoffset); + get_bit_fields(expected, &tag, &index, &offset); meta = this->meta.at(index); - if (atag != etag) { + if (this->meta[index][0] != tag) { // address not in cache - if (this->meta[index][0] >= 0) { + if (this->meta[index][1] >= 0) { // occupant is dirty // TODO r = WAIT; @@ -65,6 +67,7 @@ void Cache::fetch_resource(int expected) actual = this->data->at(index); r = this->lower->read(L1CACHE, expected, actual); // clear dirty bit and set tag? + } } diff --git a/tests/cache.cc b/tests/cache.cc index 55592ae..9e6521a 100644 --- a/tests/cache.cc +++ b/tests/cache.cc @@ -12,31 +12,74 @@ TEST_CASE("Constructor singleton cache", "[cache]") delete c; } -// TEST_CASE("no delay stores instantly", "[cache]") +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); +// 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; - -// r = c->write(MEM, w, 0x0000000000000); +// 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(); -// c->resolve(); - -// expected.at(0) = w; -// actual = c->view(0, 1)[0]; -// REQUIRE(expected == actual); // actual = d->view(0, 1)[0]; // // we do NOT write back now! -// REQUIRE(expected != actual); +// REQUIRE(expected == actual); + +// expected.at(1) = w; +// actual = c->view(0, 1)[0]; +// REQUIRE(expected == actual); // delete d; // delete c; diff --git a/tests/dram.cc b/tests/dram.cc index 95ef90a..27fc24f 100644 --- a/tests/dram.cc +++ b/tests/dram.cc @@ -85,8 +85,6 @@ TEST_CASE( CHECK(r == WAIT); actual = d->view(0, 1)[0]; - CHECK(r == WAIT); - REQUIRE(expected == actual); d->resolve(); } |