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

Commit 83ed6289 authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder_ndk: stress test for retrieving binders

The logic is a bit complicated.

Fixes: 192321823
Test: fails every time w/o fix, works with fix
Change-Id: I6b4bb126a9fe1fa6d2b39a05805b3a14f53f1a7b
parent 91a96b64
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>
#include "android/binder_ibinder.h"

using namespace android;
@@ -250,6 +251,27 @@ TEST(NdkBinder, DoubleNumber) {
    EXPECT_EQ(2, out);
}

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;

    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));
                EXPECT_EQ(STATUS_OK, AIBinder_ping(binder.get()));
            }
        }));
    }

    for (auto& thread : threads) thread.join();
}

void defaultInstanceCounter(const char* instance, void* context) {
    if (strcmp(instance, "default") == 0) {
        ++*(size_t*)(context);