summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tests/CMakeLists.txt5
-rw-r--r--src/tests/core/hle/kernel/hle_ipc.cpp193
2 files changed, 196 insertions, 2 deletions
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 00d7c636a..a14df325a 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -1,8 +1,9 @@
1set(SRCS 1set(SRCS
2 glad.cpp
3 tests.cpp
4 common/param_package.cpp 2 common/param_package.cpp
5 core/file_sys/path_parser.cpp 3 core/file_sys/path_parser.cpp
4 core/hle/kernel/hle_ipc.cpp
5 glad.cpp
6 tests.cpp
6 ) 7 )
7 8
8set(HEADERS 9set(HEADERS
diff --git a/src/tests/core/hle/kernel/hle_ipc.cpp b/src/tests/core/hle/kernel/hle_ipc.cpp
new file mode 100644
index 000000000..e07a28c5b
--- /dev/null
+++ b/src/tests/core/hle/kernel/hle_ipc.cpp
@@ -0,0 +1,193 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <catch.hpp>
6#include "core/hle/ipc.h"
7#include "core/hle/kernel/client_port.h"
8#include "core/hle/kernel/client_session.h"
9#include "core/hle/kernel/event.h"
10#include "core/hle/kernel/handle_table.h"
11#include "core/hle/kernel/hle_ipc.h"
12#include "core/hle/kernel/process.h"
13#include "core/hle/kernel/server_session.h"
14
15namespace Kernel {
16
17static SharedPtr<Object> MakeObject() {
18 return Event::Create(ResetType::OneShot);
19}
20
21TEST_CASE("HLERequestContext::PopoulateFromIncomingCommandBuffer", "[core][kernel]") {
22 auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
23 HLERequestContext context(std::move(session));
24
25 auto process = Process::Create(CodeSet::Create("", 0));
26 HandleTable handle_table;
27
28 SECTION("works with empty cmdbuf") {
29 const u32_le input[]{
30 IPC::MakeHeader(0x1234, 0, 0),
31 };
32
33 context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
34
35 REQUIRE(context.CommandBuffer()[0] == 0x12340000);
36 }
37
38 SECTION("translates regular params") {
39 const u32_le input[]{
40 IPC::MakeHeader(0, 3, 0), 0x12345678, 0x21122112, 0xAABBCCDD,
41 };
42
43 context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
44
45 auto* output = context.CommandBuffer();
46 REQUIRE(output[1] == 0x12345678);
47 REQUIRE(output[2] == 0x21122112);
48 REQUIRE(output[3] == 0xAABBCCDD);
49 }
50
51 SECTION("translates move handles") {
52 auto a = MakeObject();
53 Handle a_handle = handle_table.Create(a).Unwrap();
54 const u32_le input[]{
55 IPC::MakeHeader(0, 0, 2), IPC::MoveHandleDesc(1), a_handle,
56 };
57
58 context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
59
60 auto* output = context.CommandBuffer();
61 REQUIRE(context.GetIncomingHandle(output[2]) == a);
62 REQUIRE(handle_table.GetGeneric(a_handle) == nullptr);
63 }
64
65 SECTION("translates copy handles") {
66 auto a = MakeObject();
67 Handle a_handle = handle_table.Create(a).Unwrap();
68 const u32_le input[]{
69 IPC::MakeHeader(0, 0, 2), IPC::CopyHandleDesc(1), a_handle,
70 };
71
72 context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
73
74 auto* output = context.CommandBuffer();
75 REQUIRE(context.GetIncomingHandle(output[2]) == a);
76 REQUIRE(handle_table.GetGeneric(a_handle) == a);
77 }
78
79 SECTION("translates multi-handle descriptors") {
80 auto a = MakeObject();
81 auto b = MakeObject();
82 auto c = MakeObject();
83 const u32_le input[]{
84 IPC::MakeHeader(0, 0, 5), IPC::MoveHandleDesc(2),
85 handle_table.Create(a).Unwrap(), handle_table.Create(b).Unwrap(),
86 IPC::MoveHandleDesc(1), handle_table.Create(c).Unwrap(),
87 };
88
89 context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
90
91 auto* output = context.CommandBuffer();
92 REQUIRE(context.GetIncomingHandle(output[2]) == a);
93 REQUIRE(context.GetIncomingHandle(output[3]) == b);
94 REQUIRE(context.GetIncomingHandle(output[5]) == c);
95 }
96
97 SECTION("translates CallingPid descriptors") {
98 const u32_le input[]{
99 IPC::MakeHeader(0, 0, 2), IPC::CallingPidDesc(), 0x98989898,
100 };
101
102 context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
103
104 REQUIRE(context.CommandBuffer()[2] == process->process_id);
105 }
106
107 SECTION("translates mixed params") {
108 auto a = MakeObject();
109 const u32_le input[]{
110 IPC::MakeHeader(0, 2, 4),
111 0x12345678,
112 0xABCDEF00,
113 IPC::MoveHandleDesc(1),
114 handle_table.Create(a).Unwrap(),
115 IPC::CallingPidDesc(),
116 0,
117 };
118
119 context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
120
121 auto* output = context.CommandBuffer();
122 REQUIRE(output[1] == 0x12345678);
123 REQUIRE(output[2] == 0xABCDEF00);
124 REQUIRE(context.GetIncomingHandle(output[4]) == a);
125 REQUIRE(output[6] == process->process_id);
126 }
127}
128
129TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
130 auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
131 HLERequestContext context(std::move(session));
132
133 auto process = Process::Create(CodeSet::Create("", 0));
134 HandleTable handle_table;
135 auto* input = context.CommandBuffer();
136 u32_le output[IPC::COMMAND_BUFFER_LENGTH];
137
138 SECTION("works with empty cmdbuf") {
139 input[0] = IPC::MakeHeader(0x1234, 0, 0);
140
141 context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
142
143 REQUIRE(output[0] == 0x12340000);
144 }
145
146 SECTION("translates regular params") {
147 input[0] = IPC::MakeHeader(0, 3, 0);
148 input[1] = 0x12345678;
149 input[2] = 0x21122112;
150 input[3] = 0xAABBCCDD;
151
152 context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
153
154 REQUIRE(output[1] == 0x12345678);
155 REQUIRE(output[2] == 0x21122112);
156 REQUIRE(output[3] == 0xAABBCCDD);
157 }
158
159 SECTION("translates move/copy handles") {
160 auto a = MakeObject();
161 auto b = MakeObject();
162 input[0] = IPC::MakeHeader(0, 0, 4);
163 input[1] = IPC::MoveHandleDesc(1);
164 input[2] = context.AddOutgoingHandle(a);
165 input[3] = IPC::CopyHandleDesc(1);
166 input[4] = context.AddOutgoingHandle(b);
167
168 context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
169
170 REQUIRE(handle_table.GetGeneric(output[2]) == a);
171 REQUIRE(handle_table.GetGeneric(output[4]) == b);
172 }
173
174 SECTION("translates multi-handle descriptors") {
175 auto a = MakeObject();
176 auto b = MakeObject();
177 auto c = MakeObject();
178 input[0] = IPC::MakeHeader(0, 0, 5);
179 input[1] = IPC::MoveHandleDesc(2);
180 input[2] = context.AddOutgoingHandle(a);
181 input[3] = context.AddOutgoingHandle(b);
182 input[4] = IPC::CopyHandleDesc(1);
183 input[5] = context.AddOutgoingHandle(c);
184
185 context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
186
187 REQUIRE(handle_table.GetGeneric(output[2]) == a);
188 REQUIRE(handle_table.GetGeneric(output[3]) == b);
189 REQUIRE(handle_table.GetGeneric(output[5]) == c);
190 }
191}
192
193} // namespace Kernel