blob: 2cec243c386f6f317592f83505fb0af1f8084533 [file] [log] [blame]
Andrei Homescu9a9b1b42022-10-14 01:40:59 +00001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <chrono>
18#include <cstdlib>
19#include <type_traits>
20
21#include "binderRpcTestCommon.h"
22#include "binderRpcTestFixture.h"
23
24using namespace std::chrono_literals;
25using namespace std::placeholders;
26using testing::AssertionFailure;
27using testing::AssertionResult;
28using testing::AssertionSuccess;
29
30namespace android {
31
32static_assert(RPC_WIRE_PROTOCOL_VERSION + 1 == RPC_WIRE_PROTOCOL_VERSION_NEXT ||
33 RPC_WIRE_PROTOCOL_VERSION == RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL);
34
35TEST(BinderRpcParcel, EntireParcelFormatted) {
36 Parcel p;
37 p.writeInt32(3);
38
39 EXPECT_DEATH_IF_SUPPORTED(p.markForBinder(sp<BBinder>::make()),
40 "format must be set before data is written");
41}
42
43TEST(BinderRpc, CannotUseNextWireVersion) {
44 auto session = RpcSession::make();
45 EXPECT_FALSE(session->setProtocolVersion(RPC_WIRE_PROTOCOL_VERSION_NEXT));
46 EXPECT_FALSE(session->setProtocolVersion(RPC_WIRE_PROTOCOL_VERSION_NEXT + 1));
47 EXPECT_FALSE(session->setProtocolVersion(RPC_WIRE_PROTOCOL_VERSION_NEXT + 2));
48 EXPECT_FALSE(session->setProtocolVersion(RPC_WIRE_PROTOCOL_VERSION_NEXT + 15));
49}
50
Andrei Homescu331c67e2024-03-27 23:07:01 +000051#ifndef BINDER_RPC_TO_TRUSTY_TEST
Andrei Homescu9a9b1b42022-10-14 01:40:59 +000052TEST(BinderRpc, CanUseExperimentalWireVersion) {
53 auto session = RpcSession::make();
Steven Moreland0884c552023-10-17 18:23:31 +000054 EXPECT_EQ(hasExperimentalRpc(),
55 session->setProtocolVersion(RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL));
Andrei Homescu9a9b1b42022-10-14 01:40:59 +000056}
Andrei Homescu331c67e2024-03-27 23:07:01 +000057#endif
Andrei Homescu9a9b1b42022-10-14 01:40:59 +000058
59TEST_P(BinderRpc, Ping) {
60 auto proc = createRpcTestSocketServerProcess({});
61 ASSERT_NE(proc.rootBinder, nullptr);
62 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
63}
64
65TEST_P(BinderRpc, GetInterfaceDescriptor) {
66 auto proc = createRpcTestSocketServerProcess({});
67 ASSERT_NE(proc.rootBinder, nullptr);
68 EXPECT_EQ(IBinderRpcTest::descriptor, proc.rootBinder->getInterfaceDescriptor());
69}
70
71TEST_P(BinderRpc, MultipleSessions) {
72 if (serverSingleThreaded()) {
73 // Tests with multiple sessions require a multi-threaded service,
74 // but work fine on a single-threaded client
75 GTEST_SKIP() << "This test requires a multi-threaded service";
76 }
77
78 auto proc = createRpcTestSocketServerProcess({.numThreads = 1, .numSessions = 5});
79 for (auto session : proc.proc->sessions) {
80 ASSERT_NE(nullptr, session.root);
81 EXPECT_EQ(OK, session.root->pingBinder());
82 }
83}
84
85TEST_P(BinderRpc, SeparateRootObject) {
86 if (serverSingleThreaded()) {
87 GTEST_SKIP() << "This test requires a multi-threaded service";
88 }
89
Steven Morelandb469f432023-07-28 22:13:47 +000090 SocketType type = GetParam().type;
Andrei Homescu9a9b1b42022-10-14 01:40:59 +000091 if (type == SocketType::PRECONNECTED || type == SocketType::UNIX ||
Alice Wang893a9912022-10-24 10:44:09 +000092 type == SocketType::UNIX_BOOTSTRAP || type == SocketType::UNIX_RAW) {
Andrei Homescu9a9b1b42022-10-14 01:40:59 +000093 // we can't get port numbers for unix sockets
94 return;
95 }
96
97 auto proc = createRpcTestSocketServerProcess({.numSessions = 2});
98
99 int port1 = 0;
100 EXPECT_OK(proc.rootIface->getClientPort(&port1));
101
102 sp<IBinderRpcTest> rootIface2 = interface_cast<IBinderRpcTest>(proc.proc->sessions.at(1).root);
103 int port2;
104 EXPECT_OK(rootIface2->getClientPort(&port2));
105
106 // we should have a different IBinderRpcTest object created for each
107 // session, because we use setPerSessionRootObject
108 EXPECT_NE(port1, port2);
109}
110
111TEST_P(BinderRpc, TransactionsMustBeMarkedRpc) {
112 auto proc = createRpcTestSocketServerProcess({});
113 Parcel data;
114 Parcel reply;
115 EXPECT_EQ(BAD_TYPE, proc.rootBinder->transact(IBinder::PING_TRANSACTION, data, &reply, 0));
116}
117
118TEST_P(BinderRpc, AppendSeparateFormats) {
Andrei Homescu68a55612022-08-02 01:25:15 +0000119 if (socketType() == SocketType::TIPC) {
120 GTEST_SKIP() << "Trusty does not support multiple server processes";
121 }
122
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000123 auto proc1 = createRpcTestSocketServerProcess({});
124 auto proc2 = createRpcTestSocketServerProcess({});
125
126 Parcel pRaw;
127
128 Parcel p1;
129 p1.markForBinder(proc1.rootBinder);
130 p1.writeInt32(3);
131
132 EXPECT_EQ(BAD_TYPE, p1.appendFrom(&pRaw, 0, pRaw.dataSize()));
133 EXPECT_EQ(BAD_TYPE, pRaw.appendFrom(&p1, 0, p1.dataSize()));
134
135 Parcel p2;
136 p2.markForBinder(proc2.rootBinder);
137 p2.writeInt32(7);
138
139 EXPECT_EQ(BAD_TYPE, p1.appendFrom(&p2, 0, p2.dataSize()));
140 EXPECT_EQ(BAD_TYPE, p2.appendFrom(&p1, 0, p1.dataSize()));
141}
142
143TEST_P(BinderRpc, UnknownTransaction) {
144 auto proc = createRpcTestSocketServerProcess({});
145 Parcel data;
146 data.markForBinder(proc.rootBinder);
147 Parcel reply;
148 EXPECT_EQ(UNKNOWN_TRANSACTION, proc.rootBinder->transact(1337, data, &reply, 0));
149}
150
151TEST_P(BinderRpc, SendSomethingOneway) {
152 auto proc = createRpcTestSocketServerProcess({});
153 EXPECT_OK(proc.rootIface->sendString("asdf"));
154}
155
156TEST_P(BinderRpc, SendAndGetResultBack) {
157 auto proc = createRpcTestSocketServerProcess({});
158 std::string doubled;
159 EXPECT_OK(proc.rootIface->doubleString("cool ", &doubled));
160 EXPECT_EQ("cool cool ", doubled);
161}
162
163TEST_P(BinderRpc, SendAndGetResultBackBig) {
164 auto proc = createRpcTestSocketServerProcess({});
Andrei Homescu68a55612022-08-02 01:25:15 +0000165 // Trusty has a limit of 4096 bytes for the entire RPC Binder message
166 size_t singleLen = socketType() == SocketType::TIPC ? 512 : 4096;
167 std::string single = std::string(singleLen, 'a');
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000168 std::string doubled;
169 EXPECT_OK(proc.rootIface->doubleString(single, &doubled));
170 EXPECT_EQ(single + single, doubled);
171}
172
173TEST_P(BinderRpc, InvalidNullBinderReturn) {
174 auto proc = createRpcTestSocketServerProcess({});
175
176 sp<IBinder> outBinder;
177 EXPECT_EQ(proc.rootIface->getNullBinder(&outBinder).transactionError(), UNEXPECTED_NULL);
178}
179
180TEST_P(BinderRpc, CallMeBack) {
181 auto proc = createRpcTestSocketServerProcess({});
182
183 int32_t pingResult;
184 EXPECT_OK(proc.rootIface->pingMe(new MyBinderRpcSession("foo"), &pingResult));
185 EXPECT_EQ(OK, pingResult);
186
187 EXPECT_EQ(0, MyBinderRpcSession::gNum);
188}
189
190TEST_P(BinderRpc, RepeatBinder) {
191 auto proc = createRpcTestSocketServerProcess({});
192
193 sp<IBinder> inBinder = new MyBinderRpcSession("foo");
194 sp<IBinder> outBinder;
195 EXPECT_OK(proc.rootIface->repeatBinder(inBinder, &outBinder));
196 EXPECT_EQ(inBinder, outBinder);
197
198 wp<IBinder> weak = inBinder;
199 inBinder = nullptr;
200 outBinder = nullptr;
201
202 // Force reading a reply, to process any pending dec refs from the other
203 // process (the other process will process dec refs there before processing
204 // the ping here).
205 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
206
207 EXPECT_EQ(nullptr, weak.promote());
208
209 EXPECT_EQ(0, MyBinderRpcSession::gNum);
210}
211
212TEST_P(BinderRpc, RepeatTheirBinder) {
213 auto proc = createRpcTestSocketServerProcess({});
214
215 sp<IBinderRpcSession> session;
216 EXPECT_OK(proc.rootIface->openSession("aoeu", &session));
217
218 sp<IBinder> inBinder = IInterface::asBinder(session);
219 sp<IBinder> outBinder;
220 EXPECT_OK(proc.rootIface->repeatBinder(inBinder, &outBinder));
221 EXPECT_EQ(inBinder, outBinder);
222
223 wp<IBinder> weak = inBinder;
224 session = nullptr;
225 inBinder = nullptr;
226 outBinder = nullptr;
227
228 // Force reading a reply, to process any pending dec refs from the other
229 // process (the other process will process dec refs there before processing
230 // the ping here).
231 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
232
233 EXPECT_EQ(nullptr, weak.promote());
234}
235
236TEST_P(BinderRpc, RepeatBinderNull) {
237 auto proc = createRpcTestSocketServerProcess({});
238
239 sp<IBinder> outBinder;
240 EXPECT_OK(proc.rootIface->repeatBinder(nullptr, &outBinder));
241 EXPECT_EQ(nullptr, outBinder);
242}
243
244TEST_P(BinderRpc, HoldBinder) {
245 auto proc = createRpcTestSocketServerProcess({});
246
247 IBinder* ptr = nullptr;
248 {
249 sp<IBinder> binder = new BBinder();
250 ptr = binder.get();
251 EXPECT_OK(proc.rootIface->holdBinder(binder));
252 }
253
254 sp<IBinder> held;
255 EXPECT_OK(proc.rootIface->getHeldBinder(&held));
256
257 EXPECT_EQ(held.get(), ptr);
258
259 // stop holding binder, because we test to make sure references are cleaned
260 // up
261 EXPECT_OK(proc.rootIface->holdBinder(nullptr));
262 // and flush ref counts
263 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
264}
265
266// START TESTS FOR LIMITATIONS OF SOCKET BINDER
267// These are behavioral differences form regular binder, where certain usecases
268// aren't supported.
269
270TEST_P(BinderRpc, CannotMixBindersBetweenUnrelatedSocketSessions) {
Andrei Homescu68a55612022-08-02 01:25:15 +0000271 if (socketType() == SocketType::TIPC) {
272 GTEST_SKIP() << "Trusty does not support multiple server processes";
273 }
274
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000275 auto proc1 = createRpcTestSocketServerProcess({});
276 auto proc2 = createRpcTestSocketServerProcess({});
277
278 sp<IBinder> outBinder;
279 EXPECT_EQ(INVALID_OPERATION,
280 proc1.rootIface->repeatBinder(proc2.rootBinder, &outBinder).transactionError());
281}
282
283TEST_P(BinderRpc, CannotMixBindersBetweenTwoSessionsToTheSameServer) {
284 if (serverSingleThreaded()) {
285 GTEST_SKIP() << "This test requires a multi-threaded service";
286 }
287
288 auto proc = createRpcTestSocketServerProcess({.numThreads = 1, .numSessions = 2});
289
290 sp<IBinder> outBinder;
291 EXPECT_EQ(INVALID_OPERATION,
292 proc.rootIface->repeatBinder(proc.proc->sessions.at(1).root, &outBinder)
293 .transactionError());
294}
295
296TEST_P(BinderRpc, CannotSendRegularBinderOverSocketBinder) {
297 if (!kEnableKernelIpc || noKernel()) {
298 GTEST_SKIP() << "Test disabled because Binder kernel driver was disabled "
299 "at build time.";
300 }
301
302 auto proc = createRpcTestSocketServerProcess({});
303
304 sp<IBinder> someRealBinder = IInterface::asBinder(defaultServiceManager());
305 sp<IBinder> outBinder;
306 EXPECT_EQ(INVALID_OPERATION,
307 proc.rootIface->repeatBinder(someRealBinder, &outBinder).transactionError());
308}
309
310TEST_P(BinderRpc, CannotSendSocketBinderOverRegularBinder) {
311 if (!kEnableKernelIpc || noKernel()) {
312 GTEST_SKIP() << "Test disabled because Binder kernel driver was disabled "
313 "at build time.";
314 }
315
316 auto proc = createRpcTestSocketServerProcess({});
317
318 // for historical reasons, IServiceManager interface only returns the
319 // exception code
320 EXPECT_EQ(binder::Status::EX_TRANSACTION_FAILED,
321 defaultServiceManager()->addService(String16("not_suspicious"), proc.rootBinder));
322}
323
324// END TESTS FOR LIMITATIONS OF SOCKET BINDER
325
Yu-Ting Tsengd5fc4462024-04-30 15:07:13 -0700326class TestFrozenStateChangeCallback : public IBinder::FrozenStateChangeCallback {
327public:
328 virtual void onStateChanged(const wp<IBinder>&, State) {}
329};
330
331TEST_P(BinderRpc, RpcBinderShouldFailOnFrozenStateCallbacks) {
332 auto proc = createRpcTestSocketServerProcess({});
333
334 sp<IBinder> a;
335 sp<TestFrozenStateChangeCallback> callback = sp<TestFrozenStateChangeCallback>::make();
336 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&a));
337 EXPECT_DEATH_IF_SUPPORTED(
338 { std::ignore = a->addFrozenStateChangeCallback(callback); },
339 "addFrozenStateChangeCallback\\(\\) is not supported for RPC Binder.");
340}
341
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000342TEST_P(BinderRpc, RepeatRootObject) {
343 auto proc = createRpcTestSocketServerProcess({});
344
345 sp<IBinder> outBinder;
346 EXPECT_OK(proc.rootIface->repeatBinder(proc.rootBinder, &outBinder));
347 EXPECT_EQ(proc.rootBinder, outBinder);
348}
349
350TEST_P(BinderRpc, NestedTransactions) {
Andrei Homescu68a55612022-08-02 01:25:15 +0000351 auto fileDescriptorTransportMode = RpcSession::FileDescriptorTransportMode::UNIX;
352 if (socketType() == SocketType::TIPC) {
353 // TIPC does not support file descriptors yet
354 fileDescriptorTransportMode = RpcSession::FileDescriptorTransportMode::NONE;
355 }
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000356 auto proc = createRpcTestSocketServerProcess({
357 // Enable FD support because it uses more stack space and so represents
358 // something closer to a worst case scenario.
Andrei Homescu68a55612022-08-02 01:25:15 +0000359 .clientFileDescriptorTransportMode = fileDescriptorTransportMode,
360 .serverSupportedFileDescriptorTransportModes = {fileDescriptorTransportMode},
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000361 });
362
Andrei Homescu9d8adb12022-08-02 04:38:30 +0000363 auto nastyNester = sp<MyBinderRpcTestDefault>::make();
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000364 EXPECT_OK(proc.rootIface->nestMe(nastyNester, 10));
365
366 wp<IBinder> weak = nastyNester;
367 nastyNester = nullptr;
368 EXPECT_EQ(nullptr, weak.promote());
369}
370
371TEST_P(BinderRpc, SameBinderEquality) {
372 auto proc = createRpcTestSocketServerProcess({});
373
374 sp<IBinder> a;
375 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&a));
376
377 sp<IBinder> b;
378 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&b));
379
380 EXPECT_EQ(a, b);
381}
382
383TEST_P(BinderRpc, SameBinderEqualityWeak) {
384 auto proc = createRpcTestSocketServerProcess({});
385
386 sp<IBinder> a;
387 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&a));
388 wp<IBinder> weak = a;
389 a = nullptr;
390
391 sp<IBinder> b;
392 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&b));
393
394 // this is the wrong behavior, since BpBinder
395 // doesn't implement onIncStrongAttempted
396 // but make sure there is no crash
397 EXPECT_EQ(nullptr, weak.promote());
398
399 GTEST_SKIP() << "Weak binders aren't currently re-promotable for RPC binder.";
400
401 // In order to fix this:
402 // - need to have incStrongAttempted reflected across IPC boundary (wait for
403 // response to promote - round trip...)
404 // - sendOnLastWeakRef, to delete entries out of RpcState table
405 EXPECT_EQ(b, weak.promote());
406}
407
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000408#define EXPECT_SESSIONS(expected, iface) \
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000409 do { \
410 int session; \
411 EXPECT_OK((iface)->getNumOpenSessions(&session)); \
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000412 EXPECT_EQ(static_cast<int>(expected), session); \
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000413 } while (false)
414
415TEST_P(BinderRpc, SingleSession) {
416 auto proc = createRpcTestSocketServerProcess({});
417
418 sp<IBinderRpcSession> session;
419 EXPECT_OK(proc.rootIface->openSession("aoeu", &session));
420 std::string out;
421 EXPECT_OK(session->getName(&out));
422 EXPECT_EQ("aoeu", out);
423
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000424 EXPECT_SESSIONS(1, proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000425 session = nullptr;
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000426 EXPECT_SESSIONS(0, proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000427}
428
429TEST_P(BinderRpc, ManySessions) {
430 auto proc = createRpcTestSocketServerProcess({});
431
432 std::vector<sp<IBinderRpcSession>> sessions;
433
434 for (size_t i = 0; i < 15; i++) {
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000435 EXPECT_SESSIONS(i, proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000436 sp<IBinderRpcSession> session;
437 EXPECT_OK(proc.rootIface->openSession(std::to_string(i), &session));
438 sessions.push_back(session);
439 }
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000440 EXPECT_SESSIONS(sessions.size(), proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000441 for (size_t i = 0; i < sessions.size(); i++) {
442 std::string out;
443 EXPECT_OK(sessions.at(i)->getName(&out));
444 EXPECT_EQ(std::to_string(i), out);
445 }
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000446 EXPECT_SESSIONS(sessions.size(), proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000447
448 while (!sessions.empty()) {
449 sessions.pop_back();
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000450 EXPECT_SESSIONS(sessions.size(), proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000451 }
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000452 EXPECT_SESSIONS(0, proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000453}
454
455TEST_P(BinderRpc, OnewayCallDoesNotWait) {
456 constexpr size_t kReallyLongTimeMs = 100;
457 constexpr size_t kSleepMs = kReallyLongTimeMs * 5;
458
459 auto proc = createRpcTestSocketServerProcess({});
460
461 size_t epochMsBefore = epochMillis();
462
463 EXPECT_OK(proc.rootIface->sleepMsAsync(kSleepMs));
464
465 size_t epochMsAfter = epochMillis();
466 EXPECT_LT(epochMsAfter, epochMsBefore + kReallyLongTimeMs);
467}
468
469TEST_P(BinderRpc, Callbacks) {
470 const static std::string kTestString = "good afternoon!";
471
472 for (bool callIsOneway : {true, false}) {
473 for (bool callbackIsOneway : {true, false}) {
474 for (bool delayed : {true, false}) {
475 if (clientOrServerSingleThreaded() &&
476 (callIsOneway || callbackIsOneway || delayed)) {
477 // we have no incoming connections to receive the callback
478 continue;
479 }
480
481 size_t numIncomingConnections = clientOrServerSingleThreaded() ? 0 : 1;
482 auto proc = createRpcTestSocketServerProcess(
483 {.numThreads = 1,
484 .numSessions = 1,
Steven Moreland67f85902023-03-15 01:13:49 +0000485 .numIncomingConnectionsBySession = {numIncomingConnections}});
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000486 auto cb = sp<MyBinderRpcCallback>::make();
487
488 if (callIsOneway) {
489 EXPECT_OK(proc.rootIface->doCallbackAsync(cb, callbackIsOneway, delayed,
490 kTestString));
491 } else {
492 EXPECT_OK(
493 proc.rootIface->doCallback(cb, callbackIsOneway, delayed, kTestString));
494 }
495
496 // if both transactions are synchronous and the response is sent back on the
497 // same thread, everything should have happened in a nested call. Otherwise,
498 // the callback will be processed on another thread.
499 if (callIsOneway || callbackIsOneway || delayed) {
500 using std::literals::chrono_literals::operator""s;
501 RpcMutexUniqueLock _l(cb->mMutex);
502 cb->mCv.wait_for(_l, 1s, [&] { return !cb->mValues.empty(); });
503 }
504
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000505 EXPECT_EQ(cb->mValues.size(), 1UL)
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000506 << "callIsOneway: " << callIsOneway
507 << " callbackIsOneway: " << callbackIsOneway << " delayed: " << delayed;
508 if (cb->mValues.empty()) continue;
509 EXPECT_EQ(cb->mValues.at(0), kTestString)
510 << "callIsOneway: " << callIsOneway
511 << " callbackIsOneway: " << callbackIsOneway << " delayed: " << delayed;
512
Steven Moreland67f85902023-03-15 01:13:49 +0000513 proc.forceShutdown();
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000514 }
515 }
516 }
517}
518
519TEST_P(BinderRpc, OnewayCallbackWithNoThread) {
520 auto proc = createRpcTestSocketServerProcess({});
521 auto cb = sp<MyBinderRpcCallback>::make();
522
523 Status status = proc.rootIface->doCallback(cb, true /*oneway*/, false /*delayed*/, "anything");
524 EXPECT_EQ(WOULD_BLOCK, status.transactionError());
525}
526
527TEST_P(BinderRpc, AidlDelegatorTest) {
528 auto proc = createRpcTestSocketServerProcess({});
529 auto myDelegator = sp<IBinderRpcTestDelegator>::make(proc.rootIface);
530 ASSERT_NE(nullptr, myDelegator);
531
532 std::string doubled;
533 EXPECT_OK(myDelegator->doubleString("cool ", &doubled));
534 EXPECT_EQ("cool cool ", doubled);
535}
536
537} // namespace android