From a83191de9ba60097f0d6f923cc8f633d2076e4f5 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Wed, 27 Oct 2021 10:14:53 -0700 Subject: binderRpcTest: fix CallingId test failure This test was failing on-device only, and only when certain other tests were run on it (after ProcessState detects fork). This is an example of where the fork detection logic is actually being over zealous (we didn't use kernel binder in the other process, so we actually introduce an abort). However, this is incorrect usage, and the other process couldn't actually use kernel binder for this reason. Global state: not even once! Fixes: 204265622 Test: binderRpcTest (as a whole and also these specific cases, on host and on device) Change-Id: Id5bceb596127479e3156bb548ecbe4f60f4f4f0a --- libs/binder/tests/binderRpcTest.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp index 7bbe3d7724..55ad3c6975 100644 --- a/libs/binder/tests/binderRpcTest.cpp +++ b/libs/binder/tests/binderRpcTest.cpp @@ -1303,11 +1303,20 @@ TEST_P(BinderRpc, Die) { } TEST_P(BinderRpc, UseKernelBinderCallingId) { + bool okToFork = ProcessState::selfOrNull() == nullptr; + auto proc = createRpcTestSocketServerProcess({}); - // we can't allocate IPCThreadState so actually the first time should - // succeed :( - EXPECT_OK(proc.rootIface->useKernelBinderCallingId()); + // If this process has used ProcessState already, then the forked process + // cannot use it at all. If this process hasn't used it (depending on the + // order tests are run), then the forked process can use it, and we'll only + // catch the invalid usage the second time. Such is the burden of global + // state! + if (okToFork) { + // we can't allocate IPCThreadState so actually the first time should + // succeed :( + EXPECT_OK(proc.rootIface->useKernelBinderCallingId()); + } // second time! we catch the error :) EXPECT_EQ(DEAD_OBJECT, proc.rootIface->useKernelBinderCallingId().transactionError()); @@ -1999,5 +2008,6 @@ INSTANTIATE_TEST_CASE_P( int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); android::base::InitLogging(argv, android::base::StderrLogger, android::base::DefaultAborter); + return RUN_ALL_TESTS(); } -- cgit v1.2.3-59-g8ed1b