blob: 260be570f9bb6e35b51abc075962eb0aac811e75 [file] [log] [blame]
Steven Moreland5553ac42020-11-11 02:14:45 +00001/*
2 * Copyright (C) 2020 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
Steven Moreland5553ac42020-11-11 02:14:45 +000017#include <BnBinderRpcSession.h>
18#include <BnBinderRpcTest.h>
Steven Moreland37aff182021-03-26 02:04:16 +000019#include <aidl/IBinderRpcTest.h>
Yifan Hong6d82c8a2021-04-26 20:26:45 -070020#include <android-base/file.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000021#include <android-base/logging.h>
Steven Moreland37aff182021-03-26 02:04:16 +000022#include <android/binder_auto_utils.h>
23#include <android/binder_libbinder.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000024#include <binder/Binder.h>
25#include <binder/BpBinder.h>
26#include <binder/IServiceManager.h>
27#include <binder/ProcessState.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000028#include <binder/RpcServer.h>
Steven Morelandbdb53ab2021-05-05 17:57:41 +000029#include <binder/RpcSession.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000030#include <gtest/gtest.h>
31
Steven Morelandc1635952021-04-01 16:20:47 +000032#include <chrono>
33#include <cstdlib>
34#include <iostream>
35#include <thread>
36
Steven Morelandc1635952021-04-01 16:20:47 +000037#include <sys/prctl.h>
38#include <unistd.h>
39
Steven Morelandbd5002b2021-05-04 23:12:56 +000040#include "../RpcState.h" // for debugging
41#include "../vm_sockets.h" // for VMADDR_*
Steven Moreland5553ac42020-11-11 02:14:45 +000042
43namespace android {
44
Steven Moreland1fda67b2021-04-02 18:35:50 +000045TEST(BinderRpcParcel, EntireParcelFormatted) {
46 Parcel p;
47 p.writeInt32(3);
48
49 EXPECT_DEATH(p.markForBinder(sp<BBinder>::make()), "");
50}
51
Steven Moreland5553ac42020-11-11 02:14:45 +000052using android::binder::Status;
53
54#define EXPECT_OK(status) \
55 do { \
56 Status stat = (status); \
57 EXPECT_TRUE(stat.isOk()) << stat; \
58 } while (false)
59
60class MyBinderRpcSession : public BnBinderRpcSession {
61public:
62 static std::atomic<int32_t> gNum;
63
64 MyBinderRpcSession(const std::string& name) : mName(name) { gNum++; }
65 Status getName(std::string* name) override {
66 *name = mName;
67 return Status::ok();
68 }
69 ~MyBinderRpcSession() { gNum--; }
70
71private:
72 std::string mName;
73};
74std::atomic<int32_t> MyBinderRpcSession::gNum;
75
76class MyBinderRpcTest : public BnBinderRpcTest {
77public:
Steven Moreland611d15f2021-05-01 01:28:27 +000078 wp<RpcServer> server;
Steven Moreland5553ac42020-11-11 02:14:45 +000079
80 Status sendString(const std::string& str) override {
Steven Morelandc6046982021-04-20 00:49:42 +000081 (void)str;
Steven Moreland5553ac42020-11-11 02:14:45 +000082 return Status::ok();
83 }
84 Status doubleString(const std::string& str, std::string* strstr) override {
Steven Moreland5553ac42020-11-11 02:14:45 +000085 *strstr = str + str;
86 return Status::ok();
87 }
Steven Moreland736664b2021-05-01 04:27:25 +000088 Status countBinders(std::vector<int32_t>* out) override {
Steven Moreland611d15f2021-05-01 01:28:27 +000089 sp<RpcServer> spServer = server.promote();
90 if (spServer == nullptr) {
Steven Moreland5553ac42020-11-11 02:14:45 +000091 return Status::fromExceptionCode(Status::EX_NULL_POINTER);
92 }
Steven Moreland736664b2021-05-01 04:27:25 +000093 out->clear();
Steven Morelandbdb53ab2021-05-05 17:57:41 +000094 for (auto session : spServer->listSessions()) {
95 size_t count = session->state()->countBinders();
Steven Moreland736664b2021-05-01 04:27:25 +000096 if (count != 1) {
97 // this is called when there is only one binder held remaining,
98 // so to aid debugging
Steven Morelandbdb53ab2021-05-05 17:57:41 +000099 session->state()->dump();
Steven Moreland611d15f2021-05-01 01:28:27 +0000100 }
Steven Moreland736664b2021-05-01 04:27:25 +0000101 out->push_back(count);
Steven Moreland611d15f2021-05-01 01:28:27 +0000102 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000103 return Status::ok();
104 }
105 Status pingMe(const sp<IBinder>& binder, int32_t* out) override {
106 if (binder == nullptr) {
107 std::cout << "Received null binder!" << std::endl;
108 return Status::fromExceptionCode(Status::EX_NULL_POINTER);
109 }
110 *out = binder->pingBinder();
111 return Status::ok();
112 }
113 Status repeatBinder(const sp<IBinder>& binder, sp<IBinder>* out) override {
114 *out = binder;
115 return Status::ok();
116 }
117 static sp<IBinder> mHeldBinder;
118 Status holdBinder(const sp<IBinder>& binder) override {
119 mHeldBinder = binder;
120 return Status::ok();
121 }
122 Status getHeldBinder(sp<IBinder>* held) override {
123 *held = mHeldBinder;
124 return Status::ok();
125 }
126 Status nestMe(const sp<IBinderRpcTest>& binder, int count) override {
127 if (count <= 0) return Status::ok();
128 return binder->nestMe(this, count - 1);
129 }
130 Status alwaysGiveMeTheSameBinder(sp<IBinder>* out) override {
131 static sp<IBinder> binder = new BBinder;
132 *out = binder;
133 return Status::ok();
134 }
135 Status openSession(const std::string& name, sp<IBinderRpcSession>* out) override {
136 *out = new MyBinderRpcSession(name);
137 return Status::ok();
138 }
139 Status getNumOpenSessions(int32_t* out) override {
140 *out = MyBinderRpcSession::gNum;
141 return Status::ok();
142 }
143
144 std::mutex blockMutex;
145 Status lock() override {
146 blockMutex.lock();
147 return Status::ok();
148 }
149 Status unlockInMsAsync(int32_t ms) override {
150 usleep(ms * 1000);
151 blockMutex.unlock();
152 return Status::ok();
153 }
154 Status lockUnlock() override {
155 std::lock_guard<std::mutex> _l(blockMutex);
156 return Status::ok();
157 }
158
159 Status sleepMs(int32_t ms) override {
160 usleep(ms * 1000);
161 return Status::ok();
162 }
163
164 Status sleepMsAsync(int32_t ms) override {
165 // In-process binder calls are asynchronous, but the call to this method
166 // is synchronous wrt its client. This in/out-process threading model
167 // diffentiation is a classic binder leaky abstraction (for better or
168 // worse) and is preserved here the way binder sockets plugs itself
169 // into BpBinder, as nothing is changed at the higher levels
170 // (IInterface) which result in this behavior.
171 return sleepMs(ms);
172 }
173
174 Status die(bool cleanup) override {
175 if (cleanup) {
176 exit(1);
177 } else {
178 _exit(1);
179 }
180 }
181};
182sp<IBinder> MyBinderRpcTest::mHeldBinder;
183
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700184class Pipe {
185public:
186 Pipe() { CHECK(android::base::Pipe(&mRead, &mWrite)); }
187 Pipe(Pipe&&) = default;
188 android::base::borrowed_fd readEnd() { return mRead; }
189 android::base::borrowed_fd writeEnd() { return mWrite; }
190
191private:
192 android::base::unique_fd mRead;
193 android::base::unique_fd mWrite;
194};
195
Steven Moreland5553ac42020-11-11 02:14:45 +0000196class Process {
197public:
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700198 Process(Process&&) = default;
199 Process(const std::function<void(Pipe*)>& f) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000200 if (0 == (mPid = fork())) {
201 // racey: assume parent doesn't crash before this is set
202 prctl(PR_SET_PDEATHSIG, SIGHUP);
203
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700204 f(&mPipe);
Steven Moreland5553ac42020-11-11 02:14:45 +0000205 }
206 }
207 ~Process() {
208 if (mPid != 0) {
209 kill(mPid, SIGKILL);
210 }
211 }
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700212 Pipe* getPipe() { return &mPipe; }
Steven Moreland5553ac42020-11-11 02:14:45 +0000213
214private:
215 pid_t mPid = 0;
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700216 Pipe mPipe;
Steven Moreland5553ac42020-11-11 02:14:45 +0000217};
218
219static std::string allocateSocketAddress() {
220 static size_t id = 0;
Steven Moreland4bfbf2e2021-04-14 22:15:16 +0000221 std::string temp = getenv("TMPDIR") ?: "/tmp";
222 return temp + "/binderRpcTest_" + std::to_string(id++);
Steven Moreland5553ac42020-11-11 02:14:45 +0000223};
224
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000225struct ProcessSession {
Steven Moreland5553ac42020-11-11 02:14:45 +0000226 // reference to process hosting a socket server
227 Process host;
228
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000229 struct SessionInfo {
230 sp<RpcSession> session;
Steven Moreland736664b2021-05-01 04:27:25 +0000231 sp<IBinder> root;
232 };
Steven Moreland5553ac42020-11-11 02:14:45 +0000233
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000234 // client session objects associated with other process
235 // each one represents a separate session
236 std::vector<SessionInfo> sessions;
Steven Moreland5553ac42020-11-11 02:14:45 +0000237
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000238 ProcessSession(ProcessSession&&) = default;
239 ~ProcessSession() {
240 for (auto& session : sessions) {
241 session.root = nullptr;
Steven Moreland736664b2021-05-01 04:27:25 +0000242 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000243
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000244 for (auto& info : sessions) {
245 sp<RpcSession>& session = info.session;
Steven Moreland736664b2021-05-01 04:27:25 +0000246
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000247 EXPECT_NE(nullptr, session);
248 EXPECT_NE(nullptr, session->state());
249 EXPECT_EQ(0, session->state()->countBinders()) << (session->state()->dump(), "dump:");
Steven Moreland736664b2021-05-01 04:27:25 +0000250
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000251 wp<RpcSession> weakSession = session;
252 session = nullptr;
253 EXPECT_EQ(nullptr, weakSession.promote()) << "Leaked session";
Steven Moreland736664b2021-05-01 04:27:25 +0000254 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000255 }
256};
257
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000258// Process session where the process hosts IBinderRpcTest, the server used
Steven Moreland5553ac42020-11-11 02:14:45 +0000259// for most testing here
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000260struct BinderRpcTestProcessSession {
261 ProcessSession proc;
Steven Moreland5553ac42020-11-11 02:14:45 +0000262
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000263 // pre-fetched root object (for first session)
Steven Moreland5553ac42020-11-11 02:14:45 +0000264 sp<IBinder> rootBinder;
265
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000266 // pre-casted root object (for first session)
Steven Moreland5553ac42020-11-11 02:14:45 +0000267 sp<IBinderRpcTest> rootIface;
268
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000269 // whether session should be invalidated by end of run
Steven Moreland736664b2021-05-01 04:27:25 +0000270 bool expectInvalid = false;
271
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000272 BinderRpcTestProcessSession(BinderRpcTestProcessSession&&) = default;
273 ~BinderRpcTestProcessSession() {
Steven Moreland736664b2021-05-01 04:27:25 +0000274 if (!expectInvalid) {
275 std::vector<int32_t> remoteCounts;
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000276 // calling over any sessions counts across all sessions
Steven Moreland736664b2021-05-01 04:27:25 +0000277 EXPECT_OK(rootIface->countBinders(&remoteCounts));
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000278 EXPECT_EQ(remoteCounts.size(), proc.sessions.size());
Steven Moreland736664b2021-05-01 04:27:25 +0000279 for (auto remoteCount : remoteCounts) {
280 EXPECT_EQ(remoteCount, 1);
281 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000282 }
283
284 rootIface = nullptr;
285 rootBinder = nullptr;
286 }
287};
288
Steven Morelandc1635952021-04-01 16:20:47 +0000289enum class SocketType {
290 UNIX,
291 VSOCK,
Yifan Hong0d2bd112021-04-13 17:38:36 -0700292 INET,
Steven Morelandc1635952021-04-01 16:20:47 +0000293};
294static inline std::string PrintSocketType(const testing::TestParamInfo<SocketType>& info) {
295 switch (info.param) {
296 case SocketType::UNIX:
297 return "unix_domain_socket";
298 case SocketType::VSOCK:
299 return "vm_socket";
Yifan Hong0d2bd112021-04-13 17:38:36 -0700300 case SocketType::INET:
301 return "inet_socket";
Steven Morelandc1635952021-04-01 16:20:47 +0000302 default:
303 LOG_ALWAYS_FATAL("Unknown socket type");
304 return "";
305 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000306}
Steven Morelandc1635952021-04-01 16:20:47 +0000307class BinderRpc : public ::testing::TestWithParam<SocketType> {
308public:
309 // This creates a new process serving an interface on a certain number of
310 // threads.
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000311 ProcessSession createRpcTestSocketServerProcess(
312 size_t numThreads, size_t numSessions,
Steven Moreland736664b2021-05-01 04:27:25 +0000313 const std::function<void(const sp<RpcServer>&)>& configure) {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000314 CHECK_GE(numSessions, 1) << "Must have at least one session to a server";
Steven Moreland736664b2021-05-01 04:27:25 +0000315
Steven Morelandc1635952021-04-01 16:20:47 +0000316 SocketType socketType = GetParam();
317
318 std::string addr = allocateSocketAddress();
319 unlink(addr.c_str());
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700320 static unsigned int vsockPort = 3456;
321 vsockPort++;
Steven Morelandc1635952021-04-01 16:20:47 +0000322
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000323 auto ret = ProcessSession{
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700324 .host = Process([&](Pipe* pipe) {
Steven Morelandc1635952021-04-01 16:20:47 +0000325 sp<RpcServer> server = RpcServer::make();
326
327 server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
Steven Morelandf137de92021-04-24 01:54:26 +0000328 server->setMaxThreads(numThreads);
Steven Morelandc1635952021-04-01 16:20:47 +0000329
Steven Moreland76d2c1f2021-05-05 20:28:58 +0000330 unsigned int outPort = 0;
331
Steven Morelandc1635952021-04-01 16:20:47 +0000332 switch (socketType) {
333 case SocketType::UNIX:
Steven Moreland611d15f2021-05-01 01:28:27 +0000334 CHECK(server->setupUnixDomainServer(addr.c_str())) << addr;
Steven Morelandc1635952021-04-01 16:20:47 +0000335 break;
336 case SocketType::VSOCK:
Steven Moreland611d15f2021-05-01 01:28:27 +0000337 CHECK(server->setupVsockServer(vsockPort));
Steven Morelandc1635952021-04-01 16:20:47 +0000338 break;
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700339 case SocketType::INET: {
Steven Moreland611d15f2021-05-01 01:28:27 +0000340 CHECK(server->setupInetServer(0, &outPort));
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700341 CHECK_NE(0, outPort);
Yifan Hong0d2bd112021-04-13 17:38:36 -0700342 break;
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700343 }
Steven Morelandc1635952021-04-01 16:20:47 +0000344 default:
345 LOG_ALWAYS_FATAL("Unknown socket type");
346 }
347
Steven Moreland76d2c1f2021-05-05 20:28:58 +0000348 CHECK(android::base::WriteFully(pipe->writeEnd(), &outPort, sizeof(outPort)));
349
Steven Moreland611d15f2021-05-01 01:28:27 +0000350 configure(server);
Steven Morelandc1635952021-04-01 16:20:47 +0000351
Steven Morelandf137de92021-04-24 01:54:26 +0000352 server->join();
Steven Morelandc1635952021-04-01 16:20:47 +0000353 }),
Steven Morelandc1635952021-04-01 16:20:47 +0000354 };
355
Steven Moreland76d2c1f2021-05-05 20:28:58 +0000356 // always read socket, so that we have waited for the server to start
357 unsigned int outPort = 0;
358 CHECK(android::base::ReadFully(ret.host.getPipe()->readEnd(), &outPort, sizeof(outPort)));
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700359 if (socketType == SocketType::INET) {
Steven Moreland76d2c1f2021-05-05 20:28:58 +0000360 CHECK_NE(0, outPort);
Yifan Hong6d82c8a2021-04-26 20:26:45 -0700361 }
362
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000363 for (size_t i = 0; i < numSessions; i++) {
364 sp<RpcSession> session = RpcSession::make();
Steven Moreland76d2c1f2021-05-05 20:28:58 +0000365 switch (socketType) {
366 case SocketType::UNIX:
367 if (session->setupUnixDomainClient(addr.c_str())) goto success;
368 break;
369 case SocketType::VSOCK:
370 if (session->setupVsockClient(VMADDR_CID_LOCAL, vsockPort)) goto success;
371 break;
372 case SocketType::INET:
373 if (session->setupInetClient("127.0.0.1", outPort)) goto success;
374 break;
375 default:
376 LOG_ALWAYS_FATAL("Unknown socket type");
Steven Morelandc1635952021-04-01 16:20:47 +0000377 }
Steven Moreland736664b2021-05-01 04:27:25 +0000378 LOG_ALWAYS_FATAL("Could not connect");
379 success:
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000380 ret.sessions.push_back({session, session->getRootObject()});
Steven Morelandc1635952021-04-01 16:20:47 +0000381 }
Steven Morelandc1635952021-04-01 16:20:47 +0000382 return ret;
383 }
384
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000385 BinderRpcTestProcessSession createRpcTestSocketServerProcess(size_t numThreads,
386 size_t numSessions = 1) {
387 BinderRpcTestProcessSession ret{
388 .proc = createRpcTestSocketServerProcess(numThreads, numSessions,
Steven Moreland611d15f2021-05-01 01:28:27 +0000389 [&](const sp<RpcServer>& server) {
Steven Morelandc1635952021-04-01 16:20:47 +0000390 sp<MyBinderRpcTest> service =
391 new MyBinderRpcTest;
392 server->setRootObject(service);
Steven Moreland611d15f2021-05-01 01:28:27 +0000393 service->server = server;
Steven Morelandc1635952021-04-01 16:20:47 +0000394 }),
395 };
396
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000397 ret.rootBinder = ret.proc.sessions.at(0).root;
Steven Morelandc1635952021-04-01 16:20:47 +0000398 ret.rootIface = interface_cast<IBinderRpcTest>(ret.rootBinder);
399
400 return ret;
401 }
402};
403
404TEST_P(BinderRpc, RootObjectIsNull) {
Steven Moreland736664b2021-05-01 04:27:25 +0000405 auto proc = createRpcTestSocketServerProcess(1, 1, [](const sp<RpcServer>& server) {
Steven Moreland611d15f2021-05-01 01:28:27 +0000406 // this is the default, but to be explicit
407 server->setRootObject(nullptr);
408 });
Steven Moreland5553ac42020-11-11 02:14:45 +0000409
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000410 EXPECT_EQ(nullptr, proc.sessions.at(0).root);
Steven Moreland5553ac42020-11-11 02:14:45 +0000411}
412
Steven Morelandc1635952021-04-01 16:20:47 +0000413TEST_P(BinderRpc, Ping) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000414 auto proc = createRpcTestSocketServerProcess(1);
415 ASSERT_NE(proc.rootBinder, nullptr);
416 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
417}
418
Steven Moreland4cf688f2021-03-31 01:48:58 +0000419TEST_P(BinderRpc, GetInterfaceDescriptor) {
420 auto proc = createRpcTestSocketServerProcess(1);
421 ASSERT_NE(proc.rootBinder, nullptr);
422 EXPECT_EQ(IBinderRpcTest::descriptor, proc.rootBinder->getInterfaceDescriptor());
423}
424
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000425TEST_P(BinderRpc, MultipleSessions) {
426 auto proc = createRpcTestSocketServerProcess(1 /*threads*/, 5 /*sessions*/);
427 for (auto session : proc.proc.sessions) {
428 ASSERT_NE(nullptr, session.root);
429 EXPECT_EQ(OK, session.root->pingBinder());
Steven Moreland736664b2021-05-01 04:27:25 +0000430 }
431}
432
Steven Morelandc1635952021-04-01 16:20:47 +0000433TEST_P(BinderRpc, TransactionsMustBeMarkedRpc) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000434 auto proc = createRpcTestSocketServerProcess(1);
435 Parcel data;
436 Parcel reply;
437 EXPECT_EQ(BAD_TYPE, proc.rootBinder->transact(IBinder::PING_TRANSACTION, data, &reply, 0));
438}
439
Steven Moreland67753c32021-04-02 18:45:19 +0000440TEST_P(BinderRpc, AppendSeparateFormats) {
441 auto proc = createRpcTestSocketServerProcess(1);
442
443 Parcel p1;
444 p1.markForBinder(proc.rootBinder);
445 p1.writeInt32(3);
446
447 Parcel p2;
448
449 EXPECT_EQ(BAD_TYPE, p1.appendFrom(&p2, 0, p2.dataSize()));
450 EXPECT_EQ(BAD_TYPE, p2.appendFrom(&p1, 0, p1.dataSize()));
451}
452
Steven Morelandc1635952021-04-01 16:20:47 +0000453TEST_P(BinderRpc, UnknownTransaction) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000454 auto proc = createRpcTestSocketServerProcess(1);
455 Parcel data;
456 data.markForBinder(proc.rootBinder);
457 Parcel reply;
458 EXPECT_EQ(UNKNOWN_TRANSACTION, proc.rootBinder->transact(1337, data, &reply, 0));
459}
460
Steven Morelandc1635952021-04-01 16:20:47 +0000461TEST_P(BinderRpc, SendSomethingOneway) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000462 auto proc = createRpcTestSocketServerProcess(1);
463 EXPECT_OK(proc.rootIface->sendString("asdf"));
464}
465
Steven Morelandc1635952021-04-01 16:20:47 +0000466TEST_P(BinderRpc, SendAndGetResultBack) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000467 auto proc = createRpcTestSocketServerProcess(1);
468 std::string doubled;
469 EXPECT_OK(proc.rootIface->doubleString("cool ", &doubled));
470 EXPECT_EQ("cool cool ", doubled);
471}
472
Steven Morelandc1635952021-04-01 16:20:47 +0000473TEST_P(BinderRpc, SendAndGetResultBackBig) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000474 auto proc = createRpcTestSocketServerProcess(1);
475 std::string single = std::string(1024, 'a');
476 std::string doubled;
477 EXPECT_OK(proc.rootIface->doubleString(single, &doubled));
478 EXPECT_EQ(single + single, doubled);
479}
480
Steven Morelandc1635952021-04-01 16:20:47 +0000481TEST_P(BinderRpc, CallMeBack) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000482 auto proc = createRpcTestSocketServerProcess(1);
483
484 int32_t pingResult;
485 EXPECT_OK(proc.rootIface->pingMe(new MyBinderRpcSession("foo"), &pingResult));
486 EXPECT_EQ(OK, pingResult);
487
488 EXPECT_EQ(0, MyBinderRpcSession::gNum);
489}
490
Steven Morelandc1635952021-04-01 16:20:47 +0000491TEST_P(BinderRpc, RepeatBinder) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000492 auto proc = createRpcTestSocketServerProcess(1);
493
494 sp<IBinder> inBinder = new MyBinderRpcSession("foo");
495 sp<IBinder> outBinder;
496 EXPECT_OK(proc.rootIface->repeatBinder(inBinder, &outBinder));
497 EXPECT_EQ(inBinder, outBinder);
498
499 wp<IBinder> weak = inBinder;
500 inBinder = nullptr;
501 outBinder = nullptr;
502
503 // Force reading a reply, to process any pending dec refs from the other
504 // process (the other process will process dec refs there before processing
505 // the ping here).
506 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
507
508 EXPECT_EQ(nullptr, weak.promote());
509
510 EXPECT_EQ(0, MyBinderRpcSession::gNum);
511}
512
Steven Morelandc1635952021-04-01 16:20:47 +0000513TEST_P(BinderRpc, RepeatTheirBinder) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000514 auto proc = createRpcTestSocketServerProcess(1);
515
516 sp<IBinderRpcSession> session;
517 EXPECT_OK(proc.rootIface->openSession("aoeu", &session));
518
519 sp<IBinder> inBinder = IInterface::asBinder(session);
520 sp<IBinder> outBinder;
521 EXPECT_OK(proc.rootIface->repeatBinder(inBinder, &outBinder));
522 EXPECT_EQ(inBinder, outBinder);
523
524 wp<IBinder> weak = inBinder;
525 session = nullptr;
526 inBinder = nullptr;
527 outBinder = nullptr;
528
529 // Force reading a reply, to process any pending dec refs from the other
530 // process (the other process will process dec refs there before processing
531 // the ping here).
532 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
533
534 EXPECT_EQ(nullptr, weak.promote());
535}
536
Steven Morelandc1635952021-04-01 16:20:47 +0000537TEST_P(BinderRpc, RepeatBinderNull) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000538 auto proc = createRpcTestSocketServerProcess(1);
539
540 sp<IBinder> outBinder;
541 EXPECT_OK(proc.rootIface->repeatBinder(nullptr, &outBinder));
542 EXPECT_EQ(nullptr, outBinder);
543}
544
Steven Morelandc1635952021-04-01 16:20:47 +0000545TEST_P(BinderRpc, HoldBinder) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000546 auto proc = createRpcTestSocketServerProcess(1);
547
548 IBinder* ptr = nullptr;
549 {
550 sp<IBinder> binder = new BBinder();
551 ptr = binder.get();
552 EXPECT_OK(proc.rootIface->holdBinder(binder));
553 }
554
555 sp<IBinder> held;
556 EXPECT_OK(proc.rootIface->getHeldBinder(&held));
557
558 EXPECT_EQ(held.get(), ptr);
559
560 // stop holding binder, because we test to make sure references are cleaned
561 // up
562 EXPECT_OK(proc.rootIface->holdBinder(nullptr));
563 // and flush ref counts
564 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
565}
566
567// START TESTS FOR LIMITATIONS OF SOCKET BINDER
568// These are behavioral differences form regular binder, where certain usecases
569// aren't supported.
570
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000571TEST_P(BinderRpc, CannotMixBindersBetweenUnrelatedSocketSessions) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000572 auto proc1 = createRpcTestSocketServerProcess(1);
573 auto proc2 = createRpcTestSocketServerProcess(1);
574
575 sp<IBinder> outBinder;
576 EXPECT_EQ(INVALID_OPERATION,
577 proc1.rootIface->repeatBinder(proc2.rootBinder, &outBinder).transactionError());
578}
579
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000580TEST_P(BinderRpc, CannotMixBindersBetweenTwoSessionsToTheSameServer) {
581 auto proc = createRpcTestSocketServerProcess(1 /*threads*/, 2 /*sessions*/);
Steven Moreland736664b2021-05-01 04:27:25 +0000582
583 sp<IBinder> outBinder;
584 EXPECT_EQ(INVALID_OPERATION,
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000585 proc.rootIface->repeatBinder(proc.proc.sessions.at(1).root, &outBinder)
Steven Moreland736664b2021-05-01 04:27:25 +0000586 .transactionError());
587}
588
Steven Morelandc1635952021-04-01 16:20:47 +0000589TEST_P(BinderRpc, CannotSendRegularBinderOverSocketBinder) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000590 auto proc = createRpcTestSocketServerProcess(1);
591
592 sp<IBinder> someRealBinder = IInterface::asBinder(defaultServiceManager());
593 sp<IBinder> outBinder;
594 EXPECT_EQ(INVALID_OPERATION,
595 proc.rootIface->repeatBinder(someRealBinder, &outBinder).transactionError());
596}
597
Steven Morelandc1635952021-04-01 16:20:47 +0000598TEST_P(BinderRpc, CannotSendSocketBinderOverRegularBinder) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000599 auto proc = createRpcTestSocketServerProcess(1);
600
601 // for historical reasons, IServiceManager interface only returns the
602 // exception code
603 EXPECT_EQ(binder::Status::EX_TRANSACTION_FAILED,
604 defaultServiceManager()->addService(String16("not_suspicious"), proc.rootBinder));
605}
606
607// END TESTS FOR LIMITATIONS OF SOCKET BINDER
608
Steven Morelandc1635952021-04-01 16:20:47 +0000609TEST_P(BinderRpc, RepeatRootObject) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000610 auto proc = createRpcTestSocketServerProcess(1);
611
612 sp<IBinder> outBinder;
613 EXPECT_OK(proc.rootIface->repeatBinder(proc.rootBinder, &outBinder));
614 EXPECT_EQ(proc.rootBinder, outBinder);
615}
616
Steven Morelandc1635952021-04-01 16:20:47 +0000617TEST_P(BinderRpc, NestedTransactions) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000618 auto proc = createRpcTestSocketServerProcess(1);
619
620 auto nastyNester = sp<MyBinderRpcTest>::make();
621 EXPECT_OK(proc.rootIface->nestMe(nastyNester, 10));
622
623 wp<IBinder> weak = nastyNester;
624 nastyNester = nullptr;
625 EXPECT_EQ(nullptr, weak.promote());
626}
627
Steven Morelandc1635952021-04-01 16:20:47 +0000628TEST_P(BinderRpc, SameBinderEquality) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000629 auto proc = createRpcTestSocketServerProcess(1);
630
631 sp<IBinder> a;
632 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&a));
633
634 sp<IBinder> b;
635 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&b));
636
637 EXPECT_EQ(a, b);
638}
639
Steven Morelandc1635952021-04-01 16:20:47 +0000640TEST_P(BinderRpc, SameBinderEqualityWeak) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000641 auto proc = createRpcTestSocketServerProcess(1);
642
643 sp<IBinder> a;
644 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&a));
645 wp<IBinder> weak = a;
646 a = nullptr;
647
648 sp<IBinder> b;
649 EXPECT_OK(proc.rootIface->alwaysGiveMeTheSameBinder(&b));
650
651 // this is the wrong behavior, since BpBinder
652 // doesn't implement onIncStrongAttempted
653 // but make sure there is no crash
654 EXPECT_EQ(nullptr, weak.promote());
655
656 GTEST_SKIP() << "Weak binders aren't currently re-promotable for RPC binder.";
657
658 // In order to fix this:
659 // - need to have incStrongAttempted reflected across IPC boundary (wait for
660 // response to promote - round trip...)
661 // - sendOnLastWeakRef, to delete entries out of RpcState table
662 EXPECT_EQ(b, weak.promote());
663}
664
665#define expectSessions(expected, iface) \
666 do { \
667 int session; \
668 EXPECT_OK((iface)->getNumOpenSessions(&session)); \
669 EXPECT_EQ(expected, session); \
670 } while (false)
671
Steven Morelandc1635952021-04-01 16:20:47 +0000672TEST_P(BinderRpc, SingleSession) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000673 auto proc = createRpcTestSocketServerProcess(1);
674
675 sp<IBinderRpcSession> session;
676 EXPECT_OK(proc.rootIface->openSession("aoeu", &session));
677 std::string out;
678 EXPECT_OK(session->getName(&out));
679 EXPECT_EQ("aoeu", out);
680
681 expectSessions(1, proc.rootIface);
682 session = nullptr;
683 expectSessions(0, proc.rootIface);
684}
685
Steven Morelandc1635952021-04-01 16:20:47 +0000686TEST_P(BinderRpc, ManySessions) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000687 auto proc = createRpcTestSocketServerProcess(1);
688
689 std::vector<sp<IBinderRpcSession>> sessions;
690
691 for (size_t i = 0; i < 15; i++) {
692 expectSessions(i, proc.rootIface);
693 sp<IBinderRpcSession> session;
694 EXPECT_OK(proc.rootIface->openSession(std::to_string(i), &session));
695 sessions.push_back(session);
696 }
697 expectSessions(sessions.size(), proc.rootIface);
698 for (size_t i = 0; i < sessions.size(); i++) {
699 std::string out;
700 EXPECT_OK(sessions.at(i)->getName(&out));
701 EXPECT_EQ(std::to_string(i), out);
702 }
703 expectSessions(sessions.size(), proc.rootIface);
704
705 while (!sessions.empty()) {
706 sessions.pop_back();
707 expectSessions(sessions.size(), proc.rootIface);
708 }
709 expectSessions(0, proc.rootIface);
710}
711
712size_t epochMillis() {
713 using std::chrono::duration_cast;
714 using std::chrono::milliseconds;
715 using std::chrono::seconds;
716 using std::chrono::system_clock;
717 return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
718}
719
Steven Morelandc1635952021-04-01 16:20:47 +0000720TEST_P(BinderRpc, ThreadPoolGreaterThanEqualRequested) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000721 constexpr size_t kNumThreads = 10;
722
723 auto proc = createRpcTestSocketServerProcess(kNumThreads);
724
725 EXPECT_OK(proc.rootIface->lock());
726
727 // block all but one thread taking locks
728 std::vector<std::thread> ts;
729 for (size_t i = 0; i < kNumThreads - 1; i++) {
730 ts.push_back(std::thread([&] { proc.rootIface->lockUnlock(); }));
731 }
732
733 usleep(100000); // give chance for calls on other threads
734
735 // other calls still work
736 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
737
738 constexpr size_t blockTimeMs = 500;
739 size_t epochMsBefore = epochMillis();
740 // after this, we should never see a response within this time
741 EXPECT_OK(proc.rootIface->unlockInMsAsync(blockTimeMs));
742
743 // this call should be blocked for blockTimeMs
744 EXPECT_EQ(OK, proc.rootBinder->pingBinder());
745
746 size_t epochMsAfter = epochMillis();
747 EXPECT_GE(epochMsAfter, epochMsBefore + blockTimeMs) << epochMsBefore;
748
749 for (auto& t : ts) t.join();
750}
751
Steven Morelandc1635952021-04-01 16:20:47 +0000752TEST_P(BinderRpc, ThreadPoolOverSaturated) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000753 constexpr size_t kNumThreads = 10;
754 constexpr size_t kNumCalls = kNumThreads + 3;
755 constexpr size_t kSleepMs = 500;
756
757 auto proc = createRpcTestSocketServerProcess(kNumThreads);
758
759 size_t epochMsBefore = epochMillis();
760
761 std::vector<std::thread> ts;
762 for (size_t i = 0; i < kNumCalls; i++) {
763 ts.push_back(std::thread([&] { proc.rootIface->sleepMs(kSleepMs); }));
764 }
765
766 for (auto& t : ts) t.join();
767
768 size_t epochMsAfter = epochMillis();
769
770 EXPECT_GE(epochMsAfter, epochMsBefore + 2 * kSleepMs);
771
772 // Potential flake, but make sure calls are handled in parallel.
773 EXPECT_LE(epochMsAfter, epochMsBefore + 3 * kSleepMs);
774}
775
Steven Morelandc1635952021-04-01 16:20:47 +0000776TEST_P(BinderRpc, ThreadingStressTest) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000777 constexpr size_t kNumClientThreads = 10;
778 constexpr size_t kNumServerThreads = 10;
779 constexpr size_t kNumCalls = 100;
780
781 auto proc = createRpcTestSocketServerProcess(kNumServerThreads);
782
783 std::vector<std::thread> threads;
784 for (size_t i = 0; i < kNumClientThreads; i++) {
785 threads.push_back(std::thread([&] {
786 for (size_t j = 0; j < kNumCalls; j++) {
787 sp<IBinder> out;
Steven Morelandc6046982021-04-20 00:49:42 +0000788 EXPECT_OK(proc.rootIface->repeatBinder(proc.rootBinder, &out));
Steven Moreland5553ac42020-11-11 02:14:45 +0000789 EXPECT_EQ(proc.rootBinder, out);
790 }
791 }));
792 }
793
794 for (auto& t : threads) t.join();
795}
796
Steven Morelandc6046982021-04-20 00:49:42 +0000797TEST_P(BinderRpc, OnewayStressTest) {
798 constexpr size_t kNumClientThreads = 10;
799 constexpr size_t kNumServerThreads = 10;
800 constexpr size_t kNumCalls = 100;
801
802 auto proc = createRpcTestSocketServerProcess(kNumServerThreads);
803
804 std::vector<std::thread> threads;
805 for (size_t i = 0; i < kNumClientThreads; i++) {
806 threads.push_back(std::thread([&] {
807 for (size_t j = 0; j < kNumCalls; j++) {
808 EXPECT_OK(proc.rootIface->sendString("a"));
809 }
810
811 // check threads are not stuck
812 EXPECT_OK(proc.rootIface->sleepMs(250));
813 }));
814 }
815
816 for (auto& t : threads) t.join();
817}
818
Steven Morelandc1635952021-04-01 16:20:47 +0000819TEST_P(BinderRpc, OnewayCallDoesNotWait) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000820 constexpr size_t kReallyLongTimeMs = 100;
821 constexpr size_t kSleepMs = kReallyLongTimeMs * 5;
822
823 // more than one thread, just so this doesn't deadlock
824 auto proc = createRpcTestSocketServerProcess(2);
825
826 size_t epochMsBefore = epochMillis();
827
828 EXPECT_OK(proc.rootIface->sleepMsAsync(kSleepMs));
829
830 size_t epochMsAfter = epochMillis();
831 EXPECT_LT(epochMsAfter, epochMsBefore + kReallyLongTimeMs);
832}
833
Steven Morelandc1635952021-04-01 16:20:47 +0000834TEST_P(BinderRpc, OnewayCallQueueing) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000835 constexpr size_t kNumSleeps = 10;
836 constexpr size_t kNumExtraServerThreads = 4;
837 constexpr size_t kSleepMs = 50;
838
839 // make sure calls to the same object happen on the same thread
840 auto proc = createRpcTestSocketServerProcess(1 + kNumExtraServerThreads);
841
842 EXPECT_OK(proc.rootIface->lock());
843
844 for (size_t i = 0; i < kNumSleeps; i++) {
845 // these should be processed serially
846 proc.rootIface->sleepMsAsync(kSleepMs);
847 }
848 // should also be processesed serially
849 EXPECT_OK(proc.rootIface->unlockInMsAsync(kSleepMs));
850
851 size_t epochMsBefore = epochMillis();
852 EXPECT_OK(proc.rootIface->lockUnlock());
853 size_t epochMsAfter = epochMillis();
854
855 EXPECT_GT(epochMsAfter, epochMsBefore + kSleepMs * kNumSleeps);
856}
857
Steven Morelandc1635952021-04-01 16:20:47 +0000858TEST_P(BinderRpc, Die) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000859 for (bool doDeathCleanup : {true, false}) {
860 auto proc = createRpcTestSocketServerProcess(1);
861
862 // make sure there is some state during crash
863 // 1. we hold their binder
864 sp<IBinderRpcSession> session;
865 EXPECT_OK(proc.rootIface->openSession("happy", &session));
866 // 2. they hold our binder
867 sp<IBinder> binder = new BBinder();
868 EXPECT_OK(proc.rootIface->holdBinder(binder));
869
870 EXPECT_EQ(DEAD_OBJECT, proc.rootIface->die(doDeathCleanup).transactionError())
871 << "Do death cleanup: " << doDeathCleanup;
872
Steven Moreland736664b2021-05-01 04:27:25 +0000873 proc.expectInvalid = true;
Steven Moreland5553ac42020-11-11 02:14:45 +0000874 }
875}
876
Steven Moreland37aff182021-03-26 02:04:16 +0000877TEST_P(BinderRpc, WorksWithLibbinderNdkPing) {
878 auto proc = createRpcTestSocketServerProcess(1);
879
880 ndk::SpAIBinder binder = ndk::SpAIBinder(AIBinder_fromPlatformBinder(proc.rootBinder));
881 ASSERT_NE(binder, nullptr);
882
883 ASSERT_EQ(STATUS_OK, AIBinder_ping(binder.get()));
884}
885
886TEST_P(BinderRpc, WorksWithLibbinderNdkUserTransaction) {
887 auto proc = createRpcTestSocketServerProcess(1);
888
889 ndk::SpAIBinder binder = ndk::SpAIBinder(AIBinder_fromPlatformBinder(proc.rootBinder));
890 ASSERT_NE(binder, nullptr);
891
892 auto ndkBinder = aidl::IBinderRpcTest::fromBinder(binder);
893 ASSERT_NE(ndkBinder, nullptr);
894
895 std::string out;
896 ndk::ScopedAStatus status = ndkBinder->doubleString("aoeu", &out);
897 ASSERT_TRUE(status.isOk()) << status.getDescription();
898 ASSERT_EQ("aoeuaoeu", out);
899}
900
Steven Moreland5553ac42020-11-11 02:14:45 +0000901ssize_t countFds() {
902 DIR* dir = opendir("/proc/self/fd/");
903 if (dir == nullptr) return -1;
904 ssize_t ret = 0;
905 dirent* ent;
906 while ((ent = readdir(dir)) != nullptr) ret++;
907 closedir(dir);
908 return ret;
909}
910
Steven Morelandc1635952021-04-01 16:20:47 +0000911TEST_P(BinderRpc, Fds) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000912 ssize_t beforeFds = countFds();
913 ASSERT_GE(beforeFds, 0);
914 {
915 auto proc = createRpcTestSocketServerProcess(10);
916 ASSERT_EQ(OK, proc.rootBinder->pingBinder());
917 }
918 ASSERT_EQ(beforeFds, countFds()) << (system("ls -l /proc/self/fd/"), "fd leak?");
919}
920
Steven Morelandc1635952021-04-01 16:20:47 +0000921INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc,
Yifan Hong0d2bd112021-04-13 17:38:36 -0700922 ::testing::ValuesIn({
923 SocketType::UNIX,
Steven Morelandbd5002b2021-05-04 23:12:56 +0000924// TODO(b/185269356): working on host
Steven Morelandf6ec4632021-04-01 16:20:47 +0000925#ifdef __BIONIC__
Yifan Hong0d2bd112021-04-13 17:38:36 -0700926 SocketType::VSOCK,
Steven Morelandbd5002b2021-05-04 23:12:56 +0000927#endif
Yifan Hong0d2bd112021-04-13 17:38:36 -0700928 SocketType::INET,
929 }),
Steven Morelandf6ec4632021-04-01 16:20:47 +0000930 PrintSocketType);
Steven Morelandc1635952021-04-01 16:20:47 +0000931
Yifan Hong4ffb0c72021-05-07 18:35:14 -0700932class BinderRpcServerRootObject : public ::testing::TestWithParam<std::tuple<bool, bool>> {};
933
934TEST_P(BinderRpcServerRootObject, WeakRootObject) {
935 using SetFn = std::function<void(RpcServer*, sp<IBinder>)>;
936 auto setRootObject = [](bool isStrong) -> SetFn {
937 return isStrong ? SetFn(&RpcServer::setRootObject) : SetFn(&RpcServer::setRootObjectWeak);
938 };
939
940 auto server = RpcServer::make();
941 auto [isStrong1, isStrong2] = GetParam();
942 auto binder1 = sp<BBinder>::make();
943 IBinder* binderRaw1 = binder1.get();
944 setRootObject(isStrong1)(server.get(), binder1);
945 EXPECT_EQ(binderRaw1, server->getRootObject());
946 binder1.clear();
947 EXPECT_EQ((isStrong1 ? binderRaw1 : nullptr), server->getRootObject());
948
949 auto binder2 = sp<BBinder>::make();
950 IBinder* binderRaw2 = binder2.get();
951 setRootObject(isStrong2)(server.get(), binder2);
952 EXPECT_EQ(binderRaw2, server->getRootObject());
953 binder2.clear();
954 EXPECT_EQ((isStrong2 ? binderRaw2 : nullptr), server->getRootObject());
955}
956
957INSTANTIATE_TEST_CASE_P(BinderRpc, BinderRpcServerRootObject,
958 ::testing::Combine(::testing::Bool(), ::testing::Bool()));
959
Steven Morelandc1635952021-04-01 16:20:47 +0000960} // namespace android
961
962int main(int argc, char** argv) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000963 ::testing::InitGoogleTest(&argc, argv);
964 android::base::InitLogging(argv, android::base::StderrLogger, android::base::DefaultAborter);
965 return RUN_ALL_TESTS();
966}