blob: c6fd4870a007168abf5720ccc0239cfba4ff9558 [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
Parth Sanebee6be12024-08-19 18:58:49 +0000304 sp<IBinder> someRealBinder = defaultServiceManager()->getService(String16("activity"));
305 ASSERT_NE(someRealBinder, nullptr);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000306 sp<IBinder> outBinder;
307 EXPECT_EQ(INVALID_OPERATION,
308 proc.rootIface->repeatBinder(someRealBinder, &outBinder).transactionError());
309}
310
311TEST_P(BinderRpc, CannotSendSocketBinderOverRegularBinder) {
312 if (!kEnableKernelIpc || noKernel()) {
313 GTEST_SKIP() << "Test disabled because Binder kernel driver was disabled "
314 "at build time.";
315 }
316
317 auto proc = createRpcTestSocketServerProcess({});
318
319 // for historical reasons, IServiceManager interface only returns the
320 // exception code
321 EXPECT_EQ(binder::Status::EX_TRANSACTION_FAILED,
322 defaultServiceManager()->addService(String16("not_suspicious"), proc.rootBinder));
323}
324
325// END TESTS FOR LIMITATIONS OF SOCKET BINDER
326
Yu-Ting Tsengd5fc4462024-04-30 15:07:13 -0700327class TestFrozenStateChangeCallback : public IBinder::FrozenStateChangeCallback {
328public:
329 virtual void onStateChanged(const wp<IBinder>&, State) {}
330};
331
332TEST_P(BinderRpc, RpcBinderShouldFailOnFrozenStateCallbacks) {
333 auto proc = createRpcTestSocketServerProcess({});
334
335 sp<IBinder> a;
336 sp<TestFrozenStateChangeCallback> callback = sp<TestFrozenStateChangeCallback>::make();
337 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&a));
338 EXPECT_DEATH_IF_SUPPORTED(
339 { std::ignore = a->addFrozenStateChangeCallback(callback); },
340 "addFrozenStateChangeCallback\\(\\) is not supported for RPC Binder.");
341}
342
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000343TEST_P(BinderRpc, RepeatRootObject) {
344 auto proc = createRpcTestSocketServerProcess({});
345
346 sp<IBinder> outBinder;
347 EXPECT_OK(proc.rootIface->repeatBinder(proc.rootBinder, &outBinder));
348 EXPECT_EQ(proc.rootBinder, outBinder);
349}
350
351TEST_P(BinderRpc, NestedTransactions) {
Andrei Homescu68a55612022-08-02 01:25:15 +0000352 auto fileDescriptorTransportMode = RpcSession::FileDescriptorTransportMode::UNIX;
353 if (socketType() == SocketType::TIPC) {
354 // TIPC does not support file descriptors yet
355 fileDescriptorTransportMode = RpcSession::FileDescriptorTransportMode::NONE;
356 }
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000357 auto proc = createRpcTestSocketServerProcess({
358 // Enable FD support because it uses more stack space and so represents
359 // something closer to a worst case scenario.
Andrei Homescu68a55612022-08-02 01:25:15 +0000360 .clientFileDescriptorTransportMode = fileDescriptorTransportMode,
361 .serverSupportedFileDescriptorTransportModes = {fileDescriptorTransportMode},
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000362 });
363
Andrei Homescu9d8adb12022-08-02 04:38:30 +0000364 auto nastyNester = sp<MyBinderRpcTestDefault>::make();
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000365 EXPECT_OK(proc.rootIface->nestMe(nastyNester, 10));
366
367 wp<IBinder> weak = nastyNester;
368 nastyNester = nullptr;
369 EXPECT_EQ(nullptr, weak.promote());
370}
371
372TEST_P(BinderRpc, SameBinderEquality) {
373 auto proc = createRpcTestSocketServerProcess({});
374
375 sp<IBinder> a;
376 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&a));
377
378 sp<IBinder> b;
379 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&b));
380
381 EXPECT_EQ(a, b);
382}
383
384TEST_P(BinderRpc, SameBinderEqualityWeak) {
385 auto proc = createRpcTestSocketServerProcess({});
386
387 sp<IBinder> a;
388 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&a));
389 wp<IBinder> weak = a;
390 a = nullptr;
391
392 sp<IBinder> b;
393 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&b));
394
395 // this is the wrong behavior, since BpBinder
396 // doesn't implement onIncStrongAttempted
397 // but make sure there is no crash
398 EXPECT_EQ(nullptr, weak.promote());
399
400 GTEST_SKIP() << "Weak binders aren't currently re-promotable for RPC binder.";
401
402 // In order to fix this:
403 // - need to have incStrongAttempted reflected across IPC boundary (wait for
404 // response to promote - round trip...)
405 // - sendOnLastWeakRef, to delete entries out of RpcState table
406 EXPECT_EQ(b, weak.promote());
407}
408
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000409#define EXPECT_SESSIONS(expected, iface) \
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000410 do { \
411 int session; \
412 EXPECT_OK((iface)->getNumOpenSessions(&session)); \
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000413 EXPECT_EQ(static_cast<int>(expected), session); \
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000414 } while (false)
415
416TEST_P(BinderRpc, SingleSession) {
417 auto proc = createRpcTestSocketServerProcess({});
418
419 sp<IBinderRpcSession> session;
420 EXPECT_OK(proc.rootIface->openSession("aoeu", &session));
421 std::string out;
422 EXPECT_OK(session->getName(&out));
423 EXPECT_EQ("aoeu", out);
424
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000425 EXPECT_SESSIONS(1, proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000426 session = nullptr;
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000427 EXPECT_SESSIONS(0, proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000428}
429
430TEST_P(BinderRpc, ManySessions) {
431 auto proc = createRpcTestSocketServerProcess({});
432
433 std::vector<sp<IBinderRpcSession>> sessions;
434
435 for (size_t i = 0; i < 15; i++) {
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000436 EXPECT_SESSIONS(i, proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000437 sp<IBinderRpcSession> session;
438 EXPECT_OK(proc.rootIface->openSession(std::to_string(i), &session));
439 sessions.push_back(session);
440 }
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000441 EXPECT_SESSIONS(sessions.size(), proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000442 for (size_t i = 0; i < sessions.size(); i++) {
443 std::string out;
444 EXPECT_OK(sessions.at(i)->getName(&out));
445 EXPECT_EQ(std::to_string(i), out);
446 }
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000447 EXPECT_SESSIONS(sessions.size(), proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000448
449 while (!sessions.empty()) {
450 sessions.pop_back();
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000451 EXPECT_SESSIONS(sessions.size(), proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000452 }
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000453 EXPECT_SESSIONS(0, proc.rootIface);
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000454}
455
456TEST_P(BinderRpc, OnewayCallDoesNotWait) {
457 constexpr size_t kReallyLongTimeMs = 100;
458 constexpr size_t kSleepMs = kReallyLongTimeMs * 5;
459
460 auto proc = createRpcTestSocketServerProcess({});
461
462 size_t epochMsBefore = epochMillis();
463
464 EXPECT_OK(proc.rootIface->sleepMsAsync(kSleepMs));
465
466 size_t epochMsAfter = epochMillis();
467 EXPECT_LT(epochMsAfter, epochMsBefore + kReallyLongTimeMs);
468}
469
470TEST_P(BinderRpc, Callbacks) {
471 const static std::string kTestString = "good afternoon!";
472
473 for (bool callIsOneway : {true, false}) {
474 for (bool callbackIsOneway : {true, false}) {
475 for (bool delayed : {true, false}) {
476 if (clientOrServerSingleThreaded() &&
477 (callIsOneway || callbackIsOneway || delayed)) {
478 // we have no incoming connections to receive the callback
479 continue;
480 }
481
482 size_t numIncomingConnections = clientOrServerSingleThreaded() ? 0 : 1;
483 auto proc = createRpcTestSocketServerProcess(
484 {.numThreads = 1,
485 .numSessions = 1,
Steven Moreland67f85902023-03-15 01:13:49 +0000486 .numIncomingConnectionsBySession = {numIncomingConnections}});
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000487 auto cb = sp<MyBinderRpcCallback>::make();
488
489 if (callIsOneway) {
490 EXPECT_OK(proc.rootIface->doCallbackAsync(cb, callbackIsOneway, delayed,
491 kTestString));
492 } else {
493 EXPECT_OK(
494 proc.rootIface->doCallback(cb, callbackIsOneway, delayed, kTestString));
495 }
496
497 // if both transactions are synchronous and the response is sent back on the
498 // same thread, everything should have happened in a nested call. Otherwise,
499 // the callback will be processed on another thread.
500 if (callIsOneway || callbackIsOneway || delayed) {
501 using std::literals::chrono_literals::operator""s;
502 RpcMutexUniqueLock _l(cb->mMutex);
503 cb->mCv.wait_for(_l, 1s, [&] { return !cb->mValues.empty(); });
504 }
505
Andrei Homescu4d9420e2023-01-31 01:38:48 +0000506 EXPECT_EQ(cb->mValues.size(), 1UL)
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000507 << "callIsOneway: " << callIsOneway
508 << " callbackIsOneway: " << callbackIsOneway << " delayed: " << delayed;
509 if (cb->mValues.empty()) continue;
510 EXPECT_EQ(cb->mValues.at(0), kTestString)
511 << "callIsOneway: " << callIsOneway
512 << " callbackIsOneway: " << callbackIsOneway << " delayed: " << delayed;
513
Steven Moreland67f85902023-03-15 01:13:49 +0000514 proc.forceShutdown();
Andrei Homescu9a9b1b42022-10-14 01:40:59 +0000515 }
516 }
517 }
518}
519
520TEST_P(BinderRpc, OnewayCallbackWithNoThread) {
521 auto proc = createRpcTestSocketServerProcess({});
522 auto cb = sp<MyBinderRpcCallback>::make();
523
524 Status status = proc.rootIface->doCallback(cb, true /*oneway*/, false /*delayed*/, "anything");
525 EXPECT_EQ(WOULD_BLOCK, status.transactionError());
526}
527
528TEST_P(BinderRpc, AidlDelegatorTest) {
529 auto proc = createRpcTestSocketServerProcess({});
530 auto myDelegator = sp<IBinderRpcTestDelegator>::make(proc.rootIface);
531 ASSERT_NE(nullptr, myDelegator);
532
533 std::string doubled;
534 EXPECT_OK(myDelegator->doubleString("cool ", &doubled));
535 EXPECT_EQ("cool cool ", doubled);
536}
537
538} // namespace android