Limit threads in pthread_leak#detach for low power devices.
This patch decreases created threads to 90 (instead of 100)
on devices with 2 cores CPU. This test can fail with timeout
on such devices.
Bug: b/129924384
Test: Run CtsBionic module on 2 core device with command
"run cts -m CtsBionicTestCases"
Change-Id: Ic770006a324748d7d6dfbe8d4fb301e21e494ff9
Signed-off-by: Dmytro Chystiakov <dmytro.chystiakov@intel.com>
diff --git a/tests/leak_test.cpp b/tests/leak_test.cpp
index 1fa9e56..6005209 100644
--- a/tests/leak_test.cpp
+++ b/tests/leak_test.cpp
@@ -124,17 +124,22 @@
// http://b/36045112
TEST(pthread_leak, detach) {
LeakChecker lc;
+ constexpr int kThreadCount = 100;
- for (size_t pass = 0; pass < 2; ++pass) {
- constexpr int kThreadCount = 100;
+ // Devices with low power cores/low number of cores can not finish test in time hence decreasing
+ // threads count to 90.
+ // http://b/129924384.
+ int threads_count = (sysconf(_SC_NPROCESSORS_CONF) > 2) ? kThreadCount : (kThreadCount - 10);
+
+ for (size_t pass = 0; pass < 1; ++pass) {
struct thread_data { pthread_barrier_t* barrier; pid_t* tid; } threads[kThreadCount] = {};
pthread_barrier_t barrier;
- ASSERT_EQ(pthread_barrier_init(&barrier, nullptr, kThreadCount + 1), 0);
+ ASSERT_EQ(pthread_barrier_init(&barrier, nullptr, threads_count + 1), 0);
// Start child threads.
pid_t tids[kThreadCount];
- for (int i = 0; i < kThreadCount; ++i) {
+ for (int i = 0; i < threads_count; ++i) {
threads[i] = {&barrier, &tids[i]};
const auto thread_function = +[](void* ptr) -> void* {
thread_data* data = static_cast<thread_data*>(ptr);