]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests/tunit: make a separate directory for tool-based unit tests
authorDaniel Stenberg <daniel@haxx.se>
Sat, 5 Apr 2025 20:42:09 +0000 (22:42 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 8 Apr 2025 06:08:05 +0000 (08:08 +0200)
Separated from library based unit tests to not confuse memory management
etc. Move 1394 and 1604 there.

Closes #16983

13 files changed:
configure.ac
tests/Makefile.am
tests/data/test1394
tests/data/test1604
tests/globalconfig.pm
tests/runner.pm
tests/tunit/CMakeLists.txt [new file with mode: 0644]
tests/tunit/Makefile.am [new file with mode: 0644]
tests/tunit/Makefile.inc [new file with mode: 0644]
tests/tunit/README.md [new file with mode: 0644]
tests/tunit/tool1394.c [moved from tests/unit/unit1394.c with 100% similarity]
tests/tunit/tool1604.c [moved from tests/unit/unit1604.c with 100% similarity]
tests/unit/Makefile.inc

index f99548e290658eb6ebbe93f83055b3c928ddc2cf..1bd039055ce8859fb3feb960c08144677f5c6981 100644 (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 \
index 2bcd27d6cc6d7e1ec3822a699991812120b8f15e..b885a7edd08a209738648cf76d9aa450f29b6387 100644 (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)
 
index 30be0c85a75e7b979d334e58b4b4d5690cba3200..312a995b35a9f77f9882dbe514ee8ac32634586b 100644 (file)
@@ -17,6 +17,9 @@ unittest
 <name>
 unit test for parse_cert_parameter()
 </name>
+<tool>
+tool%TESTNUMBER
+</tool>
 </client>
 
 <verify>
index c8d19f54808a9dab6bf70110117323aa8ba8a885..6fa7702f16a3d4e0db957c12db52012eb5c1a207 100644 (file)
@@ -17,5 +17,8 @@ unittest
 <name>
 Test Windows/MS-DOS filename sanitization
 </name>
+<tool>
+tool%TESTNUMBER
+</tool>
 </client>
 </testcase>
index d04068fb5f3b238b7107da188e4c139510116c10..3b77406fa064a203fa39f856d48bf142dac94a20 100644 (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
index d003a334e3169856680c1b889ca58dc4a41962b3..8b7ab19bafec568e98b1bef5ef37620bf94588e7 100644 (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";
diff --git a/tests/tunit/CMakeLists.txt b/tests/tunit/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0164b25
--- /dev/null
@@ -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()
diff --git a/tests/tunit/Makefile.am b/tests/tunit/Makefile.am
new file mode 100644 (file)
index 0000000..21d7744
--- /dev/null
@@ -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])
diff --git a/tests/tunit/Makefile.inc b/tests/tunit/Makefile.inc
new file mode 100644 (file)
index 0000000..c28a16c
--- /dev/null
@@ -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)
diff --git a/tests/tunit/README.md b/tests/tunit/README.md
new file mode 100644 (file)
index 0000000..0dc29f0
--- /dev/null
@@ -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*.
similarity index 100%
rename from tests/unit/unit1394.c
rename to tests/tunit/tool1394.c
similarity index 100%
rename from tests/unit/unit1604.c
rename to tests/tunit/tool1604.c
index 0c13da94c93c272c7c0c75c7ec03070839429eaa..6d0b29641614d61ba221ac3fd6a33756a0f22bfb 100644 (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)