Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb9be55f authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "libbinder_ndk_unit_test: avoid race" into main

parents ded9bda9 21e1447a
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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()));
            }
        }));