summaryrefslogtreecommitdiff
path: root/src/tests/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar bunnei2017-10-14 22:18:42 -0400
committerGravatar bunnei2017-10-14 22:18:42 -0400
commit960a1416de3780e91855d9389c4534acf8c061df (patch)
tree6b373fed639eb39098ba33e6247893919005a2c8 /src/tests/core/hle/kernel
parentnso: Add a log for loading submodules. (diff)
downloadyuzu-960a1416de3780e91855d9389c4534acf8c061df.tar.gz
yuzu-960a1416de3780e91855d9389c4534acf8c061df.tar.xz
yuzu-960a1416de3780e91855d9389c4534acf8c061df.zip
hle: Initial implementation of NX service framework and IPC.
Diffstat (limited to 'src/tests/core/hle/kernel')
-rw-r--r--src/tests/core/hle/kernel/hle_ipc.cpp216
1 files changed, 0 insertions, 216 deletions
diff --git a/src/tests/core/hle/kernel/hle_ipc.cpp b/src/tests/core/hle/kernel/hle_ipc.cpp
deleted file mode 100644
index 4143a3ab8..000000000
--- a/src/tests/core/hle/kernel/hle_ipc.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
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::PopulateFromIncomingCommandBuffer", "[core][kernel]") {
22 auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
23 HLERequestContext context(std::move(session));
24
25 auto process = Process::Create("");
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 null handles") {
98 const u32_le input[]{
99 IPC::MakeHeader(0, 0, 2), IPC::MoveHandleDesc(1), 0,
100 };
101
102 auto result = context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
103
104 REQUIRE(result == RESULT_SUCCESS);
105 auto* output = context.CommandBuffer();
106 REQUIRE(context.GetIncomingHandle(output[2]) == nullptr);
107 }
108
109 SECTION("translates CallingPid descriptors") {
110 const u32_le input[]{
111 IPC::MakeHeader(0, 0, 2), IPC::CallingPidDesc(), 0x98989898,
112 };
113
114 context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
115
116 REQUIRE(context.CommandBuffer()[2] == process->process_id);
117 }
118
119 SECTION("translates mixed params") {
120 auto a = MakeObject();
121 const u32_le input[]{
122 IPC::MakeHeader(0, 2, 4),
123 0x12345678,
124 0xABCDEF00,
125 IPC::MoveHandleDesc(1),
126 handle_table.Create(a).Unwrap(),
127 IPC::CallingPidDesc(),
128 0,
129 };
130
131 context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
132
133 auto* output = context.CommandBuffer();
134 REQUIRE(output[1] == 0x12345678);
135 REQUIRE(output[2] == 0xABCDEF00);
136 REQUIRE(context.GetIncomingHandle(output[4]) == a);
137 REQUIRE(output[6] == process->process_id);
138 }
139}
140
141TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
142 auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
143 HLERequestContext context(std::move(session));
144
145 auto process = Process::Create("");
146 HandleTable handle_table;
147 auto* input = context.CommandBuffer();
148 u32_le output[IPC::COMMAND_BUFFER_LENGTH];
149
150 SECTION("works with empty cmdbuf") {
151 input[0] = IPC::MakeHeader(0x1234, 0, 0);
152
153 context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
154
155 REQUIRE(output[0] == 0x12340000);
156 }
157
158 SECTION("translates regular params") {
159 input[0] = IPC::MakeHeader(0, 3, 0);
160 input[1] = 0x12345678;
161 input[2] = 0x21122112;
162 input[3] = 0xAABBCCDD;
163
164 context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
165
166 REQUIRE(output[1] == 0x12345678);
167 REQUIRE(output[2] == 0x21122112);
168 REQUIRE(output[3] == 0xAABBCCDD);
169 }
170
171 SECTION("translates move/copy handles") {
172 auto a = MakeObject();
173 auto b = MakeObject();
174 input[0] = IPC::MakeHeader(0, 0, 4);
175 input[1] = IPC::MoveHandleDesc(1);
176 input[2] = context.AddOutgoingHandle(a);
177 input[3] = IPC::CopyHandleDesc(1);
178 input[4] = context.AddOutgoingHandle(b);
179
180 context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
181
182 REQUIRE(handle_table.GetGeneric(output[2]) == a);
183 REQUIRE(handle_table.GetGeneric(output[4]) == b);
184 }
185
186 SECTION("translates null handles") {
187 input[0] = IPC::MakeHeader(0, 0, 2);
188 input[1] = IPC::MoveHandleDesc(1);
189 input[2] = context.AddOutgoingHandle(nullptr);
190
191 auto result = context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
192
193 REQUIRE(result == RESULT_SUCCESS);
194 REQUIRE(output[2] == 0);
195 }
196
197 SECTION("translates multi-handle descriptors") {
198 auto a = MakeObject();
199 auto b = MakeObject();
200 auto c = MakeObject();
201 input[0] = IPC::MakeHeader(0, 0, 5);
202 input[1] = IPC::MoveHandleDesc(2);
203 input[2] = context.AddOutgoingHandle(a);
204 input[3] = context.AddOutgoingHandle(b);
205 input[4] = IPC::CopyHandleDesc(1);
206 input[5] = context.AddOutgoingHandle(c);
207
208 context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
209
210 REQUIRE(handle_table.GetGeneric(output[2]) == a);
211 REQUIRE(handle_table.GetGeneric(output[3]) == b);
212 REQUIRE(handle_table.GetGeneric(output[5]) == c);
213 }
214}
215
216} // namespace Kernel