Skip to content

Commit 085282d

Browse files
[memprof] Use gtest matchers at more places
These gtest matchers reduce the number of times we mention the variables under examined.
1 parent 9f98949 commit 085282d

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

llvm/unittests/ProfileData/InstrProfTest.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
using namespace llvm;
2828
using ::llvm::memprof::LineLocation;
29+
using ::testing::ElementsAre;
2930
using ::testing::EndsWith;
3031
using ::testing::IsSubsetOf;
3132
using ::testing::Pair;
@@ -564,19 +565,16 @@ TEST_F(InstrProfTest, test_caller_callee_pairs) {
564565

565566
auto It = Pairs.find(0x123);
566567
ASSERT_NE(It, Pairs.end());
567-
ASSERT_THAT(It->second, SizeIs(2));
568-
EXPECT_THAT(It->second[0], Pair(LineLocation(1, 2), 0x234U));
569-
EXPECT_THAT(It->second[1], Pair(LineLocation(5, 6), 0x345U));
568+
EXPECT_THAT(It->second, ElementsAre(Pair(LineLocation(1, 2), 0x234U),
569+
Pair(LineLocation(5, 6), 0x345U)));
570570

571571
It = Pairs.find(0x234);
572572
ASSERT_NE(It, Pairs.end());
573-
ASSERT_THAT(It->second, SizeIs(1));
574-
EXPECT_THAT(It->second[0], Pair(LineLocation(3, 4), 0U));
573+
EXPECT_THAT(It->second, ElementsAre(Pair(LineLocation(3, 4), 0U)));
575574

576575
It = Pairs.find(0x345);
577576
ASSERT_NE(It, Pairs.end());
578-
ASSERT_THAT(It->second, SizeIs(1));
579-
EXPECT_THAT(It->second[0], Pair(LineLocation(7, 8), 0U));
577+
EXPECT_THAT(It->second, ElementsAre(Pair(LineLocation(7, 8), 0U)));
580578
}
581579

582580
TEST_F(InstrProfTest, test_memprof_getrecord_error) {

llvm/unittests/ProfileData/MemProfTest.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -221,31 +221,28 @@ TEST(MemProf, FillsValue) {
221221
EXPECT_THAT(Bar.AllocSites[0].CallStack[3],
222222
FrameContains("abc", 5U, 30U, false));
223223

224-
ASSERT_THAT(Bar.CallSites, SizeIs(1));
225-
ASSERT_THAT(Bar.CallSites[0], SizeIs(2));
226-
EXPECT_THAT(Bar.CallSites[0][0], FrameContains("foo", 5U, 30U, true));
227-
EXPECT_THAT(Bar.CallSites[0][1], FrameContains("bar", 51U, 20U, false));
224+
EXPECT_THAT(Bar.CallSites,
225+
ElementsAre(ElementsAre(FrameContains("foo", 5U, 30U, true),
226+
FrameContains("bar", 51U, 20U, false))));
228227

229228
// Check the memprof record for xyz.
230229
const llvm::GlobalValue::GUID XyzId = IndexedMemProfRecord::getGUID("xyz");
231230
ASSERT_TRUE(Records.contains(XyzId));
232231
const MemProfRecord &Xyz = Records[XyzId];
233-
ASSERT_THAT(Xyz.CallSites, SizeIs(1));
234-
ASSERT_THAT(Xyz.CallSites[0], SizeIs(2));
235232
// Expect the entire frame even though in practice we only need the first
236233
// entry here.
237-
EXPECT_THAT(Xyz.CallSites[0][0], FrameContains("xyz", 5U, 30U, true));
238-
EXPECT_THAT(Xyz.CallSites[0][1], FrameContains("abc", 5U, 30U, false));
234+
EXPECT_THAT(Xyz.CallSites,
235+
ElementsAre(ElementsAre(FrameContains("xyz", 5U, 30U, true),
236+
FrameContains("abc", 5U, 30U, false))));
239237

240238
// Check the memprof record for abc.
241239
const llvm::GlobalValue::GUID AbcId = IndexedMemProfRecord::getGUID("abc");
242240
ASSERT_TRUE(Records.contains(AbcId));
243241
const MemProfRecord &Abc = Records[AbcId];
244242
EXPECT_TRUE(Abc.AllocSites.empty());
245-
ASSERT_THAT(Abc.CallSites, SizeIs(1));
246-
ASSERT_THAT(Abc.CallSites[0], SizeIs(2));
247-
EXPECT_THAT(Abc.CallSites[0][0], FrameContains("xyz", 5U, 30U, true));
248-
EXPECT_THAT(Abc.CallSites[0][1], FrameContains("abc", 5U, 30U, false));
243+
EXPECT_THAT(Abc.CallSites,
244+
ElementsAre(ElementsAre(FrameContains("xyz", 5U, 30U, true),
245+
FrameContains("abc", 5U, 30U, false))));
249246
}
250247

251248
TEST(MemProf, PortableWrapper) {
@@ -419,9 +416,8 @@ TEST(MemProf, SymbolizationFilter) {
419416

420417
ASSERT_THAT(Records, SizeIs(1));
421418
ASSERT_THAT(Records[0].AllocSites, SizeIs(1));
422-
ASSERT_THAT(Records[0].AllocSites[0].CallStack, SizeIs(1));
423-
EXPECT_THAT(Records[0].AllocSites[0].CallStack[0],
424-
FrameContains("foo", 5U, 30U, false));
419+
EXPECT_THAT(Records[0].AllocSites[0].CallStack,
420+
ElementsAre(FrameContains("foo", 5U, 30U, false)));
425421
}
426422

427423
TEST(MemProf, BaseMemProfReader) {
@@ -452,11 +448,9 @@ TEST(MemProf, BaseMemProfReader) {
452448

453449
ASSERT_THAT(Records, SizeIs(1));
454450
ASSERT_THAT(Records[0].AllocSites, SizeIs(1));
455-
ASSERT_THAT(Records[0].AllocSites[0].CallStack, SizeIs(2));
456-
EXPECT_THAT(Records[0].AllocSites[0].CallStack[0],
457-
FrameContains("foo", 20U, 5U, true));
458-
EXPECT_THAT(Records[0].AllocSites[0].CallStack[1],
459-
FrameContains("bar", 10U, 2U, false));
451+
EXPECT_THAT(Records[0].AllocSites[0].CallStack,
452+
ElementsAre(FrameContains("foo", 20U, 5U, true),
453+
FrameContains("bar", 10U, 2U, false)));
460454
}
461455

462456
TEST(MemProf, BaseMemProfReaderWithCSIdMap) {
@@ -489,11 +483,9 @@ TEST(MemProf, BaseMemProfReaderWithCSIdMap) {
489483

490484
ASSERT_THAT(Records, SizeIs(1));
491485
ASSERT_THAT(Records[0].AllocSites, SizeIs(1));
492-
ASSERT_THAT(Records[0].AllocSites[0].CallStack, SizeIs(2));
493-
EXPECT_THAT(Records[0].AllocSites[0].CallStack[0],
494-
FrameContains("foo", 20U, 5U, true));
495-
EXPECT_THAT(Records[0].AllocSites[0].CallStack[1],
496-
FrameContains("bar", 10U, 2U, false));
486+
EXPECT_THAT(Records[0].AllocSites[0].CallStack,
487+
ElementsAre(FrameContains("foo", 20U, 5U, true),
488+
FrameContains("bar", 10U, 2U, false)));
497489
}
498490

499491
TEST(MemProf, IndexedMemProfRecordToMemProfRecord) {

0 commit comments

Comments
 (0)