diff options
| author | 2022-06-04 00:22:38 +0000 | |
|---|---|---|
| committer | 2022-06-04 00:22:38 +0000 | |
| commit | 604e7ee6b1552d97dd40666d15b95015e3902081 (patch) | |
| tree | 79d4b249a3e12e5b5262d081514df75ac43d5ff7 | |
| parent | bddea9364b29601ba11516504f5d32cf5999977d (diff) | |
| parent | a70c45dbfec0c6a05470459b5aba5e5ac6d348d3 (diff) | |
Merge "Initial RPC binder allocation test" am: a70c45dbfe
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2115894
Change-Id: I4e0c10b6aa8ad38a113d43345019c83f00123c58
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | libs/binder/tests/binderAllocationLimits.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/libs/binder/tests/binderAllocationLimits.cpp b/libs/binder/tests/binderAllocationLimits.cpp index e1f5ed5381..b14ec5550e 100644 --- a/libs/binder/tests/binderAllocationLimits.cpp +++ b/libs/binder/tests/binderAllocationLimits.cpp @@ -15,8 +15,11 @@ */ #include <android-base/logging.h> -#include <binder/Parcel.h> +#include <binder/Binder.h> #include <binder/IServiceManager.h> +#include <binder/Parcel.h> +#include <binder/RpcServer.h> +#include <binder/RpcSession.h> #include <gtest/gtest.h> #include <utils/CallStack.h> @@ -124,12 +127,18 @@ DestructionAction ScopeDisallowMalloc() { }); } +using android::BBinder; +using android::defaultServiceManager; using android::IBinder; +using android::IServiceManager; +using android::OK; using android::Parcel; -using android::String16; -using android::defaultServiceManager; +using android::RpcServer; +using android::RpcSession; using android::sp; -using android::IServiceManager; +using android::status_t; +using android::statusToString; +using android::String16; static sp<IBinder> GetRemoteBinder() { // This gets binder representing the service manager @@ -175,6 +184,34 @@ TEST(BinderAllocation, SmallTransaction) { EXPECT_EQ(mallocs, 1); } +TEST(RpcBinderAllocation, SetupRpcServer) { + std::string tmp = getenv("TMPDIR") ?: "/tmp"; + std::string addr = tmp + "/binderRpcBenchmark"; + (void)unlink(addr.c_str()); + auto server = RpcServer::make(); + server->setRootObject(sp<BBinder>::make()); + + CHECK_EQ(OK, server->setupUnixDomainServer(addr.c_str())); + + std::thread([server]() { server->join(); }).detach(); + + status_t status; + auto session = RpcSession::make(); + status = session->setupUnixDomainClient(addr.c_str()); + CHECK_EQ(status, OK) << "Could not connect: " << addr << ": " << statusToString(status).c_str(); + + auto remoteBinder = session->getRootObject(); + + size_t mallocs = 0, totalBytes = 0; + const auto on_malloc = OnMalloc([&](size_t bytes) { + mallocs++; + totalBytes += bytes; + }); + CHECK_EQ(OK, remoteBinder->pingBinder()); + EXPECT_EQ(mallocs, 4); + EXPECT_EQ(totalBytes, 108); +} + int main(int argc, char** argv) { if (getenv("LIBC_HOOKS_ENABLE") == nullptr) { CHECK(0 == setenv("LIBC_HOOKS_ENABLE", "1", true /*overwrite*/)); |