Skip to content

Commit d1a80db

Browse files
Use wrapper instead of manual restore.
Change-Id: If394797132d67c7b36a29d42cf6f6d9809baf2c2
1 parent 1fccbe3 commit d1a80db

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

unit_tests/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDefaultDrmMemoryManage
20782078
}
20792079

20802080
TEST(Allocator32BitUsingHeapAllocator, given32BitAllocatorWhenMMapFailsThenNullptrIsReturned) {
2081-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2081+
DebugManagerStateRestore restore;
20822082
DebugManager.flags.UseNewHeapAllocator.set(true);
20832083

20842084
mockAllocator32Bit::resetState();
@@ -2092,11 +2092,10 @@ TEST(Allocator32BitUsingHeapAllocator, given32BitAllocatorWhenMMapFailsThenNullp
20922092
EXPECT_EQ(0llu, ptr);
20932093
EXPECT_EQ(2u, mmapCallCount);
20942094
delete mock32BitAllocator;
2095-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
20962095
}
20972096

20982097
TEST(Allocator32BitUsingHeapAllocator, given32BitAllocatorWhenFirstMMapFailsThenSecondIsCalledWithSmallerSize) {
2099-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2098+
DebugManagerStateRestore restore;
21002099
DebugManager.flags.UseNewHeapAllocator.set(true);
21012100

21022101
mockAllocator32Bit::resetState();
@@ -2114,11 +2113,10 @@ TEST(Allocator32BitUsingHeapAllocator, given32BitAllocatorWhenFirstMMapFailsThen
21142113
EXPECT_NE(0u, osInternals->heapSize);
21152114

21162115
delete mock32BitAllocator;
2117-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
21182116
}
21192117

21202118
TEST(DrmAllocator32Bit, allocateReturnsPointer) {
2121-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2119+
DebugManagerStateRestore restore;
21222120
DebugManager.flags.UseNewHeapAllocator.set(false);
21232121

21242122
mockAllocator32Bit mock32BitAllocator;
@@ -2127,35 +2125,30 @@ TEST(DrmAllocator32Bit, allocateReturnsPointer) {
21272125
EXPECT_NE(0u, (uintptr_t)ptr);
21282126
EXPECT_EQ(1u, mmapCallCount);
21292127
mock32BitAllocator.free(ptr, size);
2130-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
21312128
}
21322129

21332130
TEST(DrmAllocator32Bit, freeMapFailedPointer) {
2134-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2131+
DebugManagerStateRestore restore;
21352132
DebugManager.flags.UseNewHeapAllocator.set(false);
21362133

21372134
mockAllocator32Bit mock32BitAllocator;
21382135
size_t size = 100u;
21392136
int result = mock32BitAllocator.free(reinterpret_cast<uint64_t>(MAP_FAILED), size);
21402137
EXPECT_EQ(0, result);
2141-
2142-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
21432138
}
21442139

21452140
TEST(DrmAllocator32Bit, freeNullPtrPointer) {
2146-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2141+
DebugManagerStateRestore restore;
21472142
DebugManager.flags.UseNewHeapAllocator.set(false);
21482143

21492144
mockAllocator32Bit mock32BitAllocator;
21502145
uint32_t size = 100u;
21512146
int result = mock32BitAllocator.free(0llu, size);
21522147
EXPECT_EQ(0, result);
2153-
2154-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
21552148
}
21562149

21572150
TEST(DrmAllocator32Bit, freeLowerRangeAfterTwoMmapFails) {
2158-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2151+
DebugManagerStateRestore restore;
21592152
DebugManager.flags.UseNewHeapAllocator.set(false);
21602153

21612154
mockAllocator32Bit mock32BitAllocator;
@@ -2165,11 +2158,10 @@ TEST(DrmAllocator32Bit, freeLowerRangeAfterTwoMmapFails) {
21652158
EXPECT_EQ(3u, mmapCallCount);
21662159
int result = mock32BitAllocator.free(ptr, size);
21672160
EXPECT_EQ(0, result);
2168-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
21692161
}
21702162

21712163
TEST(DrmAllocator32Bit, given32BitAllocatorWhenMMapFailsThenUpperHeapIsBrowsedForAllocations) {
2172-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2164+
DebugManagerStateRestore restore;
21732165
DebugManager.flags.UseNewHeapAllocator.set(false);
21742166

21752167
mockAllocator32Bit mock32BitAllocator;
@@ -2178,11 +2170,10 @@ TEST(DrmAllocator32Bit, given32BitAllocatorWhenMMapFailsThenUpperHeapIsBrowsedFo
21782170
auto ptr = mock32BitAllocator.allocate(size);
21792171
EXPECT_EQ(maxMmap32BitAddress, (uintptr_t)ptr);
21802172
EXPECT_EQ(2u, mmapCallCount);
2181-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
21822173
}
21832174

21842175
TEST(DrmAllocator32Bit, given32BitAllocatorWith32AndUpperHeapsExhaustedThenPointerFromLowerHeapIsReturned) {
2185-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2176+
DebugManagerStateRestore restore;
21862177
DebugManager.flags.UseNewHeapAllocator.set(false);
21872178

21882179
mockAllocator32Bit mock32BitAllocator;
@@ -2192,11 +2183,10 @@ TEST(DrmAllocator32Bit, given32BitAllocatorWith32AndUpperHeapsExhaustedThenPoint
21922183
auto ptr = mock32BitAllocator.allocate(size);
21932184
EXPECT_EQ(lowerRangeStart, (uintptr_t)ptr);
21942185
EXPECT_EQ(3u, mmapCallCount);
2195-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
21962186
}
21972187

21982188
TEST(DrmAllocator32Bit, given32bitRegionExhaustedWhenTwoAllocationsAreCreatedThenSecondIsAfterFirst) {
2199-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2189+
DebugManagerStateRestore restore;
22002190
DebugManager.flags.UseNewHeapAllocator.set(false);
22012191

22022192
mockAllocator32Bit mock32BitAllocator;
@@ -2219,11 +2209,10 @@ TEST(DrmAllocator32Bit, given32bitRegionExhaustedWhenTwoAllocationsAreCreatedThe
22192209
EXPECT_EQ(ptr, getInternals->upperRangeAddress);
22202210

22212211
EXPECT_EQ(2u, unmapCallCount);
2222-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
22232212
}
22242213

22252214
TEST(DrmAllocator32Bit, given32bitRegionAndUpperRegionExhaustedWhenTwoAllocationsAreCreatedThenSecondIsAfterFirst) {
2226-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2215+
DebugManagerStateRestore restore;
22272216
DebugManager.flags.UseNewHeapAllocator.set(false);
22282217

22292218
mockAllocator32Bit mock32BitAllocator;
@@ -2247,11 +2236,10 @@ TEST(DrmAllocator32Bit, given32bitRegionAndUpperRegionExhaustedWhenTwoAllocation
22472236
EXPECT_EQ(ptr, getInternals->lowerRangeAddress);
22482237

22492238
EXPECT_EQ(4u, unmapCallCount);
2250-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
22512239
}
22522240

22532241
TEST(DrmAllocator32Bit, given32bitAllocatorWithAllHeapsExhaustedWhenAskedForAllocationThenNullptrIsReturned) {
2254-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2242+
DebugManagerStateRestore restore;
22552243
DebugManager.flags.UseNewHeapAllocator.set(false);
22562244

22572245
mockAllocator32Bit mock32BitAllocator;
@@ -2266,11 +2254,10 @@ TEST(DrmAllocator32Bit, given32bitAllocatorWithAllHeapsExhaustedWhenAskedForAllo
22662254

22672255
EXPECT_EQ(3u, mmapCallCount);
22682256
EXPECT_EQ(2u, unmapCallCount);
2269-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
22702257
}
22712258

22722259
TEST(DrmAllocator32Bit, given32bitAllocatorWithUpperHeapCloseToFullWhenAskedForAllocationThenAllocationFromLowerHeapIsReturned) {
2273-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2260+
DebugManagerStateRestore restore;
22742261
DebugManager.flags.UseNewHeapAllocator.set(false);
22752262

22762263
mockAllocator32Bit mock32BitAllocator;
@@ -2282,27 +2269,24 @@ TEST(DrmAllocator32Bit, given32bitAllocatorWithUpperHeapCloseToFullWhenAskedForA
22822269
EXPECT_EQ(lowerRangeHeapStart, (uintptr_t)ptr);
22832270
EXPECT_EQ(3u, mmapCallCount);
22842271
EXPECT_EQ(1u, unmapCallCount);
2285-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
22862272
}
22872273

22882274
TEST(DrmAllocator32Bit, givenMapFailedAsInputToFreeFunctionWhenItIsCalledThenUnmapIsNotCalled) {
2289-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2275+
DebugManagerStateRestore restore;
22902276
DebugManager.flags.UseNewHeapAllocator.set(false);
22912277

22922278
mockAllocator32Bit mock32BitAllocator;
22932279
mock32BitAllocator.free(reinterpret_cast<uint64_t>(MAP_FAILED), 100u);
22942280
EXPECT_EQ(0u, unmapCallCount);
2295-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
22962281
}
22972282

22982283
TEST(DrmAllocator32Bit, givenNullptrAsInputToFreeFunctionWhenItIsCalledThenUnmapIsNotCalled) {
2299-
bool flagToRestore = DebugManager.flags.UseNewHeapAllocator.get();
2284+
DebugManagerStateRestore restore;
23002285
DebugManager.flags.UseNewHeapAllocator.set(false);
23012286

23022287
mockAllocator32Bit mock32BitAllocator;
23032288
mock32BitAllocator.free(0llu, 100u);
23042289
EXPECT_EQ(0u, unmapCallCount);
2305-
DebugManager.flags.UseNewHeapAllocator.set(flagToRestore);
23062290
}
23072291

23082292
#include <chrono>

0 commit comments

Comments
 (0)