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
This commit is contained in:
Daniel Stenberg
2025-04-05 22:42:09 +02:00
parent 04c78c897b
commit 461ebbd336
13 changed files with 215 additions and 8 deletions

View File

@@ -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 \

View File

@@ -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)

View File

@@ -17,6 +17,9 @@ unittest
<name>
unit test for parse_cert_parameter()
</name>
<tool>
tool%TESTNUMBER
</tool>
</client>
<verify>

View File

@@ -17,5 +17,8 @@ unittest
<name>
Test Windows/MS-DOS filename sanitization
</name>
<tool>
tool%TESTNUMBER
</tool>
</client>
</testcase>

View File

@@ -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

View File

@@ -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";

View File

@@ -0,0 +1,60 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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()

88
tests/tunit/Makefile.am Normal file
View File

@@ -0,0 +1,88 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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])

36
tests/tunit/Makefile.inc Normal file
View File

@@ -0,0 +1,36 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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)

11
tests/tunit/README.md Normal file
View File

@@ -0,0 +1,11 @@
<!--
Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
SPDX-License-Identifier: curl
-->
# 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*.

View File

@@ -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)