Skip to content

Commit ed6588a

Browse files
committed
test: Add unit test verifying c application can dlopen library
This test checks whether plugin library can be loaded with dlopen from c application . The reason is that plugin formerly didn't link against libstdc++ and relied on application to provide required linkage. This has been fixed by recent commit but test was not added. Signed-off-by: Michael Axtmann <[email protected]>
1 parent b635afb commit ed6588a

12 files changed

+84
-14
lines changed

tests/unit/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ region_based_tuner
88
scheduler
99
histogram
1010
histogram_binner
11+
dlopen_c_test

tests/unit/Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
1111
AM_CPPFLAGS += -isystem $(abs_top_srcdir)/3rd-party/nccl/$(DEVICE_INTERFACE)/include
1212
AM_CPPFLAGS += -isystem $(abs_top_srcdir)/3rd-party/uthash/include
1313
LDADD = $(top_builddir)/src/libinternal_net_plugin.la
14-
noinst_HEADERS = test-common.h
14+
noinst_HEADERS = test-logger.h
1515

1616
noinst_PROGRAMS = \
1717
freelist \
@@ -21,7 +21,8 @@ noinst_PROGRAMS = \
2121
ep_addr_list \
2222
mr \
2323
histogram_binner \
24-
histogram
24+
histogram \
25+
dlopen_c_test
2526

2627
if WANT_PLATFORM_AWS
2728
noinst_PROGRAMS += aws_platform_mapper
@@ -47,6 +48,7 @@ mr_SOURCES = mr.cpp
4748
aws_platform_mapper_SOURCES = aws_platform_mapper.cpp
4849
histogram_binner_SOURCES = histogram_binner.cpp
4950
histogram_SOURCES = histogram.cpp
51+
dlopen_c_test_SOURCES = dlopen_c_test.c
5052

5153
TESTS = $(noinst_PROGRAMS)
5254
endif

tests/unit/aws_platform_mapper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
#include "config.h"
66

7-
#include "test-common.h"
7+
#include "nccl_ofi.h"
8+
#include "test-logger.h"
89
#include <stdio.h>
910
#include <string.h>
1011

tests/unit/dlopen_c_test.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
*/
4+
5+
#include "config.h"
6+
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include <assert.h>
10+
#include <stdint.h>
11+
#include <dlfcn.h>
12+
#include <string.h>
13+
14+
#include "test-logger.h"
15+
16+
nccl_ofi_logger_t ofi_log_function = NULL;
17+
18+
/*
19+
* This is a simple C test that loads the shared object dynamically
20+
* for the AWS OFI NCCL plugin
21+
*/
22+
23+
int main(int argc, char *argv[])
24+
{
25+
void *handle = NULL;
26+
char *error = NULL;
27+
int ret = 0;
28+
char *lib_path = NULL;
29+
30+
/* Set up logging */
31+
ofi_log_function = logger;
32+
33+
/* Try to load the appropriate shared object based on build configuration */
34+
#if HAVE_NEURON
35+
lib_path = "../../src/.libs/libnccom-net.so";
36+
NCCL_OFI_INFO(NCCL_INIT, "Testing Neuron build: attempting to load %s\n", lib_path);
37+
#elif HAVE_CUDA
38+
lib_path = "../../src/.libs/libnccl_net_ofi.so";
39+
NCCL_OFI_INFO(NCCL_INIT, "Testing standard build: attempting to load %s\n", lib_path);
40+
#else
41+
#error "Need either Neuron or Cuda"
42+
#endif
43+
44+
/* Open the shared object file */
45+
handle = dlopen(lib_path, RTLD_NOW | RTLD_LOCAL);
46+
if (!handle) {
47+
NCCL_OFI_WARN("Error opening shared object: %s\n", dlerror());
48+
return 1;
49+
}
50+
51+
/* Log test progress */
52+
NCCL_OFI_INFO(NCCL_INIT, "Successfully loaded AWS OFI NCCL plugin shared object");
53+
54+
/* Close the shared object */
55+
dlclose(handle);
56+
57+
NCCL_OFI_INFO(NCCL_INIT, "Test completed successfully!\n");
58+
59+
return 0;
60+
}

tests/unit/ep_addr_list.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
#include <stdio.h>
88

9-
#include "test-common.h"
9+
#include "nccl_ofi.h"
10+
#include "test-logger.h"
1011
#include "nccl_ofi_ep_addr_list.h"
1112

1213
static void insert_addresses(nccl_ofi_ep_addr_list_t &ep_addr_list, size_t num_addr, int ep_num)

tests/unit/freelist.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
#include <stdio.h>
88

9-
#include "test-common.h"
9+
#include "nccl_ofi.h"
10+
#include "test-logger.h"
1011
#include "nccl_ofi_freelist.h"
1112

1213
void *simple_base;

tests/unit/histogram.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
#include <iostream>
88

9-
#include "test-common.h"
9+
#include "nccl_ofi.h"
10+
#include "test-logger.h"
1011
#include "stats/histogram.h"
1112

1213

tests/unit/idpool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include <stdexcept>
88
#include <stdio.h>
99

10-
#include "test-common.h"
10+
#include "nccl_ofi.h"
11+
#include "test-logger.h"
1112
#include "nccl_ofi_idpool.h"
1213
#include "nccl_ofi_math.h"
1314

tests/unit/mr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
#include <stdlib.h>
88

9-
#include "test-common.h"
9+
#include "nccl_ofi.h"
10+
#include "test-logger.h"
1011
#include "nccl_ofi_mr.h"
1112

1213
static inline bool test_lookup_impl(nccl_ofi_mr_cache_t *cache, void *addr, size_t size,

tests/unit/msgbuff.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
#include "nccl_ofi_msgbuff.h"
1010

11-
#include "test-common.h"
11+
#include "nccl_ofi.h"
12+
#include "test-logger.h"
1213

1314
int main(int argc, char *argv[])
1415
{

tests/unit/scheduler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
#include "nccl_ofi_log.h"
1313
#include "nccl_ofi_scheduler.h"
14-
#include "test-common.h"
14+
#include "nccl_ofi.h"
15+
#include "test-logger.h"
1516

1617
static inline int verify_xfer_info(nccl_net_ofi_xfer_info_t *xfer, nccl_net_ofi_xfer_info_t *ref_xfer, int xfer_id)
1718
{

tests/unit/test-common.h renamed to tests/unit/test-logger.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
* Copyright (c) 2018-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
33
*/
44

5-
#ifndef TEST_COMMON_H_
6-
#define TEST_COMMON_H_
5+
#ifndef TEST_LOGGER_H_
6+
#define TEST_LOGGER_H_
77

88
#include <stdarg.h>
99
#include <stdio.h>
1010

11-
#include "nccl_ofi.h"
1211
#include "nccl_ofi_log.h"
1312

1413
static inline void logger(ncclDebugLogLevel level, unsigned long flags, const char *filefunc,
@@ -45,5 +44,5 @@ static inline void logger(ncclDebugLogLevel level, unsigned long flags, const ch
4544
va_end(vargs);
4645
#pragma GCC diagnostic pop
4746
}
47+
#endif // End TEST_LOGGER_H_
4848

49-
#endif // End TEST_COMMON_H_

0 commit comments

Comments
 (0)