diff options
author | bd <bdunahu@operationnull.com> | 2025-03-09 23:49:29 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-09 23:49:29 -0400 |
commit | 2669ab2cfccd9b0b3954e6a68af3de67bd951938 (patch) | |
tree | b5a53b6e85f59392267a8a26e631c00445c30e94 /tests | |
parent | 95d90e454beca2e467613d0c0fbb035b02eada23 (diff) |
Properly set cache metadata when a value is loaded
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cache.cc | 169 |
1 files changed, 127 insertions, 42 deletions
diff --git a/tests/cache.cc b/tests/cache.cc index 9e6521a..64819b6 100644 --- a/tests/cache.cc +++ b/tests/cache.cc @@ -42,45 +42,130 @@ TEST_CASE("no delay stores instantly", "[cache]") 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; -// } +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); // WAIT + + 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(0) = w; + actual = c->view(0, 1)[0]; + REQUIRE(expected == actual); + + delete d; + delete c; +} + +TEST_CASE("dram takes \"forever\"", "[cache]") +{ + int delay = 0; + Dram *d = new Dram(MEM_SIZE, delay + 2); + 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; + + int i; + Response r; + for (i = 0; i < delay + 2; ++i) { + r = c->write(MEM, w, 0x0000000000000); + CHECK(r == BLOCKED); // BLOCKED + + 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(0) = w; + actual = c->view(0, 1)[0]; + REQUIRE(expected == actual); + + delete d; + delete c; +} + +TEST_CASE("dram and cache take \"forever\"", "[cache]") +{ + int delay = 2; + Dram *d = new Dram(MEM_SIZE, delay + 2); + 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; + + int i; + Response r; + for (i = 0; i < delay + 2; ++i) { + r = c->write(MEM, w, 0x0000000000000); + CHECK(r == BLOCKED); // BLOCKED + + actual = c->view(0, 1)[0]; + REQUIRE(expected == actual); + c->resolve(); + d->resolve(); + } + + for (i = 0; i < delay; ++i) { + r = c->write(MEM, w, 0x0000000000000); + CHECK(r == WAIT); // WAIT + + actual = c->view(0, 1)[0]; + REQUIRE(expected == actual); + c->resolve(); + d->resolve(); + } + + r = c->write(MEM, w, 0x0000000000000); + CHECK(r == OK); + c->resolve(); + d->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; +} |