[memory] Add Memory mapping view tests

Add test for mapping and for mapping with access.
This commit is contained in:
Sandy Carter 2019-07-11 10:26:59 -04:00 committed by Triang3l
parent 962b90f699
commit 22ef265057
1 changed files with 55 additions and 0 deletions

View File

@ -10,6 +10,9 @@
#include "xenia/base/memory.h" #include "xenia/base/memory.h"
#include "third_party/catch/include/catch.hpp" #include "third_party/catch/include/catch.hpp"
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/clock.h"
namespace xe { namespace xe {
namespace base { namespace base {
@ -414,6 +417,58 @@ TEST_CASE("copy_and_swap_16_in_32_unaligned", "Copy and Swap") {
REQUIRE(true == true); 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 test
} // namespace base } // namespace base
} // namespace xe } // namespace xe