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
commitf208e63ce553c6144a672cd35da23425fa7f86d1 (patch)
tree0574ee516499001244d33785a5fc380801c557c9 /tests/utils.cc
parente24e3cd4d296599b9ef1b705846b1c868148b0fd (diff)
parentd534555fbb9562a819d34ea874a711d737d051ae (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