diff options
author | 2023-03-22 21:05:13 +0000 | |
---|---|---|
committer | 2023-03-22 21:08:50 +0000 | |
commit | d62b89be28994b5be57b0b1587e201a11b99c97e (patch) | |
tree | 568d7e4635690a9464b9f2f5ce913117186cd576 /libs/binderthreadstate/test.cpp | |
parent | 00be693277ce4d26ab98589abb01ac5a628cb835 (diff) |
libbinderthreadstateutils: don't init binder
Don't initialize binder/hwbinder thread state if they
aren't already initialized. This is fine - if we
know they aren't initialized, then there is no binder
call going.
Bug: 205282403
Test: libbinderthreadstateutils_test
TesT: binderRpcTest (because it uses these APIs in a special way)
Change-Id: Id67010bb15559e85dd764746525562acc7e1f13c
Diffstat (limited to 'libs/binderthreadstate/test.cpp')
-rw-r--r-- | libs/binderthreadstate/test.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libs/binderthreadstate/test.cpp b/libs/binderthreadstate/test.cpp index df1f35d9a7..b5c4010c7a 100644 --- a/libs/binderthreadstate/test.cpp +++ b/libs/binderthreadstate/test.cpp @@ -16,11 +16,16 @@ #include <BnAidlStuff.h> #include <android-base/logging.h> +#include <binder/IPCThreadState.h> #include <binder/IServiceManager.h> #include <binderthreadstate/CallerUtils.h> #include <binderthreadstateutilstest/1.0/IHidlStuff.h> #include <gtest/gtest.h> #include <hidl/HidlTransportSupport.h> +#include <hwbinder/IPCThreadState.h> + +#include <thread> + #include <linux/prctl.h> #include <sys/prctl.h> @@ -154,6 +159,20 @@ TEST(BinderThreadState, LocalAidlCall) { EXPECT_TRUE(server->callLocal().isOk()); } +TEST(BinderThreadState, DoesntInitializeBinderDriver) { + // this is on another thread, because it's testing thread-specific + // state and we expect it not to be initialized. + std::thread([&] { + EXPECT_EQ(nullptr, android::IPCThreadState::selfOrNull()); + EXPECT_EQ(nullptr, android::hardware::IPCThreadState::selfOrNull()); + + (void)getCurrentServingCall(); + + EXPECT_EQ(nullptr, android::IPCThreadState::selfOrNull()); + EXPECT_EQ(nullptr, android::hardware::IPCThreadState::selfOrNull()); + }).join(); +} + TEST(BindThreadState, RemoteHidlCall) { auto stuff = IHidlStuff::getService(id2name(kP1Id)); ASSERT_NE(nullptr, stuff); |