[PATCH] fix the ThreadLister test for Android
Sergey Matveev
earthdok at google.com
Thu Feb 28 02:09:18 PST 2013
patch refresh
Hi kcc, glider, samsonov,
http://llvm-reviews.chandlerc.com/D471
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D471?vs=1148&id=1151#toc
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
@@ -21,21 +21,10 @@
#include <pthread.h>
#include <sched.h>
+#include <algorithm>
#include <set>
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.3.patch
Type: text/x-patch
Size: 2061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130228/c29161ee/attachment.bin>
More information about the llvm-commits
mailing list