From bd27655fcee7b0170d4bb45504f6896803f7c177 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 28 Feb 2022 15:28:51 -0800 Subject: binder: Fix setRpcClientDebug in binderLibTest. Similar to binderRpcTest, the test may run on VTS on a user build. In this case setRpcClientDebug is not available. Check return code accordingly. Test: TH Fixes: 221186690 Change-Id: Ib86c6f98af5652d8db0185b1889c154842a33adb --- libs/binder/tests/binderLibTest.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp index 63a4b2cc68..fc8776b0d0 100644 --- a/libs/binder/tests/binderLibTest.cpp +++ b/libs/binder/tests/binderLibTest.cpp @@ -57,6 +57,7 @@ using namespace std::chrono_literals; using android::base::testing::HasValue; using android::base::testing::Ok; using testing::ExplainMatchResult; +using testing::Matcher; using testing::Not; using testing::WithParamInterface; @@ -1245,12 +1246,23 @@ public: class BinderLibRpcTest : public BinderLibRpcTestBase {}; +// e.g. EXPECT_THAT(expr, Debuggable(StatusEq(...)) +// If device is debuggable AND not on user builds, expects matcher. +// Otherwise expects INVALID_OPERATION. +// Debuggable + non user builds is necessary but not sufficient for setRpcClientDebug to work. +static Matcher Debuggable(const Matcher &matcher) { + bool isDebuggable = android::base::GetBoolProperty("ro.debuggable", false) && + android::base::GetProperty("ro.build.type", "") != "user"; + return isDebuggable ? matcher : StatusEq(INVALID_OPERATION); +} + TEST_F(BinderLibRpcTest, SetRpcClientDebug) { auto binder = addServer(); ASSERT_TRUE(binder != nullptr); auto [socket, port] = CreateSocket(); ASSERT_TRUE(socket.ok()); - EXPECT_THAT(binder->setRpcClientDebug(std::move(socket), sp::make()), StatusEq(OK)); + EXPECT_THAT(binder->setRpcClientDebug(std::move(socket), sp::make()), + Debuggable(StatusEq(OK))); } // Tests for multiple RpcServer's on the same binder object. @@ -1261,12 +1273,14 @@ TEST_F(BinderLibRpcTest, SetRpcClientDebugTwice) { auto [socket1, port1] = CreateSocket(); ASSERT_TRUE(socket1.ok()); auto keepAliveBinder1 = sp::make(); - EXPECT_THAT(binder->setRpcClientDebug(std::move(socket1), keepAliveBinder1), StatusEq(OK)); + EXPECT_THAT(binder->setRpcClientDebug(std::move(socket1), keepAliveBinder1), + Debuggable(StatusEq(OK))); auto [socket2, port2] = CreateSocket(); ASSERT_TRUE(socket2.ok()); auto keepAliveBinder2 = sp::make(); - EXPECT_THAT(binder->setRpcClientDebug(std::move(socket2), keepAliveBinder2), StatusEq(OK)); + EXPECT_THAT(binder->setRpcClientDebug(std::move(socket2), keepAliveBinder2), + Debuggable(StatusEq(OK))); } // Negative tests for RPC APIs on IBinder. Call should fail in the same way on both remote and @@ -1285,7 +1299,7 @@ TEST_P(BinderLibRpcTestP, SetRpcClientDebugNoFd) { auto binder = GetService(); ASSERT_TRUE(binder != nullptr); EXPECT_THAT(binder->setRpcClientDebug(android::base::unique_fd(), sp::make()), - StatusEq(BAD_VALUE)); + Debuggable(StatusEq(BAD_VALUE))); } TEST_P(BinderLibRpcTestP, SetRpcClientDebugNoKeepAliveBinder) { @@ -1293,7 +1307,8 @@ TEST_P(BinderLibRpcTestP, SetRpcClientDebugNoKeepAliveBinder) { ASSERT_TRUE(binder != nullptr); auto [socket, port] = CreateSocket(); ASSERT_TRUE(socket.ok()); - EXPECT_THAT(binder->setRpcClientDebug(std::move(socket), nullptr), StatusEq(UNEXPECTED_NULL)); + EXPECT_THAT(binder->setRpcClientDebug(std::move(socket), nullptr), + Debuggable(StatusEq(UNEXPECTED_NULL))); } INSTANTIATE_TEST_CASE_P(BinderLibTest, BinderLibRpcTestP, testing::Bool(), BinderLibRpcTestP::ParamToString); -- cgit v1.2.3-59-g8ed1b