summaryrefslogtreecommitdiff
path: root/tests/pthread_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/pthread_test.cpp')
-rw-r--r--tests/pthread_test.cpp57
1 files changed, 52 insertions, 5 deletions
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index d8257381c..1a00460bc 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -38,13 +38,15 @@
#include <android-base/macros.h>
#include <android-base/parseint.h>
#include <android-base/scopeguard.h>
+#include <android-base/silent_death_test.h>
#include <android-base/strings.h>
#include "private/bionic_constants.h"
-#include "BionicDeathTest.h"
#include "SignalUtils.h"
#include "utils.h"
+using pthread_DeathTest = SilentDeathTest;
+
TEST(pthread, pthread_key_create) {
pthread_key_t key;
ASSERT_EQ(0, pthread_key_create(&key, nullptr));
@@ -352,9 +354,6 @@ struct TestBug37410 {
// Even though this isn't really a death test, we have to say "DeathTest" here so gtest knows to
// run this test (which exits normally) in its own process.
-
-class pthread_DeathTest : public BionicDeathTest {};
-
TEST_F(pthread_DeathTest, pthread_bug_37410) {
// http://code.google.com/p/android/issues/detail?id=37410
ASSERT_EXIT(TestBug37410::main(), ::testing::ExitedWithCode(0), "");
@@ -2468,7 +2467,7 @@ TEST(pthread, pthread_mutex_clocklock_invalid) {
#endif // __BIONIC__
}
-TEST(pthread, pthread_mutex_using_destroyed_mutex) {
+TEST_F(pthread_DeathTest, pthread_mutex_using_destroyed_mutex) {
#if defined(__BIONIC__)
pthread_mutex_t m;
ASSERT_EQ(0, pthread_mutex_init(&m, nullptr));
@@ -2821,6 +2820,9 @@ TEST(pthread, pthread_attr_getdetachstate__pthread_attr_setdetachstate) {
}
TEST(pthread, pthread_create__mmap_failures) {
+ // After thread is successfully created, native_bridge might need more memory to run it.
+ SKIP_WITH_NATIVE_BRIDGE;
+
pthread_attr_t attr;
ASSERT_EQ(0, pthread_attr_init(&attr));
ASSERT_EQ(0, pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED));
@@ -2972,3 +2974,48 @@ TEST(pthread, pthread_attr_setinheritsched__takes_effect_despite_SCHED_RESET_ON_
spin_helper.UnSpin();
ASSERT_EQ(0, pthread_join(t, nullptr));
}
+
+extern "C" bool android_run_on_all_threads(bool (*func)(void*), void* arg);
+
+TEST(pthread, run_on_all_threads) {
+#if defined(__BIONIC__)
+ pthread_t t;
+ ASSERT_EQ(
+ 0, pthread_create(
+ &t, nullptr,
+ [](void*) -> void* {
+ pthread_attr_t detached;
+ if (pthread_attr_init(&detached) != 0 ||
+ pthread_attr_setdetachstate(&detached, PTHREAD_CREATE_DETACHED) != 0) {
+ return reinterpret_cast<void*>(errno);
+ }
+
+ for (int i = 0; i != 1000; ++i) {
+ pthread_t t1, t2;
+ if (pthread_create(
+ &t1, &detached, [](void*) -> void* { return nullptr; }, nullptr) != 0 ||
+ pthread_create(
+ &t2, nullptr, [](void*) -> void* { return nullptr; }, nullptr) != 0 ||
+ pthread_join(t2, nullptr) != 0) {
+ return reinterpret_cast<void*>(errno);
+ }
+ }
+
+ if (pthread_attr_destroy(&detached) != 0) {
+ return reinterpret_cast<void*>(errno);
+ }
+ return nullptr;
+ },
+ nullptr));
+
+ for (int i = 0; i != 1000; ++i) {
+ ASSERT_TRUE(android_run_on_all_threads([](void* arg) { return arg == nullptr; }, nullptr));
+ }
+
+ void *retval;
+ ASSERT_EQ(0, pthread_join(t, &retval));
+ ASSERT_EQ(nullptr, retval);
+#else
+ GTEST_SKIP() << "bionic-only test";
+#endif
+}