summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests/generate_expected_output.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/testlib/selftests/generate_expected_output.py')
-rwxr-xr-xtests/auto/testlib/selftests/generate_expected_output.py76
1 files changed, 68 insertions, 8 deletions
diff --git a/tests/auto/testlib/selftests/generate_expected_output.py b/tests/auto/testlib/selftests/generate_expected_output.py
index 111870b3fb..9ec87c8fc6 100755
--- a/tests/auto/testlib/selftests/generate_expected_output.py
+++ b/tests/auto/testlib/selftests/generate_expected_output.py
@@ -221,8 +221,71 @@ class Scanner (object):
print('tst_selftests.cpp names', d, "as a test, but it doesn't exist")
del re
+# Keep in sync with tst_selftests.cpp's processEnvironment():
+def baseEnv(platname=None,
+ keep=('PATH', 'QT_QPA_PLATFORM'),
+ posix=('HOME', 'USER', 'QEMU_SET_ENV', 'QEMU_LD_PREFIX'),
+ nonapple=('DISPLAY', 'XAUTHLOCALHOSTNAME'), # and XDG_*
+ # Don't actually know how to test for QNX, so this is ignored:
+ qnx=('GRAPHICS_ROOT', 'TZ'),
+ # Probably not actually relevant
+ preserveLib=('QT_PLUGIN_PATH', 'LD_LIBRARY_PATH'),
+ # Shall be modified on first call (a *copy* is returned):
+ cached={}):
+ """Lazily-evaluated standard environment for sub-tests to run in.
+
+ This prunes the parent process environment, selecting a only those
+ variables we chose to keep. The platname passed to the first call
+ helps select which variables to keep. The environment computed
+ then is cached: a copy of this is returned on that call and each
+ subsequent call.\n"""
+
+ if not cached:
+ xdg = False
+ # The platform module may be more apt for the platform tests here.
+ if os.name == 'posix':
+ keep += posix
+ if platname != 'darwin':
+ keep += nonapple
+ xdg = True
+ if 'QT_PRESERVE_TESTLIB_PATH' in os.environ:
+ keep += preserveLib
+
+ cached = dict(
+ LC_ALL = 'C', # Use standard locale
+ # Avoid interference from any qtlogging.ini files, e.g. in
+ # /etc/xdg/QtProject/, (must match tst_selftests.cpp's
+ # processEnvironment()'s value):
+ QT_LOGGING_RULES = '*.debug=true;qt.*=false')
+
+ for k, v in os.environ.items():
+ if k in keep or (xdg and k.startswith('XDG_')):
+ cached[k] = v
+
+ return cached.copy()
+
+def testEnv(testname,
+ # Make sure this matches tst_Selftests::doRunSubTest():
+ extraEnv = {
+ "crashers": { "QTEST_DISABLE_CORE_DUMP": "1",
+ "QTEST_DISABLE_STACK_DUMP": "1" },
+ "watchdog": { "QTEST_FUNCTION_TIMEOUT": "100" },
+ },
+ # Must match tst_Selftests::runSubTest_data():
+ crashers = ("assert", "blacklisted", "crashes", "crashedterminate",
+ "exceptionthrow", "faildatatype", "failfetchtype",
+ "fetchbogus", "silent", "watchdog")):
+ """Determine the environment in which to run a test."""
+ data = baseEnv()
+ if testname in crashers:
+ data.update(extraEnv["crashers"])
+ if testname in extraEnv:
+ data.update(extraEnv[testname])
+ return data
+
def generateTestData(testname, clean,
formats = ('xml', 'txt', 'xunitxml', 'lightxml', 'teamcity', 'tap'),
+ # Make sure this matches tst_Selftests::runSubTest_data():
extraArgs = {
"commandlinedata": "fiveTablePasses fiveTablePasses:fiveTablePasses_data1 -v2",
"benchlibcallgrind": "-callgrind",
@@ -249,26 +312,22 @@ def generateTestData(testname, clean,
print("Warning: directory", testname, "contains no test executable")
return
+ # Prepare environment in which to run tests:
+ env = testEnv(testname)
+
print(" running", testname)
for format in formats:
cmd = [path, '-' + format]
if testname in extraArgs:
cmd += extraArgs[testname].split()
- data = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ data = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env,
universal_newlines=True).communicate()[0]
with open('expected_' + testname + '.' + format, 'w') as out:
out.write('\n'.join(clean(data))) # write() appends a newline, too
def main(name, *args):
"""Minimal argument parsing and driver for the real work"""
- os.environ.update(
- LC_ALL = 'C', # Use standard locale
- # Avoid interference from any qtlogging.ini files, e.g. in
- # /etc/xdg/QtProject/, (must match tst_selftests.cpp's
- # processEnvironment()'s value):
- QT_LOGGING_RULES = '*.debug=true;qt.*=false')
-
herePath = os.getcwd()
cleaner = Cleaner(herePath, name)
@@ -280,6 +339,7 @@ def main(name, *args):
if __name__ == '__main__':
# Executed when script is run, not when imported (e.g. to debug)
import sys
+ baseEnv(sys.platform) # initializes its cache
if sys.platform.startswith('win'):
print("This script does not work on Windows.")