tsan: switch sync test from EXPECT to CHECK

Gtest's EXPECT calls whole lot of libc functions
(mem*, malloc) even when EXPECT does not fail.
This does not play well with tsan runtime unit tests
b/c e.g. we call some EXPECTs with runtime mutexes locked.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112601
This commit is contained in:
Dmitry Vyukov 2021-10-27 10:57:42 +02:00
parent f719b794bc
commit f50cee2f4b
1 changed files with 30 additions and 30 deletions

View File

@ -21,13 +21,13 @@ TEST(MetaMap, Basic) {
u64 block[1] = {}; // fake malloc block
m->AllocBlock(thr, 0, (uptr)&block[0], 1 * sizeof(u64));
MBlock *mb = m->GetBlock((uptr)&block[0]);
EXPECT_NE(mb, (MBlock*)0);
EXPECT_EQ(mb->siz, 1 * sizeof(u64));
EXPECT_EQ(mb->tid, thr->tid);
CHECK_NE(mb, (MBlock *)0);
CHECK_EQ(mb->siz, 1 * sizeof(u64));
CHECK_EQ(mb->tid, thr->tid);
uptr sz = m->FreeBlock(thr->proc(), (uptr)&block[0]);
EXPECT_EQ(sz, 1 * sizeof(u64));
CHECK_EQ(sz, 1 * sizeof(u64));
mb = m->GetBlock((uptr)&block[0]);
EXPECT_EQ(mb, (MBlock*)0);
CHECK_EQ(mb, (MBlock *)0);
}
TEST(MetaMap, FreeRange) {
@ -37,18 +37,18 @@ TEST(MetaMap, FreeRange) {
m->AllocBlock(thr, 0, (uptr)&block[0], 1 * sizeof(u64));
m->AllocBlock(thr, 0, (uptr)&block[1], 3 * sizeof(u64));
MBlock *mb1 = m->GetBlock((uptr)&block[0]);
EXPECT_EQ(mb1->siz, 1 * sizeof(u64));
CHECK_EQ(mb1->siz, 1 * sizeof(u64));
MBlock *mb2 = m->GetBlock((uptr)&block[1]);
EXPECT_EQ(mb2->siz, 3 * sizeof(u64));
CHECK_EQ(mb2->siz, 3 * sizeof(u64));
m->FreeRange(thr->proc(), (uptr)&block[0], 4 * sizeof(u64));
mb1 = m->GetBlock((uptr)&block[0]);
EXPECT_EQ(mb1, (MBlock*)0);
CHECK_EQ(mb1, (MBlock *)0);
mb2 = m->GetBlock((uptr)&block[1]);
EXPECT_EQ(mb2, (MBlock*)0);
CHECK_EQ(mb2, (MBlock *)0);
}
TEST(MetaMap, Sync) {
// EXPECT can call memset/etc. Disable interceptors to prevent
// CHECK can call memset/etc. Disable interceptors to prevent
// them from detecting that we exit runtime with mutexes held.
ScopedIgnoreInterceptors ignore;
ThreadState *thr = cur_thread();
@ -56,18 +56,18 @@ TEST(MetaMap, Sync) {
u64 block[4] = {}; // fake malloc block
m->AllocBlock(thr, 0, (uptr)&block[0], 4 * sizeof(u64));
SyncVar *s1 = m->GetSyncIfExists((uptr)&block[0]);
EXPECT_EQ(s1, (SyncVar*)0);
CHECK_EQ(s1, (SyncVar *)0);
s1 = m->GetSyncOrCreate(thr, 0, (uptr)&block[0], false);
EXPECT_NE(s1, (SyncVar*)0);
EXPECT_EQ(s1->addr, (uptr)&block[0]);
CHECK_NE(s1, (SyncVar *)0);
CHECK_EQ(s1->addr, (uptr)&block[0]);
SyncVar *s2 = m->GetSyncOrCreate(thr, 0, (uptr)&block[1], false);
EXPECT_NE(s2, (SyncVar*)0);
EXPECT_EQ(s2->addr, (uptr)&block[1]);
CHECK_NE(s2, (SyncVar *)0);
CHECK_EQ(s2->addr, (uptr)&block[1]);
m->FreeBlock(thr->proc(), (uptr)&block[0]);
s1 = m->GetSyncIfExists((uptr)&block[0]);
EXPECT_EQ(s1, (SyncVar*)0);
CHECK_EQ(s1, (SyncVar *)0);
s2 = m->GetSyncIfExists((uptr)&block[1]);
EXPECT_EQ(s2, (SyncVar*)0);
CHECK_EQ(s2, (SyncVar *)0);
m->OnProcIdle(thr->proc());
}
@ -83,25 +83,25 @@ TEST(MetaMap, MoveMemory) {
SyncVar *s2 = m->GetSyncOrCreate(thr, 0, (uptr)&block1[1], false);
m->MoveMemory((uptr)&block1[0], (uptr)&block2[0], 4 * sizeof(u64));
MBlock *mb1 = m->GetBlock((uptr)&block1[0]);
EXPECT_EQ(mb1, (MBlock*)0);
CHECK_EQ(mb1, (MBlock *)0);
MBlock *mb2 = m->GetBlock((uptr)&block1[3]);
EXPECT_EQ(mb2, (MBlock*)0);
CHECK_EQ(mb2, (MBlock *)0);
mb1 = m->GetBlock((uptr)&block2[0]);
EXPECT_NE(mb1, (MBlock*)0);
EXPECT_EQ(mb1->siz, 3 * sizeof(u64));
CHECK_NE(mb1, (MBlock *)0);
CHECK_EQ(mb1->siz, 3 * sizeof(u64));
mb2 = m->GetBlock((uptr)&block2[3]);
EXPECT_NE(mb2, (MBlock*)0);
EXPECT_EQ(mb2->siz, 1 * sizeof(u64));
CHECK_NE(mb2, (MBlock *)0);
CHECK_EQ(mb2->siz, 1 * sizeof(u64));
s1 = m->GetSyncIfExists((uptr)&block1[0]);
EXPECT_EQ(s1, (SyncVar*)0);
CHECK_EQ(s1, (SyncVar *)0);
s2 = m->GetSyncIfExists((uptr)&block1[1]);
EXPECT_EQ(s2, (SyncVar*)0);
CHECK_EQ(s2, (SyncVar *)0);
s1 = m->GetSyncIfExists((uptr)&block2[0]);
EXPECT_NE(s1, (SyncVar*)0);
EXPECT_EQ(s1->addr, (uptr)&block2[0]);
CHECK_NE(s1, (SyncVar *)0);
CHECK_EQ(s1->addr, (uptr)&block2[0]);
s2 = m->GetSyncIfExists((uptr)&block2[1]);
EXPECT_NE(s2, (SyncVar*)0);
EXPECT_EQ(s2->addr, (uptr)&block2[1]);
CHECK_NE(s2, (SyncVar *)0);
CHECK_EQ(s2->addr, (uptr)&block2[1]);
m->FreeRange(thr->proc(), (uptr)&block2[0], 4 * sizeof(u64));
}
@ -114,7 +114,7 @@ TEST(MetaMap, ResetSync) {
SyncVar *s = m->GetSyncOrCreate(thr, 0, (uptr)&block[0], false);
s->Reset(thr->proc());
uptr sz = m->FreeBlock(thr->proc(), (uptr)&block[0]);
EXPECT_EQ(sz, 1 * sizeof(u64));
CHECK_EQ(sz, 1 * sizeof(u64));
}
} // namespace __tsan