summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/CMakeLists.txt2
-rw-r--r--src/tests/common/fibers.cpp4
-rw-r--r--src/tests/common/ring_buffer.cpp30
-rw-r--r--src/tests/core/arm/arm_test_common.cpp145
-rw-r--r--src/tests/core/arm/arm_test_common.h93
5 files changed, 17 insertions, 257 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 */
213TEST_CASE("Fibers::InterExchange", "[common]") { 213TEST_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 */
305TEST_CASE("Fibers::StartRace", "[common]") { 305TEST_CASE("Fibers::StartRace", "[common]") {
diff --git a/src/tests/common/ring_buffer.cpp b/src/tests/common/ring_buffer.cpp
index c883c4d56..54def22da 100644
--- a/src/tests/common/ring_buffer.cpp
+++ b/src/tests/common/ring_buffer.cpp
@@ -20,60 +20,60 @@ TEST_CASE("RingBuffer: Basic Tests", "[common]") {
20 for (std::size_t i = 0; i < 4; i++) { 20 for (std::size_t i = 0; i < 4; i++) {
21 const char elem = static_cast<char>(i); 21 const char elem = static_cast<char>(i);
22 const std::size_t count = buf.Push(&elem, 1); 22 const std::size_t count = buf.Push(&elem, 1);
23 REQUIRE(count == 1); 23 REQUIRE(count == 1U);
24 } 24 }
25 25
26 REQUIRE(buf.Size() == 4); 26 REQUIRE(buf.Size() == 4U);
27 27
28 // Pushing values into a full ring buffer should fail. 28 // Pushing values into a full ring buffer should fail.
29 { 29 {
30 const char elem = static_cast<char>(42); 30 const char elem = static_cast<char>(42);
31 const std::size_t count = buf.Push(&elem, 1); 31 const std::size_t count = buf.Push(&elem, 1);
32 REQUIRE(count == 0); 32 REQUIRE(count == 0U);
33 } 33 }
34 34
35 REQUIRE(buf.Size() == 4); 35 REQUIRE(buf.Size() == 4U);
36 36
37 // Popping multiple values from a ring buffer with values should succeed. 37 // Popping multiple values from a ring buffer with values should succeed.
38 { 38 {
39 const std::vector<char> popped = buf.Pop(2); 39 const std::vector<char> popped = buf.Pop(2);
40 REQUIRE(popped.size() == 2); 40 REQUIRE(popped.size() == 2U);
41 REQUIRE(popped[0] == 0); 41 REQUIRE(popped[0] == 0);
42 REQUIRE(popped[1] == 1); 42 REQUIRE(popped[1] == 1);
43 } 43 }
44 44
45 REQUIRE(buf.Size() == 2); 45 REQUIRE(buf.Size() == 2U);
46 46
47 // Popping a single value from a ring buffer with values should succeed. 47 // Popping a single value from a ring buffer with values should succeed.
48 { 48 {
49 const std::vector<char> popped = buf.Pop(1); 49 const std::vector<char> popped = buf.Pop(1);
50 REQUIRE(popped.size() == 1); 50 REQUIRE(popped.size() == 1U);
51 REQUIRE(popped[0] == 2); 51 REQUIRE(popped[0] == 2);
52 } 52 }
53 53
54 REQUIRE(buf.Size() == 1); 54 REQUIRE(buf.Size() == 1U);
55 55
56 // Pushing more values than space available should partially suceed. 56 // Pushing more values than space available should partially suceed.
57 { 57 {
58 std::vector<char> to_push(6); 58 std::vector<char> to_push(6);
59 std::iota(to_push.begin(), to_push.end(), 88); 59 std::iota(to_push.begin(), to_push.end(), 88);
60 const std::size_t count = buf.Push(to_push); 60 const std::size_t count = buf.Push(to_push);
61 REQUIRE(count == 3); 61 REQUIRE(count == 3U);
62 } 62 }
63 63
64 REQUIRE(buf.Size() == 4); 64 REQUIRE(buf.Size() == 4U);
65 65
66 // Doing an unlimited pop should pop all values. 66 // Doing an unlimited pop should pop all values.
67 { 67 {
68 const std::vector<char> popped = buf.Pop(); 68 const std::vector<char> popped = buf.Pop();
69 REQUIRE(popped.size() == 4); 69 REQUIRE(popped.size() == 4U);
70 REQUIRE(popped[0] == 3); 70 REQUIRE(popped[0] == 3);
71 REQUIRE(popped[1] == 88); 71 REQUIRE(popped[1] == 88);
72 REQUIRE(popped[2] == 89); 72 REQUIRE(popped[2] == 89);
73 REQUIRE(popped[3] == 90); 73 REQUIRE(popped[3] == 90);
74 } 74 }
75 75
76 REQUIRE(buf.Size() == 0); 76 REQUIRE(buf.Size() == 0U);
77} 77}
78 78
79TEST_CASE("RingBuffer: Threaded Test", "[common]") { 79TEST_CASE("RingBuffer: Threaded Test", "[common]") {
@@ -93,7 +93,7 @@ TEST_CASE("RingBuffer: Threaded Test", "[common]") {
93 std::size_t i = 0; 93 std::size_t i = 0;
94 while (i < count) { 94 while (i < count) {
95 if (const std::size_t c = buf.Push(&value[0], 1); c > 0) { 95 if (const std::size_t c = buf.Push(&value[0], 1); c > 0) {
96 REQUIRE(c == 1); 96 REQUIRE(c == 1U);
97 i++; 97 i++;
98 next_value(value); 98 next_value(value);
99 } else { 99 } else {
@@ -108,7 +108,7 @@ TEST_CASE("RingBuffer: Threaded Test", "[common]") {
108 std::size_t i = 0; 108 std::size_t i = 0;
109 while (i < count) { 109 while (i < count) {
110 if (const std::vector<char> v = buf.Pop(1); v.size() > 0) { 110 if (const std::vector<char> v = buf.Pop(1); v.size() > 0) {
111 REQUIRE(v.size() == 2); 111 REQUIRE(v.size() == 2U);
112 REQUIRE(v[0] == value[0]); 112 REQUIRE(v[0] == value[0]);
113 REQUIRE(v[1] == value[1]); 113 REQUIRE(v[1] == value[1]);
114 i++; 114 i++;
@@ -123,7 +123,7 @@ TEST_CASE("RingBuffer: Threaded Test", "[common]") {
123 producer.join(); 123 producer.join();
124 consumer.join(); 124 consumer.join();
125 125
126 REQUIRE(buf.Size() == 0); 126 REQUIRE(buf.Size() == 0U);
127 printf("RingBuffer: Threaded Test: full: %zu, empty: %zu\n", full, empty); 127 printf("RingBuffer: Threaded Test: full: %zu, empty: %zu\n", full, empty);
128} 128}
129 129
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
14namespace ArmTests {
15
16TestEnvironment::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
30TestEnvironment::~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
36void 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
41void 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
46void 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
51void TestEnvironment::SetMemory8(VAddr vaddr, u8 value) {
52 test_memory->data[vaddr] = value;
53}
54
55std::vector<WriteRecord> TestEnvironment::GetWriteRecords() const {
56 return write_records;
57}
58
59void TestEnvironment::ClearWriteRecords() {
60 write_records.clear();
61}
62
63TestEnvironment::TestMemory::~TestMemory() {}
64
65std::optional<bool> TestEnvironment::TestMemory::IsValidAddress(VAddr addr) {
66 return true;
67}
68
69std::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
80std::optional<u16> TestEnvironment::TestMemory::Read16(VAddr addr) {
81 return *Read8(addr) | static_cast<u16>(*Read8(addr + 1)) << 8;
82}
83
84std::optional<u32> TestEnvironment::TestMemory::Read32(VAddr addr) {
85 return *Read16(addr) | static_cast<u32>(*Read16(addr + 2)) << 16;
86}
87
88std::optional<u64> TestEnvironment::TestMemory::Read64(VAddr addr) {
89 return *Read32(addr) | static_cast<u64>(*Read32(addr + 4)) << 32;
90}
91
92bool 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
103bool 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
110bool 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
117bool 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
124bool 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
131bool 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
15namespace Common {
16struct PageTable;
17}
18
19namespace ArmTests {
20
21struct 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
31class TestEnvironment final {
32public:
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
59private:
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