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: #568, branch: aws-nslick/stack/15
Signed-off-by: Nicholas Sielicki <nslick@amazon.com>
  • Loading branch information
aws-nslick committed Sep 12, 2024
1 parent be3256a commit 2d28df3
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 37 deletions.
10 changes: 5 additions & 5 deletions tests/functional/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
File renamed without changes.
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,9 +9,7 @@

#include "config.h"

#include "test-common.h"

#define PROC_NAME_IDX(i) (i * MPI_MAX_PROCESSOR_NAME)
#include "test-common.hpp"

int main(int argc, char* argv[])
{
Expand Down Expand Up @@ -57,6 +55,7 @@ int main(int argc, char* argv[])
int 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;
Expand Down Expand Up @@ -133,7 +132,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++) {
Expand Down Expand Up @@ -398,7 +396,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
4 changes: 1 addition & 3 deletions tests/functional/ring.c → tests/functional/ring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

#include "config.h"

#include "test-common.h"

#define PROC_NAME_IDX(i) (i * MPI_MAX_PROCESSOR_NAME)
#include "test-common.hpp"

int main(int argc, char *argv[])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <stdarg.h>
#include <cuda.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
17 changes: 9 additions & 8 deletions tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
11 changes: 5 additions & 6 deletions 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 All @@ -32,14 +32,13 @@

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;
Expand All @@ -48,7 +47,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);
Expand All @@ -72,7 +71,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);
}
Expand All @@ -83,7 +82,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);
}
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"

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 @@ -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,
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, const char *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 @@ -40,4 +44,6 @@ static inline void logger(ncclDebugLogLevel level, unsigned long flags, const ch
va_end(vargs);
}

}

#endif // End TEST_COMMON_H_

0 comments on commit 2d28df3

Please sign in to comment.