Skip to content

[MemProf] Simplify unittest save and restore of options #139117

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
merged 1 commit into from
May 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ TEST_F(MemoryProfileInfoTest, GetAllocType) {
100);

// Make sure the option for detecting hot allocations is set.
bool OrigMemProfUseHotHints = MemProfUseHotHints;
MemProfUseHotHints = true;

// Test Hot
// More accesses per byte per sec than hot threshold is hot.
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
ColdTotalLifetimeThreshold + 1),
AllocationType::Hot);
// Undo the manual set of the option above.
cl::ResetAllOptionOccurrences();

// Restore original option value.
MemProfUseHotHints = OrigMemProfUseHotHints;

// Without MemProfUseHotHints (default) we should treat simply as NotCold.
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
Expand Down Expand Up @@ -590,12 +593,13 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
ASSERT_NE(Call, nullptr);

// Specify that all non-cold contexts should be kept.
bool OrigMemProfKeepAllNotColdContexts = MemProfKeepAllNotColdContexts;
MemProfKeepAllNotColdContexts = true;

Trie.buildAndAttachMIBMetadata(Call);

// Undo the manual set of the MemProfKeepAllNotColdContexts above.
cl::ResetAllOptionOccurrences();
// Restore original option value.
MemProfKeepAllNotColdContexts = OrigMemProfKeepAllNotColdContexts;

EXPECT_FALSE(Call->hasFnAttr("memprof"));
EXPECT_TRUE(Call->hasMetadata(LLVMContext::MD_memprof));
Expand Down
Loading