// Copyright (c) Microsoft Corporation. // Licensed under the MIT license. #include #include #include class LocalCommunicatorTest : public ::testing::Test { protected: void SetUp() override { bootstrap = std::make_shared(0, 1); bootstrap->initialize(bootstrap->createUniqueId()); comm = std::make_shared(bootstrap); } std::shared_ptr bootstrap; std::shared_ptr comm; }; class MockSetuppable : public mscclpp::Setuppable { public: MOCK_METHOD(void, beginSetup, (std::shared_ptr bootstrap), (override)); MOCK_METHOD(void, endSetup, (std::shared_ptr bootstrap), (override)); }; TEST_F(LocalCommunicatorTest, OnSetup) { auto mockSetuppable = std::make_shared(); comm->onSetup(mockSetuppable); EXPECT_CALL(*mockSetuppable, beginSetup(std::dynamic_pointer_cast(bootstrap))); EXPECT_CALL(*mockSetuppable, endSetup(std::dynamic_pointer_cast(bootstrap))); comm->setup(); } TEST_F(LocalCommunicatorTest, RegisterMemory) { int dummy[42]; auto memory = comm->registerMemory(&dummy, sizeof(dummy), mscclpp::NoTransports); EXPECT_EQ(memory.data(), &dummy); EXPECT_EQ(memory.size(), sizeof(dummy)); EXPECT_EQ(memory.transports(), mscclpp::NoTransports); } TEST_F(LocalCommunicatorTest, SendMemoryToSelf) { int dummy[42]; auto memory = comm->registerMemory(&dummy, sizeof(dummy), mscclpp::NoTransports); comm->sendMemoryOnSetup(memory, 0, 0); auto memoryFuture = comm->recvMemoryOnSetup(0, 0); comm->setup(); auto sameMemory = memoryFuture.get(); EXPECT_EQ(sameMemory.data(), memory.data()); EXPECT_EQ(sameMemory.size(), memory.size()); EXPECT_EQ(sameMemory.transports(), memory.transports()); }