mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-11 12:10:00 -04:00
new: test: Add FEATURE_* environment variables to system tests
The purpose of these variables is to be able to detect feature support without calling feature-test. This becomes useful when detecting feature support in jinja2 templates. Merge branch 'nicki/featurest-system-test-env' into 'main' See merge request isc-projects/bind9!11316
This commit is contained in:
commit
758c5973ef
5 changed files with 74 additions and 50 deletions
|
|
@ -52,11 +52,9 @@ usage(void) {
|
|||
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--md5\n");
|
||||
fprintf(stderr, "\t--rsasha1\n");
|
||||
fprintf(stderr, "\t--tsan\n");
|
||||
fprintf(stderr, "\t--with-dlz-filesystem\n");
|
||||
fprintf(stderr, "\t--with-libidn2\n");
|
||||
fprintf(stderr, "\t--with-lmdb\n");
|
||||
fprintf(stderr, "\t--with-libnghttp2\n");
|
||||
|
|
@ -207,25 +205,6 @@ main(int argc, char **argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "--ipv6only=no") == 0) {
|
||||
#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
|
||||
int s;
|
||||
int n = -1;
|
||||
int v6only = -1;
|
||||
socklen_t len = sizeof(v6only);
|
||||
|
||||
s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (s >= 0) {
|
||||
n = getsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
|
||||
(void *)&v6only, &len);
|
||||
close(s);
|
||||
}
|
||||
return (n == 0 && v6only == 0) ? 0 : 1;
|
||||
#else /* defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY) */
|
||||
return 1;
|
||||
#endif /* defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY) */
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[1], "--rsasha1") == 0) {
|
||||
if (!dst_algorithm_supported(DST_ALG_RSASHA1)) {
|
||||
return 1;
|
||||
|
|
@ -234,14 +213,6 @@ main(int argc, char **argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "--with-dlz-filesystem") == 0) {
|
||||
#ifdef DLZ_FILESYSTEM
|
||||
return 0;
|
||||
#else /* ifdef DLZ_FILESYSTEM */
|
||||
return 1;
|
||||
#endif /* ifdef DLZ_FILESYSTEM */
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "--with-libidn2") == 0) {
|
||||
#ifdef HAVE_LIBIDN2
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import os
|
|||
import platform
|
||||
import socket
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -29,24 +28,13 @@ live_internet_test = pytest.mark.skipif(
|
|||
)
|
||||
|
||||
|
||||
def feature_test(feature):
|
||||
feature_test_bin = os.environ.get("FEATURETEST")
|
||||
if not feature_test_bin: # this can be the case when running doctest
|
||||
return False
|
||||
try:
|
||||
subprocess.run([feature_test_bin, feature], check=True)
|
||||
except subprocess.CalledProcessError as exc:
|
||||
if exc.returncode != 1:
|
||||
raise
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
rsasha1 = pytest.mark.skipif(not feature_test("--rsasha1"), reason="RSASHA1 disabled")
|
||||
rsasha1 = pytest.mark.skipif(
|
||||
os.getenv("FEATURE_RSASHA1") != "1", reason="RSASHA1 disabled"
|
||||
)
|
||||
|
||||
|
||||
extended_ds_digest = pytest.mark.skipif(
|
||||
not feature_test("--extended-ds-digest"),
|
||||
os.getenv("FEATURE_EXTENDED_DS_DIGEST") != "1",
|
||||
reason="extended DS digest algorithms disabled",
|
||||
)
|
||||
|
||||
|
|
@ -62,24 +50,24 @@ def with_algorithm(name: str):
|
|||
|
||||
|
||||
with_dnstap = pytest.mark.skipif(
|
||||
not feature_test("--enable-dnstap"), reason="DNSTAP support disabled in the build"
|
||||
os.getenv("FEATURE_DNSTAP") != "1", reason="DNSTAP support disabled in the build"
|
||||
)
|
||||
|
||||
|
||||
without_fips = pytest.mark.skipif(
|
||||
feature_test("--have-fips-mode"), reason="FIPS support enabled in the build"
|
||||
os.getenv("FEATURE_FIPS_MODE") == "1", reason="FIPS support enabled in the build"
|
||||
)
|
||||
|
||||
with_libxml2 = pytest.mark.skipif(
|
||||
not feature_test("--have-libxml2"), reason="libxml2 support disabled in the build"
|
||||
os.getenv("FEATURE_LIBXML2") != "1", reason="libxml2 support disabled in the build"
|
||||
)
|
||||
|
||||
with_lmdb = pytest.mark.skipif(
|
||||
not feature_test("--with-lmdb"), reason="LMDB support disabled in the build"
|
||||
os.getenv("FEATURE_LMDB") != "1", reason="LMDB support disabled in the build"
|
||||
)
|
||||
|
||||
with_json_c = pytest.mark.skipif(
|
||||
not feature_test("--have-json-c"), reason="json-c support disabled in the build"
|
||||
os.getenv("FEATURE_JSON_C") != "1", reason="json-c support disabled in the build"
|
||||
)
|
||||
|
||||
softhsm2_environment = pytest.mark.skipif(
|
||||
|
|
|
|||
|
|
@ -13,12 +13,14 @@ import os
|
|||
|
||||
from .all import ALL
|
||||
from .algorithms import init_crypto_supported, set_algorithm_set
|
||||
from .features import init_features
|
||||
from .openssl import parse_openssl_config
|
||||
from .. import log
|
||||
|
||||
|
||||
def init_vars():
|
||||
"""Initializes the environment variables."""
|
||||
init_features()
|
||||
init_crypto_supported()
|
||||
set_algorithm_set(os.getenv("ALGORITHM_SET"))
|
||||
parse_openssl_config(ALL["OPENSSL_CONF"])
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from .build import BUILD_VARS # type: ignore
|
|||
from .algorithms import ALG_VARS, CRYPTO_SUPPORTED_VARS
|
||||
from .basic import BASIC_VARS
|
||||
from .dirs import DIR_VARS
|
||||
from .features import FEATURE_VARS
|
||||
from .openssl import OPENSSL_VARS
|
||||
from .ports import PORT_VARS
|
||||
|
||||
|
|
@ -58,6 +59,7 @@ ALL = VarLookup(
|
|||
BASIC_VARS,
|
||||
CRYPTO_SUPPORTED_VARS,
|
||||
DIR_VARS,
|
||||
FEATURE_VARS,
|
||||
BUILD_VARS,
|
||||
OPENSSL_VARS,
|
||||
PORT_VARS,
|
||||
|
|
|
|||
61
bin/tests/system/isctest/vars/features.py
Normal file
61
bin/tests/system/isctest/vars/features.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# 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.
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from .basic import BASIC_VARS
|
||||
|
||||
|
||||
FEATURES = {
|
||||
"DNSTAP": "--enable-dnstap",
|
||||
"EXTENDED_DS_DIGEST": "--extended-ds-digest",
|
||||
"FIPS_DH": "--have-fips-dh",
|
||||
"FIPS_MODE": "--have-fips-mode",
|
||||
"FIPS_PROVIDER": "--fips-provider",
|
||||
"GEOIP2": "--have-geoip2",
|
||||
"GSSAPI": "--gssapi",
|
||||
"JSON_C": "--have-json-c",
|
||||
"LIBIDN2": "--with-libidn2",
|
||||
"LIBNGHTTP2": "--with-libnghttp2",
|
||||
"LIBXML2": "--have-libxml2",
|
||||
"LMDB": "--with-lmdb",
|
||||
"MD5": "--md5",
|
||||
"QUERYTRACE": "--enable-querytrace",
|
||||
"RSASHA1": "--rsasha1",
|
||||
"TSAN": "--tsan",
|
||||
"ZLIB": "--with-zlib",
|
||||
}
|
||||
|
||||
FEATURE_VARS = {}
|
||||
|
||||
|
||||
def feature_test(feature):
|
||||
feature_test_bin = BASIC_VARS["FEATURETEST"]
|
||||
if not feature_test_bin: # this can be the case when running doctest
|
||||
return False
|
||||
try:
|
||||
subprocess.run([feature_test_bin, feature], check=True)
|
||||
except subprocess.CalledProcessError as exc:
|
||||
if exc.returncode != 1:
|
||||
raise
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def init_features():
|
||||
"""Initialize the environment variables indicating feature support."""
|
||||
for name, arg in FEATURES.items():
|
||||
supported = feature_test(arg)
|
||||
envvar = f"FEATURE_{name}"
|
||||
val = "1" if supported else "0"
|
||||
FEATURE_VARS[envvar] = val
|
||||
os.environ[envvar] = val
|
||||
Loading…
Reference in a new issue