[Git][ghc/ghc][wip/explicit-perf-baseline] 2 commits: testsuite: Refactor compiler configuration

Ben Gamari gitlab at gitlab.haskell.org
Sun Jul 5 23:14:15 UTC 2020



Ben Gamari pushed to branch wip/explicit-perf-baseline at Glasgow Haskell Compiler / GHC


Commits:
8617a7ff by Ben Gamari at 2020-07-05T17:25:53-04:00
testsuite: Refactor compiler configuration

- - - - -
1678340e by Ben Gamari at 2020-07-05T19:13:59-04:00
Further refactoring

- - - - -


8 changed files:

- hadrian/src/Settings/Builders/RunTest.hs
- − testsuite/config/ghc
- + testsuite/config/testsuite_config.py
- testsuite/driver/runtests.py
- testsuite/driver/testglobals.py
- testsuite/driver/testlib.py
- testsuite/mk/test.mk
- testsuite/tests/concurrent/prog002/all.T


Changes:

=====================================
hadrian/src/Settings/Builders/RunTest.hs
=====================================
@@ -105,38 +105,38 @@ runTestBuilderArgs = builder RunTest ? do
             , pure [ "--rootdir=" ++ testdir | testdir <- rootdirs ]
             , arg "-e", arg $ "windows=" ++ show windowsHost
             , arg "-e", arg $ "darwin=" ++ show osxHost
-            , arg "-e", arg $ "config.local=False"
-            , arg "-e", arg $ "config.cleanup=" ++ show (not keepFiles)
-            , arg "-e", arg $ "config.accept=" ++ show accept
-            , arg "-e", arg $ "config.accept_platform=" ++ show acceptPlatform
-            , arg "-e", arg $ "config.accept_os=" ++ show acceptOS
-            , arg "-e", arg $ "config.exeext=" ++ quote (if null exe then "" else "."<>exe)
-            , arg "-e", arg $ "config.compiler_debugged=" ++
+            , arg "--config", arg $ "local=False"
+            , arg "--config", arg $ "cleanup=" ++ show (not keepFiles)
+            , arg "--config", arg $ "accept=" ++ show accept
+            , arg "--config", arg $ "accept_platform=" ++ show acceptPlatform
+            , arg "--config", arg $ "accept_os=" ++ show acceptOS
+            , arg "--config", arg $ "exeext=" ++ quote (if null exe then "" else "."<>exe)
+            , arg "--config", arg $ "compiler_debugged=" ++
               show debugged
             , arg "-e", arg $ asBool "ghc_with_native_codegen=" withNativeCodeGen
 
-            , arg "-e", arg $ "config.have_interp=" ++ show withInterpreter
-            , arg "-e", arg $ "config.unregisterised=" ++ show unregisterised
+            , arg "--config", arg $ "have_interp=" ++ show withInterpreter
+            , arg "--config", arg $ "unregisterised=" ++ show unregisterised
 
-            , arg "-e", arg $ "ghc_compiler_always_flags=" ++ quote ghcFlags
-            , arg "-e", arg $ asBool "ghc_with_dynamic_rts="  (hasRtsWay "dyn")
-            , arg "-e", arg $ asBool "ghc_with_threaded_rts=" (hasRtsWay "thr")
-            , arg "-e", arg $ asBool "config.have_vanilla="   (hasLibWay vanilla)
-            , arg "-e", arg $ asBool "config.have_dynamic="   (hasLibWay dynamic)
-            , arg "-e", arg $ asBool "config.have_profiling=" (hasLibWay profiling)
-            , arg "-e", arg $ asBool "config.have_fast_bignum=" (bignumBackend /= "native" && not bignumCheck)
-            , arg "-e", arg $ asBool "ghc_with_smp=" withSMP
-            , arg "-e", arg $ asBool "ghc_with_llvm=" withLlvm
+            , arg "--extra-hc-flag", arg (quote ghcFlags)
+            , arg "--config", arg $ asBool "ghc_with_dynamic_rts="  (hasRtsWay "dyn")
+            , arg "--config", arg $ asBool "ghc_with_threaded_rts=" (hasRtsWay "thr")
+            , arg "--config", arg $ asBool "have_vanilla="   (hasLibWay vanilla)
+            , arg "--config", arg $ asBool "have_dynamic="   (hasLibWay dynamic)
+            , arg "--config", arg $ asBool "have_profiling=" (hasLibWay profiling)
+            , arg "--config", arg $ asBool "have_fast_bignum=" (bignumBackend /= "native" && not bignumCheck)
+            , arg "--config", arg $ asBool "ghc_with_smp=" withSMP
+            , arg "--config", arg $ asBool "ghc_with_llvm=" withLlvm
 
 
-            , arg "-e", arg $ "config.ghc_dynamic_by_default=" ++ show hasDynamicByDefault
-            , arg "-e", arg $ "config.ghc_dynamic=" ++ show hasDynamic
+            , arg "--config", arg $ "ghc_dynamic_by_default=" ++ show hasDynamicByDefault
+            , arg "--config", arg $ "ghc_dynamic=" ++ show hasDynamic
 
-            , arg "-e", arg $ "config.top=" ++ show (top -/- "testsuite")
-            , arg "-e", arg $ "config.wordsize=" ++ show wordsize
-            , arg "-e", arg $ "config.os="       ++ show os
-            , arg "-e", arg $ "config.arch="     ++ show arch
-            , arg "-e", arg $ "config.platform=" ++ show platform
+            , arg "--config", arg $ "top=" ++ show (top -/- "testsuite")
+            , arg "--config", arg $ "wordsize=" ++ show wordsize
+            , arg "--config", arg $ "os="       ++ show os
+            , arg "--config", arg $ "arch="     ++ show arch
+            , arg "--config", arg $ "platform=" ++ show platform
 
             , arg "--config", arg $ "gs=gs"                           -- Use the default value as in test.mk
             , arg "--config", arg $ "timeout_prog=" ++ show (top -/- timeoutProg)


=====================================
testsuite/config/ghc deleted
=====================================
@@ -1,266 +0,0 @@
-# vim: set filetype=python:
-
-import re
-
-# Testsuite configuration setup for GHC
-#
-# This file is Python source
-#
-config.compiler_always_flags = ghc_compiler_always_flags.split()
-
-# By default, the 'normal' and 'hpc' ways are enabled. In addition, certain
-# ways are enabled automatically if this GHC supports them. Ways that fall in
-# this group are 'optasm', 'optllvm', 'profasm', 'threaded1', 'threaded2',
-# 'profthreaded', 'ghci', and whichever of 'static/dyn' is not this GHC's
-# default mode. Other ways should be set explicitly from .T files.
-config.compile_ways       = ['normal', 'hpc']
-config.run_ways           = ['normal', 'hpc']
-
-# ways that are not enabled by default, but can always be invoked explicitly
-config.other_ways         = ['prof', 'normal_h',
-                             'prof_hc_hb','prof_hb',
-                             'prof_hd','prof_hy','prof_hr',
-                             'sanity',
-                             'threaded1_ls', 'threaded2_hT', 'debug_numa',
-                             'llvm', 'debugllvm',
-                             'profllvm', 'profoptllvm', 'profthreadedllvm',
-                             'debug',
-                             'ghci-ext', 'ghci-ext-prof',
-                             'ext-interp',
-                             'nonmoving',
-                             'nonmoving_thr',
-                             'nonmoving_thr_ghc',
-                             'compacting_gc',
-                             ]
-
-if ghc_with_native_codegen:
-    config.compile_ways.append('optasm')
-    config.run_ways.append('optasm')
-
-if config.have_profiling:
-    config.compile_ways.append('profasm')
-    config.run_ways.append('profasm')
-
-if config.have_interp:
-    config.run_ways.append('ghci')
-
-if ghc_with_threaded_rts:
-    config.run_ways.append('threaded1')
-    if ghc_with_smp:
-        config.have_smp = True
-        config.run_ways.append('threaded2')
-        if config.speed == 0:
-            config.run_ways.append('nonmoving_thr')
-
-if ghc_with_dynamic_rts:
-    config.have_shared_libs = True
-
-if config.ghc_dynamic_by_default and config.have_vanilla == 1:
-    config.run_ways.append('static')
-else:
-    if ghc_with_dynamic_rts:
-        config.run_ways.append('dyn')
-
-if (config.have_profiling and ghc_with_threaded_rts):
-    config.run_ways.append('profthreaded')
-
-if (ghc_with_llvm and not config.unregisterised):
-    config.compile_ways.append('optllvm')
-    config.run_ways.append('optllvm')
-
-config.way_flags = {
-    'normal'       : [],
-    'normal_h'     : [],
-    'g1'           : [],
-    'nursery_chunks' : [],
-    'debug_numa'   : ['-threaded', '-debug'],
-    'optasm'       : ['-O', '-fasm'],
-    'llvm'         : ['-fllvm'],
-    'optllvm'      : ['-O', '-fllvm'],
-    'debugllvm'    : ['-fllvm', '-keep-llvm-files'],
-    'prof'         : ['-prof', '-static', '-fprof-auto', '-fasm'],
-    'prof_no_auto' : ['-prof', '-static', '-fasm'],
-    'profasm'      : ['-O', '-prof', '-static', '-fprof-auto'],
-    'profthreaded' : ['-O', '-prof', '-static', '-fprof-auto', '-threaded'],
-    'ghci'         : ['--interactive', '-v0', '-ignore-dot-ghci', '-fno-ghci-history', '+RTS', '-I0.1', '-RTS'] + (['-fghci-leak-check'] if not config.compiler_debugged else []),
-    'sanity'       : ['-debug'],
-    'threaded1'    : ['-threaded', '-debug'],
-    'threaded1_ls' : ['-threaded', '-debug'],
-    'threaded2'    : ['-O', '-threaded', '-eventlog'],
-    'threaded2_hT' : ['-O', '-threaded'],
-    'hpc'          : ['-O', '-fhpc'],
-    'prof_hc_hb'   : ['-O', '-prof', '-static', '-fprof-auto'],
-    'prof_hb'      : ['-O', '-prof', '-static', '-fprof-auto'],
-    'prof_hd'      : ['-O', '-prof', '-static', '-fprof-auto'],
-    'prof_hy'      : ['-O', '-prof', '-static', '-fprof-auto'],
-    'prof_hr'      : ['-O', '-prof', '-static', '-fprof-auto'],
-    'dyn'          : ['-O', '-dynamic'],
-    'static'       : ['-O', '-static'],
-    'debug'        : ['-O', '-g', '-dannot-lint'],
-    # llvm variants...
-    'profllvm'         : ['-prof', '-static', '-fprof-auto', '-fllvm'],
-    'profoptllvm'      : ['-O', '-prof', '-static', '-fprof-auto', '-fllvm'],
-    'profthreadedllvm' : ['-O', '-prof', '-static', '-fprof-auto', '-threaded', '-fllvm'],
-    'ghci-ext'         : ['--interactive', '-v0', '-ignore-dot-ghci', '-fno-ghci-history', '-fexternal-interpreter', '+RTS', '-I0.1', '-RTS'],
-    'ghci-ext-prof'    : ['--interactive', '-v0', '-ignore-dot-ghci', '-fno-ghci-history', '-fexternal-interpreter', '-prof', '+RTS', '-I0.1', '-RTS'],
-    'ext-interp'   : ['-fexternal-interpreter'],
-    'nonmoving'    : [],
-    'nonmoving_thr': ['-threaded'],
-    'nonmoving_thr_ghc': ['+RTS', '-xn', '-N2', '-RTS', '-threaded'],
-    'compacting_gc': [],
-   }
-
-config.way_rts_flags = {
-    'normal'       : [],
-    'normal_h'     : ['-h'], # works without -prof
-    'g1'           : ['-G1'],
-    'nursery_chunks' : ['-n32k'],
-    'debug_numa'   : ['-N2', '--debug-numa=2'],
-    'optasm'       : [],
-    'llvm'         : [],
-    'optllvm'      : [],
-    'debugllvm'    : [],
-    'prof'         : ['-p'],
-    'prof_no_auto' : ['-p'],
-    'profasm'      : ['-hc', '-p'], # test heap profiling too
-    'profthreaded' : ['-p'],
-    'ghci'         : [],
-    'sanity'       : ['-DS'],
-    'threaded1'    : [],
-    'threaded1_ls' : ['-ls'],
-    'threaded2'    : ['-N2', '-ls'],
-    'threaded2_hT' : ['-N2', '-hT'],
-    'hpc'          : [],
-    'prof_hc_hb'   : ['-hc', '-hbvoid'],
-    'prof_hb'      : ['-hb'],
-    'prof_hd'      : ['-hd'],
-    'prof_hy'      : ['-hy'],
-    'prof_hr'      : ['-hr'],
-    'dyn'          : [],
-    'static'       : [],
-    'debug'        : [],
-    # llvm variants...
-    'profllvm'         : ['-p'],
-    'profoptllvm'      : ['-hc', '-p'],
-    'profthreadedllvm' : ['-p'],
-    'ghci-ext'         : [],
-    'ghci-ext-prof'    : [],
-    'ext-interp'       : [],
-    'nonmoving'        : ['-xn'],
-    'nonmoving_thr'    : ['-xn', '-N2'],
-    'nonmoving_thr_ghc': ['-xn', '-N2'],
-    'compacting_gc': ['-c'],
-   }
-
-# Useful classes of ways that can be used with only_ways(), omit_ways() and
-# expect_broken_for().
-
-prof_ways     = [x[0] for x in config.way_flags.items()
-                      if '-prof' in x[1]]
-
-threaded_ways = [x[0] for x in config.way_flags.items()
-                      if '-threaded' in x[1] or 'ghci' == x[0]]
-
-# Ways which run with multiple capabilities
-concurrent_ways = [name for name, flags in config.way_flags.items()
-                        if '-threaded' in flags or 'ghci' == name
-                        if '-N2' in config.way_rts_flags.get(name, [])]
-
-opt_ways      = [x[0] for x in config.way_flags.items()
-                      if '-O' in x[1]]
-
-llvm_ways     = [x[0] for x in config.way_flags.items()
-                      if '-fflvm' in x[1]]
-
-
-def get_compiler_info():
-    s = getStdout([config.compiler, '--info'])
-    s = re.sub('[\r\n]', '', s)
-    compilerInfoDict = dict(eval(s))
-    s = getStdout([config.compiler, '+RTS', '--info'])
-    s = re.sub('[\r\n]', '', s)
-    rtsInfoDict = dict(eval(s))
-
-    config.have_ncg = compilerInfoDict.get("Have native code generator", "NO") == "YES"
-
-    # Whether GHC itself was built using the LLVM backend. We need to know this
-    # since some tests in ext-interp fail when stage2 ghc is built using
-    # LLVM. See #16087.
-    #
-    # The condition here is a bit approximate: we assume that if stage2 doesn't
-    # have the NCG and isn't unregisterised then it must be using the LLVM
-    # backend by default.
-    config.ghc_built_by_llvm = not config.have_ncg and not config.unregisterised
-
-    config.have_RTS_linker = compilerInfoDict.get("target has RTS linker", "NO") == "YES"
-    # external interpreter needs RTS linker support
-    # If the field is not present (GHC 8.0 and earlier), assume we don't
-    # have -fexternal-interpreter (though GHC 8.0 actually does)
-    # so we can still run most tests.
-    config.have_ext_interp = compilerInfoDict.get("target has RTS linker", "NO") == "YES"
-
-    # See Note [Replacing backward slashes in config.libdir].
-    config.libdir = compilerInfoDict['LibDir'].replace('\\', '/')
-
-    if re.match(".*_p(_.*|$)", rtsInfoDict["RTS way"]):
-        config.compiler_profiled = True
-    else:
-        config.compiler_profiled = False
-
-    try:
-        config.package_conf_cache_file = compilerInfoDict["Global Package DB"] + '/package.cache'
-    except:
-        config.package_conf_cache_file = ''
-
-    # See Note [WayFlags]
-    if config.ghc_dynamic:
-        config.ghc_th_way_flags = "-dynamic"
-        config.ghci_way_flags   = "-dynamic"
-        config.plugin_way_flags = "-dynamic"
-        config.ghc_th_way       = "dyn"
-        config.ghc_plugin_way   = "dyn"
-    elif config.compiler_profiled:
-        config.ghc_th_way_flags = "-prof"
-        config.ghci_way_flags   = "-prof"
-        config.plugin_way_flags = "-prof"
-        config.ghc_th_way       = "prof"
-        config.ghc_plugin_way   = "prof"
-    else:
-        config.ghc_th_way_flags = "-static"
-        config.ghci_way_flags   = "-static"
-        config.plugin_way_flags = "-static"
-        config.ghc_th_way       = "normal"
-        config.ghc_plugin_way   = "normal"
-
-# Note [Replacing backward slashes in config.libdir]
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-# We *do* need to replace backslashes in config.libdir, for the following
-# reason:
-#
-# * Tests use config.libdir as follows:
-#
-#     extra_run_opts('"' + config.libdir + '"')
-#
-#   The double quotes are there because config.libdir might contain
-#   spaces.
-#
-# * This string is then written /as is/ to <testname>.genscript in
-#   testlib.interpreter_run:
-#
-#     script.write(':set args ' + opts.extra_run_opts + '\n')
-#
-# * But GHCi expects the arguments to ':set args' to be proper Haskell
-#   strings (when they are quoted), with backslashes escaped. Since
-#   config.libdir contains single backslash characters, tests such as T5313
-#   will fail for WAY=ghci with "Pattern match failure in do expression".
-#
-# Arguably the above code for writing `:set args` should be smarter. This
-# is tricky to get right though, because in GHCI `:set args foo\bar` (no
-# double quotes) works perfectly fine, and is interpreted as the Haskell
-# string "foo\\bar". Therefore, simply escaping all backward slashes in
-# opts.extra_run_opts before concatenating it with ':set args' is not right
-# either.
-#
-# Replacing backslashes to forward slashes in config.libdir works around the
-# problem.


=====================================
testsuite/config/testsuite_config.py
=====================================
@@ -0,0 +1,276 @@
+# vim: set filetype=python:
+
+import re
+
+class TestsuiteConfig:
+    @staticmethod
+    def init_config(config: TestConfig)
+        raise NotImplemented
+
+    @staticmethod
+    def get_compiler_info(config: TestConfig) -> None:
+        raise NotImplemented
+
+class GHCTestsuiteConfig(TestsuiteConfig):
+    """
+    Testsuite configuration setup for GHC
+    """
+
+    @staticmethod
+    def init_config(config: TestConfig):
+        # By default, the 'normal' and 'hpc' ways are enabled. In addition, certain
+        # ways are enabled automatically if this GHC supports them. Ways that fall in
+        # this group are 'optasm', 'optllvm', 'profasm', 'threaded1', 'threaded2',
+        # 'profthreaded', 'ghci', and whichever of 'static/dyn' is not this GHC's
+        # default mode. Other ways should be set explicitly from .T files.
+        config.compile_ways       = ['normal', 'hpc']
+        config.run_ways           = ['normal', 'hpc']
+
+        # ways that are not enabled by default, but can always be invoked explicitly
+        config.other_ways         = ['prof', 'normal_h',
+                                    'prof_hc_hb','prof_hb',
+                                    'prof_hd','prof_hy','prof_hr',
+                                    'sanity',
+                                    'threaded1_ls', 'threaded2_hT', 'debug_numa',
+                                    'llvm', 'debugllvm',
+                                    'profllvm', 'profoptllvm', 'profthreadedllvm',
+                                    'debug',
+                                    'ghci-ext', 'ghci-ext-prof',
+                                    'ext-interp',
+                                    'nonmoving',
+                                    'nonmoving_thr',
+                                    'nonmoving_thr_ghc',
+                                    'compacting_gc',
+                                    ]
+
+        if config.ghc_with_native_codegen:
+            config.compile_ways.append('optasm')
+            config.run_ways.append('optasm')
+
+        if config.have_profiling:
+            config.compile_ways.append('profasm')
+            config.run_ways.append('profasm')
+
+        if config.have_interp:
+            config.run_ways.append('ghci')
+
+        if config.ghc_with_threaded_rts:
+            config.run_ways.append('threaded1')
+            if config.ghc_with_smp:
+                config.have_smp = True
+                config.run_ways.append('threaded2')
+                if config.speed == 0:
+                    config.run_ways.append('nonmoving_thr')
+
+        if config.ghc_with_dynamic_rts:
+            config.have_shared_libs = True
+
+        if config.ghc_dynamic_by_default and config.have_vanilla == 1:
+            config.run_ways.append('static')
+        else:
+            if config.ghc_with_dynamic_rts:
+                config.run_ways.append('dyn')
+
+        if (config.have_profiling and ghc_with_threaded_rts):
+            config.run_ways.append('profthreaded')
+
+        if (ghc_with_llvm and not config.unregisterised):
+            config.compile_ways.append('optllvm')
+            config.run_ways.append('optllvm')
+
+        config.way_flags = {
+            'normal'       : [],
+            'normal_h'     : [],
+            'g1'           : [],
+            'nursery_chunks' : [],
+            'debug_numa'   : ['-threaded', '-debug'],
+            'optasm'       : ['-O', '-fasm'],
+            'llvm'         : ['-fllvm'],
+            'optllvm'      : ['-O', '-fllvm'],
+            'debugllvm'    : ['-fllvm', '-keep-llvm-files'],
+            'prof'         : ['-prof', '-static', '-fprof-auto', '-fasm'],
+            'prof_no_auto' : ['-prof', '-static', '-fasm'],
+            'profasm'      : ['-O', '-prof', '-static', '-fprof-auto'],
+            'profthreaded' : ['-O', '-prof', '-static', '-fprof-auto', '-threaded'],
+            'ghci'         : ['--interactive', '-v0', '-ignore-dot-ghci', '-fno-ghci-history', '+RTS', '-I0.1', '-RTS'] + (['-fghci-leak-check'] if not config.compiler_debugged else []),
+            'sanity'       : ['-debug'],
+            'threaded1'    : ['-threaded', '-debug'],
+            'threaded1_ls' : ['-threaded', '-debug'],
+            'threaded2'    : ['-O', '-threaded', '-eventlog'],
+            'threaded2_hT' : ['-O', '-threaded'],
+            'hpc'          : ['-O', '-fhpc'],
+            'prof_hc_hb'   : ['-O', '-prof', '-static', '-fprof-auto'],
+            'prof_hb'      : ['-O', '-prof', '-static', '-fprof-auto'],
+            'prof_hd'      : ['-O', '-prof', '-static', '-fprof-auto'],
+            'prof_hy'      : ['-O', '-prof', '-static', '-fprof-auto'],
+            'prof_hr'      : ['-O', '-prof', '-static', '-fprof-auto'],
+            'dyn'          : ['-O', '-dynamic'],
+            'static'       : ['-O', '-static'],
+            'debug'        : ['-O', '-g', '-dannot-lint'],
+            # llvm variants...
+            'profllvm'         : ['-prof', '-static', '-fprof-auto', '-fllvm'],
+            'profoptllvm'      : ['-O', '-prof', '-static', '-fprof-auto', '-fllvm'],
+            'profthreadedllvm' : ['-O', '-prof', '-static', '-fprof-auto', '-threaded', '-fllvm'],
+            'ghci-ext'         : ['--interactive', '-v0', '-ignore-dot-ghci', '-fno-ghci-history', '-fexternal-interpreter', '+RTS', '-I0.1', '-RTS'],
+            'ghci-ext-prof'    : ['--interactive', '-v0', '-ignore-dot-ghci', '-fno-ghci-history', '-fexternal-interpreter', '-prof', '+RTS', '-I0.1', '-RTS'],
+            'ext-interp'   : ['-fexternal-interpreter'],
+            'nonmoving'    : [],
+            'nonmoving_thr': ['-threaded'],
+            'nonmoving_thr_ghc': ['+RTS', '-xn', '-N2', '-RTS', '-threaded'],
+            'compacting_gc': [],
+        }
+
+        config.way_rts_flags = {
+            'normal'       : [],
+            'normal_h'     : ['-h'], # works without -prof
+            'g1'           : ['-G1'],
+            'nursery_chunks' : ['-n32k'],
+            'debug_numa'   : ['-N2', '--debug-numa=2'],
+            'optasm'       : [],
+            'llvm'         : [],
+            'optllvm'      : [],
+            'debugllvm'    : [],
+            'prof'         : ['-p'],
+            'prof_no_auto' : ['-p'],
+            'profasm'      : ['-hc', '-p'], # test heap profiling too
+            'profthreaded' : ['-p'],
+            'ghci'         : [],
+            'sanity'       : ['-DS'],
+            'threaded1'    : [],
+            'threaded1_ls' : ['-ls'],
+            'threaded2'    : ['-N2', '-ls'],
+            'threaded2_hT' : ['-N2', '-hT'],
+            'hpc'          : [],
+            'prof_hc_hb'   : ['-hc', '-hbvoid'],
+            'prof_hb'      : ['-hb'],
+            'prof_hd'      : ['-hd'],
+            'prof_hy'      : ['-hy'],
+            'prof_hr'      : ['-hr'],
+            'dyn'          : [],
+            'static'       : [],
+            'debug'        : [],
+            # llvm variants...
+            'profllvm'         : ['-p'],
+            'profoptllvm'      : ['-hc', '-p'],
+            'profthreadedllvm' : ['-p'],
+            'ghci-ext'         : [],
+            'ghci-ext-prof'    : [],
+            'ext-interp'       : [],
+            'nonmoving'        : ['-xn'],
+            'nonmoving_thr'    : ['-xn', '-N2'],
+            'nonmoving_thr_ghc': ['-xn', '-N2'],
+            'compacting_gc': ['-c'],
+        }
+
+        # Useful classes of ways that can be used with only_ways(), omit_ways() and
+        # expect_broken_for().
+
+        prof_ways     = [x[0] for x in config.way_flags.items()
+                            if '-prof' in x[1]]
+
+        threaded_ways = [x[0] for x in config.way_flags.items()
+                            if '-threaded' in x[1] or 'ghci' == x[0]]
+
+        # Ways which run with multiple capabilities
+        concurrent_ways = [name for name, flags in config.way_flags.items()
+                                if '-threaded' in flags or 'ghci' == name
+                                if '-N2' in config.way_rts_flags.get(name, [])]
+
+        opt_ways      = [x[0] for x in config.way_flags.items()
+                            if '-O' in x[1]]
+
+        llvm_ways     = [x[0] for x in config.way_flags.items()
+                            if '-fflvm' in x[1]]
+
+    @staticmethod
+    def get_compiler_info():
+        s = getStdout([config.compiler, '--info'])
+        s = re.sub('[\r\n]', '', s)
+        compilerInfoDict = dict(eval(s))
+        s = getStdout([config.compiler, '+RTS', '--info'])
+        s = re.sub('[\r\n]', '', s)
+        rtsInfoDict = dict(eval(s))
+
+        config.have_ncg = compilerInfoDict.get("Have native code generator", "NO") == "YES"
+
+        # Whether GHC itself was built using the LLVM backend. We need to know this
+        # since some tests in ext-interp fail when stage2 ghc is built using
+        # LLVM. See #16087.
+        #
+        # The condition here is a bit approximate: we assume that if stage2 doesn't
+        # have the NCG and isn't unregisterised then it must be using the LLVM
+        # backend by default.
+        config.ghc_built_by_llvm = not config.have_ncg and not config.unregisterised
+
+        config.have_RTS_linker = compilerInfoDict.get("target has RTS linker", "NO") == "YES"
+        # external interpreter needs RTS linker support
+        # If the field is not present (GHC 8.0 and earlier), assume we don't
+        # have -fexternal-interpreter (though GHC 8.0 actually does)
+        # so we can still run most tests.
+        config.have_ext_interp = compilerInfoDict.get("target has RTS linker", "NO") == "YES"
+
+        # See Note [Replacing backward slashes in config.libdir].
+        config.libdir = compilerInfoDict['LibDir'].replace('\\', '/')
+
+        if re.match(".*_p(_.*|$)", rtsInfoDict["RTS way"]):
+            config.compiler_profiled = True
+        else:
+            config.compiler_profiled = False
+
+        try:
+            config.package_conf_cache_file = compilerInfoDict["Global Package DB"] + '/package.cache'
+        except:
+            config.package_conf_cache_file = ''
+
+        # See Note [WayFlags]
+        if config.ghc_dynamic:
+            config.ghc_th_way_flags = "-dynamic"
+            config.ghci_way_flags   = "-dynamic"
+            config.plugin_way_flags = "-dynamic"
+            config.ghc_th_way       = "dyn"
+            config.ghc_plugin_way   = "dyn"
+        elif config.compiler_profiled:
+            config.ghc_th_way_flags = "-prof"
+            config.ghci_way_flags   = "-prof"
+            config.plugin_way_flags = "-prof"
+            config.ghc_th_way       = "prof"
+            config.ghc_plugin_way   = "prof"
+        else:
+            config.ghc_th_way_flags = "-static"
+            config.ghci_way_flags   = "-static"
+            config.plugin_way_flags = "-static"
+            config.ghc_th_way       = "normal"
+            config.ghc_plugin_way   = "normal"
+
+# Note [Replacing backward slashes in config.libdir]
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# We *do* need to replace backslashes in config.libdir, for the following
+# reason:
+#
+# * Tests use config.libdir as follows:
+#
+#     extra_run_opts('"' + config.libdir + '"')
+#
+#   The double quotes are there because config.libdir might contain
+#   spaces.
+#
+# * This string is then written /as is/ to <testname>.genscript in
+#   testlib.interpreter_run:
+#
+#     script.write(':set args ' + opts.extra_run_opts + '\n')
+#
+# * But GHCi expects the arguments to ':set args' to be proper Haskell
+#   strings (when they are quoted), with backslashes escaped. Since
+#   config.libdir contains single backslash characters, tests such as T5313
+#   will fail for WAY=ghci with "Pattern match failure in do expression".
+#
+# Arguably the above code for writing `:set args` should be smarter. This
+# is tricky to get right though, because in GHCI `:set args foo\bar` (no
+# double quotes) works perfectly fine, and is interpreted as the Haskell
+# string "foo\\bar". Therefore, simply escaping all backward slashes in
+# opts.extra_run_opts before concatenating it with ':set args' is not right
+# either.
+#
+# Replacing backslashes to forward slashes in config.libdir works around the
+# problem.


=====================================
testsuite/driver/runtests.py
=====================================
@@ -5,6 +5,7 @@
 #
 
 import argparse
+from copy import copy
 import signal
 import sys
 import os
@@ -30,6 +31,7 @@ from testglobals import getConfig, ghc_env, getTestRun, TestConfig, \
 from my_typing import TestName, List
 from perf_notes import MetricChange, GitRef, inside_git_repo, is_worktree_dirty, format_perf_stat
 import perf_notes as Perf
+import testsuite_config
 from junit import junit
 import term_color
 from term_color import Color, colored
@@ -243,11 +245,6 @@ def main() -> None:
     os.environ['TERM'] = 'vt100'
     ghc_env['TERM'] = 'vt100'
 
-    def get_compiler_info() -> TestConfig:
-        """ Overriddden by configuration file. """
-        raise NotImplementedError
-
-
     # -----------------------------------------------------------------------------
     # cmd-line options
 
@@ -268,6 +265,7 @@ def main() -> None:
     parser.add_argument("--verbose", type=int, choices=[0,1,2,3,4,5], help="verbose (Values 0 through 5 accepted)")
     parser.add_argument("--junit", type=argparse.FileType('wb'), help="output testsuite summary in JUnit format")
     parser.add_argument("--broken-test", action="append", default=[], help="a test name to mark as broken for this run")
+    parser.add_argument('--extra-hc-flag', action="append", default=[], help="extra flags to pass to the Haskell compiler")
     parser.add_argument("--test-env", default='local', help="Override default chosen test-env.")
     parser.add_argument("--perf-baseline", type=GitRef, metavar='COMMIT', help="Baseline commit for performance comparsons.")
     perf_group.add_argument("--skip-perf-tests", action="store_true", help="skip performance tests")
@@ -283,9 +281,8 @@ def main() -> None:
         for e in args.e:
             exec(e)
 
-    if args.config_file:
-        for arg in args.config_file:
-            exec(open(arg).read())
+    ts_config = testsuite_config.GHCTestsuiteConfig
+    ts_config_globals = ts_config.init_config(config)
 
     if args.config:
         for arg in args.config:
@@ -297,6 +294,8 @@ def main() -> None:
     if args.rootdir:
         config.rootdirs = args.rootdir
 
+    config.compiler_always_flags = args.extra_hc_flag
+
     config.metrics_file = args.metrics_file
     hasMetricsFile = config.metrics_file is not None
     config.summary_file = args.summary_file
@@ -368,7 +367,7 @@ def main() -> None:
     term_color.enable_color = config.supports_colors
 
     # This has to come after arg parsing as the args can change the compiler
-    get_compiler_info()
+    ts_config.get_compiler_info(config)
 
     # Can't import this earlier as we need to know if threading will be
     # enabled or not
@@ -445,6 +444,8 @@ def main() -> None:
 
     # First collect all the tests to be run
     t_files_ok = True
+    test_globals = copy(testlib.__dict__)
+    test_globals.update(ts_config_globals)
     for file in t_files:
         testlib.if_verbose(2, '====> Scanning %s' % file)
         testlib.newTestDir(tempdir, os.path.dirname(file))
@@ -452,7 +453,7 @@ def main() -> None:
             with io.open(file, encoding='utf8') as f:
                 src = f.read()
 
-            exec(src)
+            exec(src, test_globals)
         except Exception as e:
             traceback.print_exc()
             testlib.framework_fail(None, None, 'exception: %s' % e)


=====================================
testsuite/driver/testglobals.py
=====================================
@@ -189,6 +189,13 @@ class TestConfig:
         # I have no idea what this does
         self.package_conf_cache_file = None # type: Optional[Path]
 
+        self.ghc_compiler_always_flags = [] # type: List[str]
+        self.ghc_with_native_codegen = False
+        self.ghc_dynamic_by_default = False
+        self.ghc_with_dynamic_rts = False
+        self.ghc_with_threaded_rts = False
+        self.ghc_with_smp = False
+        self.ghc_with_llvm = False
 
 global config
 config = TestConfig()


=====================================
testsuite/driver/testlib.py
=====================================
@@ -502,6 +502,9 @@ def doing_ghci() -> bool:
 def ghc_dynamic() -> bool:
     return config.ghc_dynamic
 
+def ghc_with_threaded_rts() -> bool:
+    return config.ghc_with_threaded_rts
+
 def fast() -> bool:
     return config.speed == 2
 


=====================================
testsuite/mk/test.mk
=====================================
@@ -79,18 +79,18 @@ else
 dllext = .so
 endif
 
-RUNTEST_OPTS += -e "ghc_compiler_always_flags='$(TEST_HC_OPTS)'"
+RUNTEST_OPTS += --extra-hc-flag='$(TEST_HC_OPTS)'
 
 ifeq "$(GhcDebugged)" "YES"
-RUNTEST_OPTS += -e "config.compiler_debugged=True"
+RUNTEST_OPTS += --config "compiler_debugged=True"
 else
-RUNTEST_OPTS += -e "config.compiler_debugged=False"
+RUNTEST_OPTS += --config "compiler_debugged=False"
 endif
 
 ifeq "$(GhcWithNativeCodeGen)" "YES"
-RUNTEST_OPTS += -e ghc_with_native_codegen=True
+RUNTEST_OPTS += --config "ghc_with_native_codegen=True"
 else
-RUNTEST_OPTS += -e ghc_with_native_codegen=False
+RUNTEST_OPTS += --config "ghc_with_native_codegen=False"
 endif
 
 GHC_PRIM_LIBDIR := $(subst library-dirs: ,,$(shell "$(GHC_PKG)" field ghc-prim library-dirs --simple-output))
@@ -105,21 +105,21 @@ HAVE_READELF := $(shell if readelf --version > /dev/null 2> /dev/null; then echo
 BIGNUM_GMP := $(shell "$(GHC_PKG)" field ghc-bignum exposed-modules | grep GMP)
 
 ifeq "$(HAVE_VANILLA)" "YES"
-RUNTEST_OPTS += -e config.have_vanilla=True
+RUNTEST_OPTS += --config have_vanilla=True
 else
-RUNTEST_OPTS += -e config.have_vanilla=False
+RUNTEST_OPTS += --config have_vanilla=False
 endif
 
 ifeq "$(HAVE_DYNAMIC)" "YES"
-RUNTEST_OPTS += -e config.have_dynamic=True
+RUNTEST_OPTS += --config have_dynamic=True
 else
-RUNTEST_OPTS += -e config.have_dynamic=False
+RUNTEST_OPTS += --config have_dynamic=False
 endif
 
 ifeq "$(HAVE_PROFILING)" "YES"
-RUNTEST_OPTS += -e config.have_profiling=True
+RUNTEST_OPTS += --config have_profiling=True
 else
-RUNTEST_OPTS += -e config.have_profiling=False
+RUNTEST_OPTS += --config have_profiling=False
 endif
 
 ifeq "$(filter thr, $(GhcRTSWays))" "thr"
@@ -135,50 +135,50 @@ RUNTEST_OPTS += -e ghc_with_dynamic_rts=False
 endif
 
 ifeq "$(GhcWithInterpreter)" "NO"
-RUNTEST_OPTS += -e config.have_interp=False
+RUNTEST_OPTS += --config have_interp=False
 else ifeq "$(GhcStage)" "1"
-RUNTEST_OPTS += -e config.have_interp=False
+RUNTEST_OPTS += --config have_interp=False
 else
-RUNTEST_OPTS += -e config.have_interp=True
+RUNTEST_OPTS += --config have_interp=True
 endif
 
 ifeq "$(GhcUnregisterised)" "YES"
-RUNTEST_OPTS += -e config.unregisterised=True
+RUNTEST_OPTS += --config unregisterised=True
 else
-RUNTEST_OPTS += -e config.unregisterised=False
+RUNTEST_OPTS += --config unregisterised=False
 endif
 
 ifeq "$(HAVE_GDB)" "YES"
-RUNTEST_OPTS += -e config.have_gdb=True
+RUNTEST_OPTS += --config have_gdb=True
 else
-RUNTEST_OPTS += -e config.have_gdb=False
+RUNTEST_OPTS += --config have_gdb=False
 endif
 
 ifeq "$(HAVE_READELF)" "YES"
-RUNTEST_OPTS += -e config.have_readelf=True
+RUNTEST_OPTS += --config have_readelf=True
 else
-RUNTEST_OPTS += -e config.have_readelf=False
+RUNTEST_OPTS += --config have_readelf=False
 endif
 
 ifeq "$(BIGNUM_GMP)" ""
-RUNTEST_OPTS += -e config.have_fast_bignum=False
+RUNTEST_OPTS += --config have_fast_bignum=False
 else
-RUNTEST_OPTS += -e config.have_fast_bignum=True
+RUNTEST_OPTS += --config have_fast_bignum=True
 endif
 
 ifeq "$(GhcDynamicByDefault)" "YES"
-RUNTEST_OPTS += -e config.ghc_dynamic_by_default=True
+RUNTEST_OPTS += --config ghc_dynamic_by_default=True
 CABAL_MINIMAL_BUILD = --enable-shared --disable-library-vanilla
 else
-RUNTEST_OPTS += -e config.ghc_dynamic_by_default=False
+RUNTEST_OPTS += --config ghc_dynamic_by_default=False
 CABAL_MINIMAL_BUILD = --enable-library-vanilla --disable-shared
 endif
 
 ifeq "$(GhcDynamic)" "YES"
-RUNTEST_OPTS += -e config.ghc_dynamic=True
+RUNTEST_OPTS += --config ghc_dynamic=True
 CABAL_PLUGIN_BUILD = --enable-shared --disable-library-vanilla
 else
-RUNTEST_OPTS += -e config.ghc_dynamic=False
+RUNTEST_OPTS += --config ghc_dynamic=False
 CABAL_PLUGIN_BUILD = --enable-library-vanilla --disable-shared
 endif
 
@@ -213,9 +213,9 @@ RUNTEST_OPTS += -e darwin=False
 endif
 
 ifeq "$(IN_TREE_COMPILER)" "YES"
-RUNTEST_OPTS += -e config.in_tree_compiler=True
+RUNTEST_OPTS += --config in_tree_compiler=True
 else
-RUNTEST_OPTS += -e config.in_tree_compiler=False
+RUNTEST_OPTS += --config in_tree_compiler=False
 endif
 
 ifneq "$(THREADS)" ""
@@ -243,20 +243,20 @@ RUNTEST_OPTS += --test-env="$(TEST_ENV)"
 endif
 
 ifeq "$(CLEANUP)" "0"
-RUNTEST_OPTS += -e config.cleanup=False
+RUNTEST_OPTS += --config cleanup=False
 else ifeq "$(CLEANUP)" "NO"
-RUNTEST_OPTS += -e config.cleanup=False
+RUNTEST_OPTS += --config cleanup=False
 else
-RUNTEST_OPTS += -e config.cleanup=True
+RUNTEST_OPTS += --config cleanup=True
 endif
 
 ifeq "$(LOCAL)" "0"
 # See Note [Running tests in /tmp].
-RUNTEST_OPTS += -e config.local=False
+RUNTEST_OPTS += --config local=False
 else ifeq "$(LOCAL)" "NO"
-RUNTEST_OPTS += -e config.local=False
+RUNTEST_OPTS += --config local=False
 else
-RUNTEST_OPTS += -e config.local=True
+RUNTEST_OPTS += --config local=True
 endif
 
 RUNTEST_OPTS +=  \
@@ -315,30 +315,30 @@ RUNTEST_OPTS +=  \
 	$(EXTRA_RUNTEST_OPTS)
 
 ifeq "$(list_broken)" "YES"
-set_list_broken = -e config.list_broken=True
+set_list_broken = --config list_broken=True
 else
 set_list_broken =
 endif
 
 # See Note [validate and testsuite speed] in toplevel Makefile.
 ifneq "$(SPEED)" ""
-setspeed = -e config.speed="$(SPEED)"
+setspeed = --config speed="$(SPEED)"
 else ifeq "$(fast)" "YES"
 # Backward compatibility. Maybe some people are running 'make accept fast=YES'?
-setspeed = -e config.speed=2
+setspeed = --config speed=2
 else
 setspeed =
 endif
 
 ifeq "$(accept)" "YES"
-setaccept = -e config.accept=True
+setaccept = --config accept=True
 
 ifeq "$(PLATFORM)" "YES"
-setaccept += -e config.accept_platform=True
+setaccept += --config accept_platform=True
 endif
 
 ifeq "$(OS)" "YES"
-setaccept += -e config.accept_os=True
+setaccept += --config accept_os=True
 endif
 
 else


=====================================
testsuite/tests/concurrent/prog002/all.T
=====================================
@@ -1,7 +1,7 @@
 # Test for bug #713, results in crashes in GHC prior to 20060315 with +RTS -N2
 
 # Add 'threaded2_hT' so that we have at least one test for bug #5127
-if ghc_with_threaded_rts and ghc_with_smp:
+if ghc_with_threaded_rts():
    ways = ['threaded2_hT']
 else:
    ways = []



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2680da517ec368e3f13867c2e1a7b79e6d193b4b...1678340e6ef8265e5342abd6677371f8654b06cc

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2680da517ec368e3f13867c2e1a7b79e6d193b4b...1678340e6ef8265e5342abd6677371f8654b06cc
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200705/9e22672f/attachment-0001.html>


More information about the ghc-commits mailing list