summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandy Carter <bwrsandman@gmail.com>2019-07-11 10:26:59 -0400
committerTriang3l <hwguy.siplus@gmail.com>2020-11-22 13:54:00 +0300
commit22ef265057be6428baaafd8d40d7ff35b9125524 (patch)
tree2efe244791650057c3e1f37edd0e5d0884ca6e53
parent962b90f699f2eb195abf566bdbd93a384f3cec36 (diff)
[memory] Add Memory mapping view tests
Add test for mapping and for mapping with access.
-rw-r--r--src/xenia/base/testing/memory_test.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/xenia/base/testing/memory_test.cc b/src/xenia/base/testing/memory_test.cc
index 5433dc118..66a365c8f 100644
--- a/src/xenia/base/testing/memory_test.cc
+++ b/src/xenia/base/testing/memory_test.cc
@@ -10,6 +10,9 @@
#include "xenia/base/memory.h"
#include "third_party/catch/include/catch.hpp"
+#include "third_party/fmt/include/fmt/format.h"
+
+#include "xenia/base/clock.h"
namespace xe {
namespace base {
@@ -414,6 +417,58 @@ TEST_CASE("copy_and_swap_16_in_32_unaligned", "Copy and Swap") {
REQUIRE(true == true);
}
+TEST_CASE("create_and_close_file_mapping", "Virtual Memory Mapping") {
+ auto path = fmt::format("Local\\xenia_test_{}", Clock::QueryHostTickCount());
+ auto memory = xe::memory::CreateFileMappingHandle(
+ path, 0x100, xe::memory::PageAccess::kReadWrite, true);
+ REQUIRE(memory);
+ xe::memory::CloseFileMappingHandle(memory);
+}
+
+TEST_CASE("map_view", "Virtual Memory Mapping") {
+ auto path = fmt::format("Local\\xenia_test_{}", Clock::QueryHostTickCount());
+ const size_t length = 0x100;
+ auto memory = xe::memory::CreateFileMappingHandle(
+ path, length, xe::memory::PageAccess::kReadWrite, true);
+ REQUIRE(memory);
+
+ uintptr_t address = 0x100000000;
+ auto view =
+ xe::memory::MapFileView(memory, reinterpret_cast<void*>(address), length,
+ xe::memory::PageAccess::kReadWrite, 0);
+ REQUIRE(reinterpret_cast<uintptr_t>(view) == address);
+
+ xe::memory::UnmapFileView(memory, reinterpret_cast<void*>(address), length);
+ xe::memory::CloseFileMappingHandle(memory);
+}
+
+TEST_CASE("read_write_view", "Virtual Memory Mapping") {
+ const size_t length = 0x100;
+ auto path = fmt::format("Local\\xenia_test_{}", Clock::QueryHostTickCount());
+ auto memory = xe::memory::CreateFileMappingHandle(
+ path, length, xe::memory::PageAccess::kReadWrite, true);
+ REQUIRE(memory);
+
+ uintptr_t address = 0x100000000;
+ auto view =
+ xe::memory::MapFileView(memory, reinterpret_cast<void*>(address), length,
+ xe::memory::PageAccess::kReadWrite, 0);
+ REQUIRE(reinterpret_cast<uintptr_t>(view) == address);
+
+ for (uint32_t i = 0; i < length; i += sizeof(uint8_t)) {
+ auto p_value = reinterpret_cast<uint8_t*>(address + i);
+ *p_value = i;
+ }
+ for (uint32_t i = 0; i < length; i += sizeof(uint8_t)) {
+ auto p_value = reinterpret_cast<uint8_t*>(address + i);
+ uint8_t value = *p_value;
+ REQUIRE(value == i);
+ }
+
+ xe::memory::UnmapFileView(memory, reinterpret_cast<void*>(address), length);
+ xe::memory::CloseFileMappingHandle(memory);
+}
+
} // namespace test
} // namespace base
} // namespace xe