summaryrefslogtreecommitdiff
path: root/tests/utils.cc
diff options
context:
space:
mode:
authorbd <bdunaisky@umass.edu>2025-03-11 21:16:25 +0000
committerGitHub <noreply@github.com>2025-03-11 21:16:25 +0000
commit92e8c2583695a3bf652e0e8dedb79e7a99922f5f (patch)
tree0574ee516499001244d33785a5fc380801c557c9 /tests/utils.cc
parent33c7c78b1c65c375d0291fd435e02ddc9d35681b (diff)
parent5f13f583e373bb02b7bf20cbcc9298dc1480a697 (diff)
Merge pull request #25 from bdunahu/dev-sid
support for read word, write line in all levels of storage, cache load, dirty cache eviction, memory address wrapping
Diffstat (limited to 'tests/utils.cc')
-rw-r--r--tests/utils.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/utils.cc b/tests/utils.cc
index 5368204..f0e4c24 100644
--- a/tests/utils.cc
+++ b/tests/utils.cc
@@ -21,3 +21,45 @@ TEST_CASE("Parse arbitrary fields # two", "[cache]")
CHECK(index == 0b01110);
CHECK(offset == 0b11);
}
+
+TEST_CASE("wrap address outside upper bound", "[utils]")
+{
+ int address = MEM_SIZE + 25;
+ int wrapped = wrap_address(address);
+ REQUIRE(wrapped == 25);
+}
+
+TEST_CASE("wrap address inside upper bound", "[utils]")
+{
+ int address = MEM_SIZE - 25;
+ int wrapped = wrap_address(address);
+ REQUIRE(wrapped == MEM_SIZE - 25);
+}
+
+TEST_CASE("wrap address at upper bound", "[utils]")
+{
+ int address = MEM_SIZE;
+ int wrapped = wrap_address(address);
+ REQUIRE(wrapped == 0);
+}
+
+TEST_CASE("wrap address lower than 0 with magnitude lesser than mem size", "[utils]")
+{
+ int address = -10;
+ int wrapped = wrap_address(address);
+ REQUIRE(wrapped == MEM_SIZE - 10);
+}
+
+TEST_CASE("wrap address lower than 0 but with magnitude greater than mem size", "[utils]")
+{
+ int address = -(MEM_SIZE + 10);
+ int wrapped = wrap_address(address);
+ REQUIRE(wrapped == MEM_SIZE - 10);
+}
+
+TEST_CASE("wrap address at 0", "[utils]")
+{
+ int address = 0;
+ int wrapped = wrap_address(address);
+ REQUIRE(wrapped == 0);
+} \ No newline at end of file