diff options
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/tests/common/fibers.cpp | 4 | ||||
| -rw-r--r-- | src/tests/core/arm/arm_test_common.cpp | 145 | ||||
| -rw-r--r-- | src/tests/core/arm/arm_test_common.h | 93 |
4 files changed, 2 insertions, 242 deletions
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index d80b0b688..8a606b448 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt | |||
| @@ -4,8 +4,6 @@ add_executable(tests | |||
| 4 | common/fibers.cpp | 4 | common/fibers.cpp |
| 5 | common/param_package.cpp | 5 | common/param_package.cpp |
| 6 | common/ring_buffer.cpp | 6 | common/ring_buffer.cpp |
| 7 | core/arm/arm_test_common.cpp | ||
| 8 | core/arm/arm_test_common.h | ||
| 9 | core/core_timing.cpp | 7 | core/core_timing.cpp |
| 10 | tests.cpp | 8 | tests.cpp |
| 11 | ) | 9 | ) |
diff --git a/src/tests/common/fibers.cpp b/src/tests/common/fibers.cpp index 4757dd2b4..d94492fc6 100644 --- a/src/tests/common/fibers.cpp +++ b/src/tests/common/fibers.cpp | |||
| @@ -207,7 +207,7 @@ static void ThreadStart2_2(u32 id, TestControl2& test_control) { | |||
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | /** This test checks for fiber thread exchange configuration and validates that fibers are | 209 | /** This test checks for fiber thread exchange configuration and validates that fibers are |
| 210 | * that a fiber has been succesfully transfered from one thread to another and that the TLS | 210 | * that a fiber has been successfully transferred from one thread to another and that the TLS |
| 211 | * region of the thread is kept while changing fibers. | 211 | * region of the thread is kept while changing fibers. |
| 212 | */ | 212 | */ |
| 213 | TEST_CASE("Fibers::InterExchange", "[common]") { | 213 | TEST_CASE("Fibers::InterExchange", "[common]") { |
| @@ -299,7 +299,7 @@ static void ThreadStart3(u32 id, TestControl3& test_control) { | |||
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | /** This test checks for one two threads racing for starting the same fiber. | 301 | /** This test checks for one two threads racing for starting the same fiber. |
| 302 | * It checks execution occured in an ordered manner and by no time there were | 302 | * It checks execution occurred in an ordered manner and by no time there were |
| 303 | * two contexts at the same time. | 303 | * two contexts at the same time. |
| 304 | */ | 304 | */ |
| 305 | TEST_CASE("Fibers::StartRace", "[common]") { | 305 | TEST_CASE("Fibers::StartRace", "[common]") { |
diff --git a/src/tests/core/arm/arm_test_common.cpp b/src/tests/core/arm/arm_test_common.cpp deleted file mode 100644 index e54674d11..000000000 --- a/src/tests/core/arm/arm_test_common.cpp +++ /dev/null | |||
| @@ -1,145 +0,0 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | |||
| 7 | #include "common/page_table.h" | ||
| 8 | #include "core/core.h" | ||
| 9 | #include "core/hle/kernel/memory/page_table.h" | ||
| 10 | #include "core/hle/kernel/process.h" | ||
| 11 | #include "core/memory.h" | ||
| 12 | #include "tests/core/arm/arm_test_common.h" | ||
| 13 | |||
| 14 | namespace ArmTests { | ||
| 15 | |||
| 16 | TestEnvironment::TestEnvironment(bool mutable_memory_) | ||
| 17 | : mutable_memory(mutable_memory_), | ||
| 18 | test_memory(std::make_shared<TestMemory>(this)), kernel{Core::System::GetInstance()} { | ||
| 19 | auto& system = Core::System::GetInstance(); | ||
| 20 | |||
| 21 | auto process = Kernel::Process::Create(system, "", Kernel::Process::ProcessType::Userland); | ||
| 22 | page_table = &process->PageTable().PageTableImpl(); | ||
| 23 | |||
| 24 | system.Memory().MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory); | ||
| 25 | system.Memory().MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory); | ||
| 26 | |||
| 27 | kernel.MakeCurrentProcess(process.get()); | ||
| 28 | } | ||
| 29 | |||
| 30 | TestEnvironment::~TestEnvironment() { | ||
| 31 | auto& system = Core::System::GetInstance(); | ||
| 32 | system.Memory().UnmapRegion(*page_table, 0x80000000, 0x80000000); | ||
| 33 | system.Memory().UnmapRegion(*page_table, 0x00000000, 0x80000000); | ||
| 34 | } | ||
| 35 | |||
| 36 | void TestEnvironment::SetMemory64(VAddr vaddr, u64 value) { | ||
| 37 | SetMemory32(vaddr + 0, static_cast<u32>(value)); | ||
| 38 | SetMemory32(vaddr + 4, static_cast<u32>(value >> 32)); | ||
| 39 | } | ||
| 40 | |||
| 41 | void TestEnvironment::SetMemory32(VAddr vaddr, u32 value) { | ||
| 42 | SetMemory16(vaddr + 0, static_cast<u16>(value)); | ||
| 43 | SetMemory16(vaddr + 2, static_cast<u16>(value >> 16)); | ||
| 44 | } | ||
| 45 | |||
| 46 | void TestEnvironment::SetMemory16(VAddr vaddr, u16 value) { | ||
| 47 | SetMemory8(vaddr + 0, static_cast<u8>(value)); | ||
| 48 | SetMemory8(vaddr + 1, static_cast<u8>(value >> 8)); | ||
| 49 | } | ||
| 50 | |||
| 51 | void TestEnvironment::SetMemory8(VAddr vaddr, u8 value) { | ||
| 52 | test_memory->data[vaddr] = value; | ||
| 53 | } | ||
| 54 | |||
| 55 | std::vector<WriteRecord> TestEnvironment::GetWriteRecords() const { | ||
| 56 | return write_records; | ||
| 57 | } | ||
| 58 | |||
| 59 | void TestEnvironment::ClearWriteRecords() { | ||
| 60 | write_records.clear(); | ||
| 61 | } | ||
| 62 | |||
| 63 | TestEnvironment::TestMemory::~TestMemory() {} | ||
| 64 | |||
| 65 | std::optional<bool> TestEnvironment::TestMemory::IsValidAddress(VAddr addr) { | ||
| 66 | return true; | ||
| 67 | } | ||
| 68 | |||
| 69 | std::optional<u8> TestEnvironment::TestMemory::Read8(VAddr addr) { | ||
| 70 | const auto iter = data.find(addr); | ||
| 71 | |||
| 72 | if (iter == data.end()) { | ||
| 73 | // Some arbitrary data | ||
| 74 | return static_cast<u8>(addr); | ||
| 75 | } | ||
| 76 | |||
| 77 | return iter->second; | ||
| 78 | } | ||
| 79 | |||
| 80 | std::optional<u16> TestEnvironment::TestMemory::Read16(VAddr addr) { | ||
| 81 | return *Read8(addr) | static_cast<u16>(*Read8(addr + 1)) << 8; | ||
| 82 | } | ||
| 83 | |||
| 84 | std::optional<u32> TestEnvironment::TestMemory::Read32(VAddr addr) { | ||
| 85 | return *Read16(addr) | static_cast<u32>(*Read16(addr + 2)) << 16; | ||
| 86 | } | ||
| 87 | |||
| 88 | std::optional<u64> TestEnvironment::TestMemory::Read64(VAddr addr) { | ||
| 89 | return *Read32(addr) | static_cast<u64>(*Read32(addr + 4)) << 32; | ||
| 90 | } | ||
| 91 | |||
| 92 | bool TestEnvironment::TestMemory::ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) { | ||
| 93 | VAddr addr = src_addr; | ||
| 94 | u8* data = static_cast<u8*>(dest_buffer); | ||
| 95 | |||
| 96 | for (std::size_t i = 0; i < size; i++, addr++, data++) { | ||
| 97 | *data = *Read8(addr); | ||
| 98 | } | ||
| 99 | |||
| 100 | return true; | ||
| 101 | } | ||
| 102 | |||
| 103 | bool TestEnvironment::TestMemory::Write8(VAddr addr, u8 data) { | ||
| 104 | env->write_records.emplace_back(8, addr, data); | ||
| 105 | if (env->mutable_memory) | ||
| 106 | env->SetMemory8(addr, data); | ||
| 107 | return true; | ||
| 108 | } | ||
| 109 | |||
| 110 | bool TestEnvironment::TestMemory::Write16(VAddr addr, u16 data) { | ||
| 111 | env->write_records.emplace_back(16, addr, data); | ||
| 112 | if (env->mutable_memory) | ||
| 113 | env->SetMemory16(addr, data); | ||
| 114 | return true; | ||
| 115 | } | ||
| 116 | |||
| 117 | bool TestEnvironment::TestMemory::Write32(VAddr addr, u32 data) { | ||
| 118 | env->write_records.emplace_back(32, addr, data); | ||
| 119 | if (env->mutable_memory) | ||
| 120 | env->SetMemory32(addr, data); | ||
| 121 | return true; | ||
| 122 | } | ||
| 123 | |||
| 124 | bool TestEnvironment::TestMemory::Write64(VAddr addr, u64 data) { | ||
| 125 | env->write_records.emplace_back(64, addr, data); | ||
| 126 | if (env->mutable_memory) | ||
| 127 | env->SetMemory64(addr, data); | ||
| 128 | return true; | ||
| 129 | } | ||
| 130 | |||
| 131 | bool TestEnvironment::TestMemory::WriteBlock(VAddr dest_addr, const void* src_buffer, | ||
| 132 | std::size_t size) { | ||
| 133 | VAddr addr = dest_addr; | ||
| 134 | const u8* data = static_cast<const u8*>(src_buffer); | ||
| 135 | |||
| 136 | for (std::size_t i = 0; i < size; i++, addr++, data++) { | ||
| 137 | env->write_records.emplace_back(8, addr, *data); | ||
| 138 | if (env->mutable_memory) | ||
| 139 | env->SetMemory8(addr, *data); | ||
| 140 | } | ||
| 141 | |||
| 142 | return true; | ||
| 143 | } | ||
| 144 | |||
| 145 | } // namespace ArmTests | ||
diff --git a/src/tests/core/arm/arm_test_common.h b/src/tests/core/arm/arm_test_common.h deleted file mode 100644 index d145dbfcc..000000000 --- a/src/tests/core/arm/arm_test_common.h +++ /dev/null | |||
| @@ -1,93 +0,0 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <tuple> | ||
| 8 | #include <unordered_map> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "common/memory_hook.h" | ||
| 13 | #include "core/hle/kernel/kernel.h" | ||
| 14 | |||
| 15 | namespace Common { | ||
| 16 | struct PageTable; | ||
| 17 | } | ||
| 18 | |||
| 19 | namespace ArmTests { | ||
| 20 | |||
| 21 | struct WriteRecord { | ||
| 22 | WriteRecord(std::size_t size, VAddr addr, u64 data) : size(size), addr(addr), data(data) {} | ||
| 23 | std::size_t size; | ||
| 24 | VAddr addr; | ||
| 25 | u64 data; | ||
| 26 | bool operator==(const WriteRecord& o) const { | ||
| 27 | return std::tie(size, addr, data) == std::tie(o.size, o.addr, o.data); | ||
| 28 | } | ||
| 29 | }; | ||
| 30 | |||
| 31 | class TestEnvironment final { | ||
| 32 | public: | ||
| 33 | /* | ||
| 34 | * Inititalise test environment | ||
| 35 | * @param mutable_memory If false, writes to memory can never be read back. | ||
| 36 | * (Memory is immutable.) | ||
| 37 | */ | ||
| 38 | explicit TestEnvironment(bool mutable_memory = false); | ||
| 39 | |||
| 40 | /// Shutdown test environment | ||
| 41 | ~TestEnvironment(); | ||
| 42 | |||
| 43 | /// Sets value at memory location vaddr. | ||
| 44 | void SetMemory8(VAddr vaddr, u8 value); | ||
| 45 | void SetMemory16(VAddr vaddr, u16 value); | ||
| 46 | void SetMemory32(VAddr vaddr, u32 value); | ||
| 47 | void SetMemory64(VAddr vaddr, u64 value); | ||
| 48 | |||
| 49 | /** | ||
| 50 | * Whenever Memory::Write{8,16,32,64} is called within the test environment, | ||
| 51 | * a new write-record is made. | ||
| 52 | * @returns A vector of write records made since they were last cleared. | ||
| 53 | */ | ||
| 54 | std::vector<WriteRecord> GetWriteRecords() const; | ||
| 55 | |||
| 56 | /// Empties the internal write-record store. | ||
| 57 | void ClearWriteRecords(); | ||
| 58 | |||
| 59 | private: | ||
| 60 | friend struct TestMemory; | ||
| 61 | struct TestMemory final : Common::MemoryHook { | ||
| 62 | explicit TestMemory(TestEnvironment* env_) : env(env_) {} | ||
| 63 | TestEnvironment* env; | ||
| 64 | |||
| 65 | ~TestMemory() override; | ||
| 66 | |||
| 67 | std::optional<bool> IsValidAddress(VAddr addr) override; | ||
| 68 | |||
| 69 | std::optional<u8> Read8(VAddr addr) override; | ||
| 70 | std::optional<u16> Read16(VAddr addr) override; | ||
| 71 | std::optional<u32> Read32(VAddr addr) override; | ||
| 72 | std::optional<u64> Read64(VAddr addr) override; | ||
| 73 | |||
| 74 | bool ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) override; | ||
| 75 | |||
| 76 | bool Write8(VAddr addr, u8 data) override; | ||
| 77 | bool Write16(VAddr addr, u16 data) override; | ||
| 78 | bool Write32(VAddr addr, u32 data) override; | ||
| 79 | bool Write64(VAddr addr, u64 data) override; | ||
| 80 | |||
| 81 | bool WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size) override; | ||
| 82 | |||
| 83 | std::unordered_map<VAddr, u8> data; | ||
| 84 | }; | ||
| 85 | |||
| 86 | bool mutable_memory; | ||
| 87 | std::shared_ptr<TestMemory> test_memory; | ||
| 88 | std::vector<WriteRecord> write_records; | ||
| 89 | Common::PageTable* page_table = nullptr; | ||
| 90 | Kernel::KernelCore kernel; | ||
| 91 | }; | ||
| 92 | |||
| 93 | } // namespace ArmTests | ||