From bcdbbea862267a1923d7ec3f0cc006d2c957c7bb Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Mon, 24 Feb 2025 23:07:35 +0800 Subject: [PATCH 1/4] CI: be explicit when skipping unit tests The Automake test framework uses a specific return value from tests to signify they have been skipped. Use it. --- src/Makefile.am | 9 ++++++--- src/tests/testSkipped.cc | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/tests/testSkipped.cc diff --git a/src/Makefile.am b/src/Makefile.am index cfd26b31867..5ecd97e4c3f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1018,8 +1018,8 @@ tests_testString_LDFLAGS = $(LIBADD_DL) ## Tests of fs/* -if ENABLE_FS_ROCK check_PROGRAMS += tests/testRock +if ENABLE_FS_ROCK tests_testRock_SOURCES = \ $(DELAY_POOL_SOURCE) \ $(UNLINKDSOURCE) \ @@ -1180,14 +1180,15 @@ tests_testRock_LDADD = \ $(XTRA_LIBS) tests_testRock_LDFLAGS = $(AM_CPPFLAGS) $(LIBADD_DL) else +tests_testRock_SOURCES = tests/testSkipped.cc EXTRA_DIST += \ tests/testRock.cc \ tests/testStoreSupport.cc \ tests/testStoreSupport.h endif -if ENABLE_FS_UFS check_PROGRAMS += tests/testUfs +if ENABLE_FS_UFS tests_testUfs_SOURCES = \ $(DELAY_POOL_SOURCE) \ $(UNLINKDSOURCE) \ @@ -1356,6 +1357,7 @@ tests_testUfs_LDADD = \ $(XTRA_LIBS) tests_testUfs_LDFLAGS = $(LIBADD_DL) else +tests_testUfs_SOURCES = tests/testSkipped.cc EXTRA_DIST += \ tests/testUfs.cc endif @@ -1696,8 +1698,8 @@ tests_testDiskIO_LDFLAGS = $(LIBADD_DL) ## Tests of auth/* -if ENABLE_AUTH check_PROGRAMS += tests/testACLMaxUserIP +if ENABLE_AUTH tests_testACLMaxUserIP_SOURCES = \ tests/testACLMaxUserIP.cc nodist_tests_testACLMaxUserIP_SOURCES = \ @@ -1743,6 +1745,7 @@ tests_testACLMaxUserIP_LDADD = \ $(XTRA_LIBS) tests_testACLMaxUserIP_LDFLAGS = $(LIBADD_DL) else +tests_testACLMaxUserIP_SOURCES = tests/testSkipped.cc EXTRA_DIST += \ tests/testACLMaxUserIP.cc endif diff --git a/src/tests/testSkipped.cc b/src/tests/testSkipped.cc new file mode 100644 index 00000000000..619c1e90d11 --- /dev/null +++ b/src/tests/testSkipped.cc @@ -0,0 +1,19 @@ +/* + * Copyright (C) 1996-2023 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +/* + * this is a dummy unit test file, meant to be used when a feature + * is not available to be tested. + */ + + int main() { + /* 77 is a magic return code, informing Makefile's test harness + * that a test was skipped + */ + return 77; + } \ No newline at end of file From 25bc860eebde0bf25a3b46434b72129e87560c78 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Mon, 24 Feb 2025 23:55:50 +0800 Subject: [PATCH 2/4] Source format --- src/tests/testSkipped.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tests/testSkipped.cc b/src/tests/testSkipped.cc index 619c1e90d11..c509053b717 100644 --- a/src/tests/testSkipped.cc +++ b/src/tests/testSkipped.cc @@ -11,9 +11,12 @@ * is not available to be tested. */ - int main() { +#include "squid.h" + +int main() { /* 77 is a magic return code, informing Makefile's test harness * that a test was skipped */ return 77; - } \ No newline at end of file +} + From 288e27817e1ea2671e13c8f5fde2fc6d17c6062f Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Tue, 25 Feb 2025 17:54:22 +0800 Subject: [PATCH 3/4] Emulate SKIP for squid.conf test --- test-suite/Makefile.am | 22 +++++++++++++--------- test-suite/test-squid-conf.sh | 4 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 5803f21b4e1..5fe7f2c91bc 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -124,23 +124,27 @@ squid-conf-tests: $(srcdir)/test-squid-conf.sh $(top_builddir)/src/squid.conf.de exit 1; \ fi; \ done; \ - failed=0; \ + result=0; \ cfglist="$(top_builddir)/src/squid.conf.default $(srcdir)/squidconf/*.conf"; \ rm -f $@ || $(TRUE); \ for cfg in $$cfglist ; do \ - $(srcdir)/test-squid-conf.sh $(top_builddir) $(sbindir) $$cfg || \ - { echo "FAIL: squid.conf test: $$cfg" | \ + $(srcdir)/test-squid-conf.sh $(top_builddir) $(sbindir) $$cfg; result=$$?; \ + case $$result in \ + 0) echo "PASS: squid.conf test: $$cfg" | \ sed s%$(top_builddir)/src/%% | \ sed s%$(srcdir)/squidconf/%% ; \ - failed=1; break; \ - }; \ - if test "$$failed" -eq 0; then \ - echo "PASS: squid.conf test: $$cfg" | \ + continue ;; \ + 77) echo "SKIP: squid.conf test: $$cfg" | \ sed s%$(top_builddir)/src/%% | \ sed s%$(srcdir)/squidconf/%% ; \ - else break; fi; \ + continue ;; \ + *) echo "FAIL: squid.conf test: $$cfg" | \ + sed s%$(top_builddir)/src/%% | \ + sed s%$(srcdir)/squidconf/%% ; \ + exit $$result ;; \ + esac; \ done; \ - if test "$$failed" -eq 0; then cp $(TRUE) $@ ; else exit 1; fi + if test "$$result" -eq 0; then cp $(TRUE) $@ ; else exit 1; fi CLEANFILES += \ squid-conf-tests \ diff --git a/test-suite/test-squid-conf.sh b/test-suite/test-squid-conf.sh index 8cdbc0e95b0..c349c642364 100755 --- a/test-suite/test-squid-conf.sh +++ b/test-suite/test-squid-conf.sh @@ -216,7 +216,7 @@ then if grep -q "# *undef *\b$defineName\b" $autoconfHeader then echo "$here: WARNING: Skipping $configFile test because $defineName is not defined in $autoconfHeader"; - exit 0; + exit 77 fi if ! grep -q "# *define *\b$defineName\b" $autoconfHeader @@ -230,7 +230,7 @@ then if ! grep -q "# *define *\b$defineName *$defineValue\b" $autoconfHeader then echo "$here: WARNING: Skipping $configFile test because $defineName is not $defineValue in $autoconfHeader"; - exit 0; + exit 77 fi fi From e31d0843a9c6f3c8521e09a2b49efcbe1dea372c Mon Sep 17 00:00:00 2001 From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Tue, 25 Feb 2025 09:55:32 +0000 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Alex Rousskov --- src/tests/testSkipped.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tests/testSkipped.cc b/src/tests/testSkipped.cc index c509053b717..3a2be91f088 100644 --- a/src/tests/testSkipped.cc +++ b/src/tests/testSkipped.cc @@ -13,10 +13,10 @@ #include "squid.h" -int main() { - /* 77 is a magic return code, informing Makefile's test harness - * that a test was skipped - */ +int +main() { + // use this magic return code to inform Automake cfgaux/test-driver + // that a test was skipped return 77; }