From 78c8b90006ac4d0a4de4e72295f8a57de4b9beca Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Tue, 1 Oct 2024 18:57:53 +0000
Subject: [PATCH] testsuite: ensure $(ghciWayFlags) can be overridden

This commit revises boilerplate.mk in testsuite as well as a few other
places, to ensure the tests that do make use of $(ghciWayFlags) can
receive the right $(ghciWayFlags) from testsuite driver config.
---
 testsuite/mk/boilerplate.mk             | 18 +++++++++---------
 testsuite/tests/ffi/should_run/Makefile |  6 +++---
 testsuite/tests/ffi/should_run/all.T    |  6 +++---
 testsuite/tests/rts/T7040_ghci_c.c      |  2 +-
 testsuite/tests/rts/all.T               |  4 ++--
 5 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/testsuite/mk/boilerplate.mk b/testsuite/mk/boilerplate.mk
index 53bd81f3624..6a3030ac065 100644
--- a/testsuite/mk/boilerplate.mk
+++ b/testsuite/mk/boilerplate.mk
@@ -286,17 +286,17 @@ endif
 # See #11495 and TEST=TH_spliceE5_prof for a complication: trying to compile
 # code that uses TemplateHaskell with -prof, while GhcDynamic=YES.
 ifeq "$(GhcDynamic)" "YES"
-ghcThWayFlags     = -dynamic
-ghciWayFlags      = -dynamic
-ghcPluginWayFlags = -dynamic
+ghcThWayFlags     ?= -dynamic
+ghciWayFlags      ?= -dynamic
+ghcPluginWayFlags ?= -dynamic
 else ifeq "$(GhcProfiled)" "YES"
-ghcThWayFlags     = -prof
-ghciWayFlags      = -prof
-ghcPluginWayFlags = -prof
+ghcThWayFlags     ?= -prof
+ghciWayFlags      ?= -prof
+ghcPluginWayFlags ?= -prof
 else
-ghcThWayFlags     = -static
-ghciWayFlags      = -static
-ghcPluginWayFlags = -static
+ghcThWayFlags     ?= -static
+ghciWayFlags      ?= -static
+ghcPluginWayFlags ?= -static
 endif
 
 # -----------------------------------------------------------------------------
diff --git a/testsuite/tests/ffi/should_run/Makefile b/testsuite/tests/ffi/should_run/Makefile
index 374b24154ba..f910b1c3db6 100644
--- a/testsuite/tests/ffi/should_run/Makefile
+++ b/testsuite/tests/ffi/should_run/Makefile
@@ -3,13 +3,13 @@ include $(TOP)/mk/boilerplate.mk
 include $(TOP)/mk/test.mk
 
 ffi018_ghci_setup :
-	'$(TEST_HC)' $(TEST_HC_OPTS) -c ffi018_ghci_c.c
+	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c ffi018_ghci_c.c -o ffi018_ghci_c.o
 
 T1288_ghci_setup :
-	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c T1288_ghci_c.c
+	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c T1288_ghci_c.c -o T1288_ghci_c.o
 
 T2276_ghci_setup :
-	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c T2276_ghci_c.c
+	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c T2276_ghci_c.c -o T2276_ghci_c.o
 
 ffi002_setup :
 	'$(TEST_HC)' $(TEST_HC_OPTS) -c ffi002.hs
diff --git a/testsuite/tests/ffi/should_run/all.T b/testsuite/tests/ffi/should_run/all.T
index 6680bcabd07..3e430111333 100644
--- a/testsuite/tests/ffi/should_run/all.T
+++ b/testsuite/tests/ffi/should_run/all.T
@@ -82,7 +82,7 @@ test('ffi018_ghci',
      [extra_files(['ffi018.h']),
       only_ways(['ghci']),
       when(unregisterised(), fragile(16085)),
-      pre_cmd('$MAKE -s --no-print-directory ffi018_ghci_setup'),
+      pre_cmd('$MAKE -s --no-print-directory ffi018_ghci_setup ghciWayFlags=' + config.ghci_way_flags),
       req_c],
      compile_and_run, ['ffi018_ghci_c.o'])
 
@@ -95,12 +95,12 @@ test('T1288', [req_c], compile_and_run, ['T1288_c.c'])
 test('T1288_ghci',
      [only_ghci,
       when(unregisterised(), fragile(16085)),
-      pre_cmd('$MAKE -s --no-print-directory T1288_ghci_setup')],
+      pre_cmd('$MAKE -s --no-print-directory T1288_ghci_setup ghciWayFlags=' + config.ghci_way_flags)],
      compile_and_run, ['T1288_ghci_c.o'])
 
 test('T2276', [req_c], compile_and_run, ['T2276_c.c'])
 test('T2276_ghci', [ only_ghci,
-                     pre_cmd('$MAKE -s --no-print-directory T2276_ghci_setup') ],
+                     pre_cmd('$MAKE -s --no-print-directory T2276_ghci_setup ghciWayFlags=' + config.ghci_way_flags) ],
                    compile_and_run, ['-fobject-code T2276_ghci_c.o'])
 
 test('T2469', normal, compile_and_run, ['-optc-std=gnu99'])
diff --git a/testsuite/tests/rts/T7040_ghci_c.c b/testsuite/tests/rts/T7040_ghci_c.c
index ee6ddd53286..84e71e18d8e 100644
--- a/testsuite/tests/rts/T7040_ghci_c.c
+++ b/testsuite/tests/rts/T7040_ghci_c.c
@@ -7,5 +7,5 @@ void printx() {
   printf("x: %d\n", x);
   x = 1;
   printf("x: %d\n", x);
+  fflush(stdout);
 }
-
diff --git a/testsuite/tests/rts/all.T b/testsuite/tests/rts/all.T
index 5535308d62f..bac79df1a37 100644
--- a/testsuite/tests/rts/all.T
+++ b/testsuite/tests/rts/all.T
@@ -278,8 +278,8 @@ test('T7040_ghci',
       only_ways(['ghci']),
       # Fragile when unregisterised; see #16085
       when(unregisterised(), skip),
-      pre_cmd('$MAKE -s --no-print-directory T7040_ghci_setup'),
-      when(opsys('linux') and not ghc_dynamic(), expect_broken(20706))],
+      pre_cmd('$MAKE -s --no-print-directory T7040_ghci_setup ghciWayFlags=' + config.ghci_way_flags),
+      when(opsys('linux') and not ghc_dynamic() and not arch('wasm32'), fragile(20706))],
      compile_and_run, ['T7040_ghci_c.o'])
 
 test('T7227', [extra_run_opts('+RTS -tT7227.stat --machine-readable -RTS')],
-- 
GitLab