diff options
author | Devin Moore <devinmoore@google.com> | 2024-01-13 03:31:16 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-01-13 03:31:16 +0000 |
commit | 975680af0b97a3f9790c8560b602340fb6b3b574 (patch) | |
tree | 057dfbe33c594257a612532c9bea805766031d8e | |
parent | 352ab810bc1bd0f74dd38e416828fb52394901b3 (diff) | |
parent | 53d54b39c81f64e517dcfc146ad9a34d5a112331 (diff) | |
download | hidl-975680af0b97a3f9790c8560b602340fb6b3b574.tar.gz |
hidl_test(_java) handle missing ashmem allocator am: 77649f5792 am: 702addabff am: 53d54b39c8
Original change: https://android-review.googlesource.com/c/platform/system/tools/hidl/+/2904968
Change-Id: I3092be9d89a18d0797ab16b5294f6f69b3cc3b62
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | test/hidl_test/hidl_test_client.cpp | 20 | ||||
-rw-r--r-- | test/java_test/hidl_test_java_native.cpp | 13 | ||||
-rw-r--r-- | test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java | 8 |
3 files changed, 31 insertions, 10 deletions
diff --git a/test/hidl_test/hidl_test_client.cpp b/test/hidl_test/hidl_test_client.cpp index 55490d28..614ffdbc 100644 --- a/test/hidl_test/hidl_test_client.cpp +++ b/test/hidl_test/hidl_test_client.cpp @@ -367,15 +367,20 @@ public: ASSERT_NE(manager, nullptr); ASSERT_TRUE(manager->isRemote()); // manager is always remote - // Token manager only exists on devices before Android V - tokenManager = ITokenManager::getService(); - if (tokenManager) { + if (IServiceManager::Transport::EMPTY != + manager->getTransport(ITokenManager::descriptor, "default")) { + // Token manager only exists on devices before Android V + tokenManager = ITokenManager::getService(); + ASSERT_TRUE(tokenManager); ASSERT_TRUE(tokenManager->isRemote()); // tokenManager is always remote } - ashmemAllocator = IAllocator::getService("ashmem"); - ASSERT_NE(ashmemAllocator, nullptr); - ASSERT_TRUE(ashmemAllocator->isRemote()); // allocator is always remote + if (IServiceManager::Transport::EMPTY != + manager->getTransport(IAllocator::descriptor, "ashmem")) { + ashmemAllocator = IAllocator::getService("ashmem"); + ASSERT_NE(ashmemAllocator, nullptr); + ASSERT_TRUE(ashmemAllocator->isRemote()); // allocator is always remote + } // getStub is true if we are in passthrough mode to skip checking // binderized server, false for binderized mode. @@ -897,6 +902,7 @@ TEST_F(HidlTest, TestToken) { } TEST_F(HidlTest, TestSharedMemory) { + if (!ashmemAllocator) GTEST_SKIP() << "ashmem allocator is not on the device"; const uint8_t kValue = 0xCA; hidl_memory mem_copy; EXPECT_OK(ashmemAllocator->allocate(1024, [&](bool success, const hidl_memory& mem) { @@ -960,6 +966,7 @@ TEST_F(HidlTest, TestSharedMemory) { } TEST_F(HidlTest, BatchSharedMemory) { + if (!ashmemAllocator) GTEST_SKIP() << "ashmem allocator is not on the device"; const uint8_t kValue = 0xCA; const uint64_t kBatchSize = 2; hidl_vec<hidl_memory> batchCopy; @@ -1009,6 +1016,7 @@ TEST_F(HidlTest, BatchSharedMemory) { } TEST_F(HidlTest, MemoryBlock) { + if (!ashmemAllocator) GTEST_SKIP() << "ashmem allocator is not on the device"; const uint8_t kValue = 0xCA; using ::android::hardware::IBinder; using ::android::hardware::interfacesEqual; diff --git a/test/java_test/hidl_test_java_native.cpp b/test/java_test/hidl_test_java_native.cpp index 9827f072..149a17bf 100644 --- a/test/java_test/hidl_test_java_native.cpp +++ b/test/java_test/hidl_test_java_native.cpp @@ -1278,9 +1278,16 @@ int main(int argc, char **argv) { status = registerPassthroughServiceImplementation<ISafeUnion>(); CHECK(status == ::android::OK) << "ISafeUnion didn't register"; - sp<IMemoryInterface> memoryInterface = new MemoryInterface(); - status = memoryInterface->registerAsService(); - CHECK(status == ::android::OK) << "IMemoryInterface didn't register"; + using android::hardware::defaultServiceManager; + using android::hidl::manager::V1_0::IServiceManager; + // If the android.hidl.allocator service isn't on the device, then don't + // create or register the MemoryInterface + if (IServiceManager::Transport::EMPTY != + defaultServiceManager()->getTransport(IAllocator::descriptor, "ashmem")) { + sp<IMemoryInterface> memoryInterface = new MemoryInterface(); + status = memoryInterface->registerAsService(); + CHECK(status == ::android::OK) << "IMemoryInterface didn't register"; + } joinRpcThreadpool(); return 0; diff --git a/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java b/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java index 47adad8f..0999a92a 100644 --- a/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java +++ b/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java @@ -245,7 +245,13 @@ public final class HidlTestJava { } private void runClientMemoryTests() throws RemoteException, IOException, ErrnoException { - IMemoryInterface memoryInterface = IMemoryInterface.getService(); + IMemoryInterface memoryInterface; + try { + memoryInterface = IMemoryInterface.getService(); + } catch (NoSuchElementException e) { + // If the test didn't register the memory interface, don't try to test it. + return; + } { HidlMemory hidlMem = HidlMemoryUtil.byteArrayToHidlMemory( |