From f98a153c8dcb9aa1eb0937e89eddd11103e8cdd6 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Fri, 2 Aug 2019 18:55:22 +0000 Subject: [PATCH] [sanitizer_common][tests] Fix SanitizerCommon-Unit :: ./Sanitizer-*-Test/SanitizerCommon.PthreadDestructorIterations on Solaris SanitizerCommon.PthreadDestructorIterations currently FAILs on Solaris: [ RUN ] SanitizerCommon.PthreadDestructorIterations /vol/llvm/src/compiler-rt/local/lib/sanitizer_common/tests/sanitizer_posix_test.cc:58: Failure Value of: destructor_executed Actual: true Expected: false [ FAILED ] SanitizerCommon.PthreadDestructorIterations (1 ms) It turns out that destructor is called 4 times after the first call to SpawnThread, but 5 times after the second. While PTHREAD_DESTRUCTOR_ITERATIONS is 4 in , the Solaris pthread_key_create(3C) man page documents If, after all the destructors have been called for all keys with non- null values, there are still some keys with non-null values, the process will be repeated. POSIX requires that this process be executed at least PTHREAD_DESTRUCTOR_ITERATIONS times. Solaris calls the destructors repeatedly until all values with associated destructors are NULL. Destructors that set new values can cause an infinite loop. The patch adjusts the test case to allow for this. Tested on x86_64-pc-solaris2.11. Differential Revision: https://reviews.llvm.org/D65055 llvm-svn: 367705 --- compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp index c903846..be577c3 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp @@ -54,7 +54,12 @@ TEST(SanitizerCommon, PthreadDestructorIterations) { SpawnThread(GetPthreadDestructorIterations()); EXPECT_TRUE(destructor_executed); SpawnThread(GetPthreadDestructorIterations() + 1); +#if SANITIZER_SOLARIS + // Solaris continues calling destructors beyond PTHREAD_DESTRUCTOR_ITERATIONS. + EXPECT_TRUE(destructor_executed); +#else EXPECT_FALSE(destructor_executed); +#endif ASSERT_EQ(0, pthread_key_delete(key)); } -- 2.7.4