summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-09 21:39:07 -0400
committerbd <bdunahu@operationnull.com>2025-03-09 21:39:07 -0400
commit95d90e454beca2e467613d0c0fbb035b02eada23 (patch)
tree3010c9f7270f7dc0374119f2bcd9b5c883f8e1b0 /tests
parent4676d633edaea37b5661e4f91742b42fcf5b7881 (diff)
Cache object issues with uninitialized fields, another cache test
Diffstat (limited to 'tests')
-rw-r--r--tests/cache.cc63
-rw-r--r--tests/dram.cc2
2 files changed, 53 insertions, 12 deletions
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();
}