From 1869778042fb02a73aead710e176c52ba9771680 Mon Sep 17 00:00:00 2001 From: Nicholas Sielicki Date: Mon, 12 Aug 2024 12:37:04 -0700 Subject: [PATCH] feat(test): parse as c++ source All included headers are fully safe to be parsed as C++, so these unit tests can now use C++. Rename them to `.cc' files and use a few c++ keywords to enforce that the compiler is actually treating them as such. Actual C++ cleanups to follow later, hopefully alongside a unit test framework like gtest or catch2. Signed-off-by: Nicholas Sielicki --- .github/workflows/distcheck.yaml | 2 +- configure.ac | 1 + m4/check_pkg_mpi.m4 | 3 +++ tests/functional/Makefile.am | 9 +++++---- .../{nccl_connection.c => nccl_connection.cc} | 2 +- ...age_transfer.c => nccl_message_transfer.cc} | 4 ++-- tests/functional/{ring.c => ring.cc} | 2 +- .../{test-common.h => test-common.hpp} | 4 ++++ tests/unit/Makefile.am | 18 +++++++++--------- tests/unit/{deque.c => deque.cc} | 2 +- tests/unit/{ep_addr_list.c => ep_addr_list.cc} | 2 +- tests/unit/{freelist.c => freelist.cc} | 2 +- tests/unit/{idpool.c => idpool.cc} | 2 +- tests/unit/{mr.c => mr.cc} | 2 +- tests/unit/{msgbuff.c => msgbuff.cc} | 2 +- tests/unit/{scheduler.c => scheduler.cc} | 2 +- ...ner_decisions.c => show_tuner_decisions.cc} | 0 tests/unit/{test-common.h => test-common.hpp} | 12 +++++++++--- 18 files changed, 43 insertions(+), 28 deletions(-) rename tests/functional/{nccl_connection.c => nccl_connection.cc} (99%) rename tests/functional/{nccl_message_transfer.c => nccl_message_transfer.cc} (99%) rename tests/functional/{ring.c => ring.cc} (99%) rename tests/functional/{test-common.h => test-common.hpp} (98%) rename tests/unit/{deque.c => deque.cc} (99%) rename tests/unit/{ep_addr_list.c => ep_addr_list.cc} (99%) rename tests/unit/{freelist.c => freelist.cc} (99%) rename tests/unit/{idpool.c => idpool.cc} (99%) rename tests/unit/{mr.c => mr.cc} (99%) rename tests/unit/{msgbuff.c => msgbuff.cc} (99%) rename tests/unit/{scheduler.c => scheduler.cc} (99%) rename tests/unit/{show_tuner_decisions.c => show_tuner_decisions.cc} (100%) rename tests/unit/{test-common.h => test-common.hpp} (80%) diff --git a/.github/workflows/distcheck.yaml b/.github/workflows/distcheck.yaml index 336b0b1a1..9fc4bdc2a 100644 --- a/.github/workflows/distcheck.yaml +++ b/.github/workflows/distcheck.yaml @@ -86,7 +86,7 @@ jobs: - name: Install hwloc, utilities. run: | - yum -y install hwloc-devel autoconf automake libtool gcc g++ git make + yum -y install hwloc-devel autoconf automake libtool gcc gcc-c++ git make - name: Install CUDA if: matrix.sdk == 'cuda' diff --git a/configure.ac b/configure.ac index 8f15d8757..cd2dc7a88 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,7 @@ NCCL_NET_OFI_DISTCHCK_CONFIGURE_FLAGS= AC_PROG_CC AM_PROG_CC_C_O m4_version_prereq([2.70], [], [AC_PROG_CC_STDC]) +AC_PROG_CXX AC_C_INLINE dnl ac_check_enable_debug will make sure AC_PROG_CC doesn't add a diff --git a/m4/check_pkg_mpi.m4 b/m4/check_pkg_mpi.m4 index a89333ad9..1b57b552d 100644 --- a/m4/check_pkg_mpi.m4 +++ b/m4/check_pkg_mpi.m4 @@ -31,6 +31,7 @@ AC_DEFUN([CHECK_PKG_MPI], [ LDFLAGS="${MPI_LDFLAGS} ${LDFLAGS}"]) MPICC=${mpi_bindir}mpicc + MPICXX=${mpi_bindir}mpicxx AC_MSG_CHECKING([for working mpicc]) ${MPICC} --help >& AS_MESSAGE_LOG_FD @@ -38,6 +39,7 @@ AC_DEFUN([CHECK_PKG_MPI], [ [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no]) MPICC="${CC}" + MPICXX="${CXX}" AS_IF([test "${check_pkg_found}" = "yes"], [AC_CHECK_HEADERS([mpi.h], [], [check_pkg_found=no])]) @@ -49,6 +51,7 @@ AC_DEFUN([CHECK_PKG_MPI], [ [$2]) AC_SUBST([MPICC]) + AC_SUBST([MPICXX]) AC_SUBST([MPI_CPPFLAGS]) AC_SUBST([MPI_LDFLAGS]) AC_SUBST([MPI_LIBS]) diff --git a/tests/functional/Makefile.am b/tests/functional/Makefile.am index 7238e6c35..7a4c0986d 100644 --- a/tests/functional/Makefile.am +++ b/tests/functional/Makefile.am @@ -12,13 +12,14 @@ AM_CPPFLAGS += $(MPI_CPPFLAGS) $(CUDA_CPPFLAGS) AM_LDFLAGS = $(MPI_LDFLAGS) $(CUDA_LDFLAGS) LDADD = $(top_builddir)/src/libinternal_net_plugin.la $(MPI_LIBS) $(CUDA_LIBS) CC = $(MPICC) +CXX = $(MPICXX) if ENABLE_FUNC_TESTS -noinst_HEADERS = test-common.h +noinst_HEADERS = test-common.hpp bin_PROGRAMS = nccl_connection nccl_message_transfer ring -nccl_connection_SOURCES = nccl_connection.c -nccl_message_transfer_SOURCES = nccl_message_transfer.c -ring_SOURCES = ring.c +nccl_connection_SOURCES = nccl_connection.cc +nccl_message_transfer_SOURCES = nccl_message_transfer.cc +ring_SOURCES = ring.cc endif diff --git a/tests/functional/nccl_connection.c b/tests/functional/nccl_connection.cc similarity index 99% rename from tests/functional/nccl_connection.c rename to tests/functional/nccl_connection.cc index ebe541d9a..96f63cd02 100644 --- a/tests/functional/nccl_connection.c +++ b/tests/functional/nccl_connection.cc @@ -8,7 +8,7 @@ #include "config.h" -#include "test-common.h" +#include "test-common.hpp" int main(int argc, char* argv[]) { diff --git a/tests/functional/nccl_message_transfer.c b/tests/functional/nccl_message_transfer.cc similarity index 99% rename from tests/functional/nccl_message_transfer.c rename to tests/functional/nccl_message_transfer.cc index 1c02ca277..598a8afd9 100644 --- a/tests/functional/nccl_message_transfer.c +++ b/tests/functional/nccl_message_transfer.cc @@ -9,7 +9,7 @@ #include "config.h" -#include "test-common.h" +#include "test-common.hpp" #define PROC_NAME_IDX(i) (i * MPI_MAX_PROCESSOR_NAME) @@ -390,7 +390,7 @@ int main(int argc, char* argv[]) MPI_Finalize(); NCCL_OFI_INFO(NCCL_NET, "Test completed successfully for rank %d", rank); -exit:; +exit: ncclResult_t close_res = ncclSuccess; diff --git a/tests/functional/ring.c b/tests/functional/ring.cc similarity index 99% rename from tests/functional/ring.c rename to tests/functional/ring.cc index 77aac75a6..abc4ccb48 100644 --- a/tests/functional/ring.c +++ b/tests/functional/ring.cc @@ -4,7 +4,7 @@ #include "config.h" -#include "test-common.h" +#include "test-common.hpp" #define PROC_NAME_IDX(i) (i * MPI_MAX_PROCESSOR_NAME) diff --git a/tests/functional/test-common.h b/tests/functional/test-common.hpp similarity index 98% rename from tests/functional/test-common.h rename to tests/functional/test-common.hpp index e83017423..51118c1cc 100644 --- a/tests/functional/test-common.h +++ b/tests/functional/test-common.hpp @@ -23,6 +23,10 @@ #include "nccl_ofi_math.h" #include "nccl_ofi_param.h" + +template +constexpr T PROC_NAME_IDX(T i) { return i * MPI_MAX_PROCESSOR_NAME; }; + #define STR2(v) #v #define STR(v) STR2(v) diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 81535ade9..9c3dafd99 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -9,7 +9,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include AM_CPPFLAGS += -isystem $(abs_top_srcdir)/3rd-party/nccl/$(DEVICE_INTERFACE)/include AM_CPPFLAGS += -isystem $(abs_top_srcdir)/3rd-party/uthash/include LDADD = $(top_builddir)/src/libinternal_net_plugin.la -noinst_HEADERS = test-common.h +noinst_HEADERS = test-common.hpp noinst_PROGRAMS = \ deque \ @@ -26,18 +26,18 @@ if WANT_PLATFORM_AWS AM_CPPFLAGS += $(CUDA_CPPFLAGS) LDADD += $(CUDA_LIBS) noinst_PROGRAMS += show_tuner_decisions - show_tuner_decisions_SOURCES = show_tuner_decisions.c + show_tuner_decisions_SOURCES = show_tuner_decisions.cc show_tuner_decisions_LDADD = $(top_builddir)/src/tuner/libinternal_tuner_plugin.la endif endif -idpool_SOURCES = idpool.c -deque_SOURCES = deque.c -freelist_SOURCES = freelist.c -msgbuff_SOURCES = msgbuff.c -scheduler_SOURCES = scheduler.c -ep_addr_list_SOURCES = ep_addr_list.c -mr_SOURCES = mr.c +idpool_SOURCES = idpool.cc +deque_SOURCES = deque.cc +freelist_SOURCES = freelist.cc +msgbuff_SOURCES = msgbuff.cc +scheduler_SOURCES = scheduler.cc +ep_addr_list_SOURCES = ep_addr_list.cc +mr_SOURCES = mr.cc TESTS = $(noinst_PROGRAMS) endif diff --git a/tests/unit/deque.c b/tests/unit/deque.cc similarity index 99% rename from tests/unit/deque.c rename to tests/unit/deque.cc index be356cfcb..c562c728f 100644 --- a/tests/unit/deque.c +++ b/tests/unit/deque.cc @@ -6,7 +6,7 @@ #include -#include "test-common.h" +#include "test-common.hpp" #include "nccl_ofi_deque.h" #define test_get_front(deque, expected) \ diff --git a/tests/unit/ep_addr_list.c b/tests/unit/ep_addr_list.cc similarity index 99% rename from tests/unit/ep_addr_list.c rename to tests/unit/ep_addr_list.cc index 7be5dd106..15d85d5ef 100644 --- a/tests/unit/ep_addr_list.c +++ b/tests/unit/ep_addr_list.cc @@ -6,7 +6,7 @@ #include -#include "test-common.h" +#include "test-common.hpp" #include "nccl_ofi_ep_addr_list.h" static void insert_addresses(nccl_ofi_ep_addr_list_t *ep_addr_list, size_t num_addr, int ep_num) diff --git a/tests/unit/freelist.c b/tests/unit/freelist.cc similarity index 99% rename from tests/unit/freelist.c rename to tests/unit/freelist.cc index aff7a9536..74c3e846b 100644 --- a/tests/unit/freelist.c +++ b/tests/unit/freelist.cc @@ -6,7 +6,7 @@ #include -#include "test-common.h" +#include "test-common.hpp" #include "nccl_ofi_freelist.h" void *simple_base; diff --git a/tests/unit/idpool.c b/tests/unit/idpool.cc similarity index 99% rename from tests/unit/idpool.c rename to tests/unit/idpool.cc index 770e98a2c..48076eeb3 100644 --- a/tests/unit/idpool.c +++ b/tests/unit/idpool.cc @@ -6,7 +6,7 @@ #include -#include "test-common.h" +#include "test-common.hpp" #include "nccl_ofi_idpool.h" #include "nccl_ofi_math.h" diff --git a/tests/unit/mr.c b/tests/unit/mr.cc similarity index 99% rename from tests/unit/mr.c rename to tests/unit/mr.cc index 549cfef55..9fa7ebdb9 100644 --- a/tests/unit/mr.c +++ b/tests/unit/mr.cc @@ -6,7 +6,7 @@ #include -#include "test-common.h" +#include "test-common.hpp" #include "nccl_ofi_mr.h" static inline bool test_lookup_impl(nccl_ofi_mr_cache_t *cache, void *addr, size_t size, diff --git a/tests/unit/msgbuff.c b/tests/unit/msgbuff.cc similarity index 99% rename from tests/unit/msgbuff.c rename to tests/unit/msgbuff.cc index f697ec8ed..0571be812 100644 --- a/tests/unit/msgbuff.c +++ b/tests/unit/msgbuff.cc @@ -8,7 +8,7 @@ #include "nccl_ofi_msgbuff.h" -#include "test-common.h" +#include "test-common.hpp" int main(int argc, char *argv[]) { diff --git a/tests/unit/scheduler.c b/tests/unit/scheduler.cc similarity index 99% rename from tests/unit/scheduler.c rename to tests/unit/scheduler.cc index d4e5fed3a..b55be1993 100644 --- a/tests/unit/scheduler.c +++ b/tests/unit/scheduler.cc @@ -10,8 +10,8 @@ #include #include "nccl_ofi_log.h" +#include "test-common.hpp" #include "nccl_ofi_scheduler.h" -#include "test-common.h" static inline int create_multiplexed(size_t size, int num_rails, diff --git a/tests/unit/show_tuner_decisions.c b/tests/unit/show_tuner_decisions.cc similarity index 100% rename from tests/unit/show_tuner_decisions.c rename to tests/unit/show_tuner_decisions.cc diff --git a/tests/unit/test-common.h b/tests/unit/test-common.hpp similarity index 80% rename from tests/unit/test-common.h rename to tests/unit/test-common.hpp index 70b97e329..adb8762dd 100644 --- a/tests/unit/test-common.h +++ b/tests/unit/test-common.hpp @@ -5,14 +5,18 @@ #ifndef TEST_COMMON_H_ #define TEST_COMMON_H_ +#include "config.h" + #include #include #include "nccl_ofi.h" #include "nccl_ofi_log.h" -static inline void logger(ncclDebugLogLevel level, unsigned long flags, const char *filefunc, - int line, const char *fmt, ...) +namespace { + +void logger(ncclDebugLogLevel level, unsigned long flags, const char *filefunc, + int line, char const *const fmt, ...) { va_list vargs; @@ -24,7 +28,7 @@ static inline void logger(ncclDebugLogLevel level, unsigned long flags, const ch printf("INFO: Function: %s Line: %d: ", filefunc, line); break; case NCCL_LOG_TRACE: -#if OFI_NCCL_TRACE +#if defined(OFI_NCCL_TRACE) && OFI_NCCL_TRACE printf("TRACE: Function: %s Line: %d: ", filefunc, line); break; #else @@ -46,4 +50,6 @@ static inline void logger(ncclDebugLogLevel level, unsigned long flags, const ch #pragma GCC diagnostic pop } +} + #endif // End TEST_COMMON_H_