diff options
author | bd <bdunahu@operationnull.com> | 2025-03-09 23:57:37 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-09 23:57:37 -0400 |
commit | 937686e73db4623d039ebad70f2654e47561c76d (patch) | |
tree | 37c4eb37d6569db773a2116e0308cb6405126545 /tests | |
parent | 2669ab2cfccd9b0b3954e6a68af3de67bd951938 (diff) |
More cache store tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cache.cc | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/tests/cache.cc b/tests/cache.cc index 64819b6..ee26d68 100644 --- a/tests/cache.cc +++ b/tests/cache.cc @@ -169,3 +169,131 @@ TEST_CASE("dram and cache take \"forever\"", "[cache]") delete d; delete c; } + +TEST_CASE("dram takes \"forever\", two concurrent requests same index", "[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 + + r = c->write(FETCH, w, 0x0000000000001); + 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); + r = c->write(FETCH, w, 0x0000000000001); + CHECK(r == WAIT); + + 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); + + r = c->write(FETCH, w, 0x0000000000001); + // this should have been loaded already! + CHECK(r == OK); + + c->resolve(); + d->resolve(); + + expected.at(1) = w; + actual = c->view(0, 1)[0]; + REQUIRE(expected == actual); + + delete d; + delete c; +} + +TEST_CASE("dram takes \"forever\", two concurrent requests different index", "[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 + + r = c->write(FETCH, w, 0x0000000000100); + 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); + r = c->write(FETCH, w, 0x0000000000001); + CHECK(r == WAIT); + + 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); + + for (i = 0; i < delay + 2; ++i) { + r = c->write(FETCH, w, 0x0000000000100); + CHECK(r == BLOCKED); // WAIT + + actual = c->view(0, 1)[0]; + REQUIRE(expected == actual); + c->resolve(); + d->resolve(); + } + + r = c->write(FETCH, w, 0x0000000000001); + CHECK(r == OK); + + c->resolve(); + d->resolve(); + + expected.at(1) = w; + actual = c->view(0, 1)[0]; + REQUIRE(expected == actual); + + delete d; + delete c; +} + +TEST_CASE("dram takes \"forever\", two concurrent requests different tag", "[cache]") +{ + // TODO +} |