]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
selftest: use common and simpler code to read config.h
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 3 Dec 2025 02:07:03 +0000 (15:07 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Thu, 4 Dec 2025 23:54:18 +0000 (23:54 +0000)
This also removes some garbage variables from these module's namespaces.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org>
Autobuild-Date(master): Thu Dec  4 23:54:18 UTC 2025 on atb-devel-224

selftest/selftesthelpers.py
selftest/tests.py
source3/selftest/tests.py
source4/selftest/tests.py

index 54f007addbe4ebcc0a46d3720aea0b8b4623f541..f0345c4e2f6929e2166b6af017fe7c9d417db1b1 100644 (file)
@@ -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()
 
index 4838bfd176f3d6c5b39f68587434f9b3029d5171..ae6a16bf014af9269eac1c07e4bfe3f6023b296d 100644 (file)
@@ -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)
index 90a1d97fd8754174fce601dd3c6a5ff43302c676..02046bcf1cb22de8d6a11da094cf96e1b26d18aa 100755 (executable)
@@ -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':
index 70ab36c868ac3c27f6151907ea38a27f64d2bfde..0035c9509bbb5fe1c2755081b4c957f1ea43ff24 100755 (executable)
@@ -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)