[Sanitizer] Fix compiler warnings and style issues in sanitizer_common tests. Use -Werror=sign-compare when building them.

llvm-svn: 177077
This commit is contained in:
Alexey Samsonov 2013-03-14 15:15:35 +00:00
parent 85cc3b3dbf
commit d1999a1ccc
5 changed files with 30 additions and 25 deletions

View File

@ -80,6 +80,8 @@ void ThreadContextBase::Reset(void *arg) {
// ThreadRegistry implementation.
const u32 ThreadRegistry::kUnknownTid = -1U;
ThreadRegistry::ThreadRegistry(ThreadContextFactory factory, u32 max_threads,
u32 thread_quarantine_size)
: context_factory_(factory),

View File

@ -77,7 +77,6 @@ class ThreadRegistry {
const u32 max_threads_;
const u32 thread_quarantine_size_;
static const u32 kUnknownTid = -1U;
BlockingMutex mtx_;
u32 n_contexts_; // Number of created thread contexts,
@ -92,6 +91,8 @@ class ThreadRegistry {
IntrusiveList<ThreadContextBase> dead_threads_;
public:
static const u32 kUnknownTid;
ThreadRegistry(ThreadContextFactory factory, u32 max_threads,
u32 thread_quarantine_size);
void GetNumberOfThreads(uptr *total = 0, uptr *running = 0, uptr *alive = 0);

View File

@ -56,7 +56,7 @@ macro(add_sanitizer_tests_for_arch arch)
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
-I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common
-O2 -g -Wall -Werror ${TARGET_FLAGS})
-O2 -g -Wall -Werror -Werror=sign-compare ${TARGET_FLAGS})
set(SANITIZER_TEST_LINK_FLAGS -lstdc++ -lpthread -ldl ${TARGET_FLAGS})
set(SANITIZER_TEST_OBJECTS)
foreach(source ${SANITIZER_TEST_SOURCES})

View File

@ -118,7 +118,7 @@ void ThreadListerTest::SpawnTidReporter(pthread_t *pthread_id,
*tid = thread_arg.reported_tid;
}
std::vector<pid_t> ReadTidsToVector(ThreadLister *thread_lister) {
static std::vector<pid_t> ReadTidsToVector(ThreadLister *thread_lister) {
std::vector<pid_t> listed_tids;
pid_t tid;
while ((tid = thread_lister->GetNextTID()) >= 0)

View File

@ -39,11 +39,11 @@ static void CheckThreadQuantity(ThreadRegistry *registry, uptr exp_total,
EXPECT_EQ(exp_alive, alive);
}
static bool is_detached(int tid) {
static bool is_detached(u32 tid) {
return (tid % 2 == 0);
}
static uptr get_uid(int tid) {
static uptr get_uid(u32 tid) {
return tid * 2;
}
@ -64,50 +64,52 @@ static void MarkUidAsPresent(ThreadContextBase *tctx, void *arg) {
static void TestRegistry(ThreadRegistry *registry, bool has_quarantine) {
// Create and start a main thread.
EXPECT_EQ(0, registry->CreateThread(get_uid(0), true, -1, 0));
EXPECT_EQ(0U, registry->CreateThread(get_uid(0), true, -1, 0));
registry->StartThread(0, 0, 0);
// Create a bunch of threads.
for (int i = 1; i <= 10; i++) {
for (u32 i = 1; i <= 10; i++) {
EXPECT_EQ(i, registry->CreateThread(get_uid(i), is_detached(i), 0, 0));
}
CheckThreadQuantity(registry, 11, 1, 11);
// Start some of them.
for (int i = 1; i <= 5; i++) {
for (u32 i = 1; i <= 5; i++) {
registry->StartThread(i, 0, 0);
}
CheckThreadQuantity(registry, 11, 6, 11);
// Finish, create and start more threads.
for (int i = 1; i <= 5; i++) {
for (u32 i = 1; i <= 5; i++) {
registry->FinishThread(i);
if (!is_detached(i))
registry->JoinThread(i, 0);
}
for (int i = 6; i <= 10; i++) {
for (u32 i = 6; i <= 10; i++) {
registry->StartThread(i, 0, 0);
}
std::vector<int> new_tids;
for (int i = 11; i <= 15; i++) {
std::vector<u32> new_tids;
for (u32 i = 11; i <= 15; i++) {
new_tids.push_back(
registry->CreateThread(get_uid(i), is_detached(i), 0, 0));
}
ASSERT_LE(kRegistryQuarantine, 5);
int exp_total = 16 - (has_quarantine ? 5 - kRegistryQuarantine : 0);
ASSERT_LE(kRegistryQuarantine, 5U);
u32 exp_total = 16 - (has_quarantine ? 5 - kRegistryQuarantine : 0);
CheckThreadQuantity(registry, exp_total, 6, 11);
// Test SetThreadName and FindThread.
registry->SetThreadName(6, "six");
registry->SetThreadName(7, "seven");
EXPECT_EQ(7, registry->FindThread(HasName, (void*)"seven"));
EXPECT_EQ(-1, registry->FindThread(HasName, (void*)"none"));
EXPECT_EQ(0, registry->FindThread(HasUid, (void*)get_uid(0)));
EXPECT_EQ(10, registry->FindThread(HasUid, (void*)get_uid(10)));
EXPECT_EQ(-1, registry->FindThread(HasUid, (void*)0x1234));
EXPECT_EQ(7U, registry->FindThread(HasName, (void*)"seven"));
EXPECT_EQ(ThreadRegistry::kUnknownTid,
registry->FindThread(HasName, (void*)"none"));
EXPECT_EQ(0U, registry->FindThread(HasUid, (void*)get_uid(0)));
EXPECT_EQ(10U, registry->FindThread(HasUid, (void*)get_uid(10)));
EXPECT_EQ(ThreadRegistry::kUnknownTid,
registry->FindThread(HasUid, (void*)0x1234));
// Detach and finish and join remaining threads.
for (int i = 6; i <= 10; i++) {
for (u32 i = 6; i <= 10; i++) {
registry->DetachThread(i);
registry->FinishThread(i);
}
for (int i = 0; i < new_tids.size(); i++) {
int tid = new_tids[i];
for (u32 i = 0; i < new_tids.size(); i++) {
u32 tid = new_tids[i];
registry->StartThread(tid, 0, 0);
registry->DetachThread(tid);
registry->FinishThread(tid);
@ -120,7 +122,7 @@ static void TestRegistry(ThreadRegistry *registry, bool has_quarantine) {
ThreadRegistryLock l(registry);
registry->RunCallbackForEachThreadLocked(MarkUidAsPresent, &has_tid[0]);
}
for (int i = 0; i < exp_total; i++) {
for (u32 i = 0; i < exp_total; i++) {
EXPECT_TRUE(has_tid[i]);
}
{
@ -130,7 +132,7 @@ static void TestRegistry(ThreadRegistry *registry, bool has_quarantine) {
EXPECT_EQ(main_thread, registry->FindThreadContextLocked(
HasUid, (void*)get_uid(0)));
}
EXPECT_EQ(11, registry->GetMaxAliveThreads());
EXPECT_EQ(11U, registry->GetMaxAliveThreads());
}
TEST(SanitizerCommon, ThreadRegistryTest) {
@ -195,7 +197,7 @@ void *RunThread(void *arg) {
static void ThreadedTestRegistry(ThreadRegistry *registry) {
// Create and start a main thread.
EXPECT_EQ(0, registry->CreateThread(0, true, -1, 0));
EXPECT_EQ(0U, registry->CreateThread(0, true, -1, 0));
registry->StartThread(0, 0, 0);
pthread_t threads[kNumShards];
RunThreadArgs args[kNumShards];