Revert^2 "libbinder: binderRpcTest on host"
For even faster development.
Modified to disable this on the Mac build, where binder can't be built.
Bug: 167966510
Test: binderRpcTest on host and device
Change-Id: I44a66c3b39d82a36d27a2660d8c5c78e15ff896d
diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp
index 985a301..936ee5e 100644
--- a/libs/binder/tests/binderRpcTest.cpp
+++ b/libs/binder/tests/binderRpcTest.cpp
@@ -30,7 +30,10 @@
#include <iostream>
#include <thread>
+#ifdef __BIONIC__
#include <linux/vm_sockets.h>
+#endif //__BIONIC__
+
#include <sys/prctl.h>
#include <unistd.h>
@@ -186,8 +189,13 @@
static std::string allocateSocketAddress() {
static size_t id = 0;
+ static bool gUseTmp = access("/tmp/", F_OK) != -1;
- return "/dev/binderRpcTest_" + std::to_string(id++);
+ if (gUseTmp) {
+ return "/tmp/binderRpcTest_" + std::to_string(id++);
+ } else {
+ return "/dev/binderRpcTest_" + std::to_string(id++);
+ }
};
struct ProcessConnection {
@@ -241,14 +249,18 @@
enum class SocketType {
UNIX,
+#ifdef __BIONIC__
VSOCK,
+#endif // __BIONIC__
};
static inline std::string PrintSocketType(const testing::TestParamInfo<SocketType>& info) {
switch (info.param) {
case SocketType::UNIX:
return "unix_domain_socket";
+#ifdef __BIONIC__
case SocketType::VSOCK:
return "vm_socket";
+#endif // __BIONIC__
default:
LOG_ALWAYS_FATAL("Unknown socket type");
return "";
@@ -283,9 +295,11 @@
case SocketType::UNIX:
CHECK(connection->setupUnixDomainServer(addr.c_str())) << addr;
break;
+#ifdef __BIONIC__
case SocketType::VSOCK:
CHECK(connection->setupVsockServer(port));
break;
+#endif // __BIONIC__
default:
LOG_ALWAYS_FATAL("Unknown socket type");
}
@@ -311,9 +325,11 @@
case SocketType::UNIX:
if (ret.connection->addUnixDomainClient(addr.c_str())) goto success;
break;
+#ifdef __BIONIC__
case SocketType::VSOCK:
if (ret.connection->addVsockClient(VMADDR_CID_LOCAL, port)) goto success;
break;
+#endif // __BIONIC__
default:
LOG_ALWAYS_FATAL("Unknown socket type");
}
@@ -791,7 +807,13 @@
}
INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc,
- ::testing::Values(SocketType::UNIX, SocketType::VSOCK), PrintSocketType);
+ ::testing::Values(SocketType::UNIX
+#ifdef __BIONIC__
+ ,
+ SocketType::VSOCK
+#endif // __BIONIC__
+ ),
+ PrintSocketType);
} // namespace android