Fix test framework for building with Docker

- Make MPI REQUIRED for test builds (clearer error messages)
- Add project include directories to test_framework library
- Fix core_tests.cc to use custom framework correctly
- Fix mp_unit_tests.hpp to use mscclpp::test namespace
- Add FAIL() macro with streaming support for test messages
- Building tests now works in Docker environment with GPU bypass

Tests can now be built using:
docker run --rm -v $(pwd):/workspace -w /workspace \
  ghcr.io/microsoft/mscclpp/mscclpp:base-dev-cuda12.4 bash -c \
  "mkdir build && cd build && cmake -DMSCCLPP_BYPASS_GPU_CHECK=ON \
   -DMSCCLPP_USE_CUDA=ON .. && make -j"

Co-authored-by: chhwang <8018170+chhwang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-11 01:13:29 +00:00
parent 5657e4a321
commit 0eae34c53d
4 changed files with 34 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
find_package(MPI)
find_package(MPI REQUIRED)
set(TEST_LIBS_COMMON mscclpp ${GPU_LIBRARIES} ${NUMA_LIBRARIES} Threads::Threads)
if(MSCCLPP_USE_IB)
@@ -40,7 +40,7 @@ include(CTest)
# Build test framework library
add_library(test_framework STATIC framework.cc)
target_include_directories(test_framework PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(test_framework PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${TEST_INC_COMMON})
target_link_libraries(test_framework PUBLIC MPI::MPI_CXX)
# Unit tests

View File

@@ -366,11 +366,34 @@ void reportSuccess();
} \
} while (0)
#define FAIL() \
do { \
::mscclpp::test::utils::reportFailure(__FILE__, __LINE__, "Test failed"); \
throw std::runtime_error("Test failed"); \
} while (0)
// Helper class for FAIL functionality with message streaming support
class FailHelper {
public:
explicit FailHelper(const char* file, int line) : file_(file), line_(line) {}
template <typename T>
FailHelper& operator<<(const T& value) {
message_ << value;
return *this;
}
~FailHelper() noexcept(false) {
std::string msg = message_.str();
if (!msg.empty()) {
::mscclpp::test::utils::reportFailure(file_, line_, "Test failed: " + msg);
} else {
::mscclpp::test::utils::reportFailure(file_, line_, "Test failed");
}
throw std::runtime_error("Test failed");
}
private:
const char* file_;
int line_;
std::ostringstream message_;
};
// Test fail macro - throws exception to fail test execution
// Usage: FAIL() << "Optional fail message";
#define FAIL() ::mscclpp::test::FailHelper(__FILE__, __LINE__)
// Helper class for GTEST_SKIP functionality
// This class uses RAII (Resource Acquisition Is Initialization) pattern:

View File

@@ -15,7 +15,7 @@
#include "ib.hpp"
#include "utils_internal.hpp"
class MultiProcessTestEnv : public ::testing::Environment {
class MultiProcessTestEnv : public ::mscclpp::test::Environment {
public:
MultiProcessTestEnv(int argc, const char** argv);
@@ -36,7 +36,7 @@ mscclpp::Transport ibIdToTransport(int id);
int rankToLocalRank(int rank);
int rankToNode(int rank);
class MultiProcessTest : public ::testing::Test {
class MultiProcessTest : public ::mscclpp::test::TestCase {
protected:
void TearDown() override;
};

View File

@@ -1,13 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include <gmock/gmock.h>
#include "../framework.hpp"
#include <mscclpp/core.hpp>
#include "../framework.hpp"
class LocalCommunicatorTest : public ::testing::Test {
class LocalCommunicatorTest : public ::mscclpp::test::TestCase {
protected:
void SetUp() override {
bootstrap = std::make_shared<mscclpp::TcpBootstrap>(0, 1);