Skip to content

Commit 4a0ba71

Browse files
author
Ossama Othman
authored
tests: Prevent installation of test plugin binaries (#74)
Test plugin binaries were inadvertently installed along with the mptcpd binaries. This was caused by the attempt to get test plugins to be built as actual Libtool modules rather than Libtool convenience libraries when listing test plugins under the Automake check_LTLIBRARIES variable. Test plugins were built and installed locally under the tests subdirectory, but the base install directory could be overriden with the DESTDIR make variable, ultimately forcing test plugin binaries to be installed outside of the mptcpd tests directory. The fix involved listing the plugins under the check_LTLIBRARIES Automake variable, and forcing Libtool to generate modules instead of convenience libraries by adding a "-rpath" option to the linker flags. Test plugins sources were then moved to appropriately named test subdirectories to make the plugin test less brittle, and more easily understood. A side benefit is that test plugins are now only built if the tests themselves are built via `make check' or `make distcheck'. Fixes #72.
1 parent f1f8b2f commit 4a0ba71

File tree

18 files changed

+230
-145
lines changed

18 files changed

+230
-145
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ autom4te.cache/
2323
compile
2424
configure
2525
depcomp
26+
.dirstamp
2627
install-sh
2728
libtool
2829
ltmain.sh

configure.ac

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ AX_CHECK_LINK_FLAG([-pie],
267267
AC_SUBST([EXECUTABLE_LDFLAGS])
268268
])
269269

270+
# ---------------------------------------------------------------
271+
# Test plugin names (centrally defined here)
272+
# ---------------------------------------------------------------
273+
AC_SUBST([TEST_PLUGIN_ONE], [plugin_one])
274+
AC_SUBST([TEST_PLUGIN_TWO], [plugin_two])
275+
AC_SUBST([TEST_PLUGIN_THREE], [plugin_three])
276+
AC_SUBST([TEST_PLUGIN_FOUR], [plugin_four])
277+
AC_SUBST([TEST_PLUGIN_NOOP], [plugin_noop])
278+
270279
# ---------------------------------------------------------------
271280
# Generate our build files.
272281
# ---------------------------------------------------------------
@@ -282,5 +291,10 @@ AC_CONFIG_FILES([Makefile
282291
plugins/Makefile
283292
plugins/path_managers/Makefile
284293
scripts/Makefile
285-
tests/Makefile])
294+
tests/Makefile
295+
tests/lib/Makefile
296+
tests/plugins/Makefile
297+
tests/plugins/noop/Makefile
298+
tests/plugins/priority/Makefile
299+
tests/plugins/security/Makefile])
286300
AC_OUTPUT

tests/Makefile.am

Lines changed: 47 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -2,120 +2,23 @@
22
##
33
## Copyright (c) 2017-2020, Intel Corporation
44

5-
## @todo Do not add the EXECUTABLE_* flags to test libraries (if any).
6-
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
7-
AM_CFLAGS = $(ELL_CFLAGS) $(EXECUTABLE_CFLAGS)
8-
AM_LDFLAGS = $(EXECUTABLE_LDFLAGS)
9-
10-
## Convenience library that contains utility functions used by the
11-
## mptcpd tests.
12-
noinst_LTLIBRARIES = libmptcpd_test.la
13-
14-
libmptcpd_test_la_SOURCES = call_count.c call_plugin.c sockaddr.c
15-
libmptcpd_test_la_CPPFLAGS = \
16-
$(CODE_COVERAGE_CPPFLAGS) $(AM_CPPFLAGS)
17-
libmptcpd_test_la_CFLAGS = $(ELL_CFLAGS) $(CODE_COVERAGE_CFLAGS)
18-
libmptcpd_test_la_LIBADD = $(ELL_LIBS) $(CODE_COVERAGE_LIBS)
19-
20-
## Build a test mptcpd plugin.
21-
##
22-
## "check_LTLIBRARIES" can't be used here since a dynamically loadable
23-
## module will not be built. A Libtool convenience library would be
24-
## built instead.
25-
##
26-
## Absolute path needed by Libtool during installation.
27-
plugin_adir = $(abs_builddir)/plugins_a
28-
plugin_bdir = $(abs_builddir)/plugins_b
29-
plugin_noopdir = $(abs_builddir)/plugins_noop
30-
31-
## For testing mptcpd plugin framework when default plugin is
32-
## explicitly specified, as well as plugin security checks.
33-
plugin_a_LTLIBRARIES = plugin_three.la plugin_four.la
34-
35-
## For testing mptcpd plugin framework when default plugin is
36-
## is the first registered plugin, i.e. the one with the *lowest*
37-
## plugin priority, as well as testing plugin operation dispatch.
38-
plugin_b_LTLIBRARIES = plugin_one.la plugin_two.la
39-
40-
## For mptcpd tests that require a plugin without testing the plugin
41-
## itself. The plugin will be a no-op in this case.
42-
plugin_noop_LTLIBRARIES = plugin_noop.la
43-
44-
TEST_PLUGIN_DIR_A = $(DESTDIR)$(plugin_adir)
45-
TEST_PLUGIN_DIR_B = $(DESTDIR)$(plugin_bdir)
46-
TEST_PLUGIN_DIR_NOOP = $(DESTDIR)$(plugin_noopdir)
47-
48-
## List of test plugin directory for use as dependencies for test
49-
## plugin installation.
50-
TEST_PLUGIN_DIRS = \
51-
$(TEST_PLUGIN_DIR_A) \
52-
$(TEST_PLUGIN_DIR_B) \
53-
$(TEST_PLUGIN_DIR_NOOP)
54-
55-
## Plugin names
56-
TEST_PLUGIN_ONE = plugin_one
57-
TEST_PLUGIN_TWO = plugin_two
58-
TEST_PLUGIN_THREE = plugin_three
59-
TEST_PLUGIN_FOUR = plugin_four
60-
TEST_PLUGIN_NOOP = plugin_noop
61-
62-
## libmptcpd hasn't been installed yet, so directly link to the
63-
## library in its build directory so that dynamic linker can find it
64-
## when relinking the "installed" test plugin binaries.
65-
PLUGIN_LIBMPTCPD_FLAGS = -L$(abs_top_builddir)/lib/.libs -lmptcpd
5+
include $(top_srcdir)/aminclude_static.am
666

67-
plugin_one_la_SOURCES = plugin_one.c
68-
plugin_one_la_CPPFLAGS = \
69-
$(AM_CPPFLAGS) \
70-
-DTEST_PLUGIN=\"$(TEST_PLUGIN_ONE)\"
71-
plugin_one_la_CFLAGS = $(ELL_CFLAGS)
72-
plugin_one_la_LDFLAGS = -no-undefined -module -avoid-version $(ELL_LIBS)
73-
plugin_one_la_LIBADD = $(PLUGIN_LIBMPTCPD_FLAGS) libmptcpd_test.la
7+
SUBDIRS = lib plugins
748

75-
plugin_two_la_SOURCES = plugin_two.c
76-
plugin_two_la_CPPFLAGS = \
77-
$(AM_CPPFLAGS) \
78-
-DTEST_PLUGIN=\"$(TEST_PLUGIN_TWO)\"
79-
plugin_two_la_CFLAGS = $(ELL_CFLAGS)
80-
plugin_two_la_LDFLAGS = -no-undefined -module -avoid-version $(ELL_LIBS)
81-
plugin_two_la_LIBADD = $(PLUGIN_LIBMPTCPD_FLAGS) libmptcpd_test.la
82-
83-
plugin_three_la_SOURCES = plugin_three.c
84-
plugin_three_la_CPPFLAGS = \
85-
$(AM_CPPFLAGS) \
86-
-DTEST_PLUGIN=\"$(TEST_PLUGIN_THREE)\"
87-
plugin_three_la_CFLAGS = $(ELL_CFLAGS)
88-
plugin_three_la_LDFLAGS = -no-undefined -module -avoid-version $(ELL_LIBS)
89-
plugin_three_la_LIBADD = $(PLUGIN_LIBMPTCPD_FLAGS) libmptcpd_test.la
90-
91-
plugin_four_la_SOURCES = plugin_four.c
92-
plugin_four_la_CPPFLAGS = \
93-
$(AM_CPPFLAGS) \
94-
-DTEST_PLUGIN=\"$(TEST_PLUGIN_FOUR)\"
95-
plugin_four_la_CFLAGS = $(ELL_CFLAGS)
96-
plugin_four_la_LDFLAGS = \
97-
-no-undefined -module -avoid-version $(ELL_LIBS)
98-
plugin_four_la_LIBADD = $(PLUGIN_LIBMPTCPD_FLAGS) libmptcpd_test.la
99-
100-
plugin_noop_la_SOURCES = plugin_noop.c
101-
plugin_noop_la_CPPFLAGS = \
102-
$(AM_CPPFLAGS) \
103-
-DTEST_PLUGIN=\"$(TEST_PLUGIN_NOOP)\"
104-
plugin_noop_la_CFLAGS = $(ELL_CFLAGS)
105-
plugin_noop_la_LDFLAGS = \
106-
-no-undefined -module -avoid-version $(ELL_LIBS)
107-
plugin_noop_la_LIBADD = $(PLUGIN_LIBMPTCPD_FLAGS)
108-
109-
## List of test plugin sources for use as dependencies for test plugin
110-
## installation.
111-
TEST_PLUGIN_SOURCE_FILES = \
112-
$(plugin_one_la_SOURCES) \
113-
$(plugin_two_la_SOURCES) \
114-
$(plugin_three_la_SOURCES) \
115-
$(plugin_four_la_SOURCES) \
116-
$(plugin_noop_la_SOURCES)
9+
## @todo Do not add the EXECUTABLE_* flags to test libraries (if any).
10+
AM_CPPFLAGS = \
11+
-I$(top_srcdir)/include \
12+
-I$(top_builddir)/include \
13+
-I$(srcdir)/lib \
14+
$(CODE_COVERAGE_CPPFLAGS)
15+
AM_CFLAGS = $(ELL_CFLAGS) $(EXECUTABLE_CFLAGS) $(CODE_COVERAGE_CFLAGS)
16+
AM_CXXFLAGS = $(ELL_CFLAGS) $(EXECUTABLE_CFLAGS) $(CODE_COVERAGE_CXXFLAGS)
17+
AM_LDFLAGS = $(EXECUTABLE_LDFLAGS)
11718

118-
check_HEADERS = test-plugin.h
19+
TEST_PLUGIN_DIR_SECURITY = $(abs_builddir)/plugins/security/.libs
20+
TEST_PLUGIN_DIR_PRIORITY = $(abs_builddir)/plugins/priority/.libs
21+
TEST_PLUGIN_DIR_NOOP = $(abs_builddir)/plugins/noop/.libs
11922

12023
check_PROGRAMS = \
12124
test-plugin \
@@ -137,22 +40,26 @@ xfail_test_scripts = \
13740
dist_check_SCRIPTS = test-start-stop $(xfail_test_scripts)
13841

13942
test_plugin_SOURCES = test-plugin.c
140-
test_plugin_CPPFLAGS = \
141-
$(AM_CPPFLAGS) \
142-
-D_POSIX_C_SOURCE=200809L \
143-
-DTEST_PLUGIN_DIR_A=\"$(TEST_PLUGIN_DIR_A)\" \
144-
-DTEST_PLUGIN_DIR_B=\"$(TEST_PLUGIN_DIR_B)\" \
145-
-DTEST_PLUGIN_DIR_NOOP=\"$(TEST_PLUGIN_DIR_NOOP)\" \
146-
-DTEST_PLUGIN_ONE=\"$(TEST_PLUGIN_ONE)\" \
147-
-DTEST_PLUGIN_TWO=\"$(TEST_PLUGIN_TWO)\" \
148-
-DTEST_PLUGIN_FOUR=\"$(TEST_PLUGIN_FOUR)\"
43+
test_plugin_CPPFLAGS = \
44+
$(AM_CPPFLAGS) \
45+
-D_POSIX_C_SOURCE=200809L \
46+
-DTEST_PLUGIN_DIR_SECURITY=\"$(TEST_PLUGIN_DIR_SECURITY)\" \
47+
-DTEST_PLUGIN_DIR_PRIORITY=\"$(TEST_PLUGIN_DIR_PRIORITY)\" \
48+
-DTEST_PLUGIN_DIR_NOOP=\"$(TEST_PLUGIN_DIR_NOOP)\" \
49+
-DTEST_PLUGIN_ONE=\"@TEST_PLUGIN_ONE@\" \
50+
-DTEST_PLUGIN_TWO=\"@TEST_PLUGIN_TWO@\" \
51+
-DTEST_PLUGIN_FOUR=\"@TEST_PLUGIN_FOUR@\"
14952
test_plugin_LDADD = \
15053
$(top_builddir)/lib/libmptcpd.la \
151-
libmptcpd_test.la \
152-
$(ELL_LIBS)
54+
$(builddir)/lib/libmptcpd_test.la \
55+
$(ELL_LIBS) \
56+
$(CODE_COVERAGE_LIBS)
15357

15458
test_network_monitor_SOURCES = test-network-monitor.c
155-
test_network_monitor_LDADD = $(top_builddir)/lib/libmptcpd.la $(ELL_LIBS)
59+
test_network_monitor_LDADD = \
60+
$(top_builddir)/lib/libmptcpd.la \
61+
$(ELL_LIBS) \
62+
$(CODE_COVERAGE_LIBS)
15663

15764
test_path_manager_SOURCES = test-path-manager.c
15865
test_path_manager_CPPFLAGS = \
@@ -161,7 +68,8 @@ test_path_manager_CPPFLAGS = \
16168
test_path_manager_LDADD = \
16269
$(top_builddir)/src/libpath_manager.la \
16370
$(top_builddir)/lib/libmptcpd.la \
164-
$(ELL_LIBS)
71+
$(ELL_LIBS) \
72+
$(CODE_COVERAGE_LIBS)
16573

16674
test_commands_SOURCES = test-commands.c
16775
test_commands_CPPFLAGS = \
@@ -170,37 +78,34 @@ test_commands_CPPFLAGS = \
17078
test_commands_LDADD = \
17179
$(top_builddir)/src/libpath_manager.la \
17280
$(top_builddir)/lib/libmptcpd.la \
173-
$(ELL_LIBS)
81+
$(ELL_LIBS) \
82+
$(CODE_COVERAGE_LIBS)
17483

17584
test_configuration_SOURCES = test-configuration.c
17685
test_configuration_LDADD = \
17786
$(top_builddir)/src/libpath_manager.la \
17887
$(top_builddir)/lib/libmptcpd.la \
179-
$(ELL_LIBS)
88+
$(ELL_LIBS) \
89+
$(CODE_COVERAGE_LIBS)
18090

18191
if HAVE_CXX
18292
check_PROGRAMS += test-cxx-build
18393
test_cxx_build_SOURCES = test-cxx-build.cpp
184-
test_cxx_build_CPPFLAGS = \
185-
$(AM_CPPFLAGS) \
186-
-DTEST_PLUGIN_DIR=\"$(TEST_PLUGIN_DIR_A)\" \
187-
-DTEST_PLUGIN_FOUR=\"$(TEST_PLUGIN_FOUR)\"
188-
test_cxx_build_CXXFLAGS = $(AM_CFLAGS) -Og
94+
test_cxx_build_CPPFLAGS = \
95+
$(AM_CPPFLAGS) \
96+
-DTEST_PLUGIN_DIR=\"$(TEST_PLUGIN_DIR_SECURITY)\" \
97+
-DTEST_PLUGIN_FOUR=\"@TEST_PLUGIN_FOUR@\"
98+
test_cxx_build_CXXFLAGS = $(AM_CXXFLAGS) -Og
18999
test_cxx_build_LDADD = \
190100
$(top_builddir)/lib/libmptcpd.la \
191-
libmptcpd_test.la \
192-
$(ELL_LIBS)
101+
$(builddir)/lib/libmptcpd_test.la \
102+
$(ELL_LIBS) \
103+
$(CODE_COVERAGE_LIBS)
193104
endif
194105

195-
## "Install" test plugins, as needed, prior to running the tests.
196-
all-local: $(TEST_PLUGIN_DIRS)
197-
198-
$(TEST_PLUGIN_DIRS): $(TEST_PLUGIN_SOURCE_FILES)
199-
$(MAKE) $(AM_MAKEFLAGS) install-data
200-
201-
clean-local:
202-
-rm -rf $(TEST_PLUGIN_DIRS)
203-
204106
AM_TESTS_ENVIRONMENT = TEST_PLUGIN_DIR=$(TEST_PLUGIN_DIR_NOOP)
205107
TESTS = $(check_PROGRAMS) $(dist_check_SCRIPTS)
206108
XFAIL_TESTS = $(xfail_test_scripts)
109+
110+
# Clean up code coverage related generated files.
111+
clean-local: code-coverage-clean

tests/lib/Makefile.am

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## SPDX-License-Identifier: BSD-3-Clause
2+
##
3+
## Copyright (c) 2019-2020, Intel Corporation
4+
5+
include $(top_srcdir)/aminclude_static.am
6+
7+
AM_CPPFLAGS = \
8+
-I$(top_srcdir)/include \
9+
-I$(top_builddir)/include \
10+
$(CODE_COVERAGE_CPPFLAGS)
11+
AM_CFLAGS = $(ELL_CFLAGS) $(CODE_COVERAGE_CFLAGS)
12+
13+
## Convenience library that contains utility functions used by the
14+
## mptcpd tests.
15+
check_LTLIBRARIES = libmptcpd_test.la
16+
17+
libmptcpd_test_la_SOURCES = \
18+
call_count.c \
19+
call_plugin.c \
20+
sockaddr.c \
21+
test-plugin.h
22+
libmptcpd_test_la_LIBADD = \
23+
$(top_builddir)/lib/libmptcpd.la \
24+
$(ELL_LIBS) \
25+
$(CODE_COVERAGE_LIBS)
26+
27+
# Clean up code coverage related generated files.
28+
clean-local: code-coverage-clean
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/plugins/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## SPDX-License-Identifier: BSD-3-Clause
2+
##
3+
## Copyright (c) 2020, Intel Corporation
4+
5+
SUBDIRS = noop priority security

tests/plugins/noop/Makefile.am

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## SPDX-License-Identifier: BSD-3-Clause
2+
##
3+
## Copyright (c) 2017-2020, Intel Corporation
4+
5+
include $(top_srcdir)/aminclude_static.am
6+
7+
AM_CPPFLAGS = \
8+
-I$(top_srcdir)/include \
9+
-I$(top_builddir)/include \
10+
$(CODE_COVERAGE_CPPFLAGS)
11+
12+
AM_CFLAGS = $(ELL_CFLAGS) $(CODE_COVERAGE_CFLAGS)
13+
14+
## -rpath is needed to force a DSO to be built when listing Libtool
15+
## modules in the Automake check_LTLIBRARIES variable. Otherwise a
16+
## convenience library would be built instead.
17+
AM_LDFLAGS = \
18+
-no-undefined \
19+
-module \
20+
-avoid-version \
21+
$(ELL_LIBS) \
22+
-rpath $(abs_builddir)
23+
24+
## For mptcpd tests that require a plugin without testing the plugin
25+
## itself. The plugin will be a no-op in this case.
26+
check_LTLIBRARIES = noop.la
27+
28+
noop_la_SOURCES = noop.c
29+
noop_la_CPPFLAGS = \
30+
$(AM_CPPFLAGS) \
31+
-DTEST_PLUGIN=\"@TEST_PLUGIN_NOOP@\"
32+
noop_la_LIBADD = $(top_builddir)/lib/libmptcpd.la $(CODE_COVERAGE_LIBS)
33+
34+
# Clean up code coverage related generated files.
35+
clean-local: code-coverage-clean

0 commit comments

Comments
 (0)