Loading libs/binder/tests/binderRpcTest.cpp +34 −11 Original line number Original line Diff line number Diff line Loading @@ -304,6 +304,11 @@ static std::string allocateSocketAddress() { return temp + "/binderRpcTest_" + std::to_string(id++); return temp + "/binderRpcTest_" + std::to_string(id++); }; }; static unsigned int allocateVsockPort() { static unsigned int vsockPort = 3456; return vsockPort++; } struct ProcessSession { struct ProcessSession { // reference to process hosting a socket server // reference to process hosting a socket server Process host; Process host; Loading Loading @@ -391,6 +396,7 @@ static inline std::string PrintSocketType(const testing::TestParamInfo<SocketTyp return ""; return ""; } } } } class BinderRpc : public ::testing::TestWithParam<SocketType> { class BinderRpc : public ::testing::TestWithParam<SocketType> { public: public: // This creates a new process serving an interface on a certain number of // This creates a new process serving an interface on a certain number of Loading @@ -402,10 +408,9 @@ public: SocketType socketType = GetParam(); SocketType socketType = GetParam(); unsigned int vsockPort = allocateVsockPort(); std::string addr = allocateSocketAddress(); std::string addr = allocateSocketAddress(); unlink(addr.c_str()); unlink(addr.c_str()); static unsigned int vsockPort = 3456; vsockPort++; auto ret = ProcessSession{ auto ret = ProcessSession{ .host = Process([&](Pipe* pipe) { .host = Process([&](Pipe* pipe) { Loading Loading @@ -1108,15 +1113,33 @@ TEST_P(BinderRpc, Fds) { ASSERT_EQ(beforeFds, countFds()) << (system("ls -l /proc/self/fd/"), "fd leak?"); ASSERT_EQ(beforeFds, countFds()) << (system("ls -l /proc/self/fd/"), "fd leak?"); } } INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc, static bool testSupportVsockLoopback() { ::testing::ValuesIn({ unsigned int vsockPort = allocateVsockPort(); SocketType::UNIX, sp<RpcServer> server = RpcServer::make(); // TODO(b/185269356): working on host server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction(); #ifdef __BIONIC__ CHECK(server->setupVsockServer(vsockPort)); SocketType::VSOCK, server->start(); #endif SocketType::INET, sp<RpcSession> session = RpcSession::make(); }), bool okay = session->setupVsockClient(VMADDR_CID_LOCAL, vsockPort); CHECK(server->shutdown()); ALOGE("Detected vsock loopback supported: %d", okay); return okay; } static std::vector<SocketType> testSocketTypes() { std::vector<SocketType> ret = {SocketType::UNIX, SocketType::INET}; static bool hasVsockLoopback = testSupportVsockLoopback(); if (hasVsockLoopback) { ret.push_back(SocketType::VSOCK); } return ret; } INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc, ::testing::ValuesIn(testSocketTypes()), PrintSocketType); PrintSocketType); class BinderRpcServerRootObject : public ::testing::TestWithParam<std::tuple<bool, bool>> {}; class BinderRpcServerRootObject : public ::testing::TestWithParam<std::tuple<bool, bool>> {}; Loading Loading
libs/binder/tests/binderRpcTest.cpp +34 −11 Original line number Original line Diff line number Diff line Loading @@ -304,6 +304,11 @@ static std::string allocateSocketAddress() { return temp + "/binderRpcTest_" + std::to_string(id++); return temp + "/binderRpcTest_" + std::to_string(id++); }; }; static unsigned int allocateVsockPort() { static unsigned int vsockPort = 3456; return vsockPort++; } struct ProcessSession { struct ProcessSession { // reference to process hosting a socket server // reference to process hosting a socket server Process host; Process host; Loading Loading @@ -391,6 +396,7 @@ static inline std::string PrintSocketType(const testing::TestParamInfo<SocketTyp return ""; return ""; } } } } class BinderRpc : public ::testing::TestWithParam<SocketType> { class BinderRpc : public ::testing::TestWithParam<SocketType> { public: public: // This creates a new process serving an interface on a certain number of // This creates a new process serving an interface on a certain number of Loading @@ -402,10 +408,9 @@ public: SocketType socketType = GetParam(); SocketType socketType = GetParam(); unsigned int vsockPort = allocateVsockPort(); std::string addr = allocateSocketAddress(); std::string addr = allocateSocketAddress(); unlink(addr.c_str()); unlink(addr.c_str()); static unsigned int vsockPort = 3456; vsockPort++; auto ret = ProcessSession{ auto ret = ProcessSession{ .host = Process([&](Pipe* pipe) { .host = Process([&](Pipe* pipe) { Loading Loading @@ -1108,15 +1113,33 @@ TEST_P(BinderRpc, Fds) { ASSERT_EQ(beforeFds, countFds()) << (system("ls -l /proc/self/fd/"), "fd leak?"); ASSERT_EQ(beforeFds, countFds()) << (system("ls -l /proc/self/fd/"), "fd leak?"); } } INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc, static bool testSupportVsockLoopback() { ::testing::ValuesIn({ unsigned int vsockPort = allocateVsockPort(); SocketType::UNIX, sp<RpcServer> server = RpcServer::make(); // TODO(b/185269356): working on host server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction(); #ifdef __BIONIC__ CHECK(server->setupVsockServer(vsockPort)); SocketType::VSOCK, server->start(); #endif SocketType::INET, sp<RpcSession> session = RpcSession::make(); }), bool okay = session->setupVsockClient(VMADDR_CID_LOCAL, vsockPort); CHECK(server->shutdown()); ALOGE("Detected vsock loopback supported: %d", okay); return okay; } static std::vector<SocketType> testSocketTypes() { std::vector<SocketType> ret = {SocketType::UNIX, SocketType::INET}; static bool hasVsockLoopback = testSupportVsockLoopback(); if (hasVsockLoopback) { ret.push_back(SocketType::VSOCK); } return ret; } INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc, ::testing::ValuesIn(testSocketTypes()), PrintSocketType); PrintSocketType); class BinderRpcServerRootObject : public ::testing::TestWithParam<std::tuple<bool, bool>> {}; class BinderRpcServerRootObject : public ::testing::TestWithParam<std::tuple<bool, bool>> {}; Loading