Skip to content

Commit

Permalink
feat(test): parse as c++ source
Browse files Browse the repository at this point in the history
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.

stack-info: PR: aws#568, branch: aws-nslick/stack/15
Signed-off-by: Nicholas Sielicki <[email protected]>
  • Loading branch information
aws-nslick committed Oct 4, 2024
1 parent 05625d4 commit c5ea412
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/distcheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
find . | grep rpm$ | xargs yum -y localinstall
- 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
run: |
${{ matrix.configmanager }} --add-repo \
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions m4/check_pkg_mpi.m4
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ 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
AS_IF([test $? -eq 0],
[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])])
Expand All @@ -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])
Expand Down
9 changes: 5 additions & 4 deletions tests/functional/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)

noinst_HEADERS = test-common.h
noinst_HEADERS = test-common.hpp

if ENABLE_TESTS
bin_PROGRAMS = nccl_connection nccl_message_transfer ring
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "config.h"

#include "test-common.h"
#include "test-common.hpp"

int main(int argc, char* argv[])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -391,7 +391,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;

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/ring.c → tests/functional/ring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "nccl_ofi_math.h"
#include "nccl_ofi_param.h"


template <typename T>
constexpr T PROC_NAME_IDX(T i) { return i * MPI_MAX_PROCESSOR_NAME; };

#define STR2(v) #v
#define STR(v) STR2(v)

Expand Down
18 changes: 9 additions & 9 deletions tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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 \
Expand All @@ -25,17 +25,17 @@ 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)
2 changes: 1 addition & 1 deletion tests/unit/deque.c → tests/unit/deque.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdio.h>

#include "test-common.h"
#include "test-common.hpp"
#include "nccl_ofi_deque.h"

#define test_get_front(deque, expected) \
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ep_addr_list.c → tests/unit/ep_addr_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdio.h>

#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)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/freelist.c → tests/unit/freelist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdio.h>

#include "test-common.h"
#include "test-common.hpp"
#include "nccl_ofi_freelist.h"

void *simple_base;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/idpool.c → tests/unit/idpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdio.h>

#include "test-common.h"
#include "test-common.hpp"
#include "nccl_ofi_idpool.h"
#include "nccl_ofi_math.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/mr.c → tests/unit/mr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdlib.h>

#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,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/msgbuff.c → tests/unit/msgbuff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "nccl_ofi_msgbuff.h"

#include "test-common.h"
#include "test-common.hpp"

int main(int argc, char *argv[])
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/scheduler.c → tests/unit/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <nccl/net.h>

#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,
Expand Down
File renamed without changes.
12 changes: 9 additions & 3 deletions tests/unit/test-common.h → tests/unit/test-common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
#ifndef TEST_COMMON_H_
#define TEST_COMMON_H_

#include "config.h"

#include <stdarg.h>
#include <stdio.h>

#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;

Expand All @@ -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
Expand All @@ -46,4 +50,6 @@ static inline void logger(ncclDebugLogLevel level, unsigned long flags, const ch
#pragma GCC diagnostic pop
}

}

#endif // End TEST_COMMON_H_

0 comments on commit c5ea412

Please sign in to comment.