diff --git a/tests/ftpserver.pl b/tests/ftpserver.pl index afdd80e80f..d4cd0f4172 100755 --- a/tests/ftpserver.pl +++ b/tests/ftpserver.pl @@ -68,7 +68,7 @@ use serverhelp qw( servername_str server_pidfilename server_logfilename - server_exe + server_exe_args mainsockf_pidfilename mainsockf_logfilename datasockf_pidfilename @@ -407,7 +407,7 @@ sub sysread_or_die { } sub startsf { - my @mainsockfcmd = (server_exe('sockfilt'), + my @mainsockfcmd = (server_exe_args('sockfilt'), "--ipv$ipvnum", "--port", $port, "--pidfile", $mainsockf_pidfile, @@ -2469,7 +2469,7 @@ sub PASV_ftp { logmsg "DATA sockfilt for passive data channel starting...\n"; # We fire up a new sockfilt to do the data transfer for us. - my @datasockfcmd = (server_exe('sockfilt'), + my @datasockfcmd = (server_exe_args('sockfilt'), "--ipv$ipvnum", "--port", 0, "--pidfile", $datasockf_pidfile, "--logfile", $datasockf_logfile); @@ -2691,7 +2691,7 @@ sub PORT_ftp { logmsg "DATA sockfilt for active data channel starting...\n"; # We fire up a new sockfilt to do the data transfer for us. - my @datasockfcmd = (server_exe('sockfilt'), + my @datasockfcmd = (server_exe_args('sockfilt'), "--ipv$ipvnum", "--connect", $port, "--addr", $addr, "--pidfile", $datasockf_pidfile, "--logfile", $datasockf_logfile); diff --git a/tests/runtests.pl b/tests/runtests.pl index 0ab2c95303..f3916738d9 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -2268,6 +2268,7 @@ while(@ARGV) { elsif ($ARGV[0] eq "-bundle") { # use test bundles $bundle=1; + $ENV{'CURL_TEST_BUNDLES'} = 1; } elsif ($ARGV[0] eq "-d") { # have the servers display protocol output diff --git a/tests/server/.gitignore b/tests/server/.gitignore index 034fe9c5f7..aa226a094e 100644 --- a/tests/server/.gitignore +++ b/tests/server/.gitignore @@ -2,6 +2,8 @@ # # SPDX-License-Identifier: curl +server_bundle.c + disabled mqttd resolve diff --git a/tests/server/CMakeLists.txt b/tests/server/CMakeLists.txt index d0c1b9e0e4..1a60a931a5 100644 --- a/tests/server/CMakeLists.txt +++ b/tests/server/CMakeLists.txt @@ -22,7 +22,7 @@ # ########################################################################### -# Get 'noinst_PROGRAMS', '_SOURCES' variables +# Get 'SERVERPROGS', '_SOURCES' variables, 'MEMDEBUG', 'CURLX_SRCS', 'USEFUL', 'INET_PTON', 'UTIL', 'FIRSTFILES' curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") @@ -30,14 +30,28 @@ if(ENABLE_SERVER_DEBUG AND ENABLE_CURLDEBUG) set_source_files_properties("../../lib/memdebug.c" "../../lib/curl_multibyte.c" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) endif() -foreach(_target IN LISTS noinst_PROGRAMS) +if(CURL_TEST_BUNDLES) + add_custom_command( + OUTPUT "server_bundle.c" + COMMAND ${PERL_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/mk-bundle.pl" ${SERVERPROGS} > "server_bundle.c" + DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/mk-bundle.pl" ${FIRSTFILES} + "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc" + VERBATIM) + + set(SERVERPROGS "servers") + set(servers_SOURCES ${MEMDEBUG} ${CURLX_SRCS} ${USEFUL} ${INET_PTON} ${UTIL} "server_bundle.c") +endif() + +foreach(_target IN LISTS SERVERPROGS) set(_target_name "${_target}") add_executable(${_target_name} EXCLUDE_FROM_ALL ${${_target}_SOURCES}) add_dependencies(testdeps ${_target_name}) target_include_directories(${_target_name} PRIVATE - "${PROJECT_BINARY_DIR}/lib" # for "curl_config.h" - "${PROJECT_SOURCE_DIR}/lib" # for "curl_setup.h" - "${PROJECT_SOURCE_DIR}/src" # for "tool_binmod.h", "tool_xattr.h" + "${PROJECT_BINARY_DIR}/lib" # for "curl_config.h" + "${PROJECT_SOURCE_DIR}/lib" # for "curl_setup.h" + "${PROJECT_SOURCE_DIR}/src" # for "tool_binmode.h", "tool_xattr.h" + "${PROJECT_SOURCE_DIR}/tests/server" # for "first.h" ) target_link_libraries(${_target_name} ${CURL_LIBS}) if(ENABLE_SERVER_DEBUG) diff --git a/tests/server/Makefile.am b/tests/server/Makefile.am index b256ecfa42..cee7f81c5e 100644 --- a/tests/server/Makefile.am +++ b/tests/server/Makefile.am @@ -31,11 +31,13 @@ AUTOMAKE_OPTIONS = foreign nostdinc # $(top_srcdir)/include is for libcurl's external include files # $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file # $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files +# $(top_srcdir)/src for "tool_binmode.h", "tool_xattr.h" AM_CPPFLAGS = -I$(top_srcdir)/include \ -I$(top_builddir)/lib \ -I$(top_srcdir)/lib \ - -I$(top_srcdir)/src + -I$(top_srcdir)/src \ + -I$(top_srcdir)/tests/server # Prevent LIBS from being used for all link targets LIBS = $(BLANK_AT_MAKETIME) @@ -57,15 +59,38 @@ endif # Makefile.inc provides neat definitions include Makefile.inc -EXTRA_DIST = CMakeLists.txt .checksrc +EXTRA_DIST = CMakeLists.txt .checksrc mk-bundle.pl $(FIRSTFILES) + +if USE_TEST_BUNDLES +server_EXCLUDE = +if ENABLE_SERVER_DEBUG +if CURLDEBUG +server_EXCLUDE += $(MEMDEBUG) +endif +endif +server_bundle.c: $(top_srcdir)/tests/server/mk-bundle.pl $(MEMDEBUG) $(CURLX_SRCS) $(USEFUL) $(INET_PTON) $(UTIL) $(FIRSTFILES) + @PERL@ $(top_srcdir)/tests/server/mk-bundle.pl $(MEMDEBUG) $(CURLX_SRCS) $(USEFUL) $(INET_PTON) $(UTIL) $(SERVERPROGS) --exclude $(server_EXCLUDE) > server_bundle.c + +noinst_PROGRAMS = servers +nodist_servers_SOURCES = server_bundle.c +servers_SOURCES = $(server_EXCLUDE) +servers_LDADD = @CURL_NETWORK_AND_TIME_LIBS@ +servers_CFLAGS = $(AM_CFLAGS) +CLEANFILES = server_bundle.c +else +noinst_PROGRAMS = $(SERVERPROGS) +endif CHECKSRC = $(CS_$(V)) CS_0 = @echo " RUN " $@; CS_1 = CS_ = $(CS_0) +# ignore generated C files since they play by slightly different rules! checksrc: - $(CHECKSRC)@PERL@ $(top_srcdir)/scripts/checksrc.pl $(srcdir)/*.[ch] + $(CHECKSRC)(@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) \ + -W$(srcdir)/server_bundle.c \ + $(srcdir)/*.[ch]) if DEBUGBUILD # for debug builds, we scan the sources on all regular make invokes diff --git a/tests/server/Makefile.inc b/tests/server/Makefile.inc index 532984913c..f3062c8d34 100644 --- a/tests/server/Makefile.inc +++ b/tests/server/Makefile.inc @@ -22,7 +22,13 @@ # ########################################################################### -noinst_PROGRAMS = resolve rtspd sockfilt sws tftpd socksd disabled mqttd +SERVERPROGS = resolve rtspd sockfilt sws tftpd socksd disabled mqttd + +MEMDEBUG = \ + ../../lib/curl_multibyte.c \ + ../../lib/curl_multibyte.h \ + ../../lib/memdebug.c \ + ../../lib/memdebug.h CURLX_SRCS = \ ../../lib/mprintf.c \ @@ -36,7 +42,6 @@ CURLX_SRCS = \ ../../lib/strcase.c \ ../../lib/strdup.c \ ../../lib/curl_get_line.c \ - ../../lib/curl_multibyte.c \ ../../lib/version_win32.c CURLX_HDRS = \ @@ -51,7 +56,6 @@ CURLX_HDRS = \ ../../lib/strcase.h \ ../../lib/strdup.h \ ../../lib/curl_get_line.h \ - ../../lib/curl_multibyte.h \ ../../lib/version_win32.h UTIL = \ @@ -62,50 +66,52 @@ UTIL = \ server_setup.h \ ../../lib/base64.c \ ../../lib/curl_base64.h \ - ../../lib/memdebug.c \ - ../../lib/memdebug.h \ ../../lib/strerror.c \ ../../lib/strerror.h +FIRSTFILES = \ + first.c \ + first.h + INET_PTON = \ ../../lib/inet_pton.c -resolve_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) \ +resolve_SOURCES = $(MEMDEBUG) $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) \ resolve.c resolve_LDADD = @CURL_NETWORK_AND_TIME_LIBS@ resolve_CFLAGS = $(AM_CFLAGS) -rtspd_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) \ +rtspd_SOURCES = $(MEMDEBUG) $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) \ server_sockaddr.h \ rtspd.c rtspd_LDADD = @CURL_NETWORK_AND_TIME_LIBS@ rtspd_CFLAGS = $(AM_CFLAGS) -sockfilt_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) $(INET_PTON) \ +sockfilt_SOURCES = $(MEMDEBUG) $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) $(INET_PTON) \ server_sockaddr.h \ sockfilt.c sockfilt_LDADD = @CURL_NETWORK_AND_TIME_LIBS@ sockfilt_CFLAGS = $(AM_CFLAGS) -socksd_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) $(INET_PTON) \ +socksd_SOURCES = $(MEMDEBUG) $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) $(INET_PTON) \ server_sockaddr.h \ socksd.c socksd_LDADD = @CURL_NETWORK_AND_TIME_LIBS@ socksd_CFLAGS = $(AM_CFLAGS) -mqttd_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) \ +mqttd_SOURCES = $(MEMDEBUG) $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) \ server_sockaddr.h \ mqttd.c mqttd_LDADD = @CURL_NETWORK_AND_TIME_LIBS@ mqttd_CFLAGS = $(AM_CFLAGS) -sws_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) $(INET_PTON) \ +sws_SOURCES = $(MEMDEBUG) $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) $(INET_PTON) \ server_sockaddr.h \ sws.c sws_LDADD = @CURL_NETWORK_AND_TIME_LIBS@ sws_CFLAGS = $(AM_CFLAGS) -tftpd_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) \ +tftpd_SOURCES = $(MEMDEBUG) $(CURLX_SRCS) $(CURLX_HDRS) $(UTIL) \ server_sockaddr.h \ tftpd.c \ tftp.h diff --git a/tests/server/first.c b/tests/server/first.c new file mode 100644 index 0000000000..13b02d41c7 --- /dev/null +++ b/tests/server/first.c @@ -0,0 +1,59 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ +#include +#include +#include "first.h" + +int main(int argc, char **argv) +{ + main_func_t main_func; + char *main_name; + + if(argc < 2) { + fprintf(stderr, "Pass servername as first argument\n"); + return 1; + } + + main_name = argv[1]; + main_func = NULL; + { + size_t tmp; + for(tmp = 0; s_mains[tmp].ptr; ++tmp) { + if(strcmp(main_name, s_mains[tmp].name) == 0) { + main_func = s_mains[tmp].ptr; + break; + } + } + } + + if(!main_func) { + fprintf(stderr, "Test '%s' not found.\n", main_name); + return 99; + } + + --argc; + ++argv; + + return main_func(argc, argv); +} diff --git a/tests/server/first.h b/tests/server/first.h new file mode 100644 index 0000000000..54863cdf38 --- /dev/null +++ b/tests/server/first.h @@ -0,0 +1,33 @@ +#ifndef HEADER_SERVER_FIRST_H +#define HEADER_SERVER_FIRST_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ +typedef int (*main_func_t)(int, char **); + +struct onemain { + const char *name; + main_func_t ptr; +}; + +#endif /* HEADER_SERVER_FIRST_H */ diff --git a/tests/server/mk-bundle.pl b/tests/server/mk-bundle.pl new file mode 100755 index 0000000000..321709bb07 --- /dev/null +++ b/tests/server/mk-bundle.pl @@ -0,0 +1,90 @@ +#!/usr/bin/env perl +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) Viktor Szakats +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at https://curl.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +# SPDX-License-Identifier: curl +# +########################################################################### + +# Bundle up individual tests into a single binary. The resulting binary can run +# individual tests by passing their name (without '.c') as the first argument. +# +# Usage: mk-bundle.pl [] + +use strict; +use warnings; + +if(!@ARGV) { + die "Usage: $0 [] [--exclude ]\n"; +} + +# Specific sources to exclude or add as an extra source file +my @src; +my %exclude; +my $in_exclude = 0; +foreach my $src (@ARGV) { + if($in_exclude) { + $exclude{$src} = 1; + } + elsif($src eq "--exclude") { + $in_exclude = 1; + } + else { + push @src, $src; + } +} + +print <