Loading libs/binder/Android.bp +3 −1 Original line number Diff line number Diff line Loading @@ -359,6 +359,7 @@ cc_library { cc_library_static { name: "libbinder_rpc_no_kernel", vendor_available: true, defaults: [ "libbinder_common_defaults", "libbinder_android_defaults", Loading Loading @@ -411,6 +412,7 @@ cc_defaults { cc_defaults { name: "libbinder_tls_defaults", defaults: ["libbinder_tls_shared_deps"], vendor_available: true, host_supported: true, header_libs: [ Loading @@ -437,7 +439,7 @@ cc_library_shared { defaults: ["libbinder_tls_defaults"], } cc_library_shared { cc_library { name: "libbinder_trusty", vendor: true, srcs: [ Loading libs/binder/tests/Android.bp +33 −0 Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ cc_test { aidl_interface { name: "binderRpcTestIface", vendor_available: true, host_supported: true, unstable: true, srcs: [ Loading @@ -159,6 +160,7 @@ aidl_interface { cc_library_static { name: "libbinder_tls_test_utils", host_supported: true, vendor_available: true, target: { darwin: { enabled: false, Loading Loading @@ -440,6 +442,37 @@ cc_test { ], } cc_test { name: "binderRpcToTrustyTest", vendor: true, host_supported: false, defaults: [ "binderRpcTest_common_defaults", "binderRpcTest_static_defaults", ], srcs: [ "binderRpcTest.cpp", "binderRpcTestCommon.cpp", "binderRpcUniversalTests.cpp", ], cflags: [ "-DBINDER_RPC_TO_TRUSTY_TEST", ], static_libs: [ // We want to link libbinder statically so we can push the binary // to the device for testing independently of the library "libbinder_rpc_no_kernel", "libbinder_trusty", "libtrusty", ], test_suites: ["device-tests"], require_root: true, } cc_test { name: "RpcTlsUtilsTest", host_supported: true, Loading libs/binder/tests/binderRpcTest.cpp +17 −28 Original line number Diff line number Diff line Loading @@ -28,10 +28,10 @@ #include <sys/prctl.h> #include <sys/socket.h> #ifdef __ANDROID_VENDOR__ #ifdef BINDER_RPC_TO_TRUSTY_TEST #include <binder/RpcTransportTipcAndroid.h> #include <trusty/tipc.h> #endif // __ANDROID_VENDOR__ #endif // BINDER_RPC_TO_TRUSTY_TEST #include "binderRpcTestCommon.h" #include "binderRpcTestFixture.h" Loading @@ -50,7 +50,7 @@ constexpr bool kEnableSharedLibs = false; constexpr bool kEnableSharedLibs = true; #endif #ifdef __ANDROID_VENDOR__ #ifdef BINDER_RPC_TO_TRUSTY_TEST constexpr char kTrustyIpcDevice[] = "/dev/trusty-ipc-dev0"; #endif Loading Loading @@ -214,6 +214,7 @@ static base::unique_fd connectTo(const RpcSocketAddress& addr) { return serverFd; } #ifndef BINDER_RPC_TO_TRUSTY_TEST static base::unique_fd connectToUnixBootstrap(const RpcTransportFd& transportFd) { base::unique_fd sockClient, sockServer; if (!base::Socketpair(SOCK_STREAM, &sockClient, &sockServer)) { Loading @@ -232,6 +233,7 @@ static base::unique_fd connectToUnixBootstrap(const RpcTransportFd& transportFd) } return std::move(sockClient); } #endif // BINDER_RPC_TO_TRUSTY_TEST std::unique_ptr<RpcTransportCtxFactory> BinderRpc::newFactory(RpcSecurity rpcSecurity) { return newTlsFactory(rpcSecurity); Loading Loading @@ -308,7 +310,7 @@ std::unique_ptr<ProcessSession> BinderRpc::createRpcTestSocketServerProcessEtc( for (size_t i = 0; i < options.numSessions; i++) { std::unique_ptr<RpcTransportCtxFactory> factory; if (socketType == SocketType::TIPC) { #ifdef __ANDROID_VENDOR__ #ifdef BINDER_RPC_TO_TRUSTY_TEST factory = RpcTransportCtxFactoryTipcAndroid::make(); #else LOG_ALWAYS_FATAL("TIPC socket type only supported on vendor"); Loading Loading @@ -378,7 +380,7 @@ std::unique_ptr<ProcessSession> BinderRpc::createRpcTestSocketServerProcessEtc( break; case SocketType::TIPC: status = session->setupPreconnectedClient({}, [=]() { #ifdef __ANDROID_VENDOR__ #ifdef BINDER_RPC_TO_TRUSTY_TEST auto port = trustyIpcPort(serverVersion); int tipcFd = tipc_connect(kTrustyIpcDevice, port.c_str()); return tipcFd >= 0 ? android::base::unique_fd(tipcFd) Loading Loading @@ -1102,6 +1104,15 @@ TEST_P(BinderRpc, Fds) { ASSERT_EQ(beforeFds, countFds()) << (system("ls -l /proc/self/fd/"), "fd leak?"); } #ifdef BINDER_RPC_TO_TRUSTY_TEST INSTANTIATE_TEST_CASE_P(Trusty, BinderRpc, ::testing::Combine(::testing::Values(SocketType::TIPC), ::testing::Values(RpcSecurity::RAW), ::testing::ValuesIn(testVersions()), ::testing::ValuesIn(testVersions()), ::testing::Values(true), ::testing::Values(true)), BinderRpc::PrintParamInfo); #else // BINDER_RPC_TO_TRUSTY_TEST static bool testSupportVsockLoopback() { // We don't need to enable TLS to know if vsock is supported. unsigned int vsockPort = allocateVsockPort(); Loading Loading @@ -1206,21 +1217,6 @@ static std::vector<SocketType> testSocketTypes(bool hasPreconnected = true) { return ret; } static std::vector<SocketType> testTipcSocketTypes() { #ifdef __ANDROID_VENDOR__ auto port = trustyIpcPort(RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL); int tipcFd = tipc_connect(kTrustyIpcDevice, port.c_str()); if (tipcFd >= 0) { close(tipcFd); return {SocketType::TIPC}; } #endif // __ANDROID_VENDOR__ // TIPC is not supported on this device, most likely // because /dev/trusty-ipc-dev0 is missing return {}; } INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc, ::testing::Combine(::testing::ValuesIn(testSocketTypes()), ::testing::ValuesIn(RpcSecurityValues()), Loading @@ -1230,14 +1226,6 @@ INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc, ::testing::Values(false, true)), BinderRpc::PrintParamInfo); INSTANTIATE_TEST_CASE_P(Trusty, BinderRpc, ::testing::Combine(::testing::ValuesIn(testTipcSocketTypes()), ::testing::Values(RpcSecurity::RAW), ::testing::ValuesIn(testVersions()), ::testing::ValuesIn(testVersions()), ::testing::Values(true), ::testing::Values(true)), BinderRpc::PrintParamInfo); class BinderRpcServerRootObject : public ::testing::TestWithParam<std::tuple<bool, bool, RpcSecurity>> {}; Loading Loading @@ -2006,6 +1994,7 @@ INSTANTIATE_TEST_CASE_P( testing::Values(RpcKeyFormat::PEM, RpcKeyFormat::DER), testing::ValuesIn(testVersions())), RpcTransportTlsKeyTest::PrintParamInfo); #endif // BINDER_RPC_TO_TRUSTY_TEST } // namespace android Loading Loading
libs/binder/Android.bp +3 −1 Original line number Diff line number Diff line Loading @@ -359,6 +359,7 @@ cc_library { cc_library_static { name: "libbinder_rpc_no_kernel", vendor_available: true, defaults: [ "libbinder_common_defaults", "libbinder_android_defaults", Loading Loading @@ -411,6 +412,7 @@ cc_defaults { cc_defaults { name: "libbinder_tls_defaults", defaults: ["libbinder_tls_shared_deps"], vendor_available: true, host_supported: true, header_libs: [ Loading @@ -437,7 +439,7 @@ cc_library_shared { defaults: ["libbinder_tls_defaults"], } cc_library_shared { cc_library { name: "libbinder_trusty", vendor: true, srcs: [ Loading
libs/binder/tests/Android.bp +33 −0 Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ cc_test { aidl_interface { name: "binderRpcTestIface", vendor_available: true, host_supported: true, unstable: true, srcs: [ Loading @@ -159,6 +160,7 @@ aidl_interface { cc_library_static { name: "libbinder_tls_test_utils", host_supported: true, vendor_available: true, target: { darwin: { enabled: false, Loading Loading @@ -440,6 +442,37 @@ cc_test { ], } cc_test { name: "binderRpcToTrustyTest", vendor: true, host_supported: false, defaults: [ "binderRpcTest_common_defaults", "binderRpcTest_static_defaults", ], srcs: [ "binderRpcTest.cpp", "binderRpcTestCommon.cpp", "binderRpcUniversalTests.cpp", ], cflags: [ "-DBINDER_RPC_TO_TRUSTY_TEST", ], static_libs: [ // We want to link libbinder statically so we can push the binary // to the device for testing independently of the library "libbinder_rpc_no_kernel", "libbinder_trusty", "libtrusty", ], test_suites: ["device-tests"], require_root: true, } cc_test { name: "RpcTlsUtilsTest", host_supported: true, Loading
libs/binder/tests/binderRpcTest.cpp +17 −28 Original line number Diff line number Diff line Loading @@ -28,10 +28,10 @@ #include <sys/prctl.h> #include <sys/socket.h> #ifdef __ANDROID_VENDOR__ #ifdef BINDER_RPC_TO_TRUSTY_TEST #include <binder/RpcTransportTipcAndroid.h> #include <trusty/tipc.h> #endif // __ANDROID_VENDOR__ #endif // BINDER_RPC_TO_TRUSTY_TEST #include "binderRpcTestCommon.h" #include "binderRpcTestFixture.h" Loading @@ -50,7 +50,7 @@ constexpr bool kEnableSharedLibs = false; constexpr bool kEnableSharedLibs = true; #endif #ifdef __ANDROID_VENDOR__ #ifdef BINDER_RPC_TO_TRUSTY_TEST constexpr char kTrustyIpcDevice[] = "/dev/trusty-ipc-dev0"; #endif Loading Loading @@ -214,6 +214,7 @@ static base::unique_fd connectTo(const RpcSocketAddress& addr) { return serverFd; } #ifndef BINDER_RPC_TO_TRUSTY_TEST static base::unique_fd connectToUnixBootstrap(const RpcTransportFd& transportFd) { base::unique_fd sockClient, sockServer; if (!base::Socketpair(SOCK_STREAM, &sockClient, &sockServer)) { Loading @@ -232,6 +233,7 @@ static base::unique_fd connectToUnixBootstrap(const RpcTransportFd& transportFd) } return std::move(sockClient); } #endif // BINDER_RPC_TO_TRUSTY_TEST std::unique_ptr<RpcTransportCtxFactory> BinderRpc::newFactory(RpcSecurity rpcSecurity) { return newTlsFactory(rpcSecurity); Loading Loading @@ -308,7 +310,7 @@ std::unique_ptr<ProcessSession> BinderRpc::createRpcTestSocketServerProcessEtc( for (size_t i = 0; i < options.numSessions; i++) { std::unique_ptr<RpcTransportCtxFactory> factory; if (socketType == SocketType::TIPC) { #ifdef __ANDROID_VENDOR__ #ifdef BINDER_RPC_TO_TRUSTY_TEST factory = RpcTransportCtxFactoryTipcAndroid::make(); #else LOG_ALWAYS_FATAL("TIPC socket type only supported on vendor"); Loading Loading @@ -378,7 +380,7 @@ std::unique_ptr<ProcessSession> BinderRpc::createRpcTestSocketServerProcessEtc( break; case SocketType::TIPC: status = session->setupPreconnectedClient({}, [=]() { #ifdef __ANDROID_VENDOR__ #ifdef BINDER_RPC_TO_TRUSTY_TEST auto port = trustyIpcPort(serverVersion); int tipcFd = tipc_connect(kTrustyIpcDevice, port.c_str()); return tipcFd >= 0 ? android::base::unique_fd(tipcFd) Loading Loading @@ -1102,6 +1104,15 @@ TEST_P(BinderRpc, Fds) { ASSERT_EQ(beforeFds, countFds()) << (system("ls -l /proc/self/fd/"), "fd leak?"); } #ifdef BINDER_RPC_TO_TRUSTY_TEST INSTANTIATE_TEST_CASE_P(Trusty, BinderRpc, ::testing::Combine(::testing::Values(SocketType::TIPC), ::testing::Values(RpcSecurity::RAW), ::testing::ValuesIn(testVersions()), ::testing::ValuesIn(testVersions()), ::testing::Values(true), ::testing::Values(true)), BinderRpc::PrintParamInfo); #else // BINDER_RPC_TO_TRUSTY_TEST static bool testSupportVsockLoopback() { // We don't need to enable TLS to know if vsock is supported. unsigned int vsockPort = allocateVsockPort(); Loading Loading @@ -1206,21 +1217,6 @@ static std::vector<SocketType> testSocketTypes(bool hasPreconnected = true) { return ret; } static std::vector<SocketType> testTipcSocketTypes() { #ifdef __ANDROID_VENDOR__ auto port = trustyIpcPort(RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL); int tipcFd = tipc_connect(kTrustyIpcDevice, port.c_str()); if (tipcFd >= 0) { close(tipcFd); return {SocketType::TIPC}; } #endif // __ANDROID_VENDOR__ // TIPC is not supported on this device, most likely // because /dev/trusty-ipc-dev0 is missing return {}; } INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc, ::testing::Combine(::testing::ValuesIn(testSocketTypes()), ::testing::ValuesIn(RpcSecurityValues()), Loading @@ -1230,14 +1226,6 @@ INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc, ::testing::Values(false, true)), BinderRpc::PrintParamInfo); INSTANTIATE_TEST_CASE_P(Trusty, BinderRpc, ::testing::Combine(::testing::ValuesIn(testTipcSocketTypes()), ::testing::Values(RpcSecurity::RAW), ::testing::ValuesIn(testVersions()), ::testing::ValuesIn(testVersions()), ::testing::Values(true), ::testing::Values(true)), BinderRpc::PrintParamInfo); class BinderRpcServerRootObject : public ::testing::TestWithParam<std::tuple<bool, bool, RpcSecurity>> {}; Loading Loading @@ -2006,6 +1994,7 @@ INSTANTIATE_TEST_CASE_P( testing::Values(RpcKeyFormat::PEM, RpcKeyFormat::DER), testing::ValuesIn(testVersions())), RpcTransportTlsKeyTest::PrintParamInfo); #endif // BINDER_RPC_TO_TRUSTY_TEST } // namespace android Loading