From ae28f30a810660ab97a8d10e140ce61bea9a64a1 Mon Sep 17 00:00:00 2001 From: Nicholas Sielicki Date: Mon, 12 Aug 2024 12:37:04 -0700 Subject: [PATCH] tests: move to c++ stack-info: PR: https://github.com/aws/aws-ofi-nccl/pull/568, branch: aws-nslick/stack/15 Signed-off-by: Nicholas Sielicki --- tests/functional/Makefile.am | 10 +++++----- .../functional/{cuda_check.c => cuda_check.cc} | 0 .../{nccl_connection.c => nccl_connection.cc} | 2 +- ...sage_transfer.c => nccl_message_transfer.cc} | 9 +++++---- tests/functional/{ring.c => ring.cc} | 2 +- .../{test-common.h => test-common.hpp} | 0 tests/unit/Makefile.am | 17 +++++++++-------- tests/unit/{deque.c => deque.cc} | 11 +++++------ 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 +- ...uner_decisions.c => show_tuner_decisions.cc} | 0 tests/unit/{test-common.h => test-common.hpp} | 2 ++ 16 files changed, 34 insertions(+), 31 deletions(-) rename tests/functional/{cuda_check.c => cuda_check.cc} (100%) 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} (100%) rename tests/unit/{deque.c => deque.cc} (89%) 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} (98%) diff --git a/tests/functional/Makefile.am b/tests/functional/Makefile.am index 092184034..ceddf1267 100644 --- a/tests/functional/Makefile.am +++ b/tests/functional/Makefile.am @@ -11,18 +11,18 @@ LDADD = $(top_builddir)/src/libinternal_net_plugin.la $(MPI_LIBS) $(CUDA_LIBS) CC = $(MPICC) CXX = $(MPICXX) -noinst_HEADERS = test-common.h +noinst_HEADERS = test-common.hpp if ENABLE_TESTS bin_PROGRAMS = nccl_connection nccl_message_transfer ring noinst_PROGRAMS = cuda_check endif -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 -cuda_check_SOURCES = cuda_check.c +cuda_check_SOURCES = cuda_check.cc # Override the LDADD for this check to avoid the -lcudart used by the # other tests, since the purpose of this test is to make sure we # didn't leak direct cuda dependencies into the plugin. diff --git a/tests/functional/cuda_check.c b/tests/functional/cuda_check.cc similarity index 100% rename from tests/functional/cuda_check.c rename to tests/functional/cuda_check.cc 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 9990a6d88..ab5380399 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 d1c7c2c0c..fb99f091f 100644 --- a/tests/functional/nccl_message_transfer.c +++ b/tests/functional/nccl_message_transfer.cc @@ -9,9 +9,10 @@ #include "config.h" -#include "test-common.h" +#include "test-common.hpp" -#define PROC_NAME_IDX(i) (i * MPI_MAX_PROCESSOR_NAME) +template +constexpr T PROC_NAME_IDX(T i) { return i * MPI_MAX_PROCESSOR_NAME; }; int main(int argc, char* argv[]) { @@ -57,6 +58,7 @@ int main(int argc, char* argv[]) size_t recv_sizes[] = {4 * 1024, 16 * 1024, 1024 * 1024, 4 * 1024, 16 * 1024, 1024 * 1024, 5 * 1024, 17 * 1024, 2 * 1024 * 1024}; + test_nccl_properties_t props = {}; /* For grouped recvs */ int tag = 1; @@ -133,7 +135,6 @@ int main(int argc, char* argv[]) goto exit; } - test_nccl_properties_t props = {}; /* Get Properties for the device */ for (int dev = 0; dev < ndev; dev++) { @@ -398,7 +399,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 aa68f67e6..d05c65a96 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 100% rename from tests/functional/test-common.h rename to tests/functional/test-common.hpp diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 985d96a19..027eff4e5 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -7,7 +7,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include LDADD = $(top_builddir)/src/libinternal_net_plugin.la -noinst_HEADERS = test-common.h +noinst_HEADERS = test-common.hpp noinst_PROGRAMS = \ deque \ @@ -21,12 +21,13 @@ noinst_PROGRAMS = \ TESTS = $(noinst_PROGRAMS) -show_tuner_decisions_SOURCES = show_tuner_decisions.c +show_tuner_decisions_SOURCES = show_tuner_decisions.cc show_tuner_decisions_LDADD = $(top_builddir)/src/libinternal_tuner_plugin.la -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 diff --git a/tests/unit/deque.c b/tests/unit/deque.cc similarity index 89% rename from tests/unit/deque.c rename to tests/unit/deque.cc index d061176c6..992013523 100644 --- a/tests/unit/deque.c +++ b/tests/unit/deque.cc @@ -6,19 +6,18 @@ #include -#include "test-common.h" +#include "test-common.hpp" #include "nccl_ofi_deque.h" int main(int argc, char *argv[]) { - const size_t num_elem = 11; + constexpr size_t num_elem = 11; struct elem_t { nccl_ofi_deque_elem_t de; int v; } elems[num_elem]; nccl_ofi_deque_elem_t *deque_elem; - int ret; size_t i; for (i = 0; i < num_elem; ++i) { elems[i].v = i; @@ -27,7 +26,7 @@ int main(int argc, char *argv[]) ofi_log_function = logger; nccl_ofi_deque_t *deque; - ret = nccl_ofi_deque_init(&deque); + int ret = nccl_ofi_deque_init(&deque); if (ret) { NCCL_OFI_WARN("deque_init failed: %d", ret); exit(1); @@ -51,7 +50,7 @@ int main(int argc, char *argv[]) for (i = 0; i < num_elem; ++i) { int expected = (i == 0 ? elems[num_elem-1].v : elems[i-1].v); ret = nccl_ofi_deque_remove_front(deque, &deque_elem); - if (ret || deque_elem == NULL) { + if (ret || deque_elem == nullptr) { NCCL_OFI_WARN("remove_front unexpectedly failed: %d", ret); exit(1); } @@ -62,7 +61,7 @@ int main(int argc, char *argv[]) } } ret = nccl_ofi_deque_remove_front(deque, &deque_elem); - if (ret != 0 || deque_elem != NULL) { + if (ret != 0 || deque_elem != nullptr) { NCCL_OFI_WARN("remove_front from empty deque unexpectedly succeeded"); exit(1); } 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 4fd040e98..690bb9a23 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 7cfcb9b60..50e75b2dd 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 e84b3e960..c25fdb913 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 1ad385f25..6f8ad3811 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" 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 1949161f3..5ae75c372 100644 --- a/tests/unit/scheduler.c +++ b/tests/unit/scheduler.cc @@ -11,7 +11,7 @@ #include "nccl-headers/net.h" -#include "test-common.h" +#include "test-common.hpp" #include "nccl_ofi_scheduler.h" int create_multiplexed(size_t size, 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 98% rename from tests/unit/test-common.h rename to tests/unit/test-common.hpp index 23437a258..36b6b1ca5 100644 --- a/tests/unit/test-common.h +++ b/tests/unit/test-common.hpp @@ -11,6 +11,7 @@ #include "nccl_ofi.h" #include "nccl_ofi_log.h" +namespace { static inline void logger(ncclDebugLogLevel level, unsigned long flags, const char *filefunc, int line, const char *fmt, ...) { @@ -39,5 +40,6 @@ static inline void logger(ncclDebugLogLevel level, unsigned long flags, const ch printf("\n"); va_end(vargs); } +} #endif // End TEST_COMMON_H_