From: Douglas Bagnall Date: Wed, 3 Dec 2025 02:07:03 +0000 (+1300) Subject: selftest: use common and simpler code to read config.h X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=209cac897ba5b7d87cb553a342240ab8cc2d9e50;p=thirdparty%2Fsamba.git selftest: use common and simpler code to read config.h This also removes some garbage variables from these module's namespaces. Signed-off-by: Douglas Bagnall Reviewed-by: Jennifer Sutton Autobuild-User(master): Douglas Bagnall Autobuild-Date(master): Thu Dec 4 23:54:18 UTC 2025 on atb-devel-224 --- diff --git a/selftest/selftesthelpers.py b/selftest/selftesthelpers.py index 54f007addbe..f0345c4e2f6 100644 --- a/selftest/selftesthelpers.py +++ b/selftest/selftesthelpers.py @@ -45,6 +45,27 @@ def binpath(name): return os.path.join(bindir(), name) +def read_config_h(): + try: + config_h = os.environ["CONFIG_H"] + except KeyError: + config_h = binpath("default/include/config.h") + + config = {} + with open(config_h) as f: + for line in f: + if line[:8] != '#define ': + continue + line = line[8:].rstrip() + if ' ' not in line: + k, v = (line, '') + else: + k, v = line.split(' ', 1) + config[k] = v + + return config + + # Split perl variable to allow $PERL to be set to e.g. "perl -W" perl = os.getenv("PERL", "perl").split() diff --git a/selftest/tests.py b/selftest/tests.py index 4838bfd176f..ae6a16bf014 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -23,24 +23,12 @@ from selftesthelpers import bindir, srcdir, python from selftesthelpers import planpythontestsuite, samba4srcdir from selftesthelpers import plantestsuite, bbdir from selftesthelpers import configuration, valgrindify -from selftesthelpers import skiptestsuite +from selftesthelpers import skiptestsuite, read_config_h samba4bindir = bindir() -try: - config_h = os.environ["CONFIG_H"] -except KeyError: - config_h = os.path.join(samba4bindir, "default/include/config.h") # check available features -config_hash = dict() -f = open(config_h, 'r') -try: - lines = f.readlines() - config_hash = dict((x[0], ' '.join(x[1:])) - for x in map(lambda line: line.strip().split(' ')[1:], - list(filter(lambda line: (line[0:7] == '#define') and (len(line.split(' ')) > 2), lines)))) -finally: - f.close() +config_hash = read_config_h() have_man_pages_support = ("XSLTPROC_MANPAGES" in config_hash) with_pam = ("WITH_PAM" in config_hash) diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 90a1d97fd87..02046bcf1cb 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -29,6 +29,7 @@ from selftesthelpers import plantestsuite, samba3srcdir from selftesthelpers import planpythontestsuite from selftesthelpers import smbtorture3, configuration, smbclient3, smbtorture4 from selftesthelpers import net, wbinfo, dbwrap_tool, rpcclient +from selftesthelpers import read_config_h from selftesthelpers import smbget, smbcacls, smbcquotas from selftesthelpers import smbtorture4_testsuites from selftesthelpers import smbtorture4_options @@ -71,25 +72,11 @@ def compare_versions(version1, version2): return -1 return 0 -# find config.h -try: - config_h = os.environ["CONFIG_H"] -except KeyError: - samba4bindir = bindir() - config_h = os.path.join(samba4bindir, "default/include/config.h") bbdir = os.path.join(srcdir(), "testprogs/blackbox") # check available features -config_hash = dict() -f = open(config_h, 'r') -try: - lines = f.readlines() - config_hash = dict((x[0], ' '.join(x[1:])) - for x in map(lambda line: line.strip().split(' ')[1:], - filter(lambda line: (line[0:7] == '#define') and (len(line.split(' ')) > 2), lines))) -finally: - f.close() +config_hash = read_config_h() linux_kernel_version = None if platform.system() == 'Linux': diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 70ab36c868a..0035c9509bb 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -28,7 +28,7 @@ from selftesthelpers import planpythontestsuite, planperltestsuite from selftesthelpers import plantestsuite_loadlist from selftesthelpers import skiptestsuite, source4dir, valgrindify from selftesthelpers import smbtorture4_options, smbtorture4_testsuites -from selftesthelpers import smbtorture4, samba3srcdir +from selftesthelpers import smbtorture4, samba3srcdir, read_config_h print("OPTIONS %s" % " ".join(smbtorture4_options), file=sys.stderr) @@ -99,22 +99,7 @@ for auth_type in ['', '-k no', '-k yes']: options = creds + ' ' + auth_type + ' ' + auth_level plantestsuite("samba4.ldb.ldap with options %r(ad_dc_default)" % options, "ad_dc_default", "%s/test_ldb.sh ldap $SERVER %s" % (bbdir, options)) -# see if we support ADS on the Samba3 side -try: - config_h = os.environ["CONFIG_H"] -except KeyError: - config_h = os.path.join(samba4bindir, "default/include/config.h") - -# check available features -config_hash = dict() -f = open(config_h, 'r') -try: - lines = f.readlines() - config_hash = dict((x[0], ' '.join(x[1:])) - for x in map(lambda line: line.strip().split(' ')[1:], - list(filter(lambda line: (line[0:7] == '#define') and (len(line.split(' ')) > 2), lines)))) -finally: - f.close() +config_hash = read_config_h() have_heimdal_support = ("SAMBA4_USES_HEIMDAL" in config_hash) have_gnutls_fips_mode_support = ("HAVE_GNUTLS_FIPS_MODE_SUPPORTED" in config_hash)