summaryrefslogtreecommitdiff
path: root/tests/c11.h
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-12 01:36:59 -0400
committerbd <bdunahu@operationnull.com>2025-04-12 01:36:59 -0400
commitb91eb002d4e6b2dc0c51b03df57c5089659ac669 (patch)
tree3ad405efc96f439a9e7af2bcac53c808a4667ef0 /tests/c11.h
parent28a2788e2c59357d9269e558b0bd45db3241c42d (diff)
Add C11 test class header as base cache fixture class
Diffstat (limited to 'tests/c11.h')
-rw-r--r--tests/c11.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/c11.h b/tests/c11.h
new file mode 100644
index 0000000..eb59cc0
--- /dev/null
+++ b/tests/c11.h
@@ -0,0 +1,47 @@
+#include "cache.h"
+#include "dram.h"
+#include "storage.h"
+#include <algorithm>
+#include <array>
+#include <catch2/catch_test_macros.hpp>
+#include <functional>
+
+class C11
+{
+ public:
+ C11() : m_delay(4), c_delay(2), mem(new int), fetch(new int)
+ {
+ this->c = new Cache(new Dram(this->m_delay), this->c_delay);
+ this->expected = {0, 0, 0, 0};
+ this->actual = this->c->view(0, 1)[0];
+ }
+
+ ~C11()
+ {
+ delete this->c;
+ delete this->mem;
+ delete this->fetch;
+ }
+
+ void
+ wait_then_do(int delay, std::function<int()> f)
+ {
+ for (int i = 0; i < delay; ++i) {
+ int r = f();
+
+ // check response
+ CHECK(!r);
+ // check for early modifications
+ actual = c->view(0, 1)[0];
+ REQUIRE(this->expected == this->actual);
+ }
+ }
+
+ int m_delay;
+ int c_delay;
+ Cache *c;
+ int *mem;
+ int *fetch;
+ std::array<signed int, LINE_SIZE> expected;
+ std::array<signed int, LINE_SIZE> actual;
+};