-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[memprof] Use gtest matchers at more places #119050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:memprof_unittest_matchers
Dec 7, 2024
Merged
[memprof] Use gtest matchers at more places #119050
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:memprof_unittest_matchers
Dec 7, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These gtest matchers reduce the number of times we mention the variables under examined.
Member
|
@llvm/pr-subscribers-pgo Author: Kazu Hirata (kazutakahirata) ChangesThese gtest matchers reduce the number of times we mention the Full diff: https://github.com/llvm/llvm-project/pull/119050.diff 2 Files Affected:
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index f366b228e63512..273b89ca26aa98 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -26,6 +26,7 @@
using namespace llvm;
using ::llvm::memprof::LineLocation;
+using ::testing::ElementsAre;
using ::testing::EndsWith;
using ::testing::IsSubsetOf;
using ::testing::Pair;
@@ -564,19 +565,16 @@ TEST_F(InstrProfTest, test_caller_callee_pairs) {
auto It = Pairs.find(0x123);
ASSERT_NE(It, Pairs.end());
- ASSERT_THAT(It->second, SizeIs(2));
- EXPECT_THAT(It->second[0], Pair(LineLocation(1, 2), 0x234U));
- EXPECT_THAT(It->second[1], Pair(LineLocation(5, 6), 0x345U));
+ EXPECT_THAT(It->second, ElementsAre(Pair(LineLocation(1, 2), 0x234U),
+ Pair(LineLocation(5, 6), 0x345U)));
It = Pairs.find(0x234);
ASSERT_NE(It, Pairs.end());
- ASSERT_THAT(It->second, SizeIs(1));
- EXPECT_THAT(It->second[0], Pair(LineLocation(3, 4), 0U));
+ EXPECT_THAT(It->second, ElementsAre(Pair(LineLocation(3, 4), 0U)));
It = Pairs.find(0x345);
ASSERT_NE(It, Pairs.end());
- ASSERT_THAT(It->second, SizeIs(1));
- EXPECT_THAT(It->second[0], Pair(LineLocation(7, 8), 0U));
+ EXPECT_THAT(It->second, ElementsAre(Pair(LineLocation(7, 8), 0U)));
}
TEST_F(InstrProfTest, test_memprof_getrecord_error) {
diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp
index 74a6acf9e9a82f..b8c932e28c8e29 100644
--- a/llvm/unittests/ProfileData/MemProfTest.cpp
+++ b/llvm/unittests/ProfileData/MemProfTest.cpp
@@ -221,31 +221,28 @@ TEST(MemProf, FillsValue) {
EXPECT_THAT(Bar.AllocSites[0].CallStack[3],
FrameContains("abc", 5U, 30U, false));
- ASSERT_THAT(Bar.CallSites, SizeIs(1));
- ASSERT_THAT(Bar.CallSites[0], SizeIs(2));
- EXPECT_THAT(Bar.CallSites[0][0], FrameContains("foo", 5U, 30U, true));
- EXPECT_THAT(Bar.CallSites[0][1], FrameContains("bar", 51U, 20U, false));
+ EXPECT_THAT(Bar.CallSites,
+ ElementsAre(ElementsAre(FrameContains("foo", 5U, 30U, true),
+ FrameContains("bar", 51U, 20U, false))));
// Check the memprof record for xyz.
const llvm::GlobalValue::GUID XyzId = IndexedMemProfRecord::getGUID("xyz");
ASSERT_TRUE(Records.contains(XyzId));
const MemProfRecord &Xyz = Records[XyzId];
- ASSERT_THAT(Xyz.CallSites, SizeIs(1));
- ASSERT_THAT(Xyz.CallSites[0], SizeIs(2));
// Expect the entire frame even though in practice we only need the first
// entry here.
- EXPECT_THAT(Xyz.CallSites[0][0], FrameContains("xyz", 5U, 30U, true));
- EXPECT_THAT(Xyz.CallSites[0][1], FrameContains("abc", 5U, 30U, false));
+ EXPECT_THAT(Xyz.CallSites,
+ ElementsAre(ElementsAre(FrameContains("xyz", 5U, 30U, true),
+ FrameContains("abc", 5U, 30U, false))));
// Check the memprof record for abc.
const llvm::GlobalValue::GUID AbcId = IndexedMemProfRecord::getGUID("abc");
ASSERT_TRUE(Records.contains(AbcId));
const MemProfRecord &Abc = Records[AbcId];
EXPECT_TRUE(Abc.AllocSites.empty());
- ASSERT_THAT(Abc.CallSites, SizeIs(1));
- ASSERT_THAT(Abc.CallSites[0], SizeIs(2));
- EXPECT_THAT(Abc.CallSites[0][0], FrameContains("xyz", 5U, 30U, true));
- EXPECT_THAT(Abc.CallSites[0][1], FrameContains("abc", 5U, 30U, false));
+ EXPECT_THAT(Abc.CallSites,
+ ElementsAre(ElementsAre(FrameContains("xyz", 5U, 30U, true),
+ FrameContains("abc", 5U, 30U, false))));
}
TEST(MemProf, PortableWrapper) {
@@ -419,9 +416,8 @@ TEST(MemProf, SymbolizationFilter) {
ASSERT_THAT(Records, SizeIs(1));
ASSERT_THAT(Records[0].AllocSites, SizeIs(1));
- ASSERT_THAT(Records[0].AllocSites[0].CallStack, SizeIs(1));
- EXPECT_THAT(Records[0].AllocSites[0].CallStack[0],
- FrameContains("foo", 5U, 30U, false));
+ EXPECT_THAT(Records[0].AllocSites[0].CallStack,
+ ElementsAre(FrameContains("foo", 5U, 30U, false)));
}
TEST(MemProf, BaseMemProfReader) {
@@ -452,11 +448,9 @@ TEST(MemProf, BaseMemProfReader) {
ASSERT_THAT(Records, SizeIs(1));
ASSERT_THAT(Records[0].AllocSites, SizeIs(1));
- ASSERT_THAT(Records[0].AllocSites[0].CallStack, SizeIs(2));
- EXPECT_THAT(Records[0].AllocSites[0].CallStack[0],
- FrameContains("foo", 20U, 5U, true));
- EXPECT_THAT(Records[0].AllocSites[0].CallStack[1],
- FrameContains("bar", 10U, 2U, false));
+ EXPECT_THAT(Records[0].AllocSites[0].CallStack,
+ ElementsAre(FrameContains("foo", 20U, 5U, true),
+ FrameContains("bar", 10U, 2U, false)));
}
TEST(MemProf, BaseMemProfReaderWithCSIdMap) {
@@ -489,11 +483,9 @@ TEST(MemProf, BaseMemProfReaderWithCSIdMap) {
ASSERT_THAT(Records, SizeIs(1));
ASSERT_THAT(Records[0].AllocSites, SizeIs(1));
- ASSERT_THAT(Records[0].AllocSites[0].CallStack, SizeIs(2));
- EXPECT_THAT(Records[0].AllocSites[0].CallStack[0],
- FrameContains("foo", 20U, 5U, true));
- EXPECT_THAT(Records[0].AllocSites[0].CallStack[1],
- FrameContains("bar", 10U, 2U, false));
+ EXPECT_THAT(Records[0].AllocSites[0].CallStack,
+ ElementsAre(FrameContains("foo", 20U, 5U, true),
+ FrameContains("bar", 10U, 2U, false)));
}
TEST(MemProf, IndexedMemProfRecordToMemProfRecord) {
|
snehasish
approved these changes
Dec 7, 2024
snehasish
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, nice!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These gtest matchers reduce the number of times we mention the
variables under examined.