From ad9838c816d68493a8081505e7fb7f8e42016ac0 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Sat, 1 Apr 2023 19:48:31 +0000
Subject: [PATCH] testsuite: add the req_ghc_with_threaded_rts predicate

This patch adds the req_ghc_with_threaded_rts predicate to the
testsuite to assert the platform has threaded RTS, and mark some tests
as req_ghc_with_threaded_rts. Also makes ghc_with_threaded_rts a
config field instead of a global variable.

(cherry picked from commit aa6afe8ab48b5fbe09d332a25ce6af4719c5cb44)
---
 hadrian/src/Settings/Builders/RunTest.hs    | 2 +-
 testsuite/config/ghc                        | 4 ++--
 testsuite/driver/testglobals.py             | 3 +++
 testsuite/driver/testlib.py                 | 5 +++++
 testsuite/mk/test.mk                        | 4 ++--
 testsuite/tests/codeGen/should_run/all.T    | 2 +-
 testsuite/tests/concurrent/should_run/all.T | 2 +-
 testsuite/tests/lib/base/all.T              | 2 +-
 testsuite/tests/rts/all.T                   | 6 +++---
 9 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/hadrian/src/Settings/Builders/RunTest.hs b/hadrian/src/Settings/Builders/RunTest.hs
index 26feb2b0667..95b7ea86b65 100644
--- a/hadrian/src/Settings/Builders/RunTest.hs
+++ b/hadrian/src/Settings/Builders/RunTest.hs
@@ -261,7 +261,7 @@ runTestBuilderArgs = builder Testsuite ? do
 
             , arg "-e", arg $ "ghc_compiler_always_flags=" ++ quote ghcFlags
             , arg "-e", arg $ asBool "ghc_with_dynamic_rts="  (hasDynamicRts)
-            , arg "-e", arg $ asBool "ghc_with_threaded_rts=" (hasThreadedRts)
+            , arg "-e", arg $ asBool "config.ghc_with_threaded_rts=" (hasThreadedRts)
             , arg "-e", arg $ asBool "config.have_fast_bignum=" (bignumBackend /= "native" && not bignumCheck)
             , arg "-e", arg $ asBool "config.target_has_smp=" targetWithSMP
             , arg "-e", arg $ "config.ghc_dynamic=" ++ show hasDynamic
diff --git a/testsuite/config/ghc b/testsuite/config/ghc
index 8ac07a24f77..6e55d868a95 100644
--- a/testsuite/config/ghc
+++ b/testsuite/config/ghc
@@ -45,7 +45,7 @@ if config.have_interp:
 
 # we read the 'Support SMP' setting from the ghcconfig file. This dictates
 # whether the target supports smp
-if ghc_with_threaded_rts:
+if config.ghc_with_threaded_rts:
     config.run_ways.append('threaded1')
     if config.target_has_smp:
         config.run_ways.append('threaded2')
@@ -265,7 +265,7 @@ def get_compiler_info():
         config.compile_ways.append('profasm')
         config.run_ways.append('profasm')
 
-    if config.have_profiling and ghc_with_threaded_rts:
+    if config.have_profiling and config.ghc_with_threaded_rts:
         config.run_ways.append('profthreaded')
         ghc_env['HAVE_PROFILING'] = 'YES'
 
diff --git a/testsuite/driver/testglobals.py b/testsuite/driver/testglobals.py
index 16251d14247..3e6861f436b 100644
--- a/testsuite/driver/testglobals.py
+++ b/testsuite/driver/testglobals.py
@@ -142,6 +142,9 @@ class TestConfig:
         # Do we have RTS linker?
         self.have_RTS_linker = False
 
+        # Do we have threaded RTS?
+        self.ghc_with_threaded_rts = False
+
         # Does the platform support loading of dynamic shared libraries? e.g.
         # some musl-based environments do not.
         self.supports_dynamic_libs = True
diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py
index 3708c165878..5389a2c4f61 100644
--- a/testsuite/driver/testlib.py
+++ b/testsuite/driver/testlib.py
@@ -313,6 +313,11 @@ def req_target_smp( name, opts ):
 def req_process( name, opts ):
     if not config.have_process:
         opts.skip = True
+
+def req_ghc_with_threaded_rts( name, opts ):
+    if not config.ghc_with_threaded_rts:
+        opts.skip = True
+
 def ignore_stdout(name, opts):
     opts.ignore_stdout = True
 
diff --git a/testsuite/mk/test.mk b/testsuite/mk/test.mk
index 64dd78ecb26..1d676f60bac 100644
--- a/testsuite/mk/test.mk
+++ b/testsuite/mk/test.mk
@@ -110,9 +110,9 @@ 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 "$(filter thr, $(GhcRTSWays))" "thr"
-RUNTEST_OPTS += -e ghc_with_threaded_rts=True
+RUNTEST_OPTS += -e config.ghc_with_threaded_rts=True
 else
-RUNTEST_OPTS += -e ghc_with_threaded_rts=False
+RUNTEST_OPTS += -e config.ghc_with_threaded_rts=False
 endif
 
 ifeq "$(filter dyn, $(GhcRTSWays))" "dyn"
diff --git a/testsuite/tests/codeGen/should_run/all.T b/testsuite/tests/codeGen/should_run/all.T
index 1d4d3b9d56d..3cb5427e66c 100644
--- a/testsuite/tests/codeGen/should_run/all.T
+++ b/testsuite/tests/codeGen/should_run/all.T
@@ -156,7 +156,7 @@ test('T10246', normal, compile_and_run, [''])
 test('T9533', normal, compile_and_run, [''])
 test('T9533b', normal, compile_and_run, [''])
 test('T9533c', normal, compile_and_run, [''])
-test('T10414', [only_ways(['threaded2']), extra_ways(['threaded2']), req_target_smp, req_ghc_smp],
+test('T10414', [only_ways(['threaded2']), extra_ways(['threaded2']), req_target_smp, req_ghc_smp, req_ghc_with_threaded_rts],
      compile_and_run, ['-feager-blackholing'])
 test('T10521', normal, compile_and_run, [''])
 test('T10521b', normal, compile_and_run, [''])
diff --git a/testsuite/tests/concurrent/should_run/all.T b/testsuite/tests/concurrent/should_run/all.T
index 7a4208ff674..541e0cc8e32 100644
--- a/testsuite/tests/concurrent/should_run/all.T
+++ b/testsuite/tests/concurrent/should_run/all.T
@@ -35,6 +35,7 @@ test('T3279', normal, compile_and_run, [''])
 
 # This test takes a long time with the default context switch interval
 test('T3429', [ extra_run_opts('+RTS -C0.001 -RTS'),
+                req_ghc_with_threaded_rts,
                 unless(unregisterised(), extra_ways(['debug_numa'])) ],
      compile_and_run, [''])
 
@@ -288,4 +289,3 @@ test('hs_try_putmvar003',
 
 # Check forkIO exception determinism under optimization
 test('T13330', normal, compile_and_run, ['-O'])
-
diff --git a/testsuite/tests/lib/base/all.T b/testsuite/tests/lib/base/all.T
index 43fc3535649..b33404dbeee 100644
--- a/testsuite/tests/lib/base/all.T
+++ b/testsuite/tests/lib/base/all.T
@@ -1,7 +1,7 @@
 test('DataTypeOrd', normal, compile_and_run, [''])
 test('T16586', normal, compile_and_run, ['-O2'])
 # Event-manager not supported on Windows
-test('T16916', [when(opsys('mingw32'), skip), js_broken(22261), fragile(16966)], compile_and_run, ['-O2 -threaded -with-rtsopts="-I0" -rtsopts'])
+test('T16916', [when(opsys('mingw32'), skip), js_broken(22261), fragile(16966), req_ghc_with_threaded_rts], compile_and_run, ['-O2 -threaded -with-rtsopts="-I0" -rtsopts'])
 test('T24672', [when(opsys('mingw32'), skip), js_broken(22261),req_process], compile_and_run, [''])
 test('T17310', normal, compile, [''])
 test('T19691', normal, compile, [''])
diff --git a/testsuite/tests/rts/all.T b/testsuite/tests/rts/all.T
index 67205188632..af93c4ce5b2 100644
--- a/testsuite/tests/rts/all.T
+++ b/testsuite/tests/rts/all.T
@@ -411,7 +411,7 @@ test('T10296a', [req_ghc_smp], makefile_test, ['T10296a'])
 
 test('T10296b', [only_ways(['threaded2'])], compile_and_run, [''])
 
-test('numa001', [ extra_run_opts('8'), unless(unregisterised(), extra_ways(['debug_numa'])) ]
+test('numa001', [ extra_run_opts('8'), unless(unregisterised(), extra_ways(['debug_numa'])), req_ghc_with_threaded_rts ]
                 , compile_and_run, [''])
 
 test('T12497', [ unless(opsys('mingw32'), skip), expect_broken(22694)
@@ -428,7 +428,7 @@ test('T12903', [ fragile(21184)
                , req_process]
                , compile_and_run, [''])
 
-test('T13832', exit_code(1), compile_and_run, ['-threaded'])
+test('T13832', [exit_code(1), req_ghc_with_threaded_rts], compile_and_run, ['-threaded'])
 test('T13894', normal, compile_and_run, [''])
 # this test fails with the profasm way on some machines but not others,
 # so we just skip it.
@@ -557,7 +557,7 @@ test('cloneMyStack2',
 
 test('cloneMyStack_retBigStackFrame', [req_c, extra_files(['cloneStackLib.c']), ignore_stdout], compile_and_run, ['cloneStackLib.c'])
 
-test('cloneThreadStack', [req_c, only_ways(['threaded1']), extra_ways(['threaded1']), extra_files(['cloneStackLib.c'])], compile_and_run, ['cloneStackLib.c -threaded'])
+test('cloneThreadStack', [req_c, only_ways(['threaded1']), extra_ways(['threaded1']), extra_files(['cloneStackLib.c']), req_ghc_with_threaded_rts], compile_and_run, ['cloneStackLib.c -threaded'])
 
 test('decodeMyStack',
   [ js_broken(22261) # cloneMyStack# not yet implemented
-- 
GitLab