summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Configure/ConfigureDryRunError.py13
-rw-r--r--test/Configure/VariantDir-SConscript.py2
-rw-r--r--test/Configure/implicit-cache.py28
-rw-r--r--test/Configure/option--config.py6
-rw-r--r--test/Repository/variants.py66
-rw-r--r--test/option/hash-format.py42
-rw-r--r--test/option/option-n.py15
-rw-r--r--test/question/Configure.py14
-rw-r--r--test/sconsign/corrupt.py13
-rw-r--r--test/sconsign/script/Configure.py4
10 files changed, 148 insertions, 55 deletions
diff --git a/test/Configure/ConfigureDryRunError.py b/test/Configure/ConfigureDryRunError.py
index 3648518..224154b 100644
--- a/test/Configure/ConfigureDryRunError.py
+++ b/test/Configure/ConfigureDryRunError.py
@@ -31,6 +31,8 @@ import os
import TestSCons
+from SCons.Util import get_current_hash_algorithm_used
+
_obj = TestSCons._obj
test = TestSCons.TestSCons()
@@ -65,7 +67,16 @@ test.run(arguments='-n', status=2, stderr=expect)
test.must_not_exist('config.log')
test.subdir('.sconf_temp')
-conftest_0_c = os.path.join(".sconf_temp", "conftest_df286a1d2f67e69d030b4eff75ca7e12_0.c")
+# depending on which default hash function we're using, we'd expect one of the following filenames.
+# The filenames are generated by the conftest changes in #3543 : https://github.com/SCons/scons/pull/3543/files
+possible_filenames = {
+ 'md5': "conftest_df286a1d2f67e69d030b4eff75ca7e12_0.c",
+ 'sha1': "conftest_6e784ac3248d146c68396335df2f9428d78c1d24_0.c",
+ 'sha256': "conftest_be4b3c1d600e20dfc3e8d98748cd8193c850331643466d800ef8a4229a5be410_0.c"
+}
+test_filename = possible_filenames[get_current_hash_algorithm_used()]
+
+conftest_0_c = os.path.join(".sconf_temp", test_filename)
SConstruct_file_line = test.python_file_line(SConstruct_path, 6)[:-1]
expect = """
diff --git a/test/Configure/VariantDir-SConscript.py b/test/Configure/VariantDir-SConscript.py
index deb7b8f..5818fc7 100644
--- a/test/Configure/VariantDir-SConscript.py
+++ b/test/Configure/VariantDir-SConscript.py
@@ -128,7 +128,7 @@ test.checkLogAndStdout( ["Checking for C header file math.h... ",
import shutil
shutil.rmtree(test.workpath(".sconf_temp"))
-test.unlink(".sconsign.dblite")
+test.unlink(test.get_sconsignname()+".dblite")
# now with SConscriptChdir(1)
test.run(arguments='chdir=yes')
diff --git a/test/Configure/implicit-cache.py b/test/Configure/implicit-cache.py
index f4f3e94..4078a98 100644
--- a/test/Configure/implicit-cache.py
+++ b/test/Configure/implicit-cache.py
@@ -55,6 +55,7 @@ get longer and longer until it blew out the users's memory.
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import TestSConsign
+from SCons.Util import get_hash_format, get_current_hash_algorithm_used
test = TestSConsign.TestSConsign()
@@ -75,7 +76,28 @@ test.write('foo.h', "#define FOO 1\n")
test.run(arguments = '.')
-test.run_sconsign('-d .sconf_temp -e conftest_5a3fa36d51dd2a28d521d6cc0e2e1d04_0.c --raw .sconsign.dblite')
+# depending on which default hash function we're using, we'd expect one of the following filenames.
+# The filenames are generated by the conftest changes in #3543 : https://github.com/SCons/scons/pull/3543/files
+# this test is different than the other tests, as the database name is used here.
+# when the database defaults to md5, that's a different name than when the user selects md5 directly.
+possible_filenames = {
+ 'default': "conftest_5a3fa36d51dd2a28d521d6cc0e2e1d04_0.c",
+ 'md5': "conftest_5a3fa36d51dd2a28d521d6cc0e2e1d04_0.c",
+ 'sha1': "conftest_80e5b88f2c7427a92f0e6c7184f144f874f10e60_0.c",
+ 'sha256': "conftest_ba8270c26647ad00993cd7777f4c5d3751018372b97d16eb993563bea051c3df_0.c"
+}
+# user left algorithm default, it defaulted to md5, with the special database name
+if get_hash_format() is None and get_current_hash_algorithm_used() == 'md5':
+ test_filename = possible_filenames['default']
+# either user selected something (like explicitly setting md5) or algorithm defaulted to something else.
+# SCons can default to something else if it detects the hashlib doesn't support it, example md5 in FIPS
+# mode prior to Python 3.9
+else:
+ test_filename = possible_filenames[get_current_hash_algorithm_used()]
+
+database_name=test.get_sconsignname() + ".dblite"
+
+test.run_sconsign(f'-d .sconf_temp -e {test_filename} --raw {database_name}')
old_sconsign_dblite = test.stdout()
# Second run: Have the configure subsystem also look for foo.h, so
@@ -88,11 +110,11 @@ old_sconsign_dblite = test.stdout()
test.run(arguments = '--implicit-cache USE_FOO=1 .')
-test.run_sconsign('-d .sconf_temp -e conftest_5a3fa36d51dd2a28d521d6cc0e2e1d04_0.c --raw .sconsign.dblite')
+test.run_sconsign(f'-d .sconf_temp -e {test_filename} --raw {database_name}')
new_sconsign_dblite = test.stdout()
if old_sconsign_dblite != new_sconsign_dblite:
- print(".sconsign.dblite did not match:")
+ print(f"{database_name} did not match:")
print("FIRST RUN ==========")
print(old_sconsign_dblite)
print("SECOND RUN ==========")
diff --git a/test/Configure/option--config.py b/test/Configure/option--config.py
index f31336f..3b38892 100644
--- a/test/Configure/option--config.py
+++ b/test/Configure/option--config.py
@@ -32,6 +32,7 @@ import os.path
from TestSCons import TestSCons, ConfigCheckInfo, _obj
from TestCmd import IS_WINDOWS
+from SCons.Util import get_current_hash_algorithm_used
test = TestSCons()
@@ -42,6 +43,11 @@ CR = test.CR # cached rebuild (up to date)
NCF = test.NCF # non-cached build failure
CF = test.CF # cached build failure
+# as this test is somewhat complicated, skip it if the library doesn't support md5
+# as the default hashing algorithm.
+if get_current_hash_algorithm_used() != 'md5':
+ test.skip_test('Skipping test as could not continue without the hash algorithm set to md5!')
+
SConstruct_path = test.workpath('SConstruct')
test.write(SConstruct_path, """
diff --git a/test/Repository/variants.py b/test/Repository/variants.py
index f89605b..c95e853 100644
--- a/test/Repository/variants.py
+++ b/test/Repository/variants.py
@@ -216,12 +216,14 @@ repository/src1/bbb.c: REPOSITORY_FOO
repository/src1/main.c: REPOSITORY_FOO
""")
+database_name=test.get_sconsignname()
+
test.fail_test(os.path.exists(
- test.workpath('repository', 'src1', '.sconsign')))
+ test.workpath('repository', 'src1', database_name)))
test.fail_test(os.path.exists(
- test.workpath('repository', 'src2', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
+ test.workpath('repository', 'src2', database_name)))
+test.fail_test(os.path.exists(test.workpath('work1', 'src1', database_name)))
+test.fail_test(os.path.exists(test.workpath('work2', 'src2', database_name)))
test.run(program=repository_build2_foo_src2_xxx_xxx, stdout="""\
repository/src2/include/my_string.h: FOO
@@ -236,11 +238,11 @@ repository/src2/xxx/main.c: BAR
""")
test.fail_test(os.path.exists(
- test.workpath('repository', 'src1', '.sconsign')))
+ test.workpath('repository', 'src1', database_name)))
test.fail_test(os.path.exists(
- test.workpath('repository', 'src2', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
+ test.workpath('repository', 'src2', database_name)))
+test.fail_test(os.path.exists(test.workpath('work1', 'src1', database_name)))
+test.fail_test(os.path.exists(test.workpath('work2', 'src2', database_name)))
# Make the entire repository non-writable, so we'll detect
# if we try to write into it accidentally.
@@ -270,11 +272,11 @@ repository/src1/main.c: REPOSITORY_BAR
""")
test.fail_test(os.path.exists(
- test.workpath('repository', 'src1', '.sconsign')))
+ test.workpath('repository', 'src1', database_name)))
test.fail_test(os.path.exists(
- test.workpath('repository', 'src2', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
+ test.workpath('repository', 'src2', database_name)))
+test.fail_test(os.path.exists(test.workpath('work1', 'src1', database_name)))
+test.fail_test(os.path.exists(test.workpath('work2', 'src2', database_name)))
test.up_to_date(chdir='work1', options=opts + " OS=bar", arguments='build1')
@@ -301,11 +303,11 @@ repository/src1/main.c: WORK_BAR
""")
test.fail_test(os.path.exists(
- test.workpath('repository', 'src1', '.sconsign')))
+ test.workpath('repository', 'src1', database_name)))
test.fail_test(os.path.exists(
- test.workpath('repository', 'src2', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
+ test.workpath('repository', 'src2', database_name)))
+test.fail_test(os.path.exists(test.workpath('work1', 'src1', database_name)))
+test.fail_test(os.path.exists(test.workpath('work2', 'src2', database_name)))
test.up_to_date(chdir='work1', options=opts + " OS=bar", arguments='build1')
@@ -319,11 +321,11 @@ repository/src1/main.c: WORK_FOO
""")
test.fail_test(os.path.exists(
- test.workpath('repository', 'src1', '.sconsign')))
+ test.workpath('repository', 'src1', database_name)))
test.fail_test(os.path.exists(
- test.workpath('repository', 'src2', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
+ test.workpath('repository', 'src2', database_name)))
+test.fail_test(os.path.exists(test.workpath('work1', 'src1', database_name)))
+test.fail_test(os.path.exists(test.workpath('work2', 'src2', database_name)))
test.up_to_date(chdir='work1', options=opts + " OS=foo", arguments='build1')
@@ -376,11 +378,11 @@ repository/src2/xxx/main.c: BAR
""")
test.fail_test(os.path.exists(
- test.workpath('repository', 'src1', '.sconsign')))
+ test.workpath('repository', 'src1', database_name)))
test.fail_test(os.path.exists(
- test.workpath('repository', 'src2', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
+ test.workpath('repository', 'src2', database_name)))
+test.fail_test(os.path.exists(test.workpath('work1', 'src1', database_name)))
+test.fail_test(os.path.exists(test.workpath('work2', 'src2', database_name)))
# Ensure file time stamps will be newer.
time.sleep(2)
@@ -411,11 +413,11 @@ repository/src2/xxx/main.c: BAR
""")
test.fail_test(os.path.exists(
- test.workpath('repository', 'src1', '.sconsign')))
+ test.workpath('repository', 'src1', database_name)))
test.fail_test(os.path.exists(
- test.workpath('repository', 'src2', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
+ test.workpath('repository', 'src2', database_name)))
+test.fail_test(os.path.exists(test.workpath('work1', 'src1', database_name)))
+test.fail_test(os.path.exists(test.workpath('work2', 'src2', database_name)))
#
test.unlink(['work2', 'src2', 'include', 'my_string.h'])
@@ -435,11 +437,11 @@ repository/src2/xxx/main.c: BAR
""")
test.fail_test(os.path.exists(
- test.workpath('repository', 'src1', '.sconsign')))
+ test.workpath('repository', 'src1', database_name)))
test.fail_test(os.path.exists(
- test.workpath('repository', 'src2', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
-test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
+ test.workpath('repository', 'src2', database_name)))
+test.fail_test(os.path.exists(test.workpath('work1', 'src1', database_name)))
+test.fail_test(os.path.exists(test.workpath('work2', 'src2', database_name)))
#
test.pass_test()
diff --git a/test/option/hash-format.py b/test/option/hash-format.py
index 9fa10ee..f0156f3 100644
--- a/test/option/hash-format.py
+++ b/test/option/hash-format.py
@@ -27,28 +27,52 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import hashlib
import os
import TestSCons
+import warnings
+from SCons.Util import ALLOWED_HASH_FORMATS, DEFAULT_HASH_FORMATS
# Test passing the hash format by command-line.
INVALID_ALGORITHM = 'testfailure'
-for algorithm in ['md5', 'sha1', 'sha256', INVALID_ALGORITHM, None]:
+
+for algorithm in [*DEFAULT_HASH_FORMATS, INVALID_ALGORITHM, None]:
test = TestSCons.TestSCons()
test.dir_fixture('hash-format')
+ # Expect failure due to an unsupported/invalid algorithm.
+ # The error message however changes if SCons detects that the host system doesn't support one or more algorithms
+ # Primary reason the message changes is so user doesn't have to start with unsupported algorithm A and then attempt
+ # to switch to unsupported algorithm B.
+ # On normal systems (allowed=default) this will output a fixed message, but on FIPS-enabled or other weird systems
+ # that don't have default allowed algorithms, it informs the user of the mismatch _and_ the currently supported
+ # algorithms on the system they're using.
+ # In Python 3.9 this becomes somewhat obselete as the hashlib is informed we don't use hashing for security but
+ # for loose integrity.
if algorithm == INVALID_ALGORITHM:
- # Expect failure due to an unsupported/invalid algorithm.
- test.run('--hash-format=%s .' % algorithm, stderr=r"""
-scons: \*\*\* Hash format "{}" is not supported by SCons. Only the following hash formats are supported: md5, sha1, sha256
+ if ALLOWED_HASH_FORMATS == DEFAULT_HASH_FORMATS:
+ test.run('--hash-format=%s .' % algorithm, stderr=r"""
+scons: \*\*\* Hash format "{}" is not supported by SCons. Only the following hash formats are supported: {}
+File "[^"]+", line \d+, in \S+
+""".format(algorithm, ', '.join(DEFAULT_HASH_FORMATS)), status=2, match=TestSCons.match_re)
+ else:
+ test.run('--hash-format=%s .' % algorithm, stderr=r"""
+scons: \*\*\* Hash format "{}" is not supported by SCons. SCons supports more hash formats than your local system is reporting; SCons supports: {}. Your local system only supports: {}
File "[^"]+", line \d+, in \S+
-""".format(algorithm), status=2, match=TestSCons.match_re)
+""".format(algorithm, ', '.join(DEFAULT_HASH_FORMATS), ', '.join(ALLOWED_HASH_FORMATS)), status=2, match=TestSCons.match_re)
continue
elif algorithm is not None:
- # Skip any algorithm that the Python interpreter doesn't have.
- if hasattr(hashlib, algorithm):
+ if algorithm in ALLOWED_HASH_FORMATS:
expected_dblite = test.workpath('.sconsign_%s.dblite' % algorithm)
test.run('--hash-format=%s .' % algorithm)
else:
- print('Skipping test with --hash-format=%s because that '
- 'algorithm is not available.' % algorithm)
+ test.run('--hash-format=%s' % algorithm, stderr=r"""
+scons: \*\*\* While hash format "{}" is supported by SCons, the local system indicates only the following hash formats are supported by the hashlib library: {}
+File "[^"]+", line \d+, in \S+
+Error in atexit._run_exitfuncs:
+Traceback \(most recent call last\):
+ File "[^"]+", line \d+, in \S+
+ assert csig == '[a-z0-9]+', csig
+AssertionError: [a-z0-9]+
+""".format(algorithm, ', '.join(ALLOWED_HASH_FORMATS)), status=2, match=TestSCons.match_re)
+ continue
else:
# The SConsign file in the hash-format folder has logic to call
# SCons.Util.set_hash_format('sha256') if the default algorithm is
diff --git a/test/option/option-n.py b/test/option/option-n.py
index e647b8e..eb8eb62 100644
--- a/test/option/option-n.py
+++ b/test/option/option-n.py
@@ -43,6 +43,7 @@ import os
import re
import TestSCons
+from SCons.Util import get_current_hash_algorithm_used
_python_ = TestSCons._python_
@@ -118,7 +119,7 @@ test.fail_test(not os.path.exists(test.workpath('f1.out')))
expect = test.wrap_stdout("""\
%(_python_)s build.py f1.out
""" % locals())
-test.unlink('.sconsign.dblite')
+test.unlink(test.get_sconsignname()+'.dblite')
test.write('f1.out', "X1.out\n")
test.run(arguments='-n f1.out', stdout=expect)
test.run(arguments='-n f1.out', stdout=expect)
@@ -204,13 +205,23 @@ test.run(arguments="-n", stderr=stderr, status=2,
test.fail_test(os.path.exists(test.workpath("configure", "config.test")))
test.fail_test(os.path.exists(test.workpath("configure", "config.log")))
+
+# depending on which default hash function we're using, we'd expect one of the following filenames.
+# The filenames are generated by the conftest changes in #3543 : https://github.com/SCons/scons/pull/3543/files
+possible_filenames = {
+ 'md5': "conftest_b10a8db164e0754105b7a99be72e3fe5_0.in",
+ 'sha1': "conftest_0a4d55a8d778e5022fab701977c5d840bbc486d0_0.in",
+ 'sha256': "conftest_a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e_0.in"
+}
+test_filename = possible_filenames[get_current_hash_algorithm_used()]
+
# test that targets are not built, if conf_dir exists.
# verify that .cache and config.log are not created.
# an error should be raised
stderr = r"""
scons: \*\*\* Cannot update configure test "%s" within a dry-run\.
File \S+, line \S+, in \S+
-""" % re.escape(os.path.join("config.test", "conftest_b10a8db164e0754105b7a99be72e3fe5_0.in"))
+""" % re.escape(os.path.join("config.test", test_filename))
test.subdir(['configure', 'config.test'])
test.run(arguments="-n", stderr=stderr, status=2,
chdir=test.workpath("configure"))
diff --git a/test/question/Configure.py b/test/question/Configure.py
index 7df29f5..d01d0fa 100644
--- a/test/question/Configure.py
+++ b/test/question/Configure.py
@@ -36,6 +36,7 @@ import re
import TestCmd
import TestSCons
+from SCons.Util import get_current_hash_algorithm_used
test = TestSCons.TestSCons(match = TestCmd.match_re_dotall)
@@ -80,13 +81,22 @@ test.run(arguments="-q aaa.out",stderr=stderr,status=2)
test.must_not_exist(test.workpath("config.test"))
test.must_not_exist(test.workpath("config.log"))
+# depending on which default hash function we're using, we'd expect one of the following filenames.
+# The filenames are generated by the conftest changes in #3543 : https://github.com/SCons/scons/pull/3543/files
+possible_filenames = {
+ 'md5': "conftest_b10a8db164e0754105b7a99be72e3fe5_0.in",
+ 'sha1': "conftest_0a4d55a8d778e5022fab701977c5d840bbc486d0_0.in",
+ 'sha256': "conftest_a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e_0.in"
+}
+test_filename = possible_filenames[get_current_hash_algorithm_used()]
+
# test that targets are not built, if conf_dir exists.
# verify that .cache and config.log are not created.
# an error should be raised
stderr=r"""
scons: \*\*\* Cannot update configure test "%s" within a dry-run\.
File \S+, line \S+, in \S+
-""" % re.escape(os.path.join("config.test", "conftest_b10a8db164e0754105b7a99be72e3fe5_0.in"))
+""" % re.escape(os.path.join("config.test", test_filename))
test.subdir('config.test')
@@ -94,7 +104,7 @@ test.run(arguments="-q aaa.out",stderr=stderr,status=2)
test.must_not_exist(test.workpath("config.test", ".cache"))
test.must_not_exist(test.workpath("config.test", "conftest_0"))
-test.must_not_exist(test.workpath("config.test", "conftest_b10a8db164e0754105b7a99be72e3fe5_0.in"))
+test.must_not_exist(test.workpath("config.test", test_filename))
test.must_not_exist(test.workpath("config.log"))
# test that no error is raised, if all targets are up-to-date. In this
diff --git a/test/sconsign/corrupt.py b/test/sconsign/corrupt.py
index 25b48e2..61da3a2 100644
--- a/test/sconsign/corrupt.py
+++ b/test/sconsign/corrupt.py
@@ -30,14 +30,19 @@ Test that we get proper warnings when .sconsign* files are corrupt.
import TestSCons
import TestCmd
+import re
test = TestSCons.TestSCons(match = TestCmd.match_re)
test.subdir('work1', ['work1', 'sub'],
'work2', ['work2', 'sub'])
-work1__sconsign_dblite = test.workpath('work1', '.sconsign.dblite')
-work2_sub__sconsign = test.workpath('work2', 'sub', '.sconsign')
+database_filename = test.get_sconsignname() + ".dblite"
+
+# for test1 we're using the default database filename
+work1__sconsign_dblite = test.workpath('work1', database_filename)
+# for test 2 we have an explicit hardcode to .sconsign
+work2_sub__sconsign = test.workpath('work2', 'sub', ".sconsign")
SConstruct_contents = """\
def build1(target, source, env):
@@ -57,9 +62,9 @@ test.write(['work1', 'SConstruct'], SConstruct_contents)
test.write(['work1', 'foo.in'], "work1/foo.in\n")
stderr = r'''
-scons: warning: Ignoring corrupt .sconsign file: \.sconsign\.dblite
+scons: warning: Ignoring corrupt .sconsign file: {}
.*
-'''
+'''.format(re.escape(database_filename))
stdout = test.wrap_stdout(r'build1\(\["sub.foo\.out"\], \["foo\.in"\]\)' + '\n')
diff --git a/test/sconsign/script/Configure.py b/test/sconsign/script/Configure.py
index 7bf1f05..02a2c20 100644
--- a/test/sconsign/script/Configure.py
+++ b/test/sconsign/script/Configure.py
@@ -90,7 +90,9 @@ conftest_%(sig_re)s_0_%(sig_re)s%(_obj)s:
%(CC_file)s: %(sig_re)s \d+ \d+
""" % locals()
-test.run_sconsign(arguments = ".sconsign",
+# grab .sconsign or .sconsign_<hashname>
+database_name=test.get_sconsignname()
+test.run_sconsign(arguments = database_name,
stdout = expect)
test.pass_test()