Skip to content

Commit 421d05a

Browse files
Fixup tests
1 parent 521ded2 commit 421d05a

5 files changed

Lines changed: 163 additions & 151 deletions

File tree

src/umpire/ResourceManager.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ ResourceManager& ResourceManager::getInstance()
101101

102102
ResourceManager::ResourceManager()
103103
: m_allocations(),
104-
m_exact_allocations(),
105104
m_allocators(),
106105
m_shared_allocator_names(),
107106
m_allocators_by_id(),
@@ -112,8 +111,7 @@ ResourceManager::ResourceManager()
112111
m_zero_byte_pool(nullptr),
113112
m_introspection_level{parse_introspection_level(std::getenv(s_introspection_level_env_name))},
114113
m_id(0),
115-
m_mutex(),
116-
m_exact_allocations_mutex()
114+
m_mutex()
117115
{
118116
UMPIRE_LOG(Debug, "() entering");
119117

@@ -133,7 +131,9 @@ ResourceManager::~ResourceManager()
133131
if (allocator->getCurrentSize() != 0) {
134132
std::stringstream ss;
135133

136-
printTrackedAllocationRecords(allocator.get(), ss);
134+
if (getIntrospectionLevel() == IntrospectionLevel::On) {
135+
printTrackedAllocationRecords(allocator.get(), ss);
136+
}
137137

138138
UMPIRE_LOG(Error, allocator->getName()
139139
<< " Allocator still has " << allocator->getCurrentSize() << " bytes allocated" << std::endl
@@ -184,9 +184,16 @@ void ResourceManager::initialize()
184184

185185
void ResourceManager::setIntrospectionLevel(IntrospectionLevel level)
186186
{
187-
if (m_allocations_exist) {
187+
const auto current_level = getIntrospectionLevel();
188+
189+
// Only block lowering from On mode if tracked allocations exist in AllocationMap
190+
// (can't switch to Basic/Off if we have tracked allocations)
191+
if (current_level == IntrospectionLevel::On &&
192+
static_cast<int>(level) < static_cast<int>(current_level) &&
193+
m_allocations.size() > 0) {
188194
UMPIRE_ERROR(runtime_error,
189-
"Cannot change introspection level after allocations have been made");
195+
fmt::format("Cannot lower introspection level from \"on\" to \"{}\" while tracked allocations exist",
196+
to_string(level)));
190197
}
191198
m_introspection_level.store(level, std::memory_order_relaxed);
192199
}
@@ -554,8 +561,9 @@ Allocator ResourceManager::getAllocator(void* ptr)
554561
{
555562
UMPIRE_LOG(Debug, "(ptr=" << ptr << ")");
556563
const auto level = getIntrospectionLevel();
557-
if (!requires_full_introspection(level)) {
558-
throw_requires_full_introspection("ResourceManager::getAllocator(void*)", level);
564+
if (level == IntrospectionLevel::Off) {
565+
UMPIRE_ERROR(runtime_error,
566+
"ResourceManager::getAllocator(void*) requires introspection to be enabled (basic or on mode)");
559567
}
560568
return Allocator(findAllocatorForPointer(ptr));
561569
}
@@ -621,8 +629,6 @@ void ResourceManager::registerAllocation(void* ptr, util::AllocationRecord recor
621629
UMPIRE_ERROR(runtime_error, "Cannot register nullptr!");
622630
}
623631

624-
m_allocations_exist = true; // Mark that allocations exist
625-
626632
UMPIRE_LOG(Debug,
627633
"(ptr=" << ptr << ", size=" << record.size << ", strategy=" << record.strategy << ") with " << this);
628634

@@ -1099,13 +1105,6 @@ void* ResourceManager::move(void* ptr, Allocator allocator)
10991105
throw_requires_full_introspection("ResourceManager::move", level);
11001106
}
11011107

1102-
const auto level = getIntrospectionLevel();
1103-
1104-
if (level != IntrospectionLevel::On) {
1105-
UMPIRE_ERROR(runtime_error,
1106-
"move() requires IntrospectionLevel::On");
1107-
}
1108-
11091108
auto alloc_record = m_allocations.find(ptr);
11101109

11111110
// short-circuit if ptr was allocated by 'allocator'
@@ -1187,13 +1186,6 @@ camp::resources::EventProxy<camp::resources::Resource> ResourceManager::prefetch
11871186
throw_requires_full_introspection("ResourceManager::prefetch", level);
11881187
}
11891188

1190-
const auto level = getIntrospectionLevel();
1191-
1192-
if (level != IntrospectionLevel::On) {
1193-
UMPIRE_ERROR(runtime_error,
1194-
"prefetch() requires IntrospectionLevel::On");
1195-
}
1196-
11971189
auto& op_registry = op::MemoryOperationRegistry::getInstance();
11981190
auto alloc_record = m_allocations.find(ptr);
11991191

src/umpire/ResourceManager.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@ class ResourceManager {
412412

413413
util::AllocationMap m_allocations;
414414

415-
bool m_allocations_exist{false}; // Track if any allocations made
416-
417415
std::list<std::unique_ptr<strategy::AllocationStrategy>> m_allocators;
418416
std::vector<std::string> m_shared_allocator_names;
419417

src/umpire/strategy/mixins/Inspector.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ Inspector::deregisterAllocation(void* ptr, strategy::AllocationStrategy* s)
4848
{
4949
auto record = ResourceManager::getInstance().deregisterAllocation(ptr);
5050

51-
if (record.strategy == s) {
51+
// In Basic/Off modes, record.strategy will be nullptr (no tracking)
52+
if (record.strategy == nullptr || record.strategy == s) {
5253
s->m_current_size -= record.size;
5354
s->m_allocation_count--;
5455
} else {

tests/integration/CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,30 @@ blt_add_executable(
239239
SOURCES introspection_tests.cpp
240240
DEPENDS_ON ${integration_tests_depends})
241241

242+
# Run introspection tests with Off mode
242243
blt_add_test(
243-
NAME introspection_tests
244+
NAME introspection_tests_off
245+
COMMAND introspection_tests)
246+
247+
set_property(TEST introspection_tests_off
248+
PROPERTY ENVIRONMENT "UMPIRE_INTROSPECTION_LEVEL=off")
249+
250+
# Run introspection tests with Basic mode
251+
blt_add_test(
252+
NAME introspection_tests_basic
244253
COMMAND introspection_tests)
245254

255+
set_property(TEST introspection_tests_basic
256+
PROPERTY ENVIRONMENT "UMPIRE_INTROSPECTION_LEVEL=basic")
257+
258+
# Run introspection tests with On mode
259+
blt_add_test(
260+
NAME introspection_tests_on
261+
COMMAND introspection_tests)
262+
263+
set_property(TEST introspection_tests_on
264+
PROPERTY ENVIRONMENT "UMPIRE_INTROSPECTION_LEVEL=on")
265+
246266
blt_add_executable(
247267
NAME destroy_allocator_tests
248268
SOURCES destroy_allocator_tests.cpp

0 commit comments

Comments
 (0)