diff options
| author | 2023-07-29 00:43:43 +0000 | |
|---|---|---|
| committer | 2023-07-29 00:44:24 +0000 | |
| commit | 21e1447a7189b2d3e17797255b6a448de11b3c00 (patch) | |
| tree | ff8211ae9d09f30f383cbdb18e5353e1a92bc5f4 | |
| parent | a1681106e379fa6b3b67441980cce4e8744648f7 (diff) | |
libbinder_ndk_unit_test: avoid race
Avoid race where the test starts before the service
it is testing is started.
Bug: 290569617
Test: libbinder_ndk_unit_test
Change-Id: I487f1ce59c6d21c87c7b54bfd721da9883f0501b
| -rw-r--r-- | libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp index 27ce615565..089e55ffb1 100644 --- a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +++ b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp @@ -377,18 +377,24 @@ TEST(NdkBinder, CantHaveTwoLocalBinderClassesWithSameDescriptor) { } TEST(NdkBinder, GetTestServiceStressTest) { - // libbinder has some complicated logic to make sure only one instance of - // ABpBinder is associated with each binder. - constexpr size_t kNumThreads = 10; constexpr size_t kNumCalls = 1000; std::vector<std::thread> threads; + // this is not a lazy service, but we must make sure that it's started before calling + // checkService on it, since the other process serving it might not be started yet. + { + // getService, not waitForService, to take advantage of timeout + auto binder = ndk::SpAIBinder(AServiceManager_getService(IFoo::kSomeInstanceName)); + ASSERT_NE(nullptr, binder.get()); + } + for (size_t i = 0; i < kNumThreads; i++) { threads.push_back(std::thread([&]() { for (size_t j = 0; j < kNumCalls; j++) { auto binder = ndk::SpAIBinder(AServiceManager_checkService(IFoo::kSomeInstanceName)); + ASSERT_NE(nullptr, binder.get()); EXPECT_EQ(STATUS_OK, AIBinder_ping(binder.get())); } })); |