[PATCH] fix the ThreadLister test for Android

Sergey Matveev earthdok at google.com
Wed Feb 27 07:51:14 PST 2013


Hi kcc, glider, samsonov,

Relax the ThreadLister test to ignore possible pre-existing threads.

http://llvm-reviews.chandlerc.com/D471

Files:
  lib/sanitizer_common/tests/sanitizer_linux_test.cc

Index: lib/sanitizer_common/tests/sanitizer_linux_test.cc
===================================================================
--- lib/sanitizer_common/tests/sanitizer_linux_test.cc
+++ lib/sanitizer_common/tests/sanitizer_linux_test.cc
@@ -22,20 +22,9 @@
 #include <sched.h>
 
 #include <set>
+#include <algorithm>
 
 namespace __sanitizer {
-// In a single-threaded process, ThreadLister should produce the TID (which
-// coincides with the PID) of the current task.
-TEST(SanitizerLinux, ThreadListerSingleThread) {
-  pid_t pid = getpid();
-  ThreadLister thread_lister(pid);
-  EXPECT_FALSE(thread_lister.error());
-  EXPECT_EQ(thread_lister.GetNextTID(), pid);
-  EXPECT_FALSE(thread_lister.error());
-  EXPECT_LT(thread_lister.GetNextTID(), 0);
-  EXPECT_FALSE(thread_lister.error());
-}
-
 static pthread_cond_t thread_exit_cond = PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t thread_exit_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t tid_reported_cond = PTHREAD_COND_INITIALIZER;
@@ -55,8 +44,9 @@
   return NULL;
 }
 
-// In a process with multiple threads, ThreadLister should produce their TIDs
-// in some order.
+// The set of TIDs produced by ThreadLister should include the TID of every
+// thread we spawn here. The two sets may differ if there are other threads
+// running in the current process that we are not aware of.
 // Calling ThreadLister::Reset() should not change this.
 TEST(SanitizerLinux, ThreadListerMultiThreaded) {
   const uptr kThreadCount = 20; // does not include the main thread
@@ -96,7 +86,11 @@
     EXPECT_LT(tid, 0);
     EXPECT_FALSE(thread_lister.error());
 
-    EXPECT_EQ(listed_tids, reported_tids);
+    std::set<pid_t> intersection;
+    std::set_intersection(reported_tids.begin(), reported_tids.end(),
+                          listed_tids.begin(), listed_tids.end(),
+                          std::inserter(intersection, intersection.begin()));
+    EXPECT_EQ(intersection, reported_tids);
     thread_lister.Reset();
   }
   pthread_mutex_lock(&thread_exit_mutex);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D471.1.patch
Type: text/x-patch
Size: 2038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130227/cd9b45f8/attachment.bin>


More information about the llvm-commits mailing list