From e22d27da71bf24625bff009d6e11bc9fae70452c Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Thu, 1 Dec 2022 15:08:36 +0100 Subject: [PATCH 1/7] Add missing options to feature-test utility --- bin/tests/system/feature-test.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/tests/system/feature-test.c b/bin/tests/system/feature-test.c index 3435c91e07..b1adaedade 100644 --- a/bin/tests/system/feature-test.c +++ b/bin/tests/system/feature-test.c @@ -34,6 +34,7 @@ usage(void) { fprintf(stderr, "\t--gethostname\n"); fprintf(stderr, "\t--gssapi\n"); fprintf(stderr, "\t--have-geoip2\n"); + fprintf(stderr, "\t--have-json-c\n"); fprintf(stderr, "\t--have-libxml2\n"); fprintf(stderr, "\t--ipv6only=no\n"); fprintf(stderr, "\t--tsan\n"); @@ -41,6 +42,7 @@ usage(void) { fprintf(stderr, "\t--with-libidn2\n"); fprintf(stderr, "\t--with-lmdb\n"); fprintf(stderr, "\t--with-libnghttp2\n"); + fprintf(stderr, "\t--with-zlib\n"); } int @@ -112,6 +114,14 @@ main(int argc, char **argv) { #endif /* ifdef HAVE_GEOIP2 */ } + if (strcmp(argv[1], "--have-json-c") == 0) { +#ifdef HAVE_JSON_C + return (0); +#else /* ifdef HAVE_JSON_C */ + return (1); +#endif /* ifdef HAVE_JSON_C */ + } + if (strcmp(argv[1], "--have-libxml2") == 0) { #ifdef HAVE_LIBXML2 return (0); @@ -179,9 +189,17 @@ main(int argc, char **argv) { if (strcmp(argv[1], "--with-libnghttp2") == 0) { #ifdef HAVE_LIBNGHTTP2 return (0); -#else /* ifdef HAVE_LMDB */ +#else /* ifdef HAVE_LIBNGHTTP2 */ return (1); -#endif /* ifdef HAVE_LMDB */ +#endif /* ifdef HAVE_LIBNGHTTP2 */ + } + + if (strcmp(argv[1], "--with-zlib") == 0) { +#ifdef HAVE_ZLIB + return (0); +#else /* ifdef HAVE_ZLIB */ + return (1); +#endif /* ifdef HAVE_ZLIB */ } fprintf(stderr, "unknown arg: %s\n", argv[1]); From d24fb1122ea3ffaf3050c79ff6b293b89e726a07 Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Thu, 1 Dec 2022 15:12:28 +0100 Subject: [PATCH 2/7] Use feature-test to detect feature support in system tests Previously, there were two different ways to detect feature support. Either through an environment variable set by configure in conf.sh, or using the feature-test utility. It is more simple and consistent to have only one way of detecting the feature support. Using the feature-test utility seems superior the the environment variables set by configure. --- bin/tests/system/addzone/tests.sh | 18 +++++++++--------- bin/tests/system/statschannel/tests.sh | 8 ++++---- bin/tests/system/synthfromdnssec/tests.sh | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bin/tests/system/addzone/tests.sh b/bin/tests/system/addzone/tests.sh index 04135c7b0c..0f81eb761b 100755 --- a/bin/tests/system/addzone/tests.sh +++ b/bin/tests/system/addzone/tests.sh @@ -45,7 +45,7 @@ n=`expr $n + 1` if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` -if [ -n "$NZD" ]; then +if $FEATURETEST --with-lmdb; then echo_i "checking that existing NZF file was renamed after migration ($n)" [ -e ns2/3bf305731dd26307.nzf~ ] || ret=1 n=`expr $n + 1` @@ -124,7 +124,7 @@ n=`expr $n + 1` if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` -if [ -z "$NZD" ]; then +if ! $FEATURETEST --with-lmdb; then echo_i "verifying no comments in NZF file ($n)" ret=0 hcount=`grep "^# New zone file for view: _default" ns2/3bf305731dd26307.nzf | wc -l` @@ -143,7 +143,7 @@ n=`expr $n + 1` if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` -if [ -n "$NZD" ]; then +if $FEATURETEST --with-lmdb; then echo_i "checking zone is present in NZD ($n)" ret=0 $NZD2NZF ns2/_default.nzd | grep previous.example > /dev/null || ret=1 @@ -169,14 +169,14 @@ check_nzd2nzf() ( ! grep previous.example nzd2nzf.out.$n > /dev/null ) -if [ -n "$NZD" ]; then +if $FEATURETEST --with-lmdb; then echo_i "checking zone was deleted from NZD ($n)" retry_quiet 10 check_nzd2nzf || ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` fi -if [ -z "$NZD" ]; then +if ! $FEATURETEST --with-lmdb; then echo_i "checking NZF file now has comment ($n)" ret=0 hcount=`grep "^# New zone file for view: _default" ns2/3bf305731dd26307.nzf | wc -l` @@ -512,7 +512,7 @@ n=`expr $n + 1` if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` -if [ -z "$NZD" ]; then +if ! $FEATURETEST --with-lmdb; then echo_i "checking new NZF file has comment ($n)" ret=0 hcount=`grep "^# New zone file for view: external" ns2/external.nzf | wc -l` @@ -522,7 +522,7 @@ if [ -z "$NZD" ]; then status=`expr $status + $ret` fi -if [ -n "$NZD" ]; then +if $FEATURETEST --with-lmdb; then echo_i "verifying added.example in external view created an external.nzd DB ($n)" ret=0 [ -e ns2/external.nzd ] || ret=1 @@ -548,7 +548,7 @@ status=`expr $status + $ret` echo_i "checking rndc showzone with newly added zone ($n)" _check_rndc_showzone_newly_added() ( - if [ -z "$NZD" ]; then + if ! $FEATURETEST --with-lmdb; then expected='zone "added.example" in external { type primary; file "added.db"; };' else expected='zone "added.example" { type primary; file "added.db"; };' @@ -655,7 +655,7 @@ n=`expr $n + 1` if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` -if [ -n "$NZD" ]; then +if $FEATURETEST --with-lmdb; then echo_i "checking NZD file was created in new-zones-directory ($n)" expect=ns2/new-zones/directory.nzd else diff --git a/bin/tests/system/statschannel/tests.sh b/bin/tests/system/statschannel/tests.sh index 7d102af3c6..7c871db27f 100644 --- a/bin/tests/system/statschannel/tests.sh +++ b/bin/tests/system/statschannel/tests.sh @@ -17,7 +17,7 @@ DIGCMD="$DIG @10.53.0.2 -p ${PORT}" RNDCCMD="$RNDC -c ../common/rndc.conf -p ${CONTROLPORT} -s" -if [ ! "$HAVEJSONSTATS" ] +if ! $FEATURETEST --have-json-c then unset PERL_JSON echo_i "JSON was not configured; skipping" >&2 @@ -29,7 +29,7 @@ else echo_i "JSON tests require JSON library; skipping" >&2 fi -if [ ! "$HAVEXMLSTATS" ] +if ! $FEATURETEST --have-libxml2 then unset PERL_XML echo_i "XML was not configured; skipping" >&2 @@ -139,7 +139,7 @@ ret=0 if [ -x "${CURL}" ] ; then for i in 1 2 3 4 5; do ret=0 - if [ "$HAVEXMLSTATS" ]; + if $FEATURETEST --have-libxml2; then URL="http://10.53.0.2:${EXTRAPORT1}/xml/v3/server" filter_str='s#.*##g' @@ -167,7 +167,7 @@ n=$((n + 1)) ret=0 echo_i "checking if compressed output is really compressed ($n)" -if [ "$HAVEZLIB" ]; +if $FEATURETEST --with-zlib; then REGSIZE=`cat regular.headers | \ grep -i Content-Length | sed -e "s/.*: \([0-9]*\).*/\1/"` diff --git a/bin/tests/system/synthfromdnssec/tests.sh b/bin/tests/system/synthfromdnssec/tests.sh index aee907e2e0..121e8ad4c9 100644 --- a/bin/tests/system/synthfromdnssec/tests.sh +++ b/bin/tests/system/synthfromdnssec/tests.sh @@ -751,7 +751,7 @@ do echo_i "Skipping XML statistics checks" fi - if [ ${HAVEJSONSTATS} ] && [ -x "${CURL}" ] ; then + if $FEATURETEST --have-json-c && [ -x "${CURL}" ] ; then echo_i "getting JSON statisistcs for (synth-from-dnssec ${description};) ($n)" ret=0 json=json.out$n From 9730ac4c5691c36d58c06deec1762a4831b268c5 Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Thu, 1 Dec 2022 15:21:22 +0100 Subject: [PATCH 3/7] Use feature-test feature detection in pytests Avoid using the environment variables for feature detection and use the feature-test utility instead. Remove the obsolete environment variables from conf.sh, since they're no longer used anywhere. --- bin/tests/system/conf.sh.in | 15 --------------- bin/tests/system/pytest_custom_markers.py | 21 +++++++++++++++++++++ bin/tests/system/statschannel/tests-json.py | 7 ++----- bin/tests/system/statschannel/tests-xml.py | 9 +++------ 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/bin/tests/system/conf.sh.in b/bin/tests/system/conf.sh.in index a41ac10b63..d6c76ea6f1 100644 --- a/bin/tests/system/conf.sh.in +++ b/bin/tests/system/conf.sh.in @@ -113,18 +113,3 @@ export PERL=$(command -v "@PERL@") export PYTHON=$(command -v "@PYTHON@" || true) export PYTEST=@PYTEST@ - -# -# Determine if we support various optional features. -# -export LIBXML2_LIBS="@LIBXML2_LIBS@" -export HAVEXMLSTATS=${LIBXML2_LIBS:+1} -export JSON_C_LIBS="@JSON_C_LIBS@" -export HAVEJSONSTATS=${JSON_C_LIBS:+1} -export MAXMINDDB_LIBS="@MAXMINDDB_LIBS@" -export HAVEGEOIP2=${MAXMINDDB_LIBS:+1} -export ZLIB_LIBS="@ZLIB_LIBS@" -export HAVEZLIB=${ZLIB_LIBS:+1} -export LMDB_LIBS="@LMDB_LIBS@" -export NZD=${LMDB_LIBS:+1} -export CRYPTO=@CRYPTO@ diff --git a/bin/tests/system/pytest_custom_markers.py b/bin/tests/system/pytest_custom_markers.py index 55b02f6c58..9714c0fbf5 100644 --- a/bin/tests/system/pytest_custom_markers.py +++ b/bin/tests/system/pytest_custom_markers.py @@ -12,6 +12,7 @@ # information regarding copyright ownership. import os +import subprocess import pytest @@ -19,3 +20,23 @@ import pytest long_test = pytest.mark.skipif( not os.environ.get("CI_ENABLE_ALL_TESTS"), reason="CI_ENABLE_ALL_TESTS not set" ) + + +def feature_test(feature): + feature_test_bin = os.environ["FEATURETEST"] + try: + subprocess.run([feature_test_bin, feature], check=True) + except subprocess.CalledProcessError as exc: + if exc.returncode != 1: + raise + return False + return True + + +have_libxml2 = pytest.mark.skipif( + feature_test("--have-libxml2"), reason="libxml2 support disabled in the build" +) + +have_json_c = pytest.mark.skipif( + feature_test("--have-json-c"), reason="json-c support disabled in the build" +) diff --git a/bin/tests/system/statschannel/tests-json.py b/bin/tests/system/statschannel/tests-json.py index d94a32f7da..312c6830a6 100755 --- a/bin/tests/system/statschannel/tests-json.py +++ b/bin/tests/system/statschannel/tests-json.py @@ -13,15 +13,12 @@ from datetime import datetime -import os - import pytest import generic +import pytest_custom_markers -pytestmark = pytest.mark.skipif( - not os.environ.get("HAVEJSONSTATS"), reason="json-c support disabled in the build" -) +pytestmark = pytest_custom_markers.have_json_c requests = pytest.importorskip("requests") diff --git a/bin/tests/system/statschannel/tests-xml.py b/bin/tests/system/statschannel/tests-xml.py index 423754916a..5b187b0f49 100755 --- a/bin/tests/system/statschannel/tests-xml.py +++ b/bin/tests/system/statschannel/tests-xml.py @@ -11,18 +11,15 @@ # See the COPYRIGHT file distributed with this work for additional # information regarding copyright ownership. -import xml.etree.ElementTree as ET from datetime import datetime - -import os +import xml.etree.ElementTree as ET import pytest import generic +import pytest_custom_markers -pytestmark = pytest.mark.skipif( - not os.environ.get("HAVEXMLSTATS"), reason="libxml2 support disabled in the build" -) +pytestmark = pytest_custom_markers.have_libxml2 requests = pytest.importorskip("requests") From e9d9f11539c4f446644884de3a3864c1db0aedff Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Fri, 23 Sep 2022 15:25:31 +0200 Subject: [PATCH 4/7] Check for pkcs11-tool in keyfromlabel system test pkcs11-tool which is typically part of the opensc package is required for the keyfromlabel test. --- bin/tests/system/keyfromlabel/prereq.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/tests/system/keyfromlabel/prereq.sh b/bin/tests/system/keyfromlabel/prereq.sh index 296452b402..2002c2a469 100644 --- a/bin/tests/system/keyfromlabel/prereq.sh +++ b/bin/tests/system/keyfromlabel/prereq.sh @@ -13,9 +13,9 @@ . ../conf.sh -if [ -n "${SOFTHSM2_MODULE}" ] && command -v softhsm2-util >/dev/null; then +if [ -n "${SOFTHSM2_MODULE}" ] && command -v pkcs11-tool >/dev/null && command -v softhsm2-util >/dev/null; then exit 0 fi -echo_i "skip: softhsm2-util not available" +echo_i "skip: softhsm2-util or pkcs11-tool not available" exit 255 From b1e011e1584e5b36e04239102648d1d502001fe8 Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Wed, 30 Nov 2022 17:43:56 +0100 Subject: [PATCH 5/7] Add lmdb prerequisite for nzd2nzf system test --- bin/tests/system/nzd2nzf/prereq.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 bin/tests/system/nzd2nzf/prereq.sh diff --git a/bin/tests/system/nzd2nzf/prereq.sh b/bin/tests/system/nzd2nzf/prereq.sh new file mode 100644 index 0000000000..7c9e25dd1c --- /dev/null +++ b/bin/tests/system/nzd2nzf/prereq.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +. ../conf.sh + +$FEATURETEST --with-lmdb || { + echo_i "This test requires LMDB support." >&2 + exit 255 +} +exit 0 From f5146046131ba1431be423343ff4721403914906 Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Wed, 30 Nov 2022 17:44:27 +0100 Subject: [PATCH 6/7] Add libnghttp2 prerequisite for doth system test While some of these tests are for DoT which doesn't require nghttp2, the server configs won't allow the server to start without nghttp2 support during compile time. It might be possible to split these tests into DoT and DoH and only require nghttp2 for DoH tests, but since almost all of our CI jobs are compiled with nghttp2, we wouldn't gain a lot of coverage, so it's probably not worth the effort. --- bin/tests/system/doth/prereq.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 bin/tests/system/doth/prereq.sh diff --git a/bin/tests/system/doth/prereq.sh b/bin/tests/system/doth/prereq.sh new file mode 100644 index 0000000000..36a8e3704b --- /dev/null +++ b/bin/tests/system/doth/prereq.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +. ../conf.sh + +$FEATURETEST --with-libnghttp2 || { + echo_i "This test requires libnghttp2 support." >&2 + exit 255 +} +exit 0 From 9846c920c36b4eb2f110abf9c3a92766150322db Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Thu, 1 Dec 2022 10:52:56 +0100 Subject: [PATCH 7/7] Add dnstap prerequisite for dnstap system test --- bin/tests/system/dnstap/prereq.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 bin/tests/system/dnstap/prereq.sh diff --git a/bin/tests/system/dnstap/prereq.sh b/bin/tests/system/dnstap/prereq.sh new file mode 100644 index 0000000000..f0748f3bf3 --- /dev/null +++ b/bin/tests/system/dnstap/prereq.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +. ../conf.sh + +$FEATURETEST --enable-dnstap || { + echo_i "This test requires dnstap support." >&2 + exit 255 +} +exit 0