diff options
author | bd <bdunahu@operationnull.com> | 2025-03-29 20:18:51 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-29 20:18:51 -0400 |
commit | 24a7d608aa84d6549a52e54726e1379e97cac146 (patch) | |
tree | 1a662d8b461c67fcd90545f841d467e8f69f414f /tests | |
parent | 6bce0485a0f9ce92bc235f063a1f9aab2d59a1c9 (diff) |
Add tests for read/write guards
Diffstat (limited to 'tests')
-rw-r--r-- | tests/id.cc | 85 |
1 files changed, 83 insertions, 2 deletions
diff --git a/tests/id.cc b/tests/id.cc index f500b07..d9c1701 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -65,7 +65,6 @@ class IDFixture t = (t << TYPE_SIZE) + type; return t; } - std::vector<signed int> p; Cache *c; ID *d; Controller *ct; @@ -167,4 +166,86 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") CHECK(s3 == -1); } -// TEST_CASE_METHOD(IDFixture, "No data hazards", "[id]") { signed int } +TEST_CASE_METHOD(IDFixture, "read does not conflict with read", "[id]") +{ + signed int v; + Response r; + + v = 0b1; + r = this->d->read_guard(v); + CHECK(v == 0b0); + REQUIRE(r == OK); + + v = 0b1; + this->d->read_guard(v); + REQUIRE(v == 0b0); +} + +TEST_CASE_METHOD(IDFixture, "write does not conflict with write", "[id]") +{ + signed int v; + + v = 0b1; + this->d->write_guard(v); + REQUIRE(v == 0b0); + + v = 0b1; + this->d->write_guard(v); + REQUIRE(v == 0b0); +} + +TEST_CASE_METHOD(IDFixture, "write does not conflict with read", "[id]") +{ + signed int v; + Response r; + + v = 0b1; + r = this->d->read_guard(v); + CHECK(v == 0b0); + REQUIRE(r == OK); + + v = 0b1; + this->d->write_guard(v); + REQUIRE(v == 0b0); +} + +TEST_CASE_METHOD(IDFixture, "read does conflict with write", "[id]") +{ + signed int v; + Response r; + + v = 0b1; + this->d->write_guard(v); + REQUIRE(v == 0b0); + + v = 0b1; + r = this->d->read_guard(v); + CHECK(v == 0b01); + REQUIRE(r == BLOCKED); +} + +TEST_CASE_METHOD(IDFixture, "stores indefinite conflicts", "[id]") +{ + signed int v, ov; + Response r; + + v = 0b0; + ov = v; + while (v < 0b110) { + this->d->write_guard(v); + REQUIRE(v == 0b0); + v = ++ov; + } + this->d->write_guard(v); + REQUIRE(v == 0b0); + + v = 0b110; + r = this->d->read_guard(v); + CHECK(v == 0b110); + REQUIRE(r == BLOCKED); + + v = 0b0; + r = this->d->read_guard(v); + CHECK(v == 0b0); + REQUIRE(r == BLOCKED); +} |