aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Moore <devinmoore@google.com>2024-01-13 02:17:23 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-01-13 02:17:23 +0000
commit53d54b39c81f64e517dcfc146ad9a34d5a112331 (patch)
tree057dfbe33c594257a612532c9bea805766031d8e
parente23db0a986e032e39a8a7085465be5778e0067e7 (diff)
parent702addabffe52bf594cfe74cb35fb4b7dbb186cd (diff)
downloadhidl-53d54b39c81f64e517dcfc146ad9a34d5a112331.tar.gz
hidl_test(_java) handle missing ashmem allocator am: 77649f5792 am: 702addabff
Original change: https://android-review.googlesource.com/c/platform/system/tools/hidl/+/2904968 Change-Id: If5e2743f53501cdd8863861039ed8fda27f086a7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--test/hidl_test/hidl_test_client.cpp20
-rw-r--r--test/java_test/hidl_test_java_native.cpp13
-rw-r--r--test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java8
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(