diff options
author | 2021-07-01 01:29:24 +0000 | |
---|---|---|
committer | 2021-07-01 01:29:24 +0000 | |
commit | 2bfbdffc26b4da2670a74b8fef640fa3741ad229 (patch) | |
tree | 155cdc9a594f9b1dafc892884eea165f6d2c8944 /libs | |
parent | af45ec09d0856112087f3296a5fe7a9ac2ae3f17 (diff) | |
parent | 83ed6289dbd1dff7873ecbecf5d2f914827a4624 (diff) |
Merge "libbinder_ndk: stress test for retrieving binders"
Diffstat (limited to 'libs')
-rw-r--r-- | libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp index 1c43948930..5ad390e107 100644 --- a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +++ b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp @@ -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); |