Skip to content

Commit 1992bdd

Browse files
authored
only register test device allocator once for multiple invoke (#19541)
Summary: On AppleMac, the XCTest harness invokes RUN_ALL_TESTS() once per test method within the same process, so DeviceAllocatorTest::SetUpTestSuite() runs multiple times. The second invocation calls register_device_allocator(&cuda_allocator()) for an already-registered CUDA slot, hitting ET_CHECK_MSG(allocators_[index] == nullptr, ...) in device_allocator.cpp:30 and aborting the process. This diff made the registration in SetUpTestSuite() idempotent by guarding it with get_device_allocator(DeviceType::CUDA) == nullptr. Differential Revision: D104955274
1 parent 52634f3 commit 1992bdd

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

runtime/core/test/device_allocator_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ class DeviceAllocatorTest : public ::testing::Test {
147147

148148
static void SetUpTestSuite() {
149149
executorch::runtime::runtime_init();
150-
register_device_allocator(&cuda_allocator());
150+
if (get_device_allocator(DeviceType::CUDA) == nullptr) {
151+
register_device_allocator(&cuda_allocator());
152+
}
151153
}
152154

153155
void SetUp() override {

0 commit comments

Comments
 (0)