From 2c688c5163555df27f691b6076fa601a908a3302 Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Thu, 28 Mar 2024 20:12:46 +0000 Subject: Skip HIDL tests in libbinderthreadstate tests when HIDL isn't supported We can get/register the HIDL service if HIDL isn't supported on the device. Test: atest libbinderthreadstateutils_test Bug: 218588089 Change-Id: Ibfe89f6e029af3acccb93278e23243b0b81b2cd3 --- libs/binderthreadstate/test.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'libs/binderthreadstate') diff --git a/libs/binderthreadstate/test.cpp b/libs/binderthreadstate/test.cpp index b5c4010c7a..e888b0aea8 100644 --- a/libs/binderthreadstate/test.cpp +++ b/libs/binderthreadstate/test.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -37,6 +38,7 @@ using android::OK; using android::sp; using android::String16; using android::binder::Status; +using android::hardware::isHidlSupported; using android::hardware::Return; using binderthreadstateutilstest::V1_0::IHidlStuff; @@ -67,6 +69,7 @@ std::string id2name(size_t id) { // complicated calls are possible, but this should do here. static void callHidl(size_t id, int32_t idx) { + CHECK_EQ(true, isHidlSupported()) << "We shouldn't be calling HIDL if it's not supported"; auto stuff = IHidlStuff::getService(id2name(id)); CHECK(stuff->call(idx).isOk()); } @@ -174,6 +177,7 @@ TEST(BinderThreadState, DoesntInitializeBinderDriver) { } TEST(BindThreadState, RemoteHidlCall) { + if (!isHidlSupported()) GTEST_SKIP() << "No HIDL support on device"; auto stuff = IHidlStuff::getService(id2name(kP1Id)); ASSERT_NE(nullptr, stuff); ASSERT_TRUE(stuff->call(0).isOk()); @@ -186,11 +190,14 @@ TEST(BindThreadState, RemoteAidlCall) { } TEST(BindThreadState, RemoteNestedStartHidlCall) { + if (!isHidlSupported()) GTEST_SKIP() << "No HIDL support on device"; auto stuff = IHidlStuff::getService(id2name(kP1Id)); ASSERT_NE(nullptr, stuff); ASSERT_TRUE(stuff->call(100).isOk()); } TEST(BindThreadState, RemoteNestedStartAidlCall) { + // this test case is trying ot nest a HIDL call which requires HIDL support + if (!isHidlSupported()) GTEST_SKIP() << "No HIDL support on device"; sp stuff; ASSERT_EQ(OK, android::getService(String16(id2name(kP1Id).c_str()), &stuff)); ASSERT_NE(nullptr, stuff); @@ -205,11 +212,15 @@ int server(size_t thisId, size_t otherId) { defaultServiceManager()->addService(String16(id2name(thisId).c_str()), aidlServer)); android::ProcessState::self()->startThreadPool(); - // HIDL - android::hardware::configureRpcThreadpool(1, true /*callerWillJoin*/); - sp hidlServer = new HidlServer(thisId, otherId); - CHECK_EQ(OK, hidlServer->registerAsService(id2name(thisId).c_str())); - android::hardware::joinRpcThreadpool(); + if (isHidlSupported()) { + // HIDL + android::hardware::configureRpcThreadpool(1, true /*callerWillJoin*/); + sp hidlServer = new HidlServer(thisId, otherId); + CHECK_EQ(OK, hidlServer->registerAsService(id2name(thisId).c_str())); + android::hardware::joinRpcThreadpool(); + } else { + android::IPCThreadState::self()->joinThreadPool(true); + } return EXIT_FAILURE; } @@ -227,9 +238,15 @@ int main(int argc, char** argv) { } android::waitForService(String16(id2name(kP1Id).c_str())); - android::hardware::details::waitForHwService(IHidlStuff::descriptor, id2name(kP1Id).c_str()); + if (isHidlSupported()) { + android::hardware::details::waitForHwService(IHidlStuff::descriptor, + id2name(kP1Id).c_str()); + } android::waitForService(String16(id2name(kP2Id).c_str())); - android::hardware::details::waitForHwService(IHidlStuff::descriptor, id2name(kP2Id).c_str()); + if (isHidlSupported()) { + android::hardware::details::waitForHwService(IHidlStuff::descriptor, + id2name(kP2Id).c_str()); + } return RUN_ALL_TESTS(); } -- cgit v1.2.3-59-g8ed1b