From: Daniel Stenberg Date: Sat, 5 Apr 2025 20:42:09 +0000 (+0200) Subject: tests/tunit: make a separate directory for tool-based unit tests X-Git-Tag: curl-8_14_0~340 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=461ebbd336280ff843ec7971775e15f35134647d;p=thirdparty%2Fcurl.git tests/tunit: make a separate directory for tool-based unit tests Separated from library based unit tests to not confuse memory management etc. Move 1394 and 1604 there. Closes #16983 --- diff --git a/configure.ac b/configure.ac index f99548e290..1bd039055c 100644 --- a/configure.ac +++ b/configure.ac @@ -5407,6 +5407,7 @@ AC_CONFIG_FILES([\ tests/server/Makefile \ tests/libtest/Makefile \ tests/unit/Makefile \ + tests/tunit/Makefile \ tests/http/config.ini \ tests/http/Makefile \ tests/http/clients/Makefile \ diff --git a/tests/Makefile.am b/tests/Makefile.am index 2bcd27d6cc..b885a7edd0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -101,11 +101,11 @@ EXTRA_DIST = \ # added twice as then targets such as 'distclean' misbehave and try to # do things twice in that subdir at times (and thus fails). if BUILD_UNITTESTS -BUILD_UNIT = unit +BUILD_UNIT = unit tunit DIST_UNIT = else BUILD_UNIT = -DIST_UNIT = unit +DIST_UNIT = unit tunit endif SUBDIRS = certs data server libtest http $(BUILD_UNIT) @@ -193,6 +193,7 @@ ci-pytest: all checksrc: (cd libtest && $(MAKE) checksrc) (cd unit && $(MAKE) checksrc) + (cd tunit && $(MAKE) checksrc) (cd server && $(MAKE) checksrc) (cd http && $(MAKE) checksrc) diff --git a/tests/data/test1394 b/tests/data/test1394 index 30be0c85a7..312a995b35 100644 --- a/tests/data/test1394 +++ b/tests/data/test1394 @@ -17,6 +17,9 @@ unittest unit test for parse_cert_parameter() + +tool%TESTNUMBER + diff --git a/tests/data/test1604 b/tests/data/test1604 index c8d19f5480..6fa7702f16 100644 --- a/tests/data/test1604 +++ b/tests/data/test1604 @@ -17,5 +17,8 @@ unittest Test Windows/MS-DOS filename sanitization + +tool%TESTNUMBER + diff --git a/tests/globalconfig.pm b/tests/globalconfig.pm index d04068fb5f..3b77406fa0 100644 --- a/tests/globalconfig.pm +++ b/tests/globalconfig.pm @@ -43,6 +43,7 @@ BEGIN { $has_shared $LIBDIR $UNITDIR + $TUNITDIR $SRVDIR $listonly $LOCKDIR @@ -110,6 +111,7 @@ our $LOGDIR="log"; # root of the log directory; this will be different for # each runner in multiprocess mode our $LIBDIR=dirsepadd("./libtest/" . ($ENV{'CURL_DIRSUFFIX'} || '')); our $UNITDIR=dirsepadd("./unit/" . ($ENV{'CURL_DIRSUFFIX'} || '')); +our $TUNITDIR=dirsepadd("./tunit/" . ($ENV{'CURL_DIRSUFFIX'} || '')); our $SRVDIR=dirsepadd("./server/" . ($ENV{'CURL_DIRSUFFIX'} || '')); our $TESTDIR="$srcdir/data"; our $CURL=dirsepadd("../src/" . ($ENV{'CURL_DIRSUFFIX'} || '')) . "curl".exe_ext('TOOL'); # what curl binary to run on the tests diff --git a/tests/runner.pm b/tests/runner.pm index d003a334e3..8b7ab19baf 100644 --- a/tests/runner.pm +++ b/tests/runner.pm @@ -930,6 +930,12 @@ sub singletest_run { } $CMDLINE=$UNITDIR . $tool; } + elsif($tool =~ /^tool/) { + if($bundle) { + $tool = "units" . exe_ext('TOOL') + } + $CMDLINE=$TUNITDIR . $tool; + } if(! -f $CMDLINE) { logmsg " $testnum: IGNORED: The tool set in the test case for this: '$tool' does not exist\n"; diff --git a/tests/tunit/CMakeLists.txt b/tests/tunit/CMakeLists.txt new file mode 100644 index 0000000000..0164b2531e --- /dev/null +++ b/tests/tunit/CMakeLists.txt @@ -0,0 +1,60 @@ +#*************************************************************************** +# _ _ ____ _ +# 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 +# +########################################################################### + +# Get 'TOOLPROGS', '*_SOURCES', 'FIRSTFILES' variables +curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") +include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") + +if(CURL_TEST_BUNDLES) + add_custom_command( + OUTPUT "tool_bundle.c" + COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/tests/mk-bundle.pl" "${CMAKE_CURRENT_SOURCE_DIR}" > "unit_bundle.c" + DEPENDS + "${PROJECT_SOURCE_DIR}/tests/mk-bundle.pl" ${FIRSTFILES} + "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc" + VERBATIM) + + set(TOOLPROGS "units") + set(units_SOURCES "tool_bundle.c") +endif() + +foreach(_target IN LISTS UNITPROGS) + set(_target_name "${_target}") + add_executable(${_target_name} EXCLUDE_FROM_ALL ${${_target}_SOURCES}) + add_dependencies(testdeps ${_target_name}) + target_link_libraries(${_target_name} curltool curlu) + 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" + "${PROJECT_SOURCE_DIR}/tests/libtest" + ) + set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}") + if(CURL_TEST_BUNDLES) + target_include_directories(${_target_name} PRIVATE "${PROJECT_SOURCE_DIR}/tests/tunit") + endif() + set_target_properties(${_target_name} PROPERTIES + OUTPUT_NAME "${_target}" + PROJECT_LABEL "Test unit ${_target}") +endforeach() diff --git a/tests/tunit/Makefile.am b/tests/tunit/Makefile.am new file mode 100644 index 0000000000..21d7744fe6 --- /dev/null +++ b/tests/tunit/Makefile.am @@ -0,0 +1,88 @@ +#*************************************************************************** +# _ _ ____ _ +# 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 +# +########################################################################### +AUTOMAKE_OPTIONS = foreign nostdinc + +# Specify our include paths here, and do it relative to $(top_srcdir) and +# $(top_builddir), to ensure that these paths which belong to the library +# being currently built and tested are searched before the library which +# might possibly already be installed in the system. +# +# $(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 + +AM_CPPFLAGS = -I$(top_srcdir)/include \ + -I$(top_builddir)/lib \ + -I$(top_srcdir)/lib \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/tests/libtest \ + -I$(top_srcdir)/tests/unit \ + -I$(top_srcdir)/tests/tunit + +EXTRA_DIST = CMakeLists.txt README.md + +CFLAGS += @CURL_CFLAG_EXTRAS@ + +# Prevent LIBS from being used for all link targets +LIBS = $(BLANK_AT_MAKETIME) + +LDADD = $(top_builddir)/src/libcurltool.la \ + $(top_builddir)/lib/libcurlu.la \ + @LIBCURL_PC_LDFLAGS_PRIVATE@ @LIBCURL_PC_LIBS_PRIVATE@ + +AM_CPPFLAGS += -DCURL_STATICLIB -DUNITTESTS +if DEBUGBUILD +AM_CPPFLAGS += -DDEBUGBUILD +endif +if CURLDEBUG +AM_CPPFLAGS += -DCURLDEBUG +endif + +if BUILD_UNITTESTS +if USE_TEST_BUNDLES +tool_bundle.c: $(top_srcdir)/tests/mk-bundle.pl Makefile.inc + @PERL@ $(top_srcdir)/tests/mk-bundle.pl $(srcdir) > tool_bundle.c + +noinst_PROGRAMS = units +nodist_units_SOURCES = tool_bundle.c +CLEANFILES = tool_bundle.c +else +# Makefile.inc provides neat definitions +include Makefile.inc +noinst_PROGRAMS = $(TOOLPROGS) +endif +else +noinst_PROGRAMS = +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 -D$(srcdir) \ + -W$(srcdir)/tool_bundle.c \ + $(srcdir)/*.[ch]) diff --git a/tests/tunit/Makefile.inc b/tests/tunit/Makefile.inc new file mode 100644 index 0000000000..c28a16c42e --- /dev/null +++ b/tests/tunit/Makefile.inc @@ -0,0 +1,36 @@ +#*************************************************************************** +# _ _ ____ _ +# 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 +# +########################################################################### + +# these files are used in every single unit test program + +FIRSTFILES = ../libtest/first.c + +TOOLFILES = $(FIRSTFILES) + +# These are all tool unit test programs +TOOLPROGS = tool1394 tool1604 + +tool1394_SOURCES = tool1394.c $(TOOLFILES) + +tool1604_SOURCES = tool1604.c $(TOOLFILES) diff --git a/tests/tunit/README.md b/tests/tunit/README.md new file mode 100644 index 0000000000..0dc29f024e --- /dev/null +++ b/tests/tunit/README.md @@ -0,0 +1,11 @@ + + +# Tool unit tests + +This directory is for unit testing of tool functions. They are separate from +libcurl unit tests, because how these live/work outside of the library and the +libcurl unit tests live/work *inside*. diff --git a/tests/unit/unit1394.c b/tests/tunit/tool1394.c similarity index 100% rename from tests/unit/unit1394.c rename to tests/tunit/tool1394.c diff --git a/tests/unit/unit1604.c b/tests/tunit/tool1604.c similarity index 100% rename from tests/unit/unit1604.c rename to tests/tunit/tool1604.c diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc index 0c13da94c9..6d0b296416 100644 --- a/tests/unit/Makefile.inc +++ b/tests/unit/Makefile.inc @@ -33,9 +33,9 @@ UNITFILES = curlcheck.h $(FIRSTFILES) # These are all unit test programs UNITPROGS = unit1300 unit1302 unit1303 unit1304 unit1305 unit1307 \ unit1309 unit1323 \ - unit1330 unit1394 unit1395 unit1396 unit1397 unit1398 \ + unit1330 unit1395 unit1396 unit1397 unit1398 \ unit1399 \ - unit1600 unit1601 unit1602 unit1603 unit1604 unit1605 unit1606 unit1607 \ + unit1600 unit1601 unit1602 unit1603 unit1605 unit1606 unit1607 \ unit1608 unit1609 unit1610 unit1611 unit1612 unit1614 unit1615 unit1616 \ unit1620 unit1621 \ unit1650 unit1651 unit1652 unit1653 unit1654 unit1655 unit1656 unit1657 \ @@ -63,8 +63,6 @@ unit1323_SOURCES = unit1323.c $(UNITFILES) unit1330_SOURCES = unit1330.c $(UNITFILES) -unit1394_SOURCES = unit1394.c $(UNITFILES) - unit1395_SOURCES = unit1395.c $(UNITFILES) unit1396_SOURCES = unit1396.c $(UNITFILES) @@ -83,8 +81,6 @@ unit1602_SOURCES = unit1602.c $(UNITFILES) unit1603_SOURCES = unit1603.c $(UNITFILES) -unit1604_SOURCES = unit1604.c $(UNITFILES) - unit1605_SOURCES = unit1605.c $(UNITFILES) unit1606_SOURCES = unit1606.c $(UNITFILES)